Repository navigation
Only accept a tuple as Any when each of its elements is - #7084
Merged
Merged
Conversation
is_tuple_sub_nominal accepted any tuple as a subtype of a top type and checked only the tuple's capability. A tuple could hold a struct, a bare lambda, a \nosupertype\ type or an unconstrained type parameter and still go into Any, though none of those can on its own. Matching such a tuple out of Any segfaulted, sending one with a struct element to an Any val parameter hung in the GC, and a tuple pattern with a \nosupertype\ element tripped an assertion in is_nominal_match_tuple. Each element must now be a subtype of the top type on its own, ignoring capability. is_nominal_match_tuple treats such an element as "can never match" and lets it win over a capability or descriptor denial from another element. could_be_subtype_ignore_cap gets a tuple case so that type-argument patterns like Box[(A, U32)] against Box[X: Any val] still unify. Closes #7023 Closes #7024 Closes #6770
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
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.
A tuple was a subtype of
Any, or of any other interface with no methods, whenever its capability fit.is_tuple_sub_nominalnever looked at the elements. So a tuple holding a struct, a bare lambda, a\nosupertype\type or an unconstrained type parameter could go intoAny, even though none of those can go there on its own. That's where three bugs came from: matching a boxed tuple with a bare lambda element segfaulted (#7023), sending a tuple with a struct element to anAny valparameter hung or segfaulted in the GC (#6770), and a tuple pattern with a\nosupertype\element tripped an assertion inis_nominal_match_tuplethat assumed every element could come out of a top type (#7024).The rule now is the one the element already has on its own: a tuple is a subtype of a top type only if each element is, checked with
is_x_sub_xwith capability ignored, since the tuple's capability is checked separately.is_nominal_match_tupleturns the old assertion into a "can never match" answer, and it looks for such an element before it reports a capability or descriptor problem, so the order of the elements doesn't change the result.could_be_subtype_ignore_cap, which decides whether a pattern's type argument could unify with a type parameter's constraint, gets a tuple case to go with the new rule. Without it,Box[(A, U32)]againstBox[X: Any val]would become "this pattern can never match".This rejects programs that compile today: a tuple with a struct (including
PointerandNullablePointer), bare,\nosupertype\or unconstrained type parameter element put intoAny, or used as a type argument constrained byAny. Each of those elements is already rejected on its own by the same rule, so I'm not opening a tracking issue for them. The release note has the migrations. Two runtime changes come with it in programs that still compile: aniftypetesting such a tuple againstAnytakes itselsebranch, and a match on a union holding such a tuple no longer takes anAnycase for it.Closes #7023
Closes #7024
Closes #6770