about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2023-06-01Rollup merge of #112155 - nnethercote:debug_dump, r=wesleywiserMatthias Krüger-0/+2
Improve CGU debug printing. - Add more total and per-CGU measurements. - Ensure CGUs are sorted by name before the first `debug_dump` calls, for deterministic output. - Print items within CGUs in sorted-by-name order, for deterministic output. - Add some assertions and comments clarifying sortedness of CGUs at various points. An example, before: ``` INITIAL PARTITIONING (5 CodegenUnits, max=29, min=1, max/min=29.0): CodegenUnit scev95ysd7g4b0z estimated size 2: - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] estimated size 2 CodegenUnit 1j0frgtl72rsz24q estimated size 29: - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] estimated size 17 - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] estimated size 12 CodegenUnit 5dbzi1e5qm0d7kj2 estimated size 4: - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] estimated size 1 - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] estimated size 1 - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] estimated size 1 - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] estimated size 1 CodegenUnit 220m1mqa2mlbg7r3 estimated size 1: - fn main [(External, Hidden)] [hb29587cdb6db5f42E] estimated size 1 CodegenUnit 4ulbh241f7tvyn7x estimated size 6: - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] estimated size 6 ``` and after: ``` INITIAL PARTITIONING (9 items, total_size=42; 5 CGUs, max_size=29, min_size=1, max_size/min_size=29.0): - CGU[0] 1j0frgtl72rsz24q (2 items, size=29): - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] (size=12) - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] (size=17) - CGU[1] 220m1mqa2mlbg7r3 (1 items, size=1): - fn main [(External, Hidden)] [hb29587cdb6db5f42E] (size=1) - CGU[2] 4ulbh241f7tvyn7x (1 items, size=6): - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] (size=6) - CGU[3] 5dbzi1e5qm0d7kj2 (4 items, size=4): - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] (size=1) - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] (size=1) - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] (size=1) - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] (size=1) - CGU[4] scev95ysd7g4b0z (1 items, size=2): - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] (size=2) ``` r? ``@wesleywiser``
2023-06-01Implement custom diagnostic for ConstParamTyMichael Goulet-0/+3
2023-06-01Remember names of `cfg`-ed out items to mention them in diagnosticsNilstrieb-1/+12
`#[cfg]`s are frequently used to gate crate content behind cargo features. This can lead to very confusing errors when features are missing. For example, `serde` doesn't have the `derive` feature by default. Therefore, `serde::Serialize` fails to resolve with a generic error, even though the macro is present in the docs. This commit adds a list of all stripped item names to metadata. This is filled during macro expansion and then, through a fed query, persisted in metadata. The downstream resolver can then access the metadata to look at possible candidates for mentioning in the errors. This slightly increases metadata (800k->809k for the feature-heavy windows crate), but not enough to really matter.
2023-06-01improve debug message by eagerly translatingDeadbeef-13/+1
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-353/+405
2023-06-01Auto merge of #112164 - Dylan-DPC:rollup-93zj7jw, r=Dylan-DPCbors-5/+1
Rollup of 7 pull requests Successful merges: - #108459 (rustdoc: Fix LinkReplacer link matching) - #111318 (Add a distinct `OperandValue::ZeroSized` variant for ZSTs) - #111892 (rustdoc: add interaction delays for tooltip popovers) - #111980 (Preserve substs in opaques recorded in typeck results) - #112024 (Don't suggest break through nested items) - #112128 (Don't compute inlining status of mono items in advance.) - #112141 (remove reference to Into in ? operator core/std docs, fix #111655) Failed merges: - #112071 (Group rfcs tests) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-01Rename `impl_defaultness` to `defaultness`Deadbeef-4/+5
2023-06-01Rollup merge of #111980 - compiler-errors:unmapped-substs, r=lcnrDylan DPC-5/+1
Preserve substs in opaques recorded in typeck results This means that we now prepopulate MIR with opaques with the right substs. The first commit is a hack that I think we discussed, having to do with `DefiningAnchor::Bubble` basically being equivalent to `DefiningAnchor::Error` in the new solver, so having to use `DefiningAnchor::Bind` instead, lol. r? `@lcnr`
2023-06-01Auto merge of #103877 - oli-obk:const_eval_step_limit, r=fee1-deadbors-26/+2
Replace const eval limit by a lint and add an exponential backoff warning The lint triggers at the first power of 2 that comes after 1 million function calls or traversed back-edges (takes less than a second on usual programs). After the first emission, an unsilenceable warning is repeated at every following power of 2 terminators, causing it to get reported less and less the longer the evaluation runs. cc `@rust-lang/wg-const-eval` fixes #93481 closes #67217
2023-06-01Improve CGU debug printing.Nicholas Nethercote-0/+2
- Add more total and per-CGU measurements. - Ensure CGUs are sorted by name before the first `debug_dump` calls, for deterministic output. - Print items within CGUs in sorted-by-name order, for deterministic output. - Add some assertions and comments clarifying sortedness of CGUs at various points. An example, before: ``` INITIAL PARTITIONING (5 CodegenUnits, max=29, min=1, max/min=29.0): CodegenUnit scev95ysd7g4b0z estimated size 2: - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] estimated size 2 CodegenUnit 1j0frgtl72rsz24q estimated size 29: - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] estimated size 17 - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] estimated size 12 CodegenUnit 5dbzi1e5qm0d7kj2 estimated size 4: - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] estimated size 1 - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] estimated size 1 - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] estimated size 1 - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] estimated size 1 CodegenUnit 220m1mqa2mlbg7r3 estimated size 1: - fn main [(External, Hidden)] [hb29587cdb6db5f42E] estimated size 1 CodegenUnit 4ulbh241f7tvyn7x estimated size 6: - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] estimated size 6 ``` and after: ``` INITIAL PARTITIONING (9 items, total_size=42; 5 CGUs, max_size=29, min_size=1, max_size/min_size=29.0): - CGU[0] 1j0frgtl72rsz24q (2 items, size=29): - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] (size=12) - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] (size=17) - CGU[1] 220m1mqa2mlbg7r3 (1 items, size=1): - fn main [(External, Hidden)] [hb29587cdb6db5f42E] (size=1) - CGU[2] 4ulbh241f7tvyn7x (1 items, size=6): - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] (size=6) - CGU[3] 5dbzi1e5qm0d7kj2 (4 items, size=4): - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] (size=1) - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] (size=1) - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] (size=1) - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] (size=1) - CGU[4] scev95ysd7g4b0z (1 items, size=2): - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] (size=2) ```
2023-05-31Check that RPITs are compatible with the opaques inferred during HIR typeck tooMichael Goulet-4/+0
2023-05-31Auto merge of #111913 - oli-obk:valtrees2, r=lcnrbors-58/+1
Only rewrite valtree-constants to patterns and keep other constants opaque Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can 1. eagerly try to convert constants to valtrees 2. then deeply convert the valtree to a pattern 3. if the to-valtree conversion failed, create an "opaque constant" pattern. This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is * move the two remaining call sites to `destructure_mir_constant` off that query * make valtree to pattern conversion infallible * this needs to be done after careful analysis of the effects. There may be user visible changes from that. based on https://github.com/rust-lang/rust/pull/111768
2023-05-31Inline from_inline_const into its sole call siteOli Scherer-46/+1
2023-05-31Remove `lit_to_mir_constant` queryOli Scherer-4/+0
2023-05-31Remove `deref_mir_constant`Oli Scherer-8/+0
2023-05-31Only rewrite valtree-constants to patterns and keep other constants opaqueOli Scherer-2/+2
2023-05-31Auto merge of #111076 - ↵bors-1/+21
notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot diagnostics: exclude indirect private deps from trait impl suggest Fixes #88696
2023-05-31Remove const eval limit and implement an exponential backoff lint insteadOli Scherer-26/+2
2023-05-31Auto merge of #111623 - BoxyUwU:move_eval_hack, r=compiler-errorsbors-11/+0
move `super_relate_consts` hack to `normalize_param_env_or_error` `super_relate_consts` has as hack in it to work around the fact that `normalize_param_env_or_error` is broken. When relating two constants we attempt to evaluate them (aka normalize them). This is not an issue in any way specific to const generics, type aliases also have the same issue as demonstrated in [this code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=84b6d3956a2c852a04b60782476b56c9). Since the hack in `super_relate_consts` only exists to make `normalize_param_env_or_error` emit less errors move it to `normalize_param_env_or_error`. This makes `super_relate_consts` act more like the normal plain structural equality its supposed to and should help ensure that the hack doesnt accidentally affect other situations. r? `@compiler-errors`
2023-05-31move hack to `normalize_param_env_or_error`Boxy-11/+0
2023-05-31Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obkbors-7/+8
change `BorrowKind::Unique` to be a mutating `PlaceContext` fixes #112056 I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-30Auto merge of #111881 - lcnr:leak-check, r=nikomatsakis,jackh726bors-13/+0
refactor and cleanup the leak check, add it to new solver ended up being a bit more involved than I wanted but is hopefully still easy enough to review as a single PR, can split it into separate ones otherwise. this can be reviewed commit by commit: a473d55cdb9284aa2b01282d1b529a2a4d26547b 31a686646534ca006d906ec757ece4e771d6f973 949039c107852a5e36361c08b62821a0613656f5 242917bf5170d9a723c6c8e23e9d9d0c2fa8dc9d ed2b25a7aa28be3184be9e3022c2796a30eaad87 are all pretty straightforward. 03dd83b4c3f4ff27558f5c8ab859bd9f83db1d04 makes it easier to refactor coherence in a later commit, see the commit description, cc `@oli-obk` 4fe311d807a77b6270f384e41689bf5d58f46aec I don't quite remember what we wanted to test here, this definitely doesn't test that the occurs check doesn't cause incorrect errors in coherence, also cc `@oli-obk` here. I may end up writing a new test for this myself later. 5c200d88a91b75bd0875b973150655bd581ef97a is the main refactor of the leak check, changing it to take the `outer_universe` instead of getting it from a snapshot. Using a snapshot requires us to be in a probe which we aren't in the new solver, it also just feels dirty as snapshots don't really have anything to do with universes. with all of this cfc230d54188d9c7ed867a9a0d1f51be77b485f9 is now kind of trivial. r? `@nikomatsakis`
2023-05-30Rollup merge of #112060 - lcnr:early-binder, r=jackh726Nilstrieb-13/+13
`EarlyBinder::new` -> `EarlyBinder::bind` for consistency with `Binder::bind`. it may make sense to also add `EarlyBinder::dummy` in places where we know that no parameters exist, but I left that out of this PR. r? `@jackh726` `@kylematsuda`
2023-05-30leak_check: remove unused codepathlcnr-13/+0
2023-05-30Auto merge of #112075 - WaffleLapkin:unmkII, r=lcnrbors-109/+127
Replace `tcx.mk_re_*` with `Region::new_*` Second step in implementing https://github.com/rust-lang/compiler-team/issues/616 r? `@lcnr`
2023-05-29Rollup merge of #111988 - BoxyUwU:make_tykind_debug_good, r=compiler-errorsMatthias Krüger-52/+84
Make `TyKind: Debug` have less verbose output Current `TyKind: Debug` impl is basically unusable for debugging, its too verbose even for verbose debugging :rofl: This PR replaces the debug logic for `TyKind` with a more manual debug impl instead of a hand expanded derived impl. This should help make #107084 more reasonable to land since the output of `Ty: Debug` will be better. This isn't a fully completed change to the `Debug` impl of `TyKind` as there's still logic from the derive macro for some variants. Some of the variants are also not consisten with the `-Zverbose` printing of `Ty`, ideally `-Zverbose` printing of `Ty` would also just defer to the debug impl instead of having lots of checks in pretty printing. I plan on fixing this in follow up PRs since it seems tricky to do in this one and its already a large PR :sweat_smile:
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-109/+127
2023-05-29add FIXMElcnr-0/+5
2023-05-29unique borrows are mutating useslcnr-7/+3
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-13/+13
2023-05-29Auto merge of #111748 - nnethercote:Cow-DiagnosticMessage, r=WaffleLapkinbors-17/+18
Use `Cow` in `{D,Subd}iagnosticMessage`. Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile. r? `@WaffleLapkin`
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-17/+18
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-28Auto merge of #111813 - scottmcm:pretty-mir, r=cjgillotbors-14/+14
MIR: opt-in normalization of `BasicBlock` and `Local` numbering This doesn't matter at all for actual codegen, but after spending some time reading pre-codegen MIR, I was wishing I didn't have to jump around so much in reading post-inlining code. So this add two passes that are off by default for every mir level, but can be enabled (`-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals`) for humans.
2023-05-28Add documentation on skip_binder on how to get &T from &EarlyBinder<T>Kyle Matsuda-0/+3
2023-05-28Make EarlyBinder's inner value private; and fix all of the resulting errorsKyle Matsuda-3/+3
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-12/+16
2023-05-28Auto merge of #111378 - jieyouxu:local-shadows-glob-reexport, r=petrochenkovbors-1/+1
Add warn-by-default lint when local binding shadows exported glob re-export item This PR introduces a warn-by-default rustc lint for when a local binding (a use statement, or a type declaration) produces a name which shadows an exported glob re-export item, causing the name from the exported glob re-export to be hidden (see #111336). ### Unresolved Questions - [x] ~~Is this approach correct? While it passes the UI tests, I'm not entirely convinced it is correct.~~ Seems to be ok now. - [x] ~~What should the lint be called / how should it be worded? I don't like calling `use x::*;` or `struct Foo;` a "local binding" but they are `NameBinding`s internally if I'm not mistaken.~~ ~~The lint is called `local_binding_shadows_glob_reexport` for now, unless a better name is suggested.~~ `hidden_glob_reexports`. Fixes #111336.
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-1/+6
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-27Add warn-by-default lint for local binding shadowing exported glob re-export ↵许杰友 Jieyou Xu (Joe)-1/+1
item
2023-05-26better `TyKind::Debug`Boxy-52/+84
2023-05-26print const and type errors in braces not square bracketsBoxy-3/+3
2023-05-26Wait until type_of to remap HIR opaques back to their defn paramsMichael Goulet-1/+1
2023-05-26Auto merge of #111984 - matthiaskrgr:rollup-6u7ynyv, r=matthiaskrgrbors-4/+1
Rollup of 5 pull requests Successful merges: - #111384 (Fix linking Mac Catalyst by including LC_BUILD_VERSION in object files) - #111899 (CGU cleanups) - #111940 (Clarify safety concern of `io::Read::read` is only relevant in unsafe code) - #111947 (Add test for RPIT defined with different hidden types with different substs) - #111951 (Correct comment on privately uninhabited pattern.) Failed merges: - #111954 (improve error message for calling a method on a raw pointer with an unknown pointee) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-26Rollup merge of #111899 - nnethercote:cgu-cleanups, r=wesleywiserMatthias Krüger-4/+1
CGU cleanups Some code clarity improvements I found when reading this code closely. r? ``@wesleywiser``
2023-05-26Auto merge of #111918 - compiler-errors:custom-type-ops-err, r=lcnrbors-2/+0
Use `ErrorGuaranteed` more in MIR type ops Delay bugs more eagerly and pass them through type op infra instead of delaying them at all the usage-sites. Follow up to: https://github.com/rust-lang/rust/pull/111741#discussion_r1203840588 r? `@lcnr`
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-1/+6
2023-05-25Fallible<_> -> Result<_, NoSolution>Michael Goulet-2/+0
2023-05-25Remove ExpnKind::Inlined.Camille GILLOT-5/+2
2023-05-25Use De Morgan's law to simplify logicMichael Howell-6/+6
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2023-05-25remove outdated comment from `is_user_visible_dep` docsMichael Howell-4/+0