-
Notifications
You must be signed in to change notification settings - Fork 177
fix preserve Literal through generic function calls #1468
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
Draft
asukaminato0721
wants to merge
8
commits into
facebook:main
Choose a base branch
from
asukaminato0721:1138
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3d4f71
fix
asukaminato0721 12a3da4
fix some
asukaminato0721 8f1cdf9
fix some
asukaminato0721 2d7569a
some more fix
asukaminato0721 e1a5358
fix some
asukaminato0721 4da45c9
fix
asukaminato0721 de2d396
class parameter back to A[int]
asukaminato0721 2ec6beb
fix
asukaminato0721 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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1196,7 +1196,22 @@ impl<'a, Ans: LookupAnswer> Subset<'a, Ans> { | |
| let t1 = t1.clone(); | ||
| drop(v1_ref); | ||
| drop(variables); | ||
| self.is_subset_eq(&t1, t2) | ||
| match self.is_subset_eq(&t1, t2) { | ||
| Ok(()) => Ok(()), | ||
| Err(err) => { | ||
| let t1_promoted = | ||
| t1.clone().promote_literals(self.type_order.stdlib()); | ||
| if t1_promoted != t1 { | ||
| self.solver | ||
| .variables | ||
| .lock() | ||
| .update(*v1, Variable::Answer(t1_promoted.clone())); | ||
| self.is_subset_eq(&t1_promoted, t2) | ||
| } else { | ||
| Err(err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Variable::Quantified(q) => { | ||
| let name = q.name.clone(); | ||
|
|
@@ -1238,24 +1253,38 @@ impl<'a, Ans: LookupAnswer> Subset<'a, Ans> { | |
| let t2 = t2.clone(); | ||
| drop(v2_ref); | ||
| drop(variables); | ||
| self.is_subset_eq(t1, &t2) | ||
| match self.is_subset_eq(t1, &t2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (same thing here - I don't think we would ever want to change an answer after it has been decided already) |
||
| Ok(()) => Ok(()), | ||
| Err(err) => { | ||
| let t2_promoted = | ||
| t2.clone().promote_literals(self.type_order.stdlib()); | ||
| if t2_promoted != t2 { | ||
| self.solver | ||
| .variables | ||
| .lock() | ||
| .update(*v2, Variable::Answer(t2_promoted.clone())); | ||
| self.is_subset_eq(t1, &t2_promoted) | ||
| } else { | ||
| Err(err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Variable::Quantified(q) => { | ||
| let t1_p = t1.clone().promote_literals(self.type_order.stdlib()); | ||
| let name = q.name.clone(); | ||
| let bound = q.restriction().as_type(self.type_order.stdlib()); | ||
| drop(v2_ref); | ||
| variables.update(*v2, Variable::Answer(t1_p.clone())); | ||
| variables.update(*v2, Variable::Answer(t1.clone())); | ||
| drop(variables); | ||
| if let Err(err_p) = self.is_subset_eq(&t1_p, &bound) { | ||
| // If the promoted type fails, try again with the original type, in case the bound itself is literal. | ||
| // This could be more optimized, but errors are rare, so this code path should not be hot. | ||
| if self.is_subset_eq(t1, &bound).is_err() { | ||
| // Fall back to the promoted type if the literal version violates the bound. | ||
| self.solver | ||
| .variables | ||
| .lock() | ||
| .update(*v2, Variable::Answer(t1.clone())); | ||
| if self.is_subset_eq(t1, &bound).is_err() { | ||
| // If the original type is also an error, use the promoted type. | ||
| .update(*v2, Variable::Answer(t1_p.clone())); | ||
| if let Err(err_p) = self.is_subset_eq(&t1_p, &bound) { | ||
| // If the promoted type also violates the bound, record the error. | ||
| self.solver | ||
| .variables | ||
| .lock() | ||
|
|
||
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
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
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
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
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
Oops, something went wrong.
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.
This section looks unsafe to me, I don't see how it could be okay to change an
Answerafter it's already been decided.Do you remember why this was needed? It may be a hint that propagating literals isn't going to work well at least at this time.