about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2023-08-19remove redundant var rebindingsMatthias Krüger-5/+2
2023-08-17Revert "Implement references VarDebugInfo."Camille GILLOT-13/+2
This reverts commit 2ec007191348ef7cc13eb55e44e007b02cf75cf3.
2023-08-17Rollup merge of #114876 - compiler-errors:non-lifetime-binders-sized, ↵Matthias Krüger-2/+2
r=wesleywiser Don't ICE in `is_trivially_sized` when encountering late-bound self ty We can see a bound ty var here: https://github.com/rust-lang/rust/blob/b531630f4255216fce1400c45976e04f1ab35a84/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs#L13-L34 Fixes #114872
2023-08-16Make TerminatorEdge plural.Camille GILLOT-13/+13
2023-08-16Allow apply_terminator_effect to customize edges.Camille GILLOT-0/+106
2023-08-16Auto merge of #114536 - cjgillot:eval-lint-levels, r=TaKO8Kibors-1/+0
Do not mark shallow_lint_levels_on as eval_always. It does not need it. Removing it allows to skip recomputation.
2023-08-16Auto merge of #114689 - m-ou-se:stabilize-thread-local-cell-methods, r=thomccbors-1/+0
Stabilize thread local cell methods. Closes #92122.
2023-08-16Don't ICE in is_trivially_sized when encountering late-bound self tyMichael Goulet-2/+2
2023-08-15Rollup merge of #114819 - estebank:issue-78124, r=compiler-errorsMatthias Krüger-3/+3
Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix #78124.
2023-08-15Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naberGuillaume Gomez-41/+154
Add `{Local}ModDefId` to more strongly type DefIds` Based on #110862 by `@Nilstrieb`
2023-08-15more span infoMichael Goulet-1/+1
2023-08-15Auto merge of #114803 - bjorn3:less_session_mutable_state, r=fee1-deadbors-8/+1
Couple of global state and driver refactors * Remove some unused global mutable state * Remove a couple of unnecessary queries (both driver and `TyCtxt` queries) * Remove an unnecessary use of `FxIndexMap`
2023-08-14Move scrutinee `HirId` into `MatchSource::TryDesugar`Esteban Küber-3/+3
2023-08-14Point at return type when it influences non-first `match` armEsteban Küber-1/+1
When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix #78124.
2023-08-14Auto merge of #114781 - fee1-dead-contrib:param-impl-source, r=davidtwcobors-7/+8
Remove constness from `ImplSource::Param`
2023-08-14Use `{Local}ModDefId` in many queriesNilstrieb-40/+103
2023-08-14Remove constness from `ImplSource::Param`Deadbeef-7/+8
2023-08-13Remove metadata_loader querybjorn3-7/+0
It is only used by CrateLoader. We can store the metadata loader in CStore instead which CrateLoader has access to.
2023-08-13Pass WorkProductMap to build_dep_graph instead of FxIndexMapbjorn3-1/+1
Constructing an FxIndexMap is useless work as the iteration order never matters.
2023-08-13Add typed `{Local}DefId` for modulesNilstrieb-1/+51
This allows for better type safety in the compiler and also improves the documentation for many things, making it clear that they expect modules.
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-0/+1
Removes two pieces of mutable state. Follow up to #114622.
2023-08-10Rollup merge of #114622 - petrochenkov:noplugin, r=oli-obkMichael Goulet-13/+60
rustc: Move `crate_types` and `stable_crate_id` from `Session` to `GlobalCtxt` Removes two pieces of mutable state. Follow up to https://github.com/rust-lang/rust/pull/114578.
2023-08-10Stabilize thread local cell methods.Mara Bos-1/+0
2023-08-09Rollup merge of #114587 - ouz-a:smir_allocation, r=oli-obkMatthias Krüger-0/+3
Convert Const to Allocation in smir Continuation of previous pr https://github.com/rust-lang/rust/pull/114466 cc https://github.com/rust-lang/project-stable-mir/issues/15 r? `@oli-obk`
2023-08-09Rollup merge of #111891 - rustbox:feat/riscv-isr-cconv, r=jackh726Matthias Krüger-0/+2
feat: `riscv-interrupt-{m,s}` calling conventions Similar to prior support added for the mips430, avr, and x86 targets this change implements the rough equivalent of clang's [`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling e.g. ```rust static mut CNT: usize = 0; pub extern "riscv-interrupt-m" fn isr_m() { unsafe { CNT += 1; } } ``` to produce highly effective assembly like: ```asm pub extern "riscv-interrupt-m" fn isr_m() { 420003a0: 1141 addi sp,sp,-16 unsafe { CNT += 1; 420003a2: c62a sw a0,12(sp) 420003a4: c42e sw a1,8(sp) 420003a6: 3fc80537 lui a0,0x3fc80 420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0> 420003ae: 0585 addi a1,a1,1 420003b0: 62b52e23 sw a1,1596(a0) } } 420003b4: 4532 lw a0,12(sp) 420003b6: 45a2 lw a1,8(sp) 420003b8: 0141 addi sp,sp,16 420003ba: 30200073 mret ``` (disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`) This outcome is superior to hand-coded interrupt routines which, lacking visibility into any non-assembly body of the interrupt handler, have to be very conservative and save the [entire CPU state to the stack frame][full-frame-save]. By instead asking LLVM to only save the registers that it uses, we defer the decision to the tool with the best context: it can more accurately account for the cost of spills if it knows that every additional register used is already at the cost of an implicit spill. At the LLVM level, this is apparently [implemented by] marking every register as "[callee-save]," matching the semantics of an interrupt handler nicely (it has to leave the CPU state just as it found it after its `{m|s}ret`). This approach is not suitable for every interrupt handler, as it makes no attempt to e.g. save the state in a user-accessible stack frame. For a full discussion of those challenges and tradeoffs, please refer to [the interrupt calling conventions RFC][rfc]. Inside rustc, this implementation differs from prior art because LLVM does not expose the "all-saved" function flavor as a calling convention directly, instead preferring to use an attribute that allows for differentiating between "machine-mode" and "superivsor-mode" interrupts. Finally, some effort has been made to guide those who may not yet be aware of the differences between machine-mode and supervisor-mode interrupts as to why no `riscv-interrupt` calling convention is exposed through rustc, and similarly for why `riscv-interrupt-u` makes no appearance (as it would complicate future LLVM upgrades). [clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v [full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469 [implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67 [callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37 [rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-08-09Convert Const to Allocation in smirouz-a-0/+3
2023-08-09rustc: Move `stable_crate_id` from `Session` to `GlobalCtxt`Vadim Petrochenkov-10/+18
Removes a piece of mutable state. Follow up to #114578.
2023-08-09rustc: Move `crate_types` from `Session` to `GlobalCtxt`Vadim Petrochenkov-3/+42
Removes a piece of mutable state. Follow up to #114578.
2023-08-09Rollup merge of #114548 - fee1-dead-contrib:migrate-to-trans, r=davidtwcoMatthias Krüger-7/+18
Migrate a trait selection error to use diagnostic translation
2023-08-08feat: `riscv-interrupt-{m,s}` calling conventionsSeth Pellegrino-0/+2
Similar to prior support added for the mips430, avr, and x86 targets this change implements the rough equivalent of clang's [`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling e.g. ```rust static mut CNT: usize = 0; pub extern "riscv-interrupt-m" fn isr_m() { unsafe { CNT += 1; } } ``` to produce highly effective assembly like: ```asm pub extern "riscv-interrupt-m" fn isr_m() { 420003a0: 1141 addi sp,sp,-16 unsafe { CNT += 1; 420003a2: c62a sw a0,12(sp) 420003a4: c42e sw a1,8(sp) 420003a6: 3fc80537 lui a0,0x3fc80 420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0> 420003ae: 0585 addi a1,a1,1 420003b0: 62b52e23 sw a1,1596(a0) } } 420003b4: 4532 lw a0,12(sp) 420003b6: 45a2 lw a1,8(sp) 420003b8: 0141 addi sp,sp,16 420003ba: 30200073 mret ``` (disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`) This outcome is superior to hand-coded interrupt routines which, lacking visibility into any non-assembly body of the interrupt handler, have to be very conservative and save the [entire CPU state to the stack frame][full-frame-save]. By instead asking LLVM to only save the registers that it uses, we defer the decision to the tool with the best context: it can more accurately account for the cost of spills if it knows that every additional register used is already at the cost of an implicit spill. At the LLVM level, this is apparently [implemented by] marking every register as "[callee-save]," matching the semantics of an interrupt handler nicely (it has to leave the CPU state just as it found it after its `{m|s}ret`). This approach is not suitable for every interrupt handler, as it makes no attempt to e.g. save the state in a user-accessible stack frame. For a full discussion of those challenges and tradeoffs, please refer to [the interrupt calling conventions RFC][rfc]. Inside rustc, this implementation differs from prior art because LLVM does not expose the "all-saved" function flavor as a calling convention directly, instead preferring to use an attribute that allows for differentiating between "machine-mode" and "superivsor-mode" interrupts. Finally, some effort has been made to guide those who may not yet be aware of the differences between machine-mode and supervisor-mode interrupts as to why no `riscv-interrupt` calling convention is exposed through rustc, and similarly for why `riscv-interrupt-u` makes no appearance (as it would complicate future LLVM upgrades). [clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v [full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469 [implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67 [callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37 [rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-08-08Auto merge of #114637 - matthiaskrgr:rollup-544y8p5, r=matthiaskrgrbors-2/+0
Rollup of 11 pull requests Successful merges: - #106425 (Make ExitStatus implement Default) - #113480 (add aarch64-unknown-teeos target) - #113586 (Mention style for new syntax in tracking issue template) - #113593 (CFI: Fix error compiling core with LLVM CFI enabled) - #114612 (update llvm-wrapper include to silence deprecation warning) - #114613 (Prevent constant rebuilds of `rustc-main` (and thus everything else)) - #114615 (interpret: remove incomplete protection against invalid where clauses) - #114628 (Allowing re-implementation of mir_drops_elaborated query) - #114629 (tests: Uncomment now valid GAT code behind FIXME) - #114630 (Migrate GUI colors test to original CSS color format) - #114631 (add provisional cache test for new solver) r? `@ghost` `@rustbot` modify labels: rollup
2023-08-08Rollup merge of #114615 - RalfJung:interpret-invalid-where, r=lcnrMatthias Krüger-2/+0
interpret: remove incomplete protection against invalid where clauses Cc https://github.com/rust-lang/rust/issues/97477, https://github.com/rust-lang/project-const-generics/issues/37 r? ``@lcnr``
2023-08-08Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obkbors-2/+7
correctly lower `impl const` to bind to host effect param r? `@oli-obk`
2023-08-08Auto merge of #114602 - compiler-errors:rpit-outlives-sadness, r=oli-obkbors-0/+78
Map RPIT duplicated lifetimes back to fn captured lifetimes Use the [`lifetime_mapping`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html#structfield.lifetime_mapping) to map an RPIT's captured lifetimes back to the early- or late-bound lifetimes from its parent function. We may be going thru several layers of mapping, since opaques can be nested, so we introduce `TyCtxt::map_rpit_lifetime_to_fn_lifetime` to loop through several opaques worth of mapping, and handle turning it into a `ty::Region` as well. We can then use this instead of the identity substs for RPITs in `check_opaque_meets_bounds` to address #114285. We can then also use `map_rpit_lifetime_to_fn_lifetime` to properly install bidirectional-outlives predicates for both RPITs and RPITITs. This addresses #114601. I based this on #114574, but I don't actually know how much of that PR we still need, so some code may be redundant now... :shrug: --- Fixes #114597 Fixes #114579 Fixes #114285 Also fixes #114601, since it turns out we had other bugs with RPITITs and their duplicated lifetime params :sweat_smile:. Supersedes #114574 r? `@oli-obk`
2023-08-08Simplify via map_rpit_lifetime_to_fn_lifetimeMichael Goulet-1/+10
2023-08-08Install bidirectional outlives predicates for RPITITs (and RPITs) correctlyMichael Goulet-0/+69
2023-08-08interpret: remove incomplete protection against invalid where clausesRalf Jung-2/+0
2023-08-08Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, ↵Matthias Krüger-13/+15
r=oli-obk Store the laziness of type aliases in their `DefKind` Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not. With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*: Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates. As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions. --- This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold. `@rustbot` label F-lazy_type_alias r? `@oli-obk`
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-13/+15
2023-08-07Migrate a trait selection error to use diagnostic translationDeadbeef-7/+18
2023-08-06Auto merge of #114553 - matthiaskrgr:rollup-5yddunv, r=matthiaskrgrbors-11/+17
Rollup of 5 pull requests Successful merges: - #114466 (Add Allocation to SMIR) - #114505 (Add documentation to has_deref) - #114519 (use offset_of! to calculate dirent64 field offsets) - #114537 (Migrate GUI colors test to original CSS color format) - #114539 (linkchecker: Remove unneeded FIXME about intra-doc links) Failed merges: - #114485 (Add trait decls to SMIR) r? `@ghost` `@rustbot` modify labels: rollup
2023-08-06Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJungMatthias Krüger-11/+17
Add documentation to has_deref Documentation of `has_deref` needed some polish to be more clear about where it should be used and what's it's purpose. cc https://github.com/rust-lang/rust/issues/114401 r? `@RalfJung`
2023-08-06cleanup misinformation regarding has_derefouz-a-11/+17
2023-08-06lower impl const to bind to host effect paramDeadbeef-2/+7
2023-08-06Do not mark shallow_lint_levels_on as eval_always.Camille GILLOT-1/+0
2023-08-05parent_module_from_def_id does not need to be a query.Camille GILLOT-21/+15
2023-08-05Auto merge of #113734 - cjgillot:no-crate-lint, r=petrochenkovbors-0/+5
Convert builtin "global" late lints to run per module The compiler currently has 4 non-incremental lints: 1. `clashing_extern_declarations`; 2. `missing_debug_implementations`; 3. ~`unnameable_test_items`;~ changed by https://github.com/rust-lang/rust/pull/114414 4. `missing_docs`. Non-incremental lints get reexecuted for each compilation, which is slow. Moreover, those lints are allow-by-default, so run for nothing most of the time. This PR attempts to make them more incremental-friendly. `clashing_extern_declarations` is moved to a standalone query. `missing_debug_implementation` can use `non_blanket_impls_for_ty` instead of recomputing it. `missing_docs` is harder as it needs to track if there is a `doc(hidden)` module surrounding. I hack around this using the lint level engine. That's easy to implement and allows to re-enable the lint for a re-exported module, while a more proper solution would reuse the same device as `unnameable_test_items`.
2023-08-04Rollup merge of #114287 - lcnr:overflow, r=compiler-errorsMichael Goulet-2/+115
update overflow handling in the new trait solver implements https://hackmd.io/QY0dfEOgSNWwU4oiGnVRLw?view. I want to clean up this doc and add it to the rustc-dev-guide, but I think this PR is ready for merge as is, even without the dev-guide entry. r? `@compiler-errors`
2023-08-04Querify clashing_extern_declarations lint.Camille GILLOT-0/+5
2023-08-04Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnrbors-8/+15
Rework upcasting confirmation to support upcasting to fewer projections in target bounds This PR implements a modified trait upcasting algorithm that is resilient to changes in the number of associated types in the bounds of the source and target trait objects. It does this by equating each bound of the target trait ref individually against the bounds of the source trait ref, rather than doing them all together by constructing a new trait object. #### The new way we do trait upcasting confirmation 1. Equate the target trait object's principal trait ref with one of the supertraits of the source trait object's principal. https://github.com/rust-lang/rust/blob/fdcab310b2a57a4e9cc0b2629abd27afda49cd80/compiler/rustc_trait_selection/src/traits/select/mod.rs#L2509-L2525 2. Make sure that every auto trait in the *target* trait object is present in the source trait ref's bounds. https://github.com/rust-lang/rust/blob/fdcab310b2a57a4e9cc0b2629abd27afda49cd80/compiler/rustc_trait_selection/src/traits/select/mod.rs#L2559-L2562 3. For each projection in the *target* trait object, make sure there is exactly one projection that equates with it in the source trait ref's bound. If there is more than one, bail with ambiguity. https://github.com/rust-lang/rust/blob/fdcab310b2a57a4e9cc0b2629abd27afda49cd80/compiler/rustc_trait_selection/src/traits/select/mod.rs#L2526-L2557 * Since there may be more than one that applies, we probe first to check that there is exactly one, then we equate it outside of a probe once we know that it's unique. 4. Make sure the lifetime of the source trait object outlives the lifetime of the target. <details> <summary>Meanwhile, this is how we used to do upcasting:</summary> 1. For each supertrait of the source trait object, take that supertrait, append the source object's projection bounds, and the *target* trait object's auto trait bounds, and make this into a new object type: https://github.com/rust-lang/rust/blob/d12c6e947ceacf3b22c154caf9532b390d8dc88a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs#L915-L929 2. Then equate it with the target trait object: https://github.com/rust-lang/rust/blob/d12c6e947ceacf3b22c154caf9532b390d8dc88a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs#L936 This will be a type mismatch if the target trait object has fewer projection bounds, since we compare the bounds structurally in relate: https://github.com/rust-lang/rust/blob/d12c6e947ceacf3b22c154caf9532b390d8dc88a/compiler/rustc_middle/src/ty/relate.rs#L696-L698 </details> Fixes #114035 Also fixes #114113, because I added a normalize call in the old solver. r? types