Skip to content

Use the new solver in the impossible_predicates #136988

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 1 commit into from
May 15, 2025

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Feb 13, 2025

The old solver is unsound for many reasons. One of which was weaponized by @lcnr in #140212, where the old solver was incompletely considering a dyn vtable method to be impossible and replacing its vtable entry with a null value. This null function could be called post-mono.

The new solver is expected to be less incomplete due to its correct handling of higher-ranked aliases in relate. This PR switches the impossible_predicates query to use the new solver, which patches this UB.

r? lcnr

@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@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. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 13, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2025
…s, r=<try>

Use the new solver in the `impossible_predicates`

r? lcnr
@bors
Copy link
Collaborator

bors commented Feb 13, 2025

⌛ Trying commit 42565da with merge 6aac808...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Feb 13, 2025

☀️ Try build successful - checks-actions
Build commit: 6aac808 (6aac80825ffa245e49ce6e80bdcfdc433dbb3559)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6aac808): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

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.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
0.5% [0.5%, 0.6%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 3
All ❌✅ (primary) 0.3% [0.3%, 0.3%] 1

Max RSS (memory usage)

Results (primary -1.6%, secondary -2.9%)

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.6% [-2.3%, -0.9%] 2
Improvements ✅
(secondary)
-2.9% [-3.7%, -2.4%] 3
All ❌✅ (primary) -1.6% [-2.3%, -0.9%] 2

Cycles

Results (secondary 2.5%)

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
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 788.486s -> 790.527s (0.26%)
Artifact size: 347.76 MiB -> 347.72 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 14, 2025
@compiler-errors
Copy link
Member Author

Ok let me fix AFIDT first.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 14, 2025
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Feb 14, 2025
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

(and crater)

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 19, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 19, 2025
…s, r=<try>

Use the new solver in the `impossible_predicates`

r? lcnr
@bors
Copy link
Collaborator

bors commented Mar 19, 2025

⌛ Trying commit 40269a1 with merge 4c525d4...

@bors
Copy link
Collaborator

bors commented Mar 19, 2025

☀️ Try build successful - checks-actions
Build commit: 4c525d4 (4c525d43052e921548191f82f6ed9e2f9e98dcb1)

@rust-timer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-136988 created and queued.
🤖 Automatically detected try build 4c525d4
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 19, 2025
@compiler-errors compiler-errors added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 23, 2025
@compiler-errors
Copy link
Member Author

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 23, 2025

Team member @compiler-errors 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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 23, 2025
@compiler-errors
Copy link
Member Author

This was the last decision we made about utilizing the new solver in the compiler: #123594 (comment)

Going to start a types FCP to officially state that going forward, the @rust-lang/initiative-trait-system-refactor has the authority to enable the use of the new solver on stable without FCPs as long as t-types is pinged in the PR and the affected area is neither relevant for soundness nor backwards compatibility.

Given that this is a soundness fix, I think it warrants a re-FCP for this specific case.

@lcnr
Copy link
Contributor

lcnr commented Apr 23, 2025

We're checking fully concrete goals in an empty environment. I believe that the new solver is able to handle this case well and certainly expect it to be more complete than the old solver. There should be far fewer, if any, cases, where we incorrectly return NoSolution even if the goal should actually hold.

This only avoids monomorphizing impossible functions, so it should not be user-visible.

// Proving `u32: Trait<fn(u32)>` fails due to incompleteness.
// We don't add the method to the vtable of `dyn Method`, so
// calling it causes UB.
generic::<u32>(&());
Copy link
Member

Choose a reason for hiding this comment

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

  • goal: u32: Trait<fn(u32)>
  • impl candidate: ?t: Trait<for<'a> fn(<?t as Id>::This<'a>)>
  • doesn't apply in old solver as u32 eq <?t as Id>::This<'a> doesn't hold because we treat all aliases as rigid, and, its an ambig alias that cant be normalized to infer because escaping bound vars?
  • applies in new solver because we emit a <?t as Id>::This<'!a_u1> alias-relate u32 goal which can succeed once we infer ?t=u32?

Is that the right understanding of what's going on here? And then its just generally unsound for checking impossible preds to consider preds to be impossible if they actually aren't.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct.

In other words, the impossible preds query needs to be complete b/c we use "this goal is impossible to satisfy" responses to skip monomorphizing items with bad where clauses in codegen. Here in vtable, but also as monomorphization roots, etc.

Comment on lines +693 to +696
let (infcx, param_env) = tcx
.infer_ctxt()
.with_next_trait_solver(true)
.build_with_typing_env(ty::TypingEnv::fully_monomorphized());
Copy link
Member

Choose a reason for hiding this comment

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

It feels kind of weird to be using the new trait solver "because its more complete" while also using a typing mode that is allowed to be incomplete (unlike coherence mode). I guess it is also true that the not-required-to-be-complete solver modes in the new solver should less incomplete than the not-required-to-be-complete-solver-modes in the old solver. So still a good change and it being weird is kind of pre-existing.

Do we expect the trait solver to always be complete even outside of coherence in some specific circumstances? What are those circumstances?

Copy link
Contributor

@lcnr lcnr May 7, 2025

Choose a reason for hiding this comment

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

Do we expect the trait solver to always be complete even outside of coherence in some specific circumstances? What are those circumstances?

I think the following is required in all TypingMode

  • goal holds without infer vars in a generic context -> goal holds in an empty env after instantiating this context (otherwise we'd have to recheck all goals during monomorphization)
  • goal holds with infer vars, constraining the infer vars to some concrete type also means the goal holds (otherwise we'd need to keep goals around until they have no infer vars, even if they hold. This would result in a MIR typeck ICE if it goes wrong)

So we'd have "for<T: Clone> Foo<T>: Clone implies Foo<u32>: Clone" and "Foo<?x>: Clone implies Foo<Vec<u32>>: Clone".

I am not totally sure whether Foo<?x>: Clone implies Foo<Vec<?x>>: Clone and think that not doing so wouldn't be unsound, just questionable.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label May 15, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented May 15, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label May 15, 2025
@compiler-errors
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 15, 2025
@lcnr
Copy link
Contributor

lcnr commented May 15, 2025

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented May 15, 2025

📌 Commit 257f687 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 15, 2025
@bors
Copy link
Collaborator

bors commented May 15, 2025

⌛ Testing commit 257f687 with merge c4e05e53d19b550a358ee8b2e29ecd5a11075800...

@bors
Copy link
Collaborator

bors commented May 15, 2025

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

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

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 d163a28 (parent) -> c4e05e5 (this PR)

Test differences

Show 4 test diffs

Stage 1

  • [ui] tests/ui/traits/vtable/impossible-method.rs#current: [missing] -> pass (J0)
  • [ui] tests/ui/traits/vtable/impossible-method.rs#next: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/traits/vtable/impossible-method.rs#current: [missing] -> pass (J1)
  • [ui] tests/ui/traits/vtable/impossible-method.rs#next: [missing] -> pass (J1)

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard c4e05e53d19b550a358ee8b2e29ecd5a11075800 --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. x86_64-apple-1: 11122.2s -> 7412.5s (-33.4%)
  2. dist-apple-various: 10358.5s -> 7424.1s (-28.3%)
  3. dist-x86_64-apple: 11586.4s -> 8656.9s (-25.3%)
  4. aarch64-apple: 5105.4s -> 4710.9s (-7.7%)
  5. dist-x86_64-musl: 7408.3s -> 7962.1s (7.5%)
  6. dist-armv7-linux: 5317.7s -> 5711.8s (7.4%)
  7. dist-aarch64-apple: 5827.8s -> 5404.2s (-7.3%)
  8. x86_64-apple-2: 5290.9s -> 5629.2s (6.4%)
  9. dist-aarch64-msvc: 8416.2s -> 8897.4s (5.7%)
  10. dist-x86_64-freebsd: 5281.0s -> 4990.2s (-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 (c4e05e5): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.9% [0.4%, 1.1%] 5
Regressions ❌
(secondary)
0.5% [0.3%, 1.0%] 27
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.1%] 6
All ❌✅ (primary) 0.8% [-0.1%, 1.1%] 6

Max RSS (memory usage)

Results (primary 1.4%, secondary 1.7%)

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)
2.4% [1.0%, 4.5%] 3
Regressions ❌
(secondary)
1.7% [1.2%, 2.2%] 2
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [-1.5%, 4.5%] 4

Cycles

Results (primary -0.8%)

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

Binary size

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

Bootstrap: 772.725s -> 773.554s (0.11%)
Artifact size: 365.38 MiB -> 365.48 MiB (0.03%)

@rustbot rustbot added the perf-regression Performance regression. label May 15, 2025
@compiler-errors
Copy link
Member Author

Lol. I'm somewhat surprised that perf has diverged so dramatically between March and May.

Previous run: #136988 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-types Relevant to the types 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.

incompletely relating alias args is unsound during vtable creation
10 participants