Skip to content

[5.6][Sema] Construct OpenedArchetypeType with a canonical existential type. #40928

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

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 20, 2022

Cherry-pick of #40925 (excluding the added compiler crasher test case)

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 via getCanonicalType() 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

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. We can support cases where the underlying existential type doesn't
depend on the type variables by canonicalizing it when opening the
existential. Cases where the underlying type requires resolved generic
arguments are still unsupported for now.
@hborla hborla requested a review from a team as a code owner January 20, 2022 17:49
@hborla
Copy link
Member Author

hborla commented Jan 20, 2022

@swift-ci please test

@hborla hborla merged commit c6fd6da into swiftlang:release/5.6 Jan 21, 2022
@hborla hborla deleted the 5.6-escaping-archetype-type-variables branch January 21, 2022 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants