[Sema] Construct OpenedArchetypeType
with a canonical existential type.
#40925
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.
Opened archetypes can be created in the constraint system, and the existential type it wraps can contain type variables. This can happen when the existential type is inferred through a typealias inside a generic type, and a member reference whose base is the opened existential gets bound before binding the generic arguments of the parent type.
However, simplifying opened archetypes to replace type variables is not yet supported, which leads to type variables escaping the constraint system. This went unnoticed until my recent
ExistentialType
refactoring, where this issue started manifesting as a use-after-free viagetCanonicalType()
and other code that attempted to touch the type variables after they were freed with the constraint system.Cases where the underlying existential type doesn't depend on the type variables previously appeared to work, despite the invalid AST, because nothing ever touched the type variable types. We can still support these cases by canonicalizing the existential type when opening it. Cases where the underlying type requires resolved generic arguments are still unsupported for now.
Resolves: SR-15742 / rdar://87684281