about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/query
AgeCommit message (Collapse)AuthorLines
2023-01-30Allow more deriving on packed structs.Nicholas Nethercote-9/+0
Currently, deriving on packed structs has some non-trivial limitations, related to the fact that taking references on unaligned fields is UB. The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `&self.0` Plus, we disallow deriving any builtin traits other than `Default` for any packed generic type, because it's possible that there might be misaligned fields. This is a fairly broad restriction. Plus, we disallow deriving any builtin traits other than `Default` for most packed types that don't derive `Copy`. (The exceptions are those where the alignments inherently satisfy the packing, e.g. in a type with `repr(packed(N))` where all the fields have alignments of `N` or less anyway. Such types are pretty strange, because the `packed` attribute is not having any effect.) This commit introduces a new, simpler approach to field accesses: - Normal case: `&self.0` - In a packed struct: `&{self.0}` In the latter case, this requires that all fields impl `Copy`, which is a new restriction. This means that the following example compiles under the old approach and doesn't compile under the new approach. ``` #[derive(Debug)] struct NonCopy(u8); #[derive(Debug) #[repr(packed)] struct MyType(NonCopy); ``` (Note that the old approach's support for cases like this was brittle. Changing the `u8` to a `u16` would be enough to stop it working. So not much capability is lost here.) However, the other constraints from the old rules are removed. We can now derive builtin traits for packed generic structs like this: ``` trait Trait { type A; } #[derive(Hash)] #[repr(packed)] pub struct Foo<T: Trait>(T, T::A); ``` To allow this, we add a `T: Copy` bound in the derived impl and a `T::A: Copy` bound in where clauses. So `T` and `T::A` must impl `Copy`. We can now also derive builtin traits for packed structs that don't derive `Copy`, so long as the fields impl `Copy`: ``` #[derive(Hash)] #[repr(packed)] pub struct Foo(u32); ``` This includes types that hand-impl `Copy` rather than deriving it, such as the following, that show up in winapi-0.2: ``` #[derive(Clone)] #[repr(packed)] struct MyType(i32); impl Copy for MyType {} ``` The new approach is simpler to understand and implement, and it avoids the need for the `unsafe_derive_on_repr_packed` check. One exception is required for backwards-compatibility: we allow `[u8]` fields for now. There is a new lint for this, `byte_slice_in_packed_struct_with_derive`.
2023-01-29Rollup merge of #107006 - b-naber:thir-tree, r=jackh726Matthias Krüger-0/+7
Output tree representation on thir-tree The current output of `-Zunpretty=thir-tree` is really cumbersome to work with, using an actual tree representation should make it easier to see what the thir looks like.
2023-01-29Auto merge of #106253 - nbdd0121:upcast, r=compiler-errorsbors-0/+3
Skip possible where_clause_object_safety lints when checking `multiple_supertrait_upcastable` Fix #106247 To achieve this, I lifted the `WhereClauseReferencesSelf` out from `object_safety_violations` and move it into `is_object_safe` (which is changed to a new query). cc `@dtolnay` r? `@compiler-errors`
2023-01-28Make unsizing_params_for_adt into a queryMichael Goulet-0/+9
2023-01-28Rename `is_object_safe` to `check_is_object_safe` to hint side effectsGary Guo-2/+2
2023-01-28Make `is_object_safe` a query and move lint_object_unsafe_trait call thereGary Guo-0/+3
2023-01-28Remove `HirId -> LocalDefId` map from HIR.Camille GILLOT-1/+1
2023-01-27Compute generator saved locals on MIR.Camille GILLOT-0/+4
2023-01-27Separate witness type computation from the generator transform.Camille GILLOT-0/+7
2023-01-26change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add ↵Kyle Matsuda-1/+1
EarlyBinder to fn_sig in metadata
2023-01-26previous thir unpretty output through thir-flatb-naber-0/+7
2023-01-26Auto merge of #106812 - oli-obk:output_filenames, r=petrochenkovbors-1/+2
make `output_filenames` a real query part of #105462 This may be a perf regression and is not obviously the right way forward. We may store this information in the resolver after freezing it for example.
2023-01-26Auto merge of #105582 - saethlin:instcombine-assert-inhabited, r=cjgillotbors-4/+4
InstCombine away intrinsic validity assertions This optimization (currently) fires 246 times on the standard library. It seems to fire hardly at all on the big crates in the benchmark suite. Interesting.
2023-01-23Thread a ParamEnv down to might_permit_raw_initBen Kimock-4/+4
2023-01-23Make `output_filenames` a real queryOli Scherer-1/+2
2023-01-21rustc_metadata: Encode `doc(hidden)` flag to metadataVadim Petrochenkov-0/+1
To retrieve these flags rustdoc currently has to mass decode full attributes for items in the whole crate tree, so it's better to pre-compute it in advance. This is especially for short-term performance of https://github.com/rust-lang/rust/pull/107054 because resolver cannot use memoization of query results yet.
2023-01-19Encode whether foreign opaques are TAITs or notMichael Goulet-0/+6
2023-01-17change item_bounds query to return EarlyBinder; remove bound_item_bounds queryKyle Matsuda-1/+1
2023-01-14change impl_trait_ref query to return EarlyBinder; remove ↵Kyle Matsuda-1/+1
bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata
2023-01-14change const_param_default query to return EarlyBinder; remove ↵Kyle Matsuda-1/+1
bound_const_param_default query; add EarlyBinder to const_param_default in metadata
2023-01-12Feed the `features_query` instead of grabbing it from the session lazilyOli Scherer-1/+1
2023-01-12Remove `output_filenames` field from TyCtxt and feed the query insteadOli Scherer-1/+1
2023-01-12Remove `untracked_crate` field and instead pass it along with the resolver.Oli Scherer-1/+1
2023-01-12Feed `crate_name` queryOli Scherer-1/+1
2023-01-12Feed `resolutions` query instead of it being a thin wrapper around an ↵Oli Scherer-1/+1
untracked field
2023-01-09Use newtype for unused generic parametersNilstrieb-1/+1
2022-12-28better names and a commentMichael Goulet-1/+1
2022-12-24Rename some compare_method functionsMichael Goulet-1/+1
2022-12-17Rollup merge of #105493 - WaffleLapkin:unchoke-r-a, r=NilstriebMatthias Krüger-1/+105
Help rust-analyzer normalize query return types See [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/rustc.20query.20types.20are.20not.20normalized.20since.20recently/near/312686086), since https://github.com/rust-lang/rust/pull/103808, rust analyzer doesn't normalize return types of queries. This is because r-a doesn't support associated type defaults (yet). The easiest fix is to not use associated type defaults (duh), which this PR does. r? `@cjgillot`
2022-12-16Add a comment warning against using associated type defaults <3Maybe Waffle-0/+8
2022-12-09Move the untracked cstore and source_span into a structOli Scherer-0/+2
2022-12-09Help rust-analyzer normalize query return typesMaybe Waffle-1/+97
2022-12-05feed resolver_for_lowering instead of storing it in a fieldOli Scherer-1/+1
2022-12-01Fill in `def_span` when creating def ids.Oli Scherer-0/+1
This makes sure that ICEing because of def ids created outside of ast lowering will be able to produce a query backtrace and not cause a double panic because of trying to call the `def_span` query
2022-11-29Make inferred_outlives_crate return ClauseSantiago Pastorino-1/+1
2022-11-26Rollup merge of #104909 - ↵Guillaume Gomez-2/+2
compiler-errors:normalize_opaque_types-is-misleading, r=fee1-dead Rename `normalize_opaque_types` to `reveal_opaque_types_in_bounds` 1. The query name is a bit misleading, since it doesn't do any associated type normalization, and 2. since it only takes a predicate list, it sounds a bit more powerful than it actually is.
2022-11-25Rename normalize_opaque_types to reveal_opaque_types_in_boundsMichael Goulet-2/+2
2022-11-25Add empty ConstKind::Abstractkadmin-11/+2
Initial pass at expr/abstract const/s Address comments Switch to using a list instead of &[ty::Const], rm `AbstractConst` Remove try_unify_abstract_consts Update comments Add edits Recurse more More edits Prevent equating associated consts Move failing test to ui Changes this test from incremental to ui, and mark it as failing and a known bug. Does not cause the compiler to ICE, so should be ok.
2022-11-24Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Kibors-0/+597
Use an IndexVec to cache queries with index-like key Revival of an old idea. Let's see if it has more effect. r? `@ghost`
2022-11-20Factor out conservative_is_privately_uninhabitedCameron Steffen-11/+0
2022-11-20Fix doctest errors related to rustc_middlereez12g-0/+2
2022-11-11Resolve lifetimes independently for each item-like.Camille GILLOT-10/+1
2022-11-05Add internal descriptions to a few queriesNilstrieb-1/+17
2022-11-01Use Key impl to select cache.Camille GILLOT-1/+10
2022-11-01Move keys module.Camille GILLOT-0/+588
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-0/+11
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-29Encode LangItem directlyCameron Steffen-1/+1
2022-10-29Auto merge of #102698 - michaelwoerister:unord-collections, r=lncrbors-1/+1
Introduce UnordMap, UnordSet, and UnordBag (MCP 533) This is the start of implementing [MCP 533](https://github.com/rust-lang/compiler-team/issues/533). I followed `@eddyb's` suggestion of naming the collection types `Unord(Map/Set/Bag)` which is a bit easier to type than `Unordered(Map/Set/Bag)` r? `@eddyb`
2022-10-27Introduce UnordMap, UnordSet, and UnordBag (see MCP 533)Michael Woerister-1/+1
MCP 533: https://github.com/rust-lang/compiler-team/issues/533 Also, as an example, substitute UnordMap for FxHashMap in used_trait_imports query result.
2022-10-26privacy: Rename "accessibility levels" to "effective visibilities"Vadim Petrochenkov-3/+3
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054