-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Chalkify: Add builtin Copy/Clone #60183
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Add builtin impls for int and float inference vars in chalk
- Loading branch information
commit 56ab3e70e7eeeaa9801c1e32c2a459df8dfc4ab8
There are no files selected for viewing
This file contains hidden or 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These four solutions are only there to artificially trigger an ambiguity if we encounter an inference variable whatever its type, because we don't want to actually enumerate all solutions.
If we want int and float vars to always be
Copy
/Clone
without having to resolve them, we should add a match arm:And probably do that for
Sized
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the match arm makes sense, but is this more of an optimization or a behavior change? (Leaving aside the fact that not all integer/float types were included.) Was there any reason that you included these four types in particular?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a change of behavior, but probably would only affect error reporting in the end?
We’re talking about goals like
?T: Clone
, eventually either?T
is resolved and the goal will be re-evaluated, or?T
remains unresolved and we’ll have a type inference error so I guess it does not matter...Anyway I think that the code in
rustc::traits::select
does say that unresolved int / float inference variables always implementCopy
/Clone
(and probably does the same forSized
), so let’s do that.—
I included these four types so that each kind of inference variable has at least two solutions to unify against, in order to trigger ambiguity. For example, if I only pushed
i32
andf32
as solutions, then an?IntVar
inference variable would only unify againsti32
and the solver would think that the only solution to my goal isi32: Clone
and would arbitrarily think that?IntVar == i32
, while I wanted an ambiguous answer.However if we only cared about triggering ambiguity for type variables (because we would now eagerly answer
Implemented(?IntVar: Clone)
), then pushing only two arbitrary solutions (e.g.f32
andi32
) would suffice since type variables will unify with whatever they want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, done.