@@ -562,22 +562,34 @@ Type TypeBase::addCurriedSelfType(const DeclContext *dc) {
562562void TypeBase::getTypeVariables (
563563 SmallPtrSetImpl<TypeVariableType *> &typeVariables) {
564564 // 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 ())) {
568581 typeVariables.insert (tv);
569582 }
570583
571- return false ;
572- };
584+ return Action::Continue;
585+ }
586+ };
573587
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!" );
581593}
582594
583595static bool isLegalSILType (CanType type);
0 commit comments