Skip to content

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

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 2 commits into from
Jan 20, 2022

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 20, 2022

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 force-pushed the escaping-archetype-type-variables branch from 81851ba to b3b24a7 Compare January 20, 2022 07:14
@hborla
Copy link
Member Author

hborla commented Jan 20, 2022

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jan 20, 2022

@swift-ci please test source compatibility

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.

3 participants