summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2021-07-23Improve `get_by_key_enumerated` moreYuki Okushi-1/+1
2021-07-22Auto merge of #87265 - Aaron1011:hir-wf-fn, r=estebankbors-1/+1
Support HIR wf checking for function signatures During function type-checking, we normalize any associated types in the function signature (argument types + return type), and then create WF obligations for each of the normalized types. The HIR wf code does not currently support this case, so any errors that we get have imprecise spans. This commit extends `ObligationCauseCode::WellFormed` to support recording a function parameter, allowing us to get the corresponding HIR type if an error occurs. Function typechecking is modified to pass this information during signature normalization and WF checking. The resulting code is fairly verbose, due to the fact that we can no longer normalize the entire signature with a single function call. As part of the refactoring, we now perform HIR-based WF checking for several other 'typed items' (statics, consts, and inherent impls). As a result, WF and projection errors in a function signature now have a precise span, which points directly at the responsible type. If a function signature is constructed via a macro, this will allow the error message to point at the code 'most responsible' for the error (e.g. a user-supplied macro argument).
2021-07-22Auto merge of #87246 - rust-lang:placeholder-pretty, r=nikomatsakisbors-35/+107
When pretty printing, name placeholders as bound regions Split from #85499 When we see a placeholder that we are going to print, treat it as a bound var (and add it to a `for<...>`
2021-07-20Support HIR wf checking for function signaturesAaron Hill-1/+1
During function type-checking, we normalize any associated types in the function signature (argument types + return type), and then create WF obligations for each of the normalized types. The HIR wf code does not currently support this case, so any errors that we get have imprecise spans. This commit extends `ObligationCauseCode::WellFormed` to support recording a function parameter, allowing us to get the corresponding HIR type if an error occurs. Function typechecking is modified to pass this information during signature normalization and WF checking. The resulting code is fairly verbose, due to the fact that we can no longer normalize the entire signature with a single function call. As part of the refactoring, we now perform HIR-based WF checking for several other 'typed items' (statics, consts, and inherent impls). As a result, WF and projection errors in a function signature now have a precise span, which points directly at the responsible type. If a function signature is constructed via a macro, this will allow the error message to point at the code 'most responsible' for the error (e.g. a user-supplied macro argument).
2021-07-19Rollup merge of #87268 - SkiFire13:fix-uninit-ref-list, r=nagisaGuillaume Gomez-6/+6
Don't create references to uninitialized data in `List::from_arena` Previously `result` and `arena_slice` were references pointing to uninitialized data, which is technically UB. They may have been fine because the pointed data is `Copy` and and they were only written to, but the semantics of this aren't clearly defined yet, and since we have a sound way to do the same thing I don't think we should keep the possibly-unsound way.
2021-07-19Don't create references to uninitialized data in List::from_arenaGiacomo Stevanato-6/+6
2021-07-18Auto merge of #86698 - cjgillot:modc, r=estebankbors-1248/+53
Move OnDiskCache to rustc_query_impl. This should be the last remnant of the query implementation that was still in rustc_middle.
2021-07-18Remove deadlock virtual call.Camille GILLOT-4/+1
2021-07-18Move OnDiskCache to rustc_query_impl.Camille GILLOT-1246/+54
2021-07-18When pretty printing, name placeholders as bound regionsjackh726-35/+107
2021-07-18Rollup merge of #87205 - matthiaskrgr:clippy_cln, r=oli-obkYuki Okushi-3/+2
rustc_middle: remove redundant clone found while looking through some clippy lint warnings
2021-07-17Auto merge of #86676 - cjgillot:localexpn, r=petrochenkovbors-35/+63
Make expansions stable for incr. comp. This PR aims to make expansions stable for incr. comp. by using the same architecture as definitions: - the interned identifier `ExpnId` contains a `CrateNum` and a crate-local id; - bidirectional maps `ExpnHash <-> ExpnId` are setup; - incr. comp. on-disk cache saves and reconstructs expansions using their `ExpnHash`. I tried to use as many `LocalExpnId` as I could in the resolver code, but I may have missed a few opportunities. All this will allow to use an `ExpnId` as a query key, and to force this query without recomputing caller queries. For instance, this will be used to implement #85999. r? `@petrochenkov`
2021-07-17Pass ExpnData by reference.Camille GILLOT-1/+1
2021-07-17Always hash spans in expn.Camille GILLOT-1/+1
2021-07-17Encode ExpnId using ExpnHash for incr. comp.Camille GILLOT-34/+59
2021-07-17Choose encoding format in caller code.Camille GILLOT-10/+13
2021-07-17Make the CrateNum part of the ExpnId.Camille GILLOT-3/+9
2021-07-17Auto merge of #87123 - RalfJung:miri-provenance-overhaul, r=oli-obkbors-29/+23
CTFE/Miri engine Pointer type overhaul This fixes the long-standing problem that we are using `Scalar` as a type to represent pointers that might be integer values (since they point to a ZST). The main problem is that with int-to-ptr casts, there are multiple ways to represent the same pointer as a `Scalar` and it is unclear if "normalization" (i.e., the cast) already happened or not. This leads to ugly methods like `force_mplace_ptr` and `force_op_ptr`. Another problem this solves is that in Miri, it would make a lot more sense to have the `Pointer::offset` field represent the full absolute address (instead of being relative to the `AllocId`). This means we can do ptr-to-int casts without access to any machine state, and it means that the overflow checks on pointer arithmetic are (finally!) accurate. To solve this, the `Pointer` type is made entirely parametric over the provenance, so that we can use `Pointer<AllocId>` inside `Scalar` but use `Pointer<Option<AllocId>>` when accessing memory (where `None` represents the case that we could not figure out an `AllocId`; in that case the `offset` is an absolute address). Moreover, the `Provenance` trait determines if a pointer with a given provenance can be cast to an integer by simply dropping the provenance. I hope this can be read commit-by-commit, but the first commit does the bulk of the work. It introduces some FIXMEs that are resolved later. Fixes https://github.com/rust-lang/miri/issues/841 Miri PR: https://github.com/rust-lang/miri/pull/1851 r? `@oli-obk`
2021-07-17rustc_middle: remove redundant cloneMatthias Krüger-3/+2
found while looking through some clippy lint warnings
2021-07-16Rollup merge of #87200 - oli-obk:fixup_fixup_opaque_types, r=nikomatsakisGuillaume Gomez-1/+1
TAIT: Infer all inference variables in opaque type substitutions via InferCx The previous algorithm was correct for the example given in its documentation, but when the TAIT was declared as a free item instead of an associated item, the generic parameters were the wrong ones. cc `@spastorino` r? `@nikomatsakis`
2021-07-16Infer all inference variables via InferCxOli Scherer-1/+1
The previous algorithm was correct for the example given in its documentation, but when the TAIT was declared as a free item instead of an associated item, the generic parameters were the wrong ones.
2021-07-16get rid of incorrect erase_for_fmtRalf Jung-5/+5
2021-07-16Auto merge of #86993 - jackh726:project-gat-binders, r=nikomatsakisbors-1/+2
Replace associated item bound vars with placeholders when projecting Fixes #76407 Fixes #76826 Similar, but more limited, to #85499. This allows us to handle things like `for<'a> <T as Trait>::Assoc<'a>` but not `for<'a> <T as Trait<'a>>::Assoc`, unblocking GATs. r? `@nikomatsakis`
2021-07-15Separate encoding paths.Camille GILLOT-10/+4
The two paths will be modified independently in the next few commits.
2021-07-15Layout error instead of an ICE for packed and aligned typesTomasz Miąsko-2/+7
2021-07-15adjustions and cleanup to make Miri build againRalf Jung-10/+1
2021-07-14consistently treat None-tagged pointers as ints; get rid of some deprecated ↵Ralf Jung-5/+8
Scalar methods
2021-07-14CTFE/Miri engine Pointer type overhaul: make Scalar-to-Pointer conversion ↵Ralf Jung-9/+9
infallible This resolves all the problems we had around "normalizing" the representation of a Scalar in case it carries a Pointer value: we can just use Pointer if we want to have a value taht we are sure is already normalized.
2021-07-14Shrink the CrateStore dynamic interface.Camille GILLOT-7/+2
2021-07-13Cache expansion hash.Camille GILLOT-4/+4
2021-07-13Conditionally call normalize_erasing_regions only if polymorhization is enabledjackh726-1/+2
2021-07-11Auto merge of #85941 - cjgillot:qresolve, r=Aaron1011bors-62/+57
Reduce the amount of untracked state in TyCtxt -- Take 2 Main part of #85153 The offending line (https://github.com/rust-lang/rust/pull/85153#discussion_r642866298) is replaced by a FIXME until the possible bug and the perf concern are both resolved. r? `@Aaron1011`
2021-07-10Auto merge of #81360 - Aaron1011:trait-caller-loc, r=nagisabors-4/+48
Support forwarding caller location through trait object method call Since PR #69251, the `#[track_caller]` attribute has been supported on traits. However, it only has an effect on direct (monomorphized) method calls. Calling a `#[track_caller]` method on a trait object will *not* propagate caller location information - instead, `Location::caller()` will return the location of the method definition. This PR forwards caller location information when `#[track_caller]` is present on the method definition in the trait. This is possible because `#[track_caller]` in this position is 'inherited' by any impls of that trait, so all implementations will have the same ABI. This PR does *not* change the behavior in the case where `#[track_caller]` is present only on the impl of a trait. While all implementations of the method might have an explicit `#[track_caller]`, we cannot know this at codegen time, since other crates may have impls of the trait. Therefore, we keep the current behavior of not forwarding the caller location, ensuring that all implementations of the trait will have the correct ABI. See the modified test for examples of how this works
2021-07-09Rollup merge of #86855 - LeSeulArtichaut:patch-1, r=davidtwcoMara Bos-1/+1
Fix comments about unique borrows
2021-07-06Correct comments about untracked accesses.Camille GILLOT-5/+5
2021-07-06Make resolutions a query.Camille GILLOT-61/+56
2021-07-06Auto merge of #86143 - bjorn3:revert_revert_merge_crate_disambiguator, ↵bors-9/+12
r=michaelwoerister Reland "Merge CrateDisambiguator into StableCrateId" Reverts https://github.com/rust-lang/rust/pull/85891 as this revert of #85804 made perf even worse. r? `@Mark-Simulacrum`
2021-07-06Make tcx.stable_crate_id() fasterbjorn3-2/+6
2021-07-06Revert "Revert "Merge CrateDisambiguator into StableCrateId""bjorn3-7/+6
This reverts commit 8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.
2021-07-06Store macro parent module in ExpnData.Camille GILLOT-7/+5
2021-07-05Auto merge of #86674 - Aaron1011:new-querify-limits, r=michaelwoeristerbors-3/+23
Query-ify global limit attribute handling Currently, we read various 'global limits' from inner attributes the crate root (`recursion_limit`, `move_size_limit`, `type_length_limit`, `const_eval_limit`). These limits are then stored in `Sessions`, allowing them to be access from a `TyCtxt` without registering a dependency on the crate root attributes. This PR moves the calculation of these global limits behind queries, so that we properly track dependencies on crate root attributes. During the setup of macro expansion (before we've created a `TyCtxt`), we need to access the recursion limit, which is now done by directly calling into the code shared by the normal query implementations.
2021-07-05Auto merge of #86867 - JohnTitor:convert-to-actual-assert, r=jackh726bors-1/+1
Convert `debug_assert!` to `assert!` in `Binder::dummy` This is needed for #85350 not to be passed. r? `@jackh726`
2021-07-04Combine individual limit queries into single `limits` queryAaron Hill-4/+21
2021-07-04Auto merge of #86866 - nikomatsakis:issue-84841, r=oli-obkbors-4/+22
Hack: Ignore inference variables in certain queries Fixes #84841 Fixes #86753 Some queries are not built to accept types with inference variables, which can lead to ICEs. These queries probably ought to be converted to canonical form, but as a quick workaround, we can return conservative results in the case that inference variables are found. We should file a follow-up issue (and update the FIXMEs...) to do the proper refactoring. cc `@arora-aman` r? `@oli-obk`
2021-07-04Query-ify global limit attribute handlingAaron Hill-3/+6
2021-07-04tag issues with FIXMENiko Matsakis-1/+1
2021-07-04Update compiler/rustc_middle/src/ty/normalize_erasing_regions.rsNiko Matsakis-1/+1
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
2021-07-05Convert `debug_assert!` to `assert!` in `Binder::dummy`Yuki Okushi-1/+1
This is needed for #85350 not to be passed.
2021-07-04be conservative in has_significant_dropNiko Matsakis-0/+9
2021-07-04Auto merge of #86255 - Smittyvb:mir-alloc-oom, r=RalfJung,oli-obkbors-1/+2
Support allocation failures when interpreting MIR This closes #79601 by handling the case where memory allocation fails during MIR interpretation, and translates that failure into an `InterpError`. The error message is "tried to allocate more memory than available to compiler" to make it clear that the memory shortage is happening at compile-time by the compiler itself, and that it is not a runtime issue. Now that memory allocation can fail, it would be neat if Miri could simulate low-memory devices to make it easy to see how much memory a Rust program needs. Note that this breaks Miri because it assumes that allocation can never fail.