Skip to content

Place Opened Archetypes in their Proper Generic Contexts #41677

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 7 commits into from
Mar 8, 2022

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Mar 4, 2022

Part 1 of a refactoring intended to ultimately support a more generic representation of opened archetypes for parameterized protocol types.

This does a massive amount of plumbing to ensure that the DeclContext corresponding to the actual usage of an existential being opened is provided to abstractions dealing with opened archetypes. This allows us to extract any outer generic parameters and prepend them to the archetype's generic signature. This ultimately means that the Self parameter of an opened archetype no longer corresponds to tau_0_0, but instead resides at generic context depth + 1 for most types. Protocol extensions are the exception as the Self type appears as tau_0_0 in context anyways. Callers should use the new OpenedArchetypeType::getSelfInterfaceTypeFromContext instead of constructing generic parameter types for Self.

@hborla hborla requested review from DougGregor and slavapestov March 4, 2022 23:20
@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 4, 2022

@swift-ci test

@CodaFi CodaFi force-pushed the substitutions-available-upon-request branch from 3b34b0a to 1fe38b0 Compare March 7, 2022 21:01
@@ -4421,6 +4422,11 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
GenericEnvironment *environment, Type interfaceType,
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
LayoutConstraint layout) {
// FIXME: It'd be great if all of our callers could submit interface types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callers should be able to provide a substitution map to map generic parameters to archetypes or type variables.

CodaFi added 6 commits March 7, 2022 22:54
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
…Composites

The requirements are not always going to appear with superclass constraints last, so we still need to ensure that superclass bounds wind up at the head of the set of members.
@CodaFi CodaFi force-pushed the substitutions-available-upon-request branch from 1fe38b0 to 445c494 Compare March 8, 2022 06:54
@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 8, 2022

@swift-ci smoke test

@CodaFi CodaFi force-pushed the substitutions-available-upon-request branch from 445c494 to f694bf5 Compare March 8, 2022 11:13
@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 8, 2022

@swift-ci smoke test

@CodaFi CodaFi merged commit 15d96ef into swiftlang:main Mar 8, 2022
@CodaFi CodaFi deleted the substitutions-available-upon-request branch March 8, 2022 18:11
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