@@ -2020,13 +2020,7 @@ void ArchetypeBuilder::dump(llvm::raw_ostream &out) {
2020
2020
2021
2021
Type ArchetypeBuilder::mapTypeIntoContext (const DeclContext *dc, Type type,
2022
2022
LazyResolver *resolver) {
2023
- // If the type is not dependent, there's nothing to map.
2024
- if (!type->hasTypeParameter ())
2025
- return type;
2026
-
2027
2023
auto genericParams = dc->getGenericParamsOfContext ();
2028
- assert (genericParams && " Missing generic parameters for dependent context" );
2029
-
2030
2024
return mapTypeIntoContext (dc->getParentModule (), genericParams, type,
2031
2025
resolver);
2032
2026
}
@@ -2035,13 +2029,15 @@ Type ArchetypeBuilder::mapTypeIntoContext(Module *M,
2035
2029
GenericParamList *genericParams,
2036
2030
Type type,
2037
2031
LazyResolver *resolver) {
2038
- // If the type is not dependent, or we have no generic params, there's nothing
2039
- // to map.
2040
- if (!genericParams || !type ->hasTypeParameter ())
2032
+ auto canType = type-> getCanonicalType ();
2033
+ assert (!canType-> hasArchetype () && " already have a contextual type " );
2034
+ if (!canType ->hasTypeParameter ())
2041
2035
return type;
2042
2036
2037
+ assert (genericParams && " dependent type in non-generic context" );
2038
+
2043
2039
unsigned genericParamsDepth = genericParams->getDepth ();
2044
- return type.transform ([&](Type type) -> Type {
2040
+ type = type.transform ([&](Type type) -> Type {
2045
2041
// Map a generic parameter type to its archetype.
2046
2042
if (auto gpType = type->getAs <GenericTypeParamType>()) {
2047
2043
auto index = gpType->getIndex ();
@@ -2064,7 +2060,7 @@ Type ArchetypeBuilder::mapTypeIntoContext(Module *M,
2064
2060
if (!myGenericParams->getAllArchetypes ().empty ())
2065
2061
return myGenericParams->getPrimaryArchetypes ()[index];
2066
2062
2067
- // During type-checking, we may try to mapTypeInContext before
2063
+ // During type-checking, we may try to mapTypeIntoContext before
2068
2064
// AllArchetypes has been built, so fall back to the generic params.
2069
2065
return myGenericParams->getParams ()[index]->getArchetype ();
2070
2066
}
@@ -2078,6 +2074,9 @@ Type ArchetypeBuilder::mapTypeIntoContext(Module *M,
2078
2074
2079
2075
return type;
2080
2076
});
2077
+
2078
+ assert (!type->hasTypeParameter () && " not fully substituted" );
2079
+ return type;
2081
2080
}
2082
2081
2083
2082
Type
@@ -2089,10 +2088,13 @@ ArchetypeBuilder::mapTypeOutOfContext(const DeclContext *dc, Type type) {
2089
2088
Type ArchetypeBuilder::mapTypeOutOfContext (ModuleDecl *M,
2090
2089
GenericParamList *genericParams,
2091
2090
Type type) {
2092
- // If the context is non-generic, we're done.
2093
- if (!genericParams)
2091
+ auto canType = type->getCanonicalType ();
2092
+ assert (!canType->hasTypeParameter () && " already have an interface type" );
2093
+ if (!canType->hasArchetype ())
2094
2094
return type;
2095
2095
2096
+ assert (genericParams && " dependent type in non-generic context" );
2097
+
2096
2098
// Capture the archetype -> interface type mapping.
2097
2099
TypeSubstitutionMap subs;
2098
2100
for (auto params = genericParams; params != nullptr ;
@@ -2102,7 +2104,10 @@ Type ArchetypeBuilder::mapTypeOutOfContext(ModuleDecl *M,
2102
2104
}
2103
2105
}
2104
2106
2105
- return type.subst (M, subs, SubstFlags::AllowLoweredTypes);
2107
+ type = type.subst (M, subs, SubstFlags::AllowLoweredTypes);
2108
+
2109
+ assert (!type->hasArchetype () && " not fully substituted" );
2110
+ return type;
2106
2111
}
2107
2112
2108
2113
bool ArchetypeBuilder::addGenericSignature (GenericSignature *sig,
0 commit comments