Skip to content
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

Fix ICE when multiple supertrait substitutions need assoc but only one is provided #133392

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 Nov 23, 2024

Dyn traits must have all of their associated types constrained either by:

  1. writing them in the dyn trait itself as an associated type bound, like dyn Iterator<Item = u32>,
  2. A supertrait bound, like trait ConstrainedIterator: Iterator<Item = u32> {}, then you may write dyn ConstrainedIterator which doesn't need to mention Item.

However, the object type lowering code did not consider the fact that there may be multiple supertraits with different substitutions, so it just used the associated type's def id as a key for keeping track of which associated types are missing:

let mut associated_types: FxIndexMap<Span, FxIndexSet<DefId>> = FxIndexMap::default();

This means that we can have missing associated types when there are mutliple supertraits with different substitutions and only one of them is constrained, like:

trait Sup<T> {
    type Assoc: Default;
}

impl<T: Default> Sup<T> for () {
    type Assoc = T;
}
impl<T: Default, U: Default> Dyn<T, U> for () {}

trait Dyn<A, B>: Sup<A, Assoc = A> + Sup<B> {}

The above example allows you to name <dyn Dyn<i32, u32> as Sup<u32>>::Assoc even though it is not possible to project since it's neither constrained by a manually written projection bound or a supertrait bound. This successfully type-checks, but leads to a codegen ICE since we are not able to project the associated type.

This PR fixes the validation for checking that a dyn trait mentions all of its associated type bounds. This is theoretically a breaking change, since you could technically use that dyn Dyn<A, B> type mentionedin the example above without actually projecting to the bad associated type, but I don't expect it to ever be relevant to a user since it's almost certainly a bug. This is corroborated with the crater results1, which show no failures2.

Crater: #133392 (comment)

Fixes #133388

Footnotes

  1. I cratered this originally with Fix dyn incompleteness with multiple supertraits with different substitutions #133397, which is a PR that is stacked on top, then re-ran crater with just the failures from that PR.

  2. If you look at the crater results, it shows all of the passes as "unknown". I believe this is a crater bug, since looking at the results manually shows them as passes.

@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 Nov 23, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2024

changes to the core type system

cc @compiler-errors, @lcnr

HIR ty lowering was modified

cc @fmease

@compiler-errors
Copy link
Member Author

@bors try

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 23, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2024
Fix ICE when multiple supertrait substitutions need assoc but only one is provided

I'll write more here when the crate run is done.

Fixes rust-lang#133388

r? lcnr
`@rustbot` author
@bors
Copy link
Contributor

bors commented Nov 23, 2024

⌛ Trying commit 8a10f68 with merge c7377f6...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 23, 2024

☀️ Try build successful - checks-actions
Build commit: c7377f6 (c7377f633f2c785ef968ab6517e5218297777ae5)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-133392 created and queued.
🤖 Automatically detected try build c7377f6
🔍 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 23, 2024
@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 Nov 29, 2024
@compiler-errors

This comment was marked as outdated.

@craterbot

This comment was marked as outdated.

@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 Nov 29, 2024
@craterbot

This comment was marked as off-topic.

@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 Nov 29, 2024
@compiler-errors
Copy link
Member Author

@craterbot
Copy link
Collaborator

👌 Experiment pr-133392-1 created and queued.
🤖 Automatically detected try build c7377f6
⚠️ Try build based on commit 8a10f68, but latest commit is 2a0ede8. Did you forget to make a new try build?
🔍 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 the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Nov 30, 2024
@craterbot
Copy link
Collaborator

🚧 Experiment pr-133392-again is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-133392-again is completed!
📊 0 regressed and 0 fixed (1598 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ 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 Nov 30, 2024
@compiler-errors

This comment was marked as outdated.

@craterbot

This comment was marked as outdated.

@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 Nov 30, 2024
@compiler-errors
Copy link
Member Author

@rfcbot fcp merge

Hi @rust-lang/types. Please see the PR description. This fixes what I consider to be a minor issue in the way we validate the associated types that are required to be specified for a dyn Trait. While it's a theoretical breakage (and therefore @lcnr asked me to start an FCP), I don't believe this is a major decision.

@rfcbot
Copy link

rfcbot commented Nov 30, 2024

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 Nov 30, 2024
@bors
Copy link
Contributor

bors commented Dec 1, 2024

☔ The latest upstream changes (presumably #133694) made this pull request unmergeable. Please resolve the merge conflicts.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Dec 4, 2024
@rfcbot
Copy link

rfcbot commented Dec 4, 2024

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

@lcnr
Copy link
Contributor

lcnr commented Dec 4, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 4, 2024

📌 Commit 24da053 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 Dec 4, 2024
@lcnr
Copy link
Contributor

lcnr commented Dec 4, 2024

oh lel, i thought it finished the fcp period 😅

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 4, 2024
Comment on lines +7 to +8
LL | let q: <dyn Dyn<i32, u32> as Sup<u32>>::Assoc = Default::default();
| ^^^^^^^^^^^^^ help: specify the associated type: `Dyn<i32, u32, Assoc = Type>`
Copy link
Member

Choose a reason for hiding this comment

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

Kind of funny that you just cant specify the associated type equality bounds here

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a fundamental limitation of Rust atm. I can't be arsed to improve the diagnostic, though I can open an issue for the diagnostic being confusing if you care.

@bors
Copy link
Contributor

bors commented Dec 11, 2024

☔ The latest upstream changes (presumably #134164) made this pull request unmergeable. Please resolve the merge conflicts.

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-author Status: This is awaiting some action (such as code changes or more information) from the author. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check for dyn providing all of its projections is incomplete w.r.t. different supertrait substitutions
8 participants