@@ -87,25 +87,6 @@ TypeResolution::forInterface(DeclContext *dc, GenericEnvironment *genericEnv,
87
87
return result;
88
88
}
89
89
90
- TypeResolution
91
- TypeResolution::forContextual (DeclContext *dc, TypeResolutionOptions options,
92
- OpenUnboundGenericTypeFn unboundTyOpener,
93
- HandlePlaceholderTypeReprFn placeholderHandler) {
94
- return forContextual (dc, dc->getGenericEnvironmentOfContext (), options,
95
- unboundTyOpener, placeholderHandler);
96
- }
97
-
98
- TypeResolution
99
- TypeResolution::forContextual (DeclContext *dc, GenericEnvironment *genericEnv,
100
- TypeResolutionOptions options,
101
- OpenUnboundGenericTypeFn unboundTyOpener,
102
- HandlePlaceholderTypeReprFn placeholderHandler) {
103
- TypeResolution result (dc, TypeResolutionStage::Contextual, options,
104
- unboundTyOpener, placeholderHandler);
105
- result.genericEnv = genericEnv;
106
- return result;
107
- }
108
-
109
90
TypeResolution TypeResolution::withOptions (TypeResolutionOptions opts) const {
110
91
TypeResolution result (dc, stage, opts, unboundTyOpener, placeholderHandler);
111
92
result.genericEnv = genericEnv;
@@ -127,30 +108,6 @@ GenericSignature TypeResolution::getGenericSignature() const {
127
108
return dc->getGenericSignatureOfContext ();
128
109
}
129
110
130
- bool TypeResolution::usesArchetypes () const {
131
- switch (stage) {
132
- case TypeResolutionStage::Structural:
133
- case TypeResolutionStage::Interface:
134
- return false ;
135
-
136
- case TypeResolutionStage::Contextual:
137
- return true ;
138
- }
139
- llvm_unreachable (" unhandled stage" );
140
- }
141
-
142
- Type TypeResolution::mapTypeIntoContext (Type type) const {
143
- switch (stage) {
144
- case TypeResolutionStage::Structural:
145
- case TypeResolutionStage::Interface:
146
- return type;
147
-
148
- case TypeResolutionStage::Contextual:
149
- return GenericEnvironment::mapTypeIntoContext (genericEnv, type);
150
- }
151
- llvm_unreachable (" unhandled stage" );
152
- }
153
-
154
111
// FIXME: It would be nice to have a 'DescriptiveTypeKind' abstraction instead.
155
112
static DescriptiveDeclKind describeDeclOfType (Type t) {
156
113
if (!t) {
@@ -174,12 +131,12 @@ Type TypeResolution::resolveDependentMemberType(
174
131
case TypeResolutionStage::Structural:
175
132
return DependentMemberType::get (baseTy, refIdentifier);
176
133
177
- case TypeResolutionStage::Contextual:
178
- llvm_unreachable (" Dependent type after archetype substitution" );
179
-
180
134
case TypeResolutionStage::Interface:
181
135
// Handled below.
182
136
break ;
137
+
138
+ case TypeResolutionStage::Contextual:
139
+ llvm_unreachable (" Use TypeResolution::resolveContextualType instead" );
183
140
}
184
141
185
142
assert (stage == TypeResolutionStage::Interface);
@@ -273,12 +230,12 @@ Type TypeResolution::resolveSelfAssociatedType(Type baseTy,
273
230
case TypeResolutionStage::Structural:
274
231
return DependentMemberType::get (baseTy, name);
275
232
276
- case TypeResolutionStage::Contextual:
277
- llvm_unreachable (" Dependent type after archetype substitution" );
278
-
279
233
case TypeResolutionStage::Interface:
280
234
// Handled below.
281
235
break ;
236
+
237
+ case TypeResolutionStage::Contextual:
238
+ llvm_unreachable (" Use TypeResolution::resolveContextualType instead" );
282
239
}
283
240
284
241
assert (stage == TypeResolutionStage::Interface);
@@ -327,9 +284,7 @@ bool TypeResolution::areSameType(Type type1, Type type2) const {
327
284
break ;
328
285
329
286
case TypeResolutionStage::Contextual:
330
- // Contextual types have already been uniqued, so the isEqual() result
331
- // above is complete.
332
- return false ;
287
+ llvm_unreachable (" Use TypeResolution::resolveContextualType instead" );
333
288
}
334
289
335
290
if (stage == TypeResolutionStage::Interface) {
@@ -395,7 +350,7 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
395
350
396
351
// If we found a generic parameter, map to the archetype if there is one.
397
352
if (auto genericParam = dyn_cast<GenericTypeParamDecl>(typeDecl)) {
398
- return mapTypeIntoContext ( genericParam->getDeclaredInterfaceType () );
353
+ return genericParam->getDeclaredInterfaceType ();
399
354
}
400
355
401
356
if (!isSpecialized) {
@@ -407,13 +362,12 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
407
362
parentDC = parentDC->getParentForLookup ()) {
408
363
auto *parentNominal = parentDC->getSelfNominalTypeDecl ();
409
364
if (parentNominal == nominalType)
410
- return mapTypeIntoContext ( parentDC->getDeclaredInterfaceType () );
365
+ return parentDC->getDeclaredInterfaceType ();
411
366
if (isa<ExtensionDecl>(parentDC)) {
412
367
auto *extendedType = parentNominal;
413
368
while (extendedType != nullptr ) {
414
369
if (extendedType == nominalType)
415
- return mapTypeIntoContext (
416
- extendedType->getDeclaredInterfaceType ());
370
+ return extendedType->getDeclaredInterfaceType ();
417
371
extendedType = extendedType->getParent ()->getSelfNominalTypeDecl ();
418
372
}
419
373
}
@@ -436,8 +390,7 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
436
390
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
437
391
return aliasDecl->getStructuralType ();
438
392
}
439
- return mapTypeIntoContext (
440
- aliasDecl->getDeclaredInterfaceType ());
393
+ return aliasDecl->getDeclaredInterfaceType ();
441
394
}
442
395
443
396
extendedType = unboundGeneric->getParent ();
@@ -451,7 +404,7 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
451
404
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
452
405
return aliasDecl->getStructuralType ();
453
406
}
454
- return mapTypeIntoContext ( aliasDecl->getDeclaredInterfaceType () );
407
+ return aliasDecl->getDeclaredInterfaceType ();
455
408
}
456
409
extendedType = aliasType->getParent ();
457
410
continue ;
@@ -476,7 +429,7 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
476
429
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
477
430
return aliasDecl->getStructuralType ();
478
431
}
479
- return mapTypeIntoContext ( aliasDecl->getDeclaredInterfaceType () );
432
+ return aliasDecl->getDeclaredInterfaceType ();
480
433
}
481
434
482
435
// When a nominal type used outside its context, return the unbound
@@ -503,11 +456,11 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
503
456
if (!foundDC->getDeclaredInterfaceType ())
504
457
return ErrorType::get (ctx);
505
458
506
- selfType = mapTypeIntoContext ( foundDC->getDeclaredInterfaceType () );
459
+ selfType = foundDC->getDeclaredInterfaceType ();
507
460
} else {
508
461
// Otherwise, we want the protocol 'Self' type for
509
462
// substituting into alias types and associated types.
510
- selfType = mapTypeIntoContext ( foundDC->getSelfInterfaceType () );
463
+ selfType = foundDC->getSelfInterfaceType ();
511
464
512
465
if (selfType->is <GenericTypeParamType>()) {
513
466
if (typeDecl->getDeclContext ()->getSelfProtocolDecl ()) {
@@ -551,7 +504,7 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
551
504
552
505
// Finally, substitute the base type into the member type.
553
506
return TypeChecker::substMemberTypeWithBase (
554
- fromDC->getParentModule (), typeDecl, selfType, usesArchetypes () );
507
+ fromDC->getParentModule (), typeDecl, selfType, /* useArchetypes= */ false );
555
508
}
556
509
557
510
static TypeResolutionOptions
@@ -880,16 +833,13 @@ Type TypeResolution::applyUnboundGenericArguments(
880
833
} else if (auto genericSig =
881
834
decl->getDeclContext ()->getGenericSignatureOfContext ()) {
882
835
for (auto gp : genericSig.getGenericParams ()) {
883
- subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
884
- (usesArchetypes ()
885
- ? genericSig.getGenericEnvironment ()->mapTypeIntoContext (gp)
886
- : gp);
836
+ subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] = gp;
887
837
}
888
838
}
889
839
890
840
// Realize the types of the generic arguments and add them to the
891
841
// substitution map.
892
- for (unsigned i = 0 , e = genericArgs. size (); i < e; ++i ) {
842
+ for (const unsigned i : indices (genericArgs) ) {
893
843
auto origTy = genericSig.getInnermostGenericParams ()[i];
894
844
auto substTy = genericArgs[i];
895
845
@@ -906,13 +856,15 @@ Type TypeResolution::applyUnboundGenericArguments(
906
856
auto *module = getDeclContext ()->getParentModule ();
907
857
908
858
if (!skipRequirementsCheck && getStage () > TypeResolutionStage::Structural) {
859
+ // Check the generic arguments against the requirements of the declaration's
860
+ // generic signature.
861
+
862
+ // First, map substitutions into context.
909
863
TypeSubstitutionMap contextualSubs = subs;
910
- if (getStage () == TypeResolutionStage::Interface) {
911
- if (const auto contextSig = getGenericSignature ()) {
912
- auto *genericEnv = contextSig.getGenericEnvironment ();
913
- for (auto &pair : contextualSubs) {
914
- pair.second = genericEnv->mapTypeIntoContext (pair.second );
915
- }
864
+ if (const auto contextSig = getGenericSignature ()) {
865
+ auto *genericEnv = contextSig.getGenericEnvironment ();
866
+ for (auto &pair : contextualSubs) {
867
+ pair.second = genericEnv->mapTypeIntoContext (pair.second );
916
868
}
917
869
}
918
870
@@ -1121,12 +1073,10 @@ static Type diagnoseUnknownType(TypeResolution resolution,
1121
1073
diags.diagnose (comp->getNameLoc (), diag::dynamic_self_invalid, name)
1122
1074
.fixItReplace (comp->getNameLoc ().getSourceRange (), name);
1123
1075
1124
- auto type = resolution.mapTypeIntoContext (
1125
- dc->getInnermostTypeContext ()->getSelfInterfaceType ());
1126
-
1127
1076
comp->overwriteNameRef (DeclNameRef (nominal->getName ()));
1128
1077
comp->setValue (nominal, nominalDC->getParent ());
1129
- return type;
1078
+
1079
+ return dc->getInnermostTypeContext ()->getSelfInterfaceType ();
1130
1080
} else {
1131
1081
diags.diagnose (comp->getNameLoc (), diag::cannot_find_type_in_scope,
1132
1082
comp->getNameRef ());
@@ -1438,8 +1388,7 @@ static Type resolveTopLevelIdentTypeComponent(TypeResolution resolution,
1438
1388
// FIXME: The passed-in TypeRepr should get 'typechecked' as well.
1439
1389
// The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl
1440
1390
// while the 'Self' type is more than just a reference to a TypeDecl.
1441
- auto selfType = resolution.mapTypeIntoContext (
1442
- typeDC->getSelfInterfaceType ());
1391
+ auto selfType = typeDC->getSelfInterfaceType ();
1443
1392
1444
1393
// Check if we can reference 'Self' here, and if so, what kind of Self it is.
1445
1394
auto selfTypeKind = getSelfTypeKind (DC, options);
0 commit comments