Skip to content

Introduce GenericEnvironment refactoring and kill AllArchetypes #4524

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 13 commits into from
Aug 29, 2016

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Aug 26, 2016

This PR adds a new GenericEnvironment type, meant to store the mapping between interface types and archetypes.

SILFunctions have a GenericEnvironment now, instead of a GenericParamList. This considerably simplifies serialization of archetypes because we no longer have to worry about serializing references to archetypes from other modules.

The GenericEnvironment replaces the AllArchetypes list, and mostly replaces the Archetype field of AbstractTypeParamDecl, however the latter still exists. I'm removing it in a separate PR, since this one is already getting rather huge.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

A GenericEnvironment stores the mapping between GenericTypeParamTypes
and context archetypes (or eventually, concrete types, once we allow
extensions to constrain a generic parameter to a concrete type).

The goals here are two-fold:

- Eliminate the GenericTypeParamDecl::getArchetype() method, and
  always use mapTypeIntoContext() instead

- Replace SILFunction::ContextGenericParams with a GenericEnvironment

This patch adds the new data type as well as serializer and AST
verifier support. but nothing else uses it yet.

Note that GenericSignature::get() now asserts if there are no
generic parameters, instead of returning null. This requires a
few tweaks here and there.
…ontext()

When we call the DeclContext variants of these, use the
DeclContext's GenericEnvironment instead of GenericParamList.

Also, these functions would take a resolver argument, but we
always passed in nullptr, so just remove it now.

The old GenericParamList-based versions are still there
since they're called directly from SIL. They will go away
once SILFunction::ContextGenericParams is replaced with
a GenericEnvironment.
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
…,OutOf}Context()

The last remaining use was in the SIL parser. Plumb through a
GenericEnvironment. The code here really could use additional
cleanup...
Now that SILFunctions store a GenericEnvironment instead of a
GenericParamList, we can remove some unused flexibility.
Now that SILFunctions no longer reference a GenericParamList, we
don't need to de-serialize cross-module references to archetypes
anymore.

This was the last remaining usage of AllArchetypes, so we can
finally rip it out.
Instead of looking at GenericParam requirements, look at the
generic signature.
…anges

I've got a big overhaul of collectRequirements() coming shortly,
so I'm not going to bother fixing this properly here.
The code here should not type check, because we're adding a requirement to
an outer archetype.

I'm working on some changes to ArchetypeBuilder that will make this kind
of thing easier to catch.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 6678ab2 into swiftlang:master Aug 29, 2016
@slavapestov slavapestov deleted the generic-environment branch September 7, 2016 04:48
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.

1 participant