@@ -490,6 +490,8 @@ class TypeSubstituter : public TypeTransform<TypeSubstituter> {
490
490
491
491
std::optional<Type> transform (TypeBase *type, TypePosition pos);
492
492
493
+ Type transformGenericTypeParam (GenericTypeParamType *param, TypePosition pos);
494
+
493
495
Type transformPackExpansion (PackExpansionType *expand, TypePosition pos);
494
496
495
497
Type transformPackElement (PackElementType *element, TypePosition pos);
@@ -512,7 +514,7 @@ TypeSubstituter::transform(TypeBase *type, TypePosition position) {
512
514
" should not be doing AST type-substitution on a lowered SIL type;"
513
515
" use SILType::subst" );
514
516
515
- auto substOrig = dyn_cast<SubstitutableType >(type);
517
+ auto substOrig = dyn_cast<ArchetypeType >(type);
516
518
if (!substOrig)
517
519
return std::nullopt;
518
520
@@ -532,41 +534,46 @@ TypeSubstituter::transform(TypeBase *type, TypePosition position) {
532
534
return known;
533
535
}
534
536
535
- // If we failed to substitute a generic type parameter, give up.
536
- if (isa<GenericTypeParamType>(substOrig))
537
- return ErrorType::get (type);
538
-
539
- auto origArchetype = cast<ArchetypeType>(substOrig);
540
- if (origArchetype->isRoot ()) {
537
+ if (substOrig->isRoot ()) {
541
538
// Root opened archetypes are not required to be substituted. Other root
542
539
// archetypes must already have been substituted above.
543
- if (isa<LocalArchetypeType>(origArchetype )) {
540
+ if (isa<LocalArchetypeType>(substOrig )) {
544
541
return Type (type);
545
542
} else {
546
543
return ErrorType::get (type);
547
544
}
548
545
}
549
546
550
547
// For nested archetypes, we can substitute the parent.
551
- Type origParent = origArchetype ->getParent ();
548
+ Type origParent = substOrig ->getParent ();
552
549
assert (origParent && " Not a nested archetype" );
553
550
554
551
// Substitute into the parent type.
555
552
Type substParent = doIt (origParent, TypePosition::Invariant);
556
553
557
554
// If the parent didn't change, we won't change.
558
- if (substParent.getPointer () == origArchetype ->getParent ())
555
+ if (substParent.getPointer () == substOrig ->getParent ())
559
556
return Type (type);
560
557
561
558
// Get the associated type reference from a child archetype.
562
- AssociatedTypeDecl *assocType = origArchetype ->getInterfaceType ()
559
+ AssociatedTypeDecl *assocType = substOrig ->getInterfaceType ()
563
560
->castTo <DependentMemberType>()->getAssocType ();
564
561
565
- return getMemberForBaseType (IFS, origArchetype ->getParent (), substParent,
562
+ return getMemberForBaseType (IFS, substOrig ->getParent (), substParent,
566
563
assocType, assocType->getName (),
567
564
level);
568
565
}
569
566
567
+ Type TypeSubstituter::transformGenericTypeParam (GenericTypeParamType *param,
568
+ TypePosition pos) {
569
+ // If we have a substitution for this type, use it.
570
+ if (auto known = IFS.substType (param, level))
571
+ return known;
572
+
573
+ // If we failed to substitute a generic type parameter, give up.
574
+ return ErrorType::get (param);
575
+ }
576
+
570
577
Type TypeSubstituter::transformPackExpansion (PackExpansionType *expand,
571
578
TypePosition pos) {
572
579
auto eltTys = IFS.expandPackExpansionType (expand);
0 commit comments