Skip to content

Don't build ParamEnv and do trait solving in ItemCtxts when lowering IATs #140247

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 1 commit into
base: master
Choose a base branch
from

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Apr 24, 2025

Fixes #108491

Fixes #125879
This was due to updating inhabited predicate stuff which I had to do to make constructing ADTs with IATs in fields not ICE

Fixes #136678 (but no test added, I don't rly care about weird IAT edge cases under GCE)

Fixes #138131
Fixes #138166
Idk random mgca/iat garbage(?) Not sure why these ICEd or why they now don't.

Avoids doing "fully correct" candidate selection for IATs during hir ty lowering when in item signatures as it almost always leads to a query cycle from trying to build a ParamEnv. I replaced it with a "simple" heuristic that assumes all aliases are equal to all other aliases and tries to unify the self type with self type of each candidate's impl.

A potential alternative would be to replace all the generic parameters in the self type with inference variables as then it would be "truly" environment agnostic. I think this is somewhat subpar as we would be weakening how much we used the self type to guide candidate selection and that's the only way for the user to attempt to specify which IAT to resolve to.

In general that's also why I think doing something hacky here instead of just throwing our hands up and saying "ItemCtxts should make inference variables" and not filtering any candidates out, is a good idea (there is no way for users to disambiguate such cases).

I'm not really sure how this interacts with #126651, though I'm also not really sure its super important to support projecting IATs from IAT self types given we don't even support T::Assoc::Other for trait-associated types so didn't give much thought to how this might fit in with that.

r? @compiler-errors
cc @fmease

@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 24, 2025
@rustbot
Copy link
Collaborator

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

HIR ty lowering was modified

cc @fmease

}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Alias(_, _) = ty.kind() {
Copy link
Member Author

@BoxyUwU BoxyUwU Apr 24, 2025

Choose a reason for hiding this comment

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

Possibly we're supposed to handle free type aliases specially here instead of replacing them with inference variables as it should be possible to just normalize them. Though that's not the behaviour that would happen w/ new solver deferred projection equality + ignoring returned goals

// are unable to explicitly disambiguate which impl to use other than by specifying the
// self type.

struct ReplaceAliasesWithInfer<'tcx, 'a>(&'a InferCtxt<'tcx>);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this folder w/ the new solver? We could just relate and throw away all the alias-relate predicates?

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 with the new solver this is unnecessary

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

☔ The latest upstream changes (presumably #140388) 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
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.
Projects
None yet
4 participants