Skip to content

Set groundwork for proper const normalization #140549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2025

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented May 1, 2025

r? lcnr

Updates a lot of our normalization/alias infrastructure to be setup to handle mgca aliases and normalization once const items are represented more like aliases than bodies. Inherent associated consts are still super busted, I didn't update the assertions that IACs the right arg setup because that winds up being somewhat involved to do before proper support for normalizing const aliases is implemented.

I dont intend for this to have any effect on stable. We continue normalizing via ctfe on stable and the codepaths in project for consts should only be reachable with mgca or ace.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 1, 2025

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in match checking

cc @Nadrieril

// system consts that we can retrieve with some `query const_arg_of_alias` query. Evaluating the
// constant is "close enough" to getting the actual rhs of the const item for now even if it might
// lead to some cycles
super::evaluate_const(selcx.infcx, alias_ct, param_env)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature(associated_const_equality) might be a bit more cycle prone now due to evaluating here instead of normalizing to the impl definition and then evaluating? All the tests still pass though so I guess its fine- and both this and the previous way it worked can't stick around long term anyway.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to rebase

also, pls move the normalize.rs move AliasKind branches into subfn into a separate commit if possible. Are there any other changes to that code while moving them?

@BoxyUwU
Copy link
Member Author

BoxyUwU commented May 1, 2025

merge conflicts :despair:

@BoxyUwU
Copy link
Member Author

BoxyUwU commented May 1, 2025

also, pls move the normalize.rs move AliasKind branches into subfn into a separate commit if possible. Are there any other changes to that code while moving them?

Kinda, I had to change stuff from being working on AliasTy to AliasTerm so there's some minor changes for getting the types to line up, but behaviourally speaking it should be the same. I originally had it as its own commit but honestly it didn't really seem to matter much when I was looking over the changes because I had to switch from AliasTy to AliasKind at the same time 🤔 though i guess i could have just not done that... okay lemme split this up

@BoxyUwU BoxyUwU force-pushed the proper_const_norm branch from 6c4b953 to ed128eb Compare May 1, 2025 13:22
@BoxyUwU BoxyUwU force-pushed the proper_const_norm branch from ed128eb to 25821fd Compare May 1, 2025 13:39
@BoxyUwU
Copy link
Member Author

BoxyUwU commented May 1, 2025

Okay first commit should contain no changes to the norm logic other than replacing the two match arms with an if/else. Second commit should be able to be reviewed to see the actual changes to the logic

@BoxyUwU BoxyUwU force-pushed the proper_const_norm branch from 25821fd to 9c29713 Compare May 1, 2025 13:43
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member Author

BoxyUwU commented May 1, 2025

Oh

@rustbot
Copy link
Collaborator

rustbot commented May 1, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@BoxyUwU
Copy link
Member Author

BoxyUwU commented May 1, 2025

One of the crashes tests is also fixed by #140553 and in an actually principled way so I've just removed it and will let that PR add the test (which ive verified still ICEs under this PR). The other test I've updated to still reproduce since this PR doesn't really fix it afaik

self.obligations.extend(
infcx.tcx.predicates_of(free.def_id).instantiate_own(infcx.tcx, free.args).map(
|(mut predicate, span)| {
if free.has_escaping_bound_vars() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do that if free has escaping bound vars instead of checking the predicate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems generally wrong to be instantiating early binders with bound vars, going to open an issue about this

@BoxyUwU BoxyUwU force-pushed the proper_const_norm branch 3 times, most recently from 5ea4762 to 5fb578e Compare May 1, 2025 19:01
@BoxyUwU BoxyUwU force-pushed the proper_const_norm branch from 5fb578e to 9ec8373 Compare May 1, 2025 19:05
@lcnr
Copy link
Contributor

lcnr commented May 2, 2025

@bors r+ rollup=iffy

@bors
Copy link
Collaborator

bors commented May 2, 2025

📌 Commit 9ec8373 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2025
VlaDexa added a commit to VlaDexa/rust that referenced this pull request May 2, 2025
Set groundwork for proper const normalization

r? lcnr

Updates a lot of our normalization/alias infrastructure to be setup to handle mgca aliases and normalization once const items are represented more like aliases than bodies. Inherent associated consts are still super busted, I didn't update the assertions that IACs the right arg setup because that winds up being somewhat involved to do *before* proper support for normalizing const aliases is implemented.

I dont *intend* for this to have any effect on stable. We continue normalizing via ctfe on stable and the codepaths in `project` for consts should only be reachable with mgca or ace.
@bors
Copy link
Collaborator

bors commented May 4, 2025

⌛ Testing commit 9ec8373 with merge 1bea580...

@bors
Copy link
Collaborator

bors commented May 4, 2025

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 1bea580 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 4, 2025
@bors bors merged commit 1bea580 into rust-lang:master May 4, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 4, 2025
Copy link

github-actions bot commented May 4, 2025

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 3559e0a (parent) -> 1bea580 (this PR)

Test differences

Show 20 test diffs

Stage 1

  • [crashes] tests/crashes/133066.rs: pass -> [missing] (J1)

Stage 2

  • [crashes] tests/crashes/133066.rs: pass -> [missing] (J0)

Additionally, 18 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 1bea580f364c65bd5f7380a1056e150df7b8a1a6 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-x86_64-apple: 11442.2s -> 8427.4s (-26.3%)
  2. dist-apple-various: 5964.0s -> 6832.9s (14.6%)
  3. x86_64-apple-1: 7001.7s -> 7779.5s (11.1%)
  4. aarch64-apple: 4040.3s -> 3621.5s (-10.4%)
  5. x86_64-apple-2: 4179.6s -> 4535.9s (8.5%)
  6. x86_64-msvc-1: 8641.9s -> 9364.2s (8.4%)
  7. test-various: 4267.9s -> 3957.0s (-7.3%)
  8. x86_64-gnu-llvm-19-3: 7168.1s -> 6751.2s (-5.8%)
  9. x86_64-gnu-distcheck: 4773.2s -> 5042.0s (5.6%)
  10. dist-x86_64-msvc-alt: 7853.7s -> 7419.8s (-5.5%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1bea580): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.7% [0.3%, 1.4%] 3
Regressions ❌
(secondary)
0.5% [0.1%, 0.6%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [0.3%, 1.4%] 3

Max RSS (memory usage)

Results (primary 0.4%, secondary 2.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.0% [0.4%, 2.9%] 12
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 2
Improvements ✅
(primary)
-0.6% [-1.0%, -0.4%] 7
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [-1.0%, 2.9%] 19

Cycles

Results (primary -0.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.8% [0.5%, 1.4%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-0.7%, -0.4%] 11
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.2% [-0.7%, 1.4%] 14

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 769.569s -> 770.15s (0.08%)
Artifact size: 365.54 MiB -> 365.38 MiB (-0.04%)

@rustbot rustbot added the perf-regression Performance regression. label May 4, 2025
@Mark-Simulacrum
Copy link
Member

Most regressions are small, and a few look like non-noise. Looking at a function-level diff of the syn-1 benchmark... it looks like the changes are mostly small-ish changes around inlining, which doesn't seem worth further investigation.

<  13,419,979  ???:
   36,250,708    <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
  -20,035,552    <rustc_trait_selection::traits::select::SelectionContext>::poly_select::{closure#0}
  -11,388,056    <rustc_trait_selection::traits::select::SelectionContext>::match_impl::{closure#0}
    9,881,516    rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::explicit_predicates_of
   -9,273,148    rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::explicit_predicates_of::dynamic_query::{closure#2}::{closure#0}, rustc_mid>
   -7,724,715    <rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation::{closure#0}::{closure#0}
    6,964,830    <rustc_trait_selection::traits::select::SelectionContext>::assemble_candidates
    5,811,720    <rustc_middle::ty::context::TyCtxt>::recursion_limit
   -1,461,675    rustc_trait_selection::traits::project::opt_normalize_projection_term

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants