-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[ty] Fix non-determinism in ConstraintSet.specialize_constrained
#21744
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5300d11
add failing test
dcreager 8086805
add sequent map tracing
dcreager 80bf666
add tracing for PathAssignment
dcreager 89cec13
quasi-reduced
dcreager c53f7bc
update docs
dcreager 32d2f40
don't worry about display impl
dcreager 4bed171
document tracing
dcreager d3d1bc1
clippy
dcreager 9e5ea4b
fix test
dcreager e432558
Merge remote-tracking branch 'origin/main' into dcreager/nondeterminism
dcreager 948a9fb
mark this TODO
dcreager 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,8 @@ def unbounded[T](): | |
| # revealed: None | ||
| reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(bool, T, bool) & ConstraintSet.range(Never, T, str))) | ||
|
|
||
| # revealed: ty_extensions.Specialization[T@unbounded = int] | ||
| # TODO: revealed: ty_extensions.Specialization[T@unbounded = int] | ||
| # revealed: ty_extensions.Specialization[T@unbounded = bool] | ||
| reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int) | ConstraintSet.range(Never, T, bool))) | ||
| # revealed: ty_extensions.Specialization[T@unbounded = Never] | ||
| reveal_type(generic_context(unbounded).specialize_constrained(ConstraintSet.range(Never, T, int) | ConstraintSet.range(Never, T, str))) | ||
|
|
@@ -175,7 +176,7 @@ def constrained_by_gradual[T: (Base, Any)](): | |
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual = Base] | ||
| reveal_type(generic_context(constrained_by_gradual).specialize_constrained(ConstraintSet.always())) | ||
| # TODO: revealed: ty_extensions.Specialization[T@constrained_by_gradual = Any] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual = object] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual = Base] | ||
| reveal_type(generic_context(constrained_by_gradual).specialize_constrained(ConstraintSet.range(Never, T, object))) | ||
| # revealed: None | ||
| reveal_type(generic_context(constrained_by_gradual).specialize_constrained(ConstraintSet.never())) | ||
|
|
@@ -251,6 +252,30 @@ def constrained_by_gradual_list[T: (list[Base], list[Any])](): | |
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list = list[Sub]] | ||
| reveal_type(generic_context(constrained_by_gradual_list).specialize_constrained(ConstraintSet.range(list[Sub], T, list[Sub]))) | ||
|
|
||
| # Same tests as above, but with the typevar constraints in a different order, to make sure the | ||
| # results do not depend on our BDD variable ordering. | ||
| def constrained_by_gradual_list_reverse[T: (list[Any], list[Base])](): | ||
|
Comment on lines
+255
to
+257
Member
Author
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. This test failed before these fixes, reproducing the test failure in the macOS CI job |
||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list_reverse = list[Base]] | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.always())) | ||
| # revealed: None | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.never())) | ||
|
|
||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list_reverse = list[Base]] | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.range(Never, T, list[Base]))) | ||
| # TODO: revealed: ty_extensions.Specialization[T@constrained_by_gradual = list[Any]] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list_reverse = list[Unrelated]] | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.range(Never, T, list[Unrelated]))) | ||
|
|
||
| # TODO: revealed: ty_extensions.Specialization[T@constrained_by_gradual = list[Any]] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list_reverse = list[Super]] | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.range(Never, T, list[Super]))) | ||
| # TODO: revealed: ty_extensions.Specialization[T@constrained_by_gradual = list[Any]] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list_reverse = list[Super]] | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.range(list[Super], T, list[Super]))) | ||
| # TODO: revealed: ty_extensions.Specialization[T@constrained_by_gradual = list[Any]] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_gradual_list_reverse = list[Sub]] | ||
| reveal_type(generic_context(constrained_by_gradual_list_reverse).specialize_constrained(ConstraintSet.range(list[Sub], T, list[Sub]))) | ||
|
|
||
| def constrained_by_two_gradual_lists[T: (list[Any], list[Any])](): | ||
| # TODO: revealed: ty_extensions.Specialization[T@constrained_by_gradual = list[Any]] | ||
| # revealed: ty_extensions.Specialization[T@constrained_by_two_gradual_lists = Top[list[Any]]] | ||
|
|
||
Oops, something went wrong.
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.
I think this test (and the other changed one below) were other possible points of nondeterminism, since the result could depend on whether
T ≤ boolwas kept in the BDD or simplified away as described in the PR body.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.
I'm not sure I understand why we solve this to
bool. The constraints areT <= int | T <= bool, which seems equivalent toT <= int. Why do we prefer solving toboolwhen there's the additional (seemingly redundant) constraint present?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 is because of our current heuristic for handling multiple paths in a BDD.
T ≤ int ∨ T ≤ boolends up looking like this now:There are two paths to the
trueterminal, one representingT ≤ booland one representingbool < T ≤ int.T = boolandT = intare the largest types that satisfy each respective path. Our current heuristic says that if there's a type that satisfies all paths, we choose that. (That is, if the intersection of the specializations is non-empty, use it.)I'm very much open to changing that heuristic, but think that should be follow-on work. I'll mark this as a TODO that we'd rather produce
T = inthere.