-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: Paper over GAT panic #11878
Merged
Merged
fix: Paper over GAT panic #11878
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TIL that Chalk expects the arguments to a generic associated type to come *before* the ones for the parent trait, not *after* as we have been doing with all other nested generics. Fixing this requires a larger refactoring, so for now this just papers over the problem by completely ignoring parameters of associated types. Fixes rust-lang#11769.
bors r+ |
@flodiebold did you mean to mention the issue ID here? (there's a stray |
Yeah, but then I decided it wasn't necessary since there's a test and then forgot... |
Merged
bors bot
added a commit
that referenced
this pull request
Apr 11, 2022
11957: fix panic on GAT r=flodiebold a=skyzh Signed-off-by: Alex Chi <iskyzh@gmail.com> This is still a workaround on GAT panic, and didn't solve the full problem. But at least we won't panic now. False positive is better than panicking and letting VSCode constantly pop out the warning 🤣 This PR is simple -- only apply the #11878 fix on const generics. For normal GATs, just follow the previous approach. This PR fixes #11939, I've added it as a test case. This PR didn't fully fix / #11923. But at least it won't panic now -- will only give a type mismatch error. Not sure if it fixes / #11921, I'll test it later. cc `@flodiebold` for review, thanks! Co-authored-by: Alex Chi <iskyzh@gmail.com>
This was referenced Sep 29, 2022
bors
added a commit
that referenced
this pull request
Oct 3, 2022
internal: change generic parameter order tl;dr: This PR changes the `Substitution` for trait items and methods like so: ```rust trait Trait<TP, const CP: usize> { // note the implicit Self as first parameter type Type<TC, const CC: usize>; fn f<TC, const CC: usize>() {} } impl<TP, const CP: usize> S { fn f<TC, const CC: usize>() {} } ``` - before this PR: `[Self, TP, CP, TC, CC]` for each trait item, `[TP, CP, TC, CC]` for `S::f` - after this PR: `[TC, CC, Self, TP, CP]` for each trait item, `[TC, CC, TP, CP]` for `S::f` --- This PR "inverts" the generic parameters/arguments of an item and its parent. This is to fulfill [chalk's expectation](https://github.com/rust-lang/chalk/blob/d875af0ff196dd6430b5f5fd87a640fa5ab59d1e/chalk-solve/src/rust_ir.rs#L498-L502) on the order of generic arguments in `Substitution`s for generic associated types and it's one step forward for GATs support (hopefully). Although chalk doesn't put any constraint for other items, it feels more natural to get everything aligned than special casing GATs. One complication is that `TyBuilder` now demands its users to pass in parent's `Substitution` upon construction unless it's obvious that the the item has no parent (e.g. an ADT never has parent). All users *should* already know the parent of the item in question, and without this, it cannot be easily reasoned about whether we're pushing the argument for the item or for its parent. Some additional notes: - f8f5a5e: This isn't related to the change, but I felt it's nicer. - 78977cd: There's one major change here other than the generic param order: Default arguments are now bound by the same `Binder` as the item in question rather than a `Binder` limited to parameters they can refer to (i.e. arguments that syntactically appear before them). Now that the order of generic parameters is changed, it would be somewhat complicated to make such `Binder`s as before, and the "full" `Binder`s shouldn't be a problem because we already make sure that the default arguments don't refer to the generic arguments after them with `fallback_bound_vars()`. - 7556f74: This is split from 4385d3d to make it easy to revert if it turns out that the GATs with const generics panic is actually not resolved with this PR. cc #11878 #11957
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TIL that Chalk expects the arguments to a generic associated type to come before the ones for the parent trait, not after as we have been doing with all other nested generics. Fixing this requires a larger refactoring, so for now this just papers over the problem by completely ignoring parameters of associated types.
Fixes #11769.