@@ -562,22 +562,34 @@ Type TypeBase::addCurriedSelfType(const DeclContext *dc) {
562
562
void TypeBase::getTypeVariables (
563
563
SmallPtrSetImpl<TypeVariableType *> &typeVariables) {
564
564
// If we know we don't have any type variables, we're done.
565
- if (hasTypeVariable ()) {
566
- auto addTypeVariables = [&](Type type) -> bool {
567
- if (auto tv = dyn_cast<TypeVariableType>(type.getPointer ())) {
565
+ if (!hasTypeVariable ())
566
+ return ;
567
+
568
+ class Walker : public TypeWalker {
569
+ SmallPtrSetImpl<TypeVariableType *> &typeVariables;
570
+
571
+ public:
572
+ explicit Walker (SmallPtrSetImpl<TypeVariableType *> &typeVariables)
573
+ : typeVariables(typeVariables) {}
574
+
575
+ Action walkToTypePre (Type ty) override {
576
+ // Skip children that don't contain type variables.
577
+ if (!ty->hasTypeVariable ())
578
+ return Action::SkipNode;
579
+
580
+ if (auto tv = dyn_cast<TypeVariableType>(ty.getPointer ())) {
568
581
typeVariables.insert (tv);
569
582
}
570
583
571
- return false ;
572
- };
584
+ return Action::Continue;
585
+ }
586
+ };
573
587
574
- // Use Type::findIf() to walk the types, finding type variables along the
575
- // way.
576
- getCanonicalType ().findIf (addTypeVariables);
577
- Type (this ).findIf (addTypeVariables);
578
- assert ((!typeVariables.empty () || hasError ()) &&
579
- " Did not find type variables!" );
580
- }
588
+ Walker walker (typeVariables);
589
+ Type (this ).walk (walker);
590
+
591
+ assert ((!typeVariables.empty () || hasError ()) &&
592
+ " Did not find type variables!" );
581
593
}
582
594
583
595
static bool isLegalSILType (CanType type);
0 commit comments