@@ -355,14 +355,13 @@ namespace {
355
355
class ReplaceDependentTypes {
356
356
ConstraintSystem &cs;
357
357
ConstraintLocatorBuilder &locator;
358
- llvm::DenseMap<CanType, TypeVariableType *> &replacements;
359
- llvm::DenseMap<CanType, Type> dependentMemberReplacements;
358
+ OpenedTypeMap &replacements;
360
359
361
360
public:
362
361
ReplaceDependentTypes (
363
362
ConstraintSystem &cs,
364
363
ConstraintLocatorBuilder &locator,
365
- llvm::DenseMap<CanType, TypeVariableType *> &replacements)
364
+ OpenedTypeMap &replacements)
366
365
: cs(cs), locator(locator), replacements(replacements) { }
367
366
368
367
Type operator ()(Type type) {
@@ -371,7 +370,8 @@ namespace {
371
370
372
371
// Replace a generic type parameter with its corresponding type variable.
373
372
if (auto genericParam = type->getAs <GenericTypeParamType>()) {
374
- auto known = replacements.find (genericParam->getCanonicalType ());
373
+ auto known = replacements.find (
374
+ cast<GenericTypeParamType>(genericParam->getCanonicalType ()));
375
375
376
376
if (known == replacements.end ())
377
377
return cs.createTypeVariable (nullptr , TVO_PrefersSubtypeBinding);
@@ -382,21 +382,11 @@ namespace {
382
382
// Replace a dependent member with a fresh type variable and make it a
383
383
// member of its base type.
384
384
if (auto dependentMember = type->getAs <DependentMemberType>()) {
385
- // Check whether we've already dealt with this dependent member.
386
- auto known = dependentMemberReplacements.find (
387
- dependentMember->getCanonicalType ());
388
- if (known != dependentMemberReplacements.end ())
389
- return known->second ;
390
-
391
- // Replace archetypes in the base type.
392
- // FIXME: Tracking the dependent members seems unnecessary.
385
+ // Replace type parameters in the base type.
393
386
if (auto base =
394
387
((*this )(dependentMember->getBase ()))->getAs <TypeVariableType>()) {
395
- auto result =
388
+ return
396
389
DependentMemberType::get (base, dependentMember->getAssocType ());
397
- dependentMemberReplacements[dependentMember->getCanonicalType ()] =
398
- result;
399
- return result;
400
390
}
401
391
}
402
392
@@ -421,7 +411,7 @@ namespace {
421
411
return ErrorType::get (type);
422
412
}
423
413
424
- llvm::DenseMap<CanType, TypeVariableType *> unboundReplacements;
414
+ OpenedTypeMap unboundReplacements;
425
415
426
416
// Open up the generic type.
427
417
cs.openGeneric (unboundDecl->getInnermostDeclContext (),
@@ -435,7 +425,8 @@ namespace {
435
425
// Map the generic parameters to their corresponding type variables.
436
426
llvm::SmallVector<TypeLoc, 4 > arguments;
437
427
for (auto gp : unboundDecl->getInnermostGenericParamTypes ()) {
438
- auto found = unboundReplacements.find (gp->getCanonicalType ());
428
+ auto found = unboundReplacements.find (
429
+ cast<GenericTypeParamType>(gp->getCanonicalType ()));
439
430
assert (found != unboundReplacements.end () &&
440
431
" Missing generic parameter?" );
441
432
arguments.push_back (TypeLoc::withoutLoc (found->second ));
@@ -461,7 +452,7 @@ namespace {
461
452
Type ConstraintSystem::openType (
462
453
Type startingType,
463
454
ConstraintLocatorBuilder locator,
464
- llvm::DenseMap<CanType, TypeVariableType *> &replacements) {
455
+ OpenedTypeMap &replacements) {
465
456
if (!startingType->hasTypeParameter () &&
466
457
!startingType->hasUnboundGenericType ())
467
458
return startingType;
@@ -498,7 +489,7 @@ Type ConstraintSystem::openFunctionType(
498
489
AnyFunctionType *funcType,
499
490
unsigned numArgumentLabelsToRemove,
500
491
ConstraintLocatorBuilder locator,
501
- llvm::DenseMap<CanType, TypeVariableType *> &replacements,
492
+ OpenedTypeMap &replacements,
502
493
DeclContext *innerDC,
503
494
DeclContext *outerDC,
504
495
bool skipProtocolSelfConstraint) {
@@ -645,7 +636,7 @@ Type ConstraintSystem::getFixedTypeRecursive(Type type,
645
636
646
637
void ConstraintSystem::recordOpenedTypes (
647
638
ConstraintLocatorBuilder locator,
648
- const llvm::DenseMap<CanType, TypeVariableType *> &replacements) {
639
+ const OpenedTypeMap &replacements) {
649
640
if (replacements.empty ())
650
641
return ;
651
642
@@ -720,7 +711,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
720
711
FunctionRefKind functionRefKind,
721
712
ConstraintLocatorBuilder locator,
722
713
const DeclRefExpr *base) {
723
- llvm::DenseMap<CanType, TypeVariableType *> replacements;
714
+ OpenedTypeMap replacements;
724
715
725
716
if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
726
717
// Unqualified lookup can find operator names within nominal types.
@@ -829,7 +820,7 @@ void ConstraintSystem::openGeneric(
829
820
GenericSignature *signature,
830
821
bool skipProtocolSelfConstraint,
831
822
ConstraintLocatorBuilder locator,
832
- llvm::DenseMap<CanType, TypeVariableType *> &replacements) {
823
+ OpenedTypeMap &replacements) {
833
824
openGeneric (innerDC,
834
825
outerDC,
835
826
signature->getGenericParams (),
@@ -874,7 +865,7 @@ static void bindArchetypesFromContext(
874
865
ConstraintSystem &cs,
875
866
DeclContext *outerDC,
876
867
ConstraintLocator *locatorPtr,
877
- const llvm::DenseMap<CanType, TypeVariableType *> &replacements) {
868
+ const OpenedTypeMap &replacements) {
878
869
879
870
auto *genericEnv = outerDC->getGenericEnvironmentOfContext ();
880
871
@@ -891,7 +882,8 @@ static void bindArchetypesFromContext(
891
882
break ;
892
883
893
884
for (auto *paramTy : genericSig->getGenericParams ()) {
894
- auto found = replacements.find (paramTy->getCanonicalType ());
885
+ auto found = replacements.find (cast<GenericTypeParamType>(
886
+ paramTy->getCanonicalType ()));
895
887
896
888
// We might not have a type variable for this generic parameter
897
889
// because either we're opening up an UnboundGenericType,
@@ -917,7 +909,7 @@ void ConstraintSystem::openGeneric(
917
909
ArrayRef<Requirement> requirements,
918
910
bool skipProtocolSelfConstraint,
919
911
ConstraintLocatorBuilder locator,
920
- llvm::DenseMap<CanType, TypeVariableType *> &replacements) {
912
+ OpenedTypeMap &replacements) {
921
913
auto locatorPtr = getConstraintLocator (locator);
922
914
auto *genericEnv = innerDC->getGenericEnvironmentOfContext ();
923
915
@@ -932,7 +924,8 @@ void ConstraintSystem::openGeneric(
932
924
TVO_PrefersSubtypeBinding |
933
925
TVO_MustBeMaterializable);
934
926
auto result = replacements.insert (
935
- std::make_pair (gp->getCanonicalType (), typeVar));
927
+ std::make_pair (cast<GenericTypeParamType>(gp->getCanonicalType ()),
928
+ typeVar));
936
929
assert (result.second );
937
930
(void ) result;
938
931
}
@@ -1033,7 +1026,7 @@ ConstraintSystem::getTypeOfMemberReference(
1033
1026
FunctionRefKind functionRefKind,
1034
1027
ConstraintLocatorBuilder locator,
1035
1028
const DeclRefExpr *base,
1036
- llvm::DenseMap<CanType, TypeVariableType *> *replacementsPtr) {
1029
+ OpenedTypeMap *replacementsPtr) {
1037
1030
// Figure out the instance type used for the base.
1038
1031
Type baseObjTy = getFixedTypeRecursive (baseTy, /* wantRValue=*/ true );
1039
1032
bool isInstance = true ;
@@ -1077,7 +1070,7 @@ ConstraintSystem::getTypeOfMemberReference(
1077
1070
1078
1071
// Open the type of the generic function or member of a generic type.
1079
1072
Type openedType;
1080
- llvm::DenseMap<CanType, TypeVariableType *> localReplacements;
1073
+ OpenedTypeMap localReplacements;
1081
1074
auto &replacements = replacementsPtr ? *replacementsPtr : localReplacements;
1082
1075
bool isCurriedInstanceReference = value->isInstanceMember () && !isInstance;
1083
1076
unsigned numRemovedArgumentLabels =
@@ -1225,8 +1218,9 @@ ConstraintSystem::getTypeOfMemberReference(
1225
1218
// parameter with the existential type, since formally the access will
1226
1219
// operate on existentials and not type parameters.
1227
1220
if (!isDynamicResult && baseObjTy->isExistentialType ()) {
1228
- auto selfTy = replacements[outerDC->getSelfInterfaceType ()
1229
- ->getCanonicalType ()];
1221
+ auto selfTy = replacements[
1222
+ cast<GenericTypeParamType>(outerDC->getSelfInterfaceType ()
1223
+ ->getCanonicalType ())];
1230
1224
type = type.transform ([&](Type t) -> Type {
1231
1225
if (auto *selfTy = t->getAs <DynamicSelfType>())
1232
1226
t = selfTy->getSelfType ();
0 commit comments