Skip to content

Make well-formedness predicates no longer coinductive #140208

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Apr 23, 2025

This PR makes well-formedness no longer coinductive. It was made coinductive in #98542, but AFAICT this was only to fix UI tests since we stopped lowering where Ty: to an empty-region outlives predicate but to a WF predicate instead.

Arguably it should lower to something completely different, something like a "type mentioned no-op predicate", but well-formedness serves this purpose fine today, and since no code (according to crater) relies on this coinductive behavior, we'd like to avoid having to emulate it in the new solver.

Fixes #123456 (I didn't want to add a test since it seems low-value to have a ICE test for a fuzzer minimization that is basically garbage code.)

Fixes #109764 (not sure if this behavior is emulatable w/o coinductive WF?)

Fixes rust-lang/trait-system-refactor-initiative#169

r? lcnr

@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. labels Apr 23, 2025
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

@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 Apr 23, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2025
@bors
Copy link
Collaborator

bors commented Apr 23, 2025

⌛ Trying commit 3f4d6c9 with merge 099e089...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Apr 23, 2025

☀️ Try build successful - checks-actions
Build commit: 099e089 (099e089ab723e6ee96175f3496051098c60a4cd4)

@rust-timer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-140208 created and queued.
🤖 Automatically detected try build 099e089
🔍 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 added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 23, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (099e089): comparison URL.

Overall result: no relevant changes - 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 benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -0.3%)

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

Cycles

Results (primary 0.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.3% [1.0%, 1.7%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.9%, -0.7%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-1.9%, 1.7%] 6

Binary size

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

Bootstrap: 775.475s -> 776.132s (0.08%)
Artifact size: 365.04 MiB -> 365.04 MiB (-0.00%)

@craterbot
Copy link
Collaborator

🚧 Experiment pr-140208 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-140208 is completed!
📊 66 regressed and 4 fixed (619632 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Apr 24, 2025
@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

⌛ Trying commit 8b2295f with merge aa39591...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 28, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

☀️ Try build successful - checks-actions
Build commit: aa39591 (aa39591f8789657c0627c7890f58b20d7a4c4b51)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot

This comment was marked as outdated.

@craterbot craterbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2025
@craterbot

This comment was marked as outdated.

@compiler-errors

This comment was marked as outdated.

@craterbot

This comment was marked as outdated.

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Apr 29, 2025
@craterbot
Copy link
Collaborator

👌 Experiment pr-140208-2 created and queued.
🤖 Automatically detected try build aa39591
🔍 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 added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-140208-2 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-140208-2 is completed!
📊 3 regressed and 0 fixed (2765 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Apr 29, 2025
@compiler-errors compiler-errors changed the title [crater] WF is not coinductive Make well-formedness predicates no longer coinductive Apr 29, 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 29, 2025
@compiler-errors compiler-errors marked this pull request as ready for review April 29, 2025 03:32
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 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.

@lcnr
Copy link
Contributor

lcnr commented Apr 29, 2025

I would like to stop treating well-formed goals as coinductive, even if the reasoning for why it will be problematic is a bit far fetched.


We may want to elaborate WellFormed(Ty) where-clauses, e.g. allow a &'a T: where-bound to imply T: 'a.

We currently only elaborate where-bounds by eagerly extending the ParamEnv. we may want to generalize elaboration to simply consider sub-traits when proving super traits, e.g.

trait Trait: Sup {}
fn is_sup<T: Sup>() {}
fn foo<T: Trait>() {
    is_sup::<T>();
}

This currently elaborates the env to [T: Trait, T: Sup] and then proves T: Sup using that environment directly.

Alternatively, we could not elaborate the env and instead have the following proof tree:

  • T: Sup prove via "super trait of Trait"
    • T: Trait via where-bound.

When doing this, we need to be careful that this doesn't allow for cyclic reasoning:

trait Trait: Sup {}
impl<T> Trait for T {}
fn is_trait<T: Trait>() {}
fn foo<T>() {
    is_trait::<T>();
}

If we simply check T: Sup when checking that he impl is well-formed:

  • T: Sup prove via "super trait of Trait"
    • T: Trait prove via impl

We therefore need to prove T: Sup non-productively whenever we want to prove T: Trait

  • T: Sup prove via "super trait of Trait"
    • T: Trait prove via impl, requires provnig super trait bounds
      • T: Sup non-productive cycle

With this, let's look at the following example:

struct WfImpliesOutlives<'a, T> {
    field: &'a T,
}
where
    T: 'a,
    Wf<'a, T>:;

Now, one could imagine that elaborating WellFormed clauses can also go backwards, i.e. proving T: 'a by checking wf(WfImpliesOutlives<'a, T>)

  • T: 'a via "implied by well-formedness"
    • wf(WfImpliesOutlives<'a, T>)
      • T: 'a cycle
      • wf(WfImpliesOutlives<'a, T>) cycle

This means these cycles would have to be non-productive. With the current setup this is only achievable by making nested goals of WellFormed goals to be non-productive. I don't see a clean design where wf -> wf cycles are productive but wf -> other-predicate -> wf are not.

While I don't know whether we'll ever lazily elaborate WellFormed goals, I would prefer to not have to worry about this at all.


This PR causes the following snippet to no longer compile

struct Foo
where
    Foo:;

struct Bar
where
   Vec<Bar>:;

We do not break crates which have feature(generic_const_exprs) enabled as this feature relies on [whatever; CONST]: where bounds at add ConstEvaluatable clauses into the environment. The feature is very much incomplete and will need to get significantly reworked before landing, and any stabilization should use a better syntax.

It's generally difficult to support feature(generic_const_exprs) with the new solver and we currently want it to get replaced by a better approach before we're stabilizing the new solver.

This is why I believe that keeping WellFormed goals coinductive only when GCE is enabled is fine for now. Removing this special case for GCE later on should not require an FCP.

There is no crater breakage.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 29, 2025

Team member @lcnr 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 29, 2025
@jackh726
Copy link
Member

I'm okay with walking this back if we avoid actual breakage, even if the reasoning is "this is a bit weird and may block us in the future". I don't like the special-casing for GCE, but we're not walking through a door that we can't step back through if its actually always going to be required there, and its unstable.

@BoxyUwU
Copy link
Member

BoxyUwU commented Apr 29, 2025

I expect this special casing will not be necessary with mgca (or a potential full gca which would subsume gce), so with my const generics hat on I'm not too worried about this special case 🤔 It kind of sucks that we seem to be accumulating lists of hacks just to avoid breaking too much (unstable) gce code, but it is a relatively pragmatic choice and hopefully won't be necessary for too much longer...

@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 5, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented May 5, 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 5, 2025
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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
10 participants