Always check ConstArgHasType even when otherwise ignoring#152931
Always check ConstArgHasType even when otherwise ignoring#152931rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ConstArgHasType even when otherwise ignoring#152931Conversation
|
thx for taking this on for me |
309ca91 to
620edeb
Compare
|
changes to the core type system cc @lcnr |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Background ContextFirst, it's important to note that:
This PR does not fundamentally change the above. Second, in the past, we lowered many things to anon consts. In doing so, we implicitly caused a typecheck of constants to happen, by enforcing that the body of the anon const matched with the type of the anon const.
This typecheck always happend, regardless of if the usage of the anon const was inside a free type alias or trait object reference. In other words, these used to cause compiler errors:
However, recently (a few months ago) we changed how some constants are desugared, no longer generating anon consts for them, and instead representing them immediately. This caused consts in these locations to stop being typechecked. Actual ChangeEventually, we would like to begin wfchecking free type aliases and trait objects. Today is not that day, so instead, this PR is reintroducing typechecking for constants, to minimize the eventual breakage that will be caused by wfchecking type aliases and trait objects.
Important to note is that ConstArgHasType cannot interact with lifetimes from a Crater BreakageA few crates have already slipped in some "invalid" code, here's a crater run: #150322 (comment) There are no crater breakages around the trait objects part of this PR. Here's an example breakage of the free type alias part of this PR: error: the constant `MODE` is not of type `usize`
--> src/lfstd.rs:92:1
|
92 | type AllocScqRing<const MODE: bool> = ScqRing<Box<[CachePadded<AtomicUsize>]>, MODE>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `bool`
|
note: required by a const generic parameter in `ScqRing`
--> src/scq.rs:47:23
|
47 | pub struct ScqRing<I, const MODE: usize> {
| ^^^^^^^^^^^^^^^^^ required by this const generic parameter in `ScqRing`Note that even though these type aliases are clearly incorrect, they are still useable by downstream code - this code compiles successfully before this PR, but fails after it: struct Struct<const N: usize> {}
type Foo<const B: bool> = Struct<B>;
type Bar<const N: usize> = Foo<N>;
let x: Bar<1_usize>;The breakage is small enough that one person (me) could easily help fix up broken crates. However, the longer we wait, the more breakage will creep in. We've waited a few months already so it's not desperately urgent, but still. |
|
r? BoxyUwU |
|
cc @rust-lang/types See: #152931 (comment) |
|
Team member @BoxyUwU has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This PR checks that the type of constant arguments matches the generic parameter instantiated by them when checking that the containing item is well-formed. We do not go back to calling HIR typeck for them. Is that correct? |
doublechecked with boxy (was only 90% sure of exact definitions of words), that is correct! "most" constants still lower to anonconsts still, it's just very simple stuff that is now directly represented (as of a few months ago), without lowering to an anon const. So, this PR is just covering those simple things that are no longer anonconsts. AFAIK, anonconsts always have been and continue to be HIR typechecked. |
This comment has been minimized.
This comment has been minimized.
|
So the RFC comment listing breaking changes wasn't fully complete, as this causes unused diverging type aliases to now fail to compile. I didn't realize that, sorry. Maybe that's ok? Is a new RFC period needed? |
|
Ah, sorry, ignore me, it only fails with the unnormalized_obligations -> obligations change (see Boxy's review comment above). Leaving it as unnormalized_obligations does not seem to attempt to const eval the diverging things. I think. |
d25c2e4 to
e9c273e
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
As far as I can tell, there were two crates broken in the crater run - one of which, |
|
@bors r+ rollup=never I don't think it makes sense to wait for the fix PR to be merged since that crate has been inactive for a while now (and of course the library author still has a couple months to merge it before this PR hits stable) |
|
📋 This PR cannot be approved because it currently has the following label: |
|
@bors r+ rollup=never |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing eb9d3ca (parent) -> f66622c (this PR) Test differencesShow 8 test diffsStage 1
Stage 2
Additionally, 2 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard f66622c7eca7fc48ccc4dac848ff911b09a4d566 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (f66622c): comparison URL. Overall result: ❌ regressions - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -2.7%, secondary -6.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.0%, secondary 6.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 484.336s -> 484.979s (0.13%) |
|
perf triage: These regressions look real, and it seems like they were not discussed before merge. Regressed benchmarks are both type-heavy and and the regression seems to be entirely in typeck ( I assume some regression is expected because there's more work to do, but is it this much? Is it possible to reduce the impact in some followup? This fixes a regression so I also assume we don't want to revert this. |
|
typenum has a lot of type aliases, so doing additional work for them causing a regression seems expected to me. Looking at the code, I don't know how to avoid this regression |
|
Ok, thanks for confirmation. Let's mark this as triaged then. @rustbot label: +perf-regression-triaged |
View all comments
fixes #149774
helping @BoxyUwU finish up #150322, this is a simple tweak/finishing-up of that PR.
this is a breaking change that crater detected has some issues with in Boxy's PR, and hence needs a t-types FCP. I can go and help fix those crates if/once the break is signed off on.