diff --git a/include/swift/AST/ConcreteDeclRef.h b/include/swift/AST/ConcreteDeclRef.h index f3659f6ba0a..6dc315931ff 100644 --- a/include/swift/AST/ConcreteDeclRef.h +++ b/include/swift/AST/ConcreteDeclRef.h @@ -113,7 +113,7 @@ public: /// Retrieve a reference to the declaration this one overrides. ConcreteDeclRef - getOverriddenDecl(ASTContext &ctx, LazyResolver *resolver) const; + getOverriddenDecl(ASTContext &ctx) const; /// Determine whether this reference specializes the declaration to which /// it refers. diff --git a/include/swift/AST/SubstitutionMap.h b/include/swift/AST/SubstitutionMap.h index 083c1f38b29..ed68f3934ab 100644 --- a/include/swift/AST/SubstitutionMap.h +++ b/include/swift/AST/SubstitutionMap.h @@ -111,8 +111,7 @@ public: static SubstitutionMap getOverrideSubstitutions(const ValueDecl *baseDecl, const ValueDecl *derivedDecl, - Optional derivedSubs, - LazyResolver *resolver); + Optional derivedSubs); /// Variant of the above for when we have the generic signatures but not /// the decls for 'derived' and 'base'. @@ -121,8 +120,7 @@ public: const ClassDecl *derivedClass, GenericSignature *baseSig, GenericSignature *derivedSig, - Optional derivedSubs, - LazyResolver *resolver); + Optional derivedSubs); /// Combine two substitution maps as follows. /// diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 4440a833365..8696004db43 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -656,18 +656,13 @@ public: /// \brief Retrieve the superclass of this type. /// - /// \param resolver The resolver for lazy type checking, or null if the - /// AST is already type-checked. - /// /// \returns The superclass of this type, or a null type if it has no /// superclass. - Type getSuperclass(LazyResolver *resolver); + Type getSuperclass(); /// \brief True if this type is the exact superclass of another type. /// /// \param ty The potential subclass. - /// \param resolver The resolver for lazy type checking, or null if the - /// AST is already type-checked. /// /// \returns True if this type is \c ty or a superclass of \c ty. /// @@ -678,7 +673,7 @@ public: /// will return false. `isBindableToSuperclassOf` should be used /// for queries that care whether a generic class type can be substituted into /// a type's subclass. - bool isExactSuperclassOf(Type ty, LazyResolver *resolver); + bool isExactSuperclassOf(Type ty); /// \brief Get the substituted base class type, starting from a base class /// declaration and a substituted derived class type. @@ -691,23 +686,21 @@ public: /// /// Calling `C`->getSuperclassForDecl(`A`) will return /// `A`. - Type getSuperclassForDecl(const ClassDecl *classDecl, LazyResolver *resolver); + Type getSuperclassForDecl(const ClassDecl *classDecl); /// \brief True if this type is the superclass of another type, or a generic /// type that could be bound to the superclass. /// /// \param ty The potential subclass. - /// \param resolver The resolver for lazy type checking, or null if the - /// AST is already type-checked. /// /// \returns True if this type is \c ty, a superclass of \c ty, or an /// archetype-parameterized type that can be bound to a superclass /// of \c ty. - bool isBindableToSuperclassOf(Type ty, LazyResolver *resolver); + bool isBindableToSuperclassOf(Type ty); /// True if this type contains archetypes that could be substituted with /// concrete types to form the argument type. - bool isBindableTo(Type ty, LazyResolver *resolver); + bool isBindableTo(Type ty); /// \brief Determines whether this type is permitted as a method override /// of the \p other. @@ -916,8 +909,7 @@ public: /// 'self' argument type as appropriate. Type adjustSuperclassMemberDeclType(const ValueDecl *baseDecl, const ValueDecl *derivedDecl, - Type memberType, - LazyResolver *resolver); + Type memberType); /// Return T if this type is Optional; otherwise, return the null type. Type getOptionalObjectType(); diff --git a/include/swift/SIL/SILCloner.h b/include/swift/SIL/SILCloner.h index ad79d6344e5..ba14bb9275d 100644 --- a/include/swift/SIL/SILCloner.h +++ b/include/swift/SIL/SILCloner.h @@ -1494,7 +1494,7 @@ SILCloner::visitWitnessMethodInst(WitnessMethodInst *Inst) { CanType Ty = conformance.getConcrete()->getType()->getCanonicalType(); if (Ty != newLookupType) { - assert(Ty->isExactSuperclassOf(newLookupType, nullptr) && + assert(Ty->isExactSuperclassOf(newLookupType) && "Should only create upcasts for sub class."); // We use the super class as the new look up type. diff --git a/include/swift/SIL/SILType.h b/include/swift/SIL/SILType.h index 67da571c1d7..7cd2df51e02 100644 --- a/include/swift/SIL/SILType.h +++ b/include/swift/SIL/SILType.h @@ -407,16 +407,15 @@ public: /// Return the immediate superclass type of this type, or null if /// it's the most-derived type. - SILType getSuperclass(LazyResolver *resolver) const { - auto superclass = getSwiftRValueType()->getSuperclass(resolver); + SILType getSuperclass() const { + auto superclass = getSwiftRValueType()->getSuperclass(); if (!superclass) return SILType(); return SILType::getPrimitiveObjectType(superclass->getCanonicalType()); } /// Return true if Ty is a subtype of this exact SILType, or false otherwise. bool isExactSuperclassOf(SILType Ty) const { - return getSwiftRValueType()->isExactSuperclassOf(Ty.getSwiftRValueType(), - nullptr); + return getSwiftRValueType()->isExactSuperclassOf(Ty.getSwiftRValueType()); } /// Return true if Ty is a subtype of this SILType, or if this SILType @@ -424,8 +423,7 @@ public: /// otherwise. bool isBindableToSuperclassOf(SILType Ty) const { return getSwiftRValueType()->isBindableToSuperclassOf( - Ty.getSwiftRValueType(), - nullptr); + Ty.getSwiftRValueType()); } /// Transform the function type SILType by replacing all of its interface diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp index b092d805e1f..07c0f55c5f0 100644 --- a/lib/AST/ASTVerifier.cpp +++ b/lib/AST/ASTVerifier.cpp @@ -2760,7 +2760,7 @@ public: // If the destination is a class, walk the supertypes of the source. if (destTy->getClassOrBoundGenericClass()) { - if (!destTy->isBindableToSuperclassOf(srcTy, nullptr)) { + if (!destTy->isBindableToSuperclassOf(srcTy)) { srcTy.print(Out); Out << " is not a superclass of "; destTy.print(Out); diff --git a/lib/AST/ConcreteDeclRef.cpp b/lib/AST/ConcreteDeclRef.cpp index 34084502315..28dadda8f99 100644 --- a/lib/AST/ConcreteDeclRef.cpp +++ b/lib/AST/ConcreteDeclRef.cpp @@ -34,8 +34,7 @@ ConcreteDeclRef::SpecializedDeclRef::create( } ConcreteDeclRef -ConcreteDeclRef::getOverriddenDecl(ASTContext &ctx, - LazyResolver *resolver) const { +ConcreteDeclRef::getOverriddenDecl(ASTContext &ctx) const { auto *derivedDecl = getDecl(); auto *baseDecl = derivedDecl->getOverriddenDecl(); @@ -50,7 +49,7 @@ ConcreteDeclRef::getOverriddenDecl(ASTContext &ctx, if (derivedSig) derivedSubMap = derivedSig->getSubstitutionMap(getSubstitutions()); auto subMap = SubstitutionMap::getOverrideSubstitutions( - baseDecl, derivedDecl, derivedSubMap, resolver); + baseDecl, derivedDecl, derivedSubMap); baseSig->getSubstitutions(subMap, subs); } return ConcreteDeclRef(ctx, baseDecl, subs); diff --git a/lib/AST/ConformanceLookupTable.cpp b/lib/AST/ConformanceLookupTable.cpp index 6cb156067be..1f04f669e49 100644 --- a/lib/AST/ConformanceLookupTable.cpp +++ b/lib/AST/ConformanceLookupTable.cpp @@ -801,9 +801,9 @@ ProtocolConformance *ConformanceLookupTable::getConformance( // Find the superclass type that matches where the conformance was // declared. - Type superclassTy = type->getSuperclass(resolver); + Type superclassTy = type->getSuperclass(); while (superclassTy->getAnyNominal() != conformingNominal) - superclassTy = superclassTy->getSuperclass(resolver); + superclassTy = superclassTy->getSuperclass(); // Look up the inherited conformance. ModuleDecl *module = entry->getDeclContext()->getParentModule(); diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp index 47600f9a8d0..70d341f4ad9 100644 --- a/lib/AST/GenericSignatureBuilder.cpp +++ b/lib/AST/GenericSignatureBuilder.cpp @@ -2532,7 +2532,7 @@ void GenericSignatureBuilder::updateSuperclass( // // then the second constraint should be allowed, constraining U to Bar // and secondarily imposing a T == Int constraint. - if (existingSuperclass->isExactSuperclassOf(superclass, nullptr)) { + if (existingSuperclass->isExactSuperclassOf(superclass)) { equivClass->superclass = superclass; // We've strengthened the bound, so update superclass conformances. @@ -4428,7 +4428,7 @@ void GenericSignatureBuilder::checkSuperclassConstraints( }, [&](Type superclass) { // If this class is a superclass of the "best" - if (superclass->isExactSuperclassOf(equivClass->superclass, nullptr)) + if (superclass->isExactSuperclassOf(equivClass->superclass)) return ConstraintRelation::Redundant; // Otherwise, it conflicts. @@ -4442,8 +4442,7 @@ void GenericSignatureBuilder::checkSuperclassConstraints( // FIXME: Substitute into the concrete type. if (equivClass->concreteType) { // Make sure the concrete type fulfills the superclass requirement. - if (!equivClass->superclass->isExactSuperclassOf(equivClass->concreteType, - nullptr)) { + if (!equivClass->superclass->isExactSuperclassOf(equivClass->concreteType)) { if (auto existing = equivClass->findAnyConcreteConstraintAsWritten( representativeConstraint.archetype)) { Diags.diagnose(existing->source->getLoc(), diag::type_does_not_inherit, diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index aff8f044fba..e92dcc00e8d 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -681,9 +681,9 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol, = rootConformance->getType()->getClassOrBoundGenericClass(); // Map up to our superclass's type. - Type superclassTy = type->getSuperclass(resolver); + Type superclassTy = type->getSuperclass(); while (superclassTy->getAnyNominal() != conformingNominal) - superclassTy = superclassTy->getSuperclass(resolver); + superclassTy = superclassTy->getSuperclass(); // Compute the conformance for the inherited type. auto inheritedConformance = lookupConformance(superclassTy, protocol, diff --git a/lib/AST/SubstitutionMap.cpp b/lib/AST/SubstitutionMap.cpp index 6321424df83..dd69ba1b7d3 100644 --- a/lib/AST/SubstitutionMap.cpp +++ b/lib/AST/SubstitutionMap.cpp @@ -237,8 +237,7 @@ SubstitutionMap::getProtocolSubstitutions(ProtocolDecl *protocol, SubstitutionMap SubstitutionMap::getOverrideSubstitutions(const ValueDecl *baseDecl, const ValueDecl *derivedDecl, - Optional derivedSubs, - LazyResolver *resolver) { + Optional derivedSubs) { auto *baseClass = baseDecl->getDeclContext() ->getAsClassOrClassExtensionContext(); auto *derivedClass = derivedDecl->getDeclContext() @@ -251,8 +250,7 @@ SubstitutionMap::getOverrideSubstitutions(const ValueDecl *baseDecl, return getOverrideSubstitutions(baseClass, derivedClass, baseSig, derivedSig, - derivedSubs, - resolver); + derivedSubs); } SubstitutionMap @@ -260,8 +258,7 @@ SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass, const ClassDecl *derivedClass, GenericSignature *baseSig, GenericSignature *derivedSig, - Optional derivedSubs, - LazyResolver *resolver) { + Optional derivedSubs) { if (baseSig == nullptr) return SubstitutionMap(); @@ -275,7 +272,7 @@ SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass, auto derivedClassTy = derivedClass->getDeclaredInterfaceType(); if (derivedSubs) derivedClassTy = derivedClassTy.subst(*derivedSubs); - auto baseClassTy = derivedClassTy->getSuperclassForDecl(baseClass, resolver); + auto baseClassTy = derivedClassTy->getSuperclassForDecl(baseClass); baseSubMap = baseClassTy->getContextSubstitutionMap(M, baseClass); } diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 5844ffd2aae..548a51ff100 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1565,7 +1565,7 @@ bool TypeBase::mayHaveSuperclass() { return is(); } -Type TypeBase::getSuperclass(LazyResolver *resolver) { +Type TypeBase::getSuperclass() { auto *nominalDecl = getAnyNominal(); auto *classDecl = dyn_cast_or_null(nominalDecl); @@ -1604,7 +1604,7 @@ Type TypeBase::getSuperclass(LazyResolver *resolver) { return superclassTy.subst(subMap); } -bool TypeBase::isExactSuperclassOf(Type ty, LazyResolver *resolver) { +bool TypeBase::isExactSuperclassOf(Type ty) { // For there to be a superclass relationship, we must be a superclass, and // the potential subtype must be a class or superclass-bounded archetype. if (!getClassOrBoundGenericClass() || !ty->mayHaveSuperclass()) @@ -1615,12 +1615,12 @@ bool TypeBase::isExactSuperclassOf(Type ty, LazyResolver *resolver) { return true; if (ty->getAnyNominal() && ty->getAnyNominal()->isInvalid()) return false; - } while ((ty = ty->getSuperclass(resolver))); + } while ((ty = ty->getSuperclass())); return false; } /// Returns true if type `a` has archetypes that can be bound to form `b`. -bool TypeBase::isBindableTo(Type b, LazyResolver *resolver) { +bool TypeBase::isBindableTo(Type b) { class IsBindableVisitor : public TypeVisitor { llvm::DenseMap Bindings; @@ -1845,10 +1845,10 @@ bool TypeBase::isBindableTo(Type b, LazyResolver *resolver) { b->getCanonicalType()); } -bool TypeBase::isBindableToSuperclassOf(Type ty, LazyResolver *resolver) { +bool TypeBase::isBindableToSuperclassOf(Type ty) { // Do an exact match if no archetypes are involved. if (!hasArchetype()) - return isExactSuperclassOf(ty, resolver); + return isExactSuperclassOf(ty); // For there to be a superclass relationship, // the potential subtype must be a class or superclass-bounded archetype. @@ -1865,11 +1865,11 @@ bool TypeBase::isBindableToSuperclassOf(Type ty, LazyResolver *resolver) { return true; do { - if (isBindableTo(ty, resolver)) + if (isBindableTo(ty)) return true; if (ty->getAnyNominal() && ty->getAnyNominal()->isInvalid()) return false; - } while ((ty = ty->getSuperclass(resolver))); + } while ((ty = ty->getSuperclass())); return false; } @@ -2418,7 +2418,7 @@ static bool canOverride(CanType t1, CanType t2, } // Class-to-class. - return t2->isExactSuperclassOf(t1, resolver); + return t2->isExactSuperclassOf(t1); } bool TypeBase::canOverride(Type other, OverrideMatchMode matchMode, @@ -3122,8 +3122,7 @@ Type Type::substDependentTypesWithErrorTypes() const { SubstFlags::UseErrorType)); } -Type TypeBase::getSuperclassForDecl(const ClassDecl *baseClass, - LazyResolver *resolver) { +Type TypeBase::getSuperclassForDecl(const ClassDecl *baseClass) { Type t(this); while (t) { // If we have a class-constrained archetype or class-constrained @@ -3132,7 +3131,7 @@ Type TypeBase::getSuperclassForDecl(const ClassDecl *baseClass, if (!nominalDecl) { assert(t->is() || t->isExistentialType() && "expected a class, archetype or existential"); - t = t->getSuperclass(resolver); + t = t->getSuperclass(); assert(t && "archetype or existential is not class constrained"); continue; } @@ -3141,7 +3140,7 @@ Type TypeBase::getSuperclassForDecl(const ClassDecl *baseClass, if (nominalDecl == baseClass) return t; - t = t->getSuperclass(resolver); + t = t->getSuperclass(); } llvm_unreachable("no inheritance relationship between given classes"); } @@ -3169,13 +3168,10 @@ TypeBase::getContextSubstitutions(const DeclContext *dc, return substitutions; } - // Extract the lazy resolver. - LazyResolver *resolver = dc->getASTContext().getLazyResolver(); - // Find the superclass type with the context matching that of the member. auto *ownerNominal = dc->getAsNominalTypeOrNominalTypeExtensionContext(); if (auto *ownerClass = dyn_cast(ownerNominal)) - baseTy = baseTy->getSuperclassForDecl(ownerClass, resolver); + baseTy = baseTy->getSuperclassForDecl(ownerClass); assert(ownerNominal == baseTy->getAnyNominal()); @@ -3307,10 +3303,9 @@ Type TypeBase::getTypeOfMember(ModuleDecl *module, const ValueDecl *member, Type TypeBase::adjustSuperclassMemberDeclType(const ValueDecl *baseDecl, const ValueDecl *derivedDecl, - Type memberType, - LazyResolver *resolver) { + Type memberType) { auto subs = SubstitutionMap::getOverrideSubstitutions( - baseDecl, derivedDecl, /*derivedSubs=*/None, resolver); + baseDecl, derivedDecl, /*derivedSubs=*/None); if (auto *genericMemberType = memberType->getAs()) { memberType = FunctionType::get(genericMemberType->getInput(), diff --git a/lib/AST/TypeJoinMeet.cpp b/lib/AST/TypeJoinMeet.cpp index 0a9b886baa1..dd568199b38 100644 --- a/lib/AST/TypeJoinMeet.cpp +++ b/lib/AST/TypeJoinMeet.cpp @@ -65,14 +65,11 @@ Type Type::join(Type type1, Type type2) { // If both are class types or opaque types that potentially have superclasses, // find the common superclass. if (type1->mayHaveSuperclass() && type2->mayHaveSuperclass()) { - ASTContext &ctx = type1->getASTContext(); - LazyResolver *resolver = ctx.getLazyResolver(); - /// Walk the superclasses of type1 looking for type2. Record them for our /// second step. llvm::SmallPtrSet superclassesOfType1; CanType canType2 = type2->getCanonicalType(); - for (Type super1 = type1; super1; super1 = super1->getSuperclass(resolver)){ + for (Type super1 = type1; super1; super1 = super1->getSuperclass()) { CanType canSuper1 = super1->getCanonicalType(); // If we have found the second type, we're done. @@ -83,7 +80,7 @@ Type Type::join(Type type1, Type type2) { // Look through the superclasses of type2 to determine if any were also // superclasses of type1. - for (Type super2 = type2; super2; super2 = super2->getSuperclass(resolver)){ + for (Type super2 = type2; super2; super2 = super2->getSuperclass()) { CanType canSuper2 = super2->getCanonicalType(); // If we found the first type, we're done. diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 2bd564b3ca3..e7be556dd2e 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -5812,7 +5812,7 @@ void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) { ->getAs(); if (!classTy) return; - auto superTy = classTy->getSuperclass(nullptr); + auto superTy = classTy->getSuperclass(); if (!superTy) return; // Dig out the Objective-C superclass. diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 8617a0c3235..0b957ee6910 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -2404,7 +2404,7 @@ bool ClangImporter::Implementation::matchesNSObjectBound(Type type) { return false; // Class type or existential that inherits from NSObject. - if (NSObjectType->isExactSuperclassOf(type, getTypeResolver())) + if (NSObjectType->isExactSuperclassOf(type)) return true; // Struct or enum type must have been bridged. diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index e8fb22628c4..96f66d954cc 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -1301,8 +1301,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks { Type DT = DC->getDeclaredTypeOfContext(); if (DT.isNull() || DT->is()) return; - OwnedResolver TypeResolver(createLazyResolver(CurDeclContext->getASTContext())); - Type ST = DT->getSuperclass(TypeResolver.get()); + Type ST = DT->getSuperclass(); if (ST.isNull() || ST->is()) return; if (ST->getNominalOrBoundGenericNominal()) { diff --git a/lib/IRGen/ClassMetadataLayout.h b/lib/IRGen/ClassMetadataLayout.h index 57374b4d738..05abe613fd2 100644 --- a/lib/IRGen/ClassMetadataLayout.h +++ b/lib/IRGen/ClassMetadataLayout.h @@ -83,7 +83,7 @@ private: // NB: We don't apply superclass substitutions to members because we want // consistent metadata layout between generic superclasses and concrete // subclasses. - if (Type superclass = type->getSuperclass(nullptr)) { + if (Type superclass = type->getSuperclass()) { ClassDecl *superclassDecl = superclass->getClassOrBoundGenericClass(); // Skip superclass fields if superclass is resilient. // FIXME: Needs runtime support to ensure the field offset vector is diff --git a/lib/IRGen/GenClass.cpp b/lib/IRGen/GenClass.cpp index 10ac14428cb..c726c35f310 100644 --- a/lib/IRGen/GenClass.cpp +++ b/lib/IRGen/GenClass.cpp @@ -76,7 +76,7 @@ ReferenceCounting irgen::getReferenceCountingForType(IRGenModule &IGM, // Class-constrained archetypes and existentials that don't use // native reference counting and yet have a superclass must be // using ObjC reference counting. - auto superclass = type->getSuperclass(nullptr); + auto superclass = type->getSuperclass(); if (superclass) return ReferenceCounting::ObjC; @@ -231,7 +231,7 @@ namespace { } if (theClass->hasSuperclass()) { - SILType superclassType = classType.getSuperclass(nullptr); + SILType superclassType = classType.getSuperclass(); auto superclass = superclassType.getClassOrBoundGenericClass(); assert(superclass); diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index 47d9a5dd693..9b516424df3 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -3699,7 +3699,7 @@ namespace { // Initialize the superclass if we didn't do so as a constant. if (HasUnfilledSuperclass) { - auto superclass = type->getSuperclass(nullptr)->getCanonicalType(); + auto superclass = type->getSuperclass()->getCanonicalType(); llvm::Value *superclassMetadata = emitClassHeapMetadataRef(IGF, superclass, MetadataValueType::TypeMetadata, @@ -4627,7 +4627,7 @@ llvm::Value *irgen::emitVirtualMethodValue(IRGenFunction &IGF, } else { // Otherwise, we can directly load the statically known superclass's // metadata. - auto superTy = instanceTy.getSuperclass(/*resolver=*/nullptr); + auto superTy = instanceTy.getSuperclass(); metadata = emitClassHeapMetadataRef(IGF, superTy.getSwiftRValueType(), MetadataValueType::TypeMetadata); } diff --git a/lib/IRGen/GenReflection.cpp b/lib/IRGen/GenReflection.cpp index 9c6c22b3d0b..9cef050913c 100644 --- a/lib/IRGen/GenReflection.cpp +++ b/lib/IRGen/GenReflection.cpp @@ -970,7 +970,7 @@ void IRGenModule::emitFieldMetadataRecord(const NominalTypeDecl *Decl) { // superclass as a special associated type named 'super' on the // 'AnyObject' protocol. if (auto Superclass = Decl->getDeclaredInterfaceType() - ->getSuperclass(nullptr)) { + ->getSuperclass()) { SuperclassMetadataBuilder builder(*this, cast(Decl), Superclass->getCanonicalType()); builder.emit(); diff --git a/lib/SIL/DynamicCasts.cpp b/lib/SIL/DynamicCasts.cpp index eedca48ee90..e88bf67adf3 100644 --- a/lib/SIL/DynamicCasts.cpp +++ b/lib/SIL/DynamicCasts.cpp @@ -240,13 +240,13 @@ classifyClassHierarchyCast(CanType source, CanType target) { // Upcast: if the target type statically matches a type in the // source type's hierarchy, this is a static upcast and the cast // will always succeed. - if (target->isExactSuperclassOf(source, nullptr)) + if (target->isExactSuperclassOf(source)) return DynamicCastFeasibility::WillSucceed; // Upcast: if the target type might dynamically match a type in the // source type's hierarchy, this might be an upcast, in which // case the cast might succeed. - if (target->isBindableToSuperclassOf(source, nullptr)) + if (target->isBindableToSuperclassOf(source)) return DynamicCastFeasibility::MaySucceed; // Downcast: if the source type might dynamically match a type in the @@ -254,7 +254,7 @@ classifyClassHierarchyCast(CanType source, CanType target) { // the cast might succeed. Note that this also covers the case where // the source type statically matches a type in the target type's // hierarchy; since it's a downcast, the cast still at best might succeed. - if (source->isBindableToSuperclassOf(target, nullptr)) + if (source->isBindableToSuperclassOf(target)) return DynamicCastFeasibility::MaySucceed; // Otherwise, the classes are unrelated and the cast will fail (at least @@ -1166,7 +1166,7 @@ bool swift::canUseScalarCheckedCastInstructions(SILModule &M, // If we statically know the source is an NSError subclass, then the cast // can go through the scalar path (and it's trivially true so can be // killed). - return targetType->isExactSuperclassOf(objectType, nullptr); + return targetType->isExactSuperclassOf(objectType); } // Three supported cases: diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp index 0c6f70b2952..2ad79f5d3d8 100644 --- a/lib/SIL/SILFunctionType.cpp +++ b/lib/SIL/SILFunctionType.cpp @@ -1906,8 +1906,8 @@ bool TypeConverter::requiresNewVTableEntryUncached(SILDeclRef derived) { auto overrideInterfaceTy = selfInterfaceTy->adjustSuperclassMemberDeclType( - base.getDecl(), derived.getDecl(), baseInterfaceTy, - /*resolver=*/nullptr)->getCanonicalType(); + base.getDecl(), derived.getDecl(), baseInterfaceTy) + ->getCanonicalType(); if (checkASTTypeForABIDifferences(derivedInterfaceTy, overrideInterfaceTy)) return true; @@ -2030,8 +2030,7 @@ SILConstantInfo TypeConverter::getConstantOverrideInfo(SILDeclRef derived, auto overrideInterfaceTy = selfInterfaceTy->adjustSuperclassMemberDeclType( - base.getDecl(), derived.getDecl(), baseInterfaceTy, - /*resolver=*/nullptr); + base.getDecl(), derived.getDecl(), baseInterfaceTy); // Copy generic signature from derived to the override type, to handle // the case where the base member is not generic (because the base class diff --git a/lib/SIL/SILType.cpp b/lib/SIL/SILType.cpp index f3d0bb2dd92..c3b1800c855 100644 --- a/lib/SIL/SILType.cpp +++ b/lib/SIL/SILType.cpp @@ -467,7 +467,7 @@ static bool isBridgedErrorClass(SILModule &M, // NSError (TODO: and CFError) can be bridged. auto nsErrorType = M.Types.getNSErrorType(); - if (t && nsErrorType && nsErrorType->isExactSuperclassOf(t, nullptr)) { + if (t && nsErrorType && nsErrorType->isExactSuperclassOf(t)) { return true; } diff --git a/lib/SIL/SILVerifier.cpp b/lib/SIL/SILVerifier.cpp index c797927f3b9..4646b5a4d3e 100644 --- a/lib/SIL/SILVerifier.cpp +++ b/lib/SIL/SILVerifier.cpp @@ -2214,7 +2214,7 @@ public: require(getDynamicMethodType(operandType, EMI->getMember()) .getSwiftRValueType() - ->isBindableTo(EMI->getType().getSwiftRValueType(), nullptr), + ->isBindableTo(EMI->getType().getSwiftRValueType()), "result must be of the method's type"); verifyOpenedArchetype(EMI, EMI->getType().getSwiftRValueType()); } @@ -2691,7 +2691,7 @@ public: } if (layout.superclass) { - require(layout.superclass->isExactSuperclassOf(concreteType, nullptr), + require(layout.superclass->isExactSuperclassOf(concreteType), "init_existential of subclass existential with wrong type"); } @@ -2984,10 +2984,10 @@ public: if (instClass->usesObjCGenericsModel()) { require(instClass->getDeclaredTypeInContext() - ->isBindableToSuperclassOf(opInstTy, nullptr), + ->isBindableToSuperclassOf(opInstTy), "upcast must cast to a superclass or an existential metatype"); } else { - require(instTy->isExactSuperclassOf(opInstTy, nullptr), + require(instTy->isExactSuperclassOf(opInstTy), "upcast must cast to a superclass or an existential metatype"); } return; @@ -3017,8 +3017,7 @@ public: "upcast must convert a class instance to a class type"); if (ToClass->usesObjCGenericsModel()) { require(ToClass->getDeclaredTypeInContext() - ->isBindableToSuperclassOf(FromTy.getSwiftRValueType(), - nullptr), + ->isBindableToSuperclassOf(FromTy.getSwiftRValueType()), "upcast must cast to a superclass or an existential metatype"); } else { require(ToTy.isExactSuperclassOf(FromTy), @@ -3557,7 +3556,7 @@ public: auto bbArgTy = DMBI->getHasMethodBB()->args_begin()[0]->getType(); require(getDynamicMethodType(operandType, DMBI->getMember()) .getSwiftRValueType() - ->isBindableTo(bbArgTy.getSwiftRValueType(), nullptr), + ->isBindableTo(bbArgTy.getSwiftRValueType()), "bb argument for dynamic_method_br must be of the method's type"); } diff --git a/lib/SILGen/SILGenConvert.cpp b/lib/SILGen/SILGenConvert.cpp index 486a3a3f7dc..4c15d4420ef 100644 --- a/lib/SILGen/SILGenConvert.cpp +++ b/lib/SILGen/SILGenConvert.cpp @@ -462,7 +462,7 @@ ManagedValue SILGenFunction::emitExistentialErasure( // If the concrete type is NSError or a subclass thereof, just erase it // directly. auto nsErrorType = nsErrorDecl->getDeclaredType()->getCanonicalType(); - if (nsErrorType->isExactSuperclassOf(concreteFormalType, nullptr)) { + if (nsErrorType->isExactSuperclassOf(concreteFormalType)) { ManagedValue nsError = F(SGFContext()); if (nsErrorType != concreteFormalType) { nsError = B.createUpcast(loc, nsError, getLoweredType(nsErrorType)); diff --git a/lib/SILGen/SILGenPoly.cpp b/lib/SILGen/SILGenPoly.cpp index 39eb2b0efae..e0191322b5b 100644 --- a/lib/SILGen/SILGenPoly.cpp +++ b/lib/SILGen/SILGenPoly.cpp @@ -475,7 +475,7 @@ ManagedValue Transform::transform(ManagedValue v, v.getCleanup()); } - if (outputSubstType->isExactSuperclassOf(inputSubstType, nullptr)) { + if (outputSubstType->isExactSuperclassOf(inputSubstType)) { // Upcast to a superclass. return ManagedValue(SGF.B.createUpcast(Loc, v.getValue(), @@ -483,7 +483,7 @@ ManagedValue Transform::transform(ManagedValue v, v.getCleanup()); } else { // Unchecked-downcast to a covariant return type. - assert(inputSubstType->isExactSuperclassOf(outputSubstType, nullptr) + assert(inputSubstType->isExactSuperclassOf(outputSubstType) && "should be inheritance relationship between input and output"); return SGF.emitManagedRValueWithCleanup( SGF.B.createUncheckedRefCast(Loc, v.forward(SGF), loweredResultTy)); diff --git a/lib/SILOptimizer/Utils/Local.cpp b/lib/SILOptimizer/Utils/Local.cpp index ae983abd766..fc3e0fb618e 100644 --- a/lib/SILOptimizer/Utils/Local.cpp +++ b/lib/SILOptimizer/Utils/Local.cpp @@ -499,7 +499,7 @@ SILValue swift::castValueToABICompatibleType(SILBuilder *B, SILLocation Loc, // A is a superclass of B, then it can be done by means // of a simple upcast. if (mt2.getInstanceType()->isExactSuperclassOf( - mt1.getInstanceType(), nullptr)) { + mt1.getInstanceType())) { return B->createUpcast(Loc, Value, DestTy); } diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 8227f454c79..7b6b6e5e264 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -4244,7 +4244,7 @@ getCallerDefaultArg(ConstraintSystem &cs, DeclContext *dc, case DefaultArgumentKind::Inherited: // Update the owner to reflect inheritance here. - owner = owner.getOverriddenDecl(tc.Context, &tc); + owner = owner.getOverriddenDecl(tc.Context); return getCallerDefaultArg(cs, dc, loc, owner, index); case DefaultArgumentKind::Column: diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index b82f22ac262..53bb06b501c 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -2509,7 +2509,7 @@ namespace { auto selfTy = CS.DC->mapTypeIntoContext( typeContext->getDeclaredInterfaceType()); - auto superclassTy = selfTy->getSuperclass(&tc); + auto superclassTy = selfTy->getSuperclass(); if (selfDecl->getInterfaceType()->is()) superclassTy = MetatypeType::get(superclassTy); diff --git a/lib/Sema/CSRanking.cpp b/lib/Sema/CSRanking.cpp index 522a88b524a..eb1c8f57e46 100644 --- a/lib/Sema/CSRanking.cpp +++ b/lib/Sema/CSRanking.cpp @@ -227,12 +227,12 @@ namespace { /// Determines whether the first type is nominally a superclass of the second /// type, ignore generic arguments. -static bool isNominallySuperclassOf(TypeChecker &tc, Type type1, Type type2) { +static bool isNominallySuperclassOf(Type type1, Type type2) { auto nominal1 = type1->getAnyNominal(); if (!nominal1) return false; - for (auto super2 = type2; super2; super2 = super2->getSuperclass(&tc)) { + for (auto super2 = type2; super2; super2 = super2->getSuperclass()) { if (super2->getAnyNominal() == nominal1) return true; } @@ -261,10 +261,10 @@ static SelfTypeRelationship computeSelfTypeRelationship(TypeChecker &tc, // If both types can have superclasses, which whether one is a superclass // of the other. The subclass is the common base type. if (type1->mayHaveSuperclass() && type2->mayHaveSuperclass()) { - if (isNominallySuperclassOf(tc, type1, type2)) + if (isNominallySuperclassOf(type1, type2)) return SelfTypeRelationship::Superclass; - if (isNominallySuperclassOf(tc, type2, type1)) + if (isNominallySuperclassOf(type2, type1)) return SelfTypeRelationship::Subclass; return SelfTypeRelationship::Unrelated; diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index d923b8a5a7d..df12bfbada4 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -726,7 +726,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E, // Casting to the same type or a superclass is a no-op. if (toTy->isEqual(fromTy) || - toTy->isExactSuperclassOf(fromTy, &TC)) { + toTy->isExactSuperclassOf(fromTy)) { auto d = TC.diagnose(DRE->getLoc(), diag::bitcasting_is_no_op, fromTy, toTy); if (subExpr) { @@ -757,7 +757,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E, } // Unchecked casting to a subclass is better done by unsafeDowncast. - if (fromTy->isBindableToSuperclassOf(toTy, &TC)) { + if (fromTy->isBindableToSuperclassOf(toTy)) { TC.diagnose(DRE->getLoc(), diag::bitcasting_to_downcast, fromTy, toTy) .fixItReplace(DRE->getNameLoc().getBaseNameLoc(), diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index 3685adbf598..887bbf2bf7b 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -3384,13 +3384,13 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType, if (toType->getClassOrBoundGenericClass()) toSuperclass = toType; else - toSuperclass = toType->getSuperclass(nullptr); + toSuperclass = toType->getSuperclass(); Type fromSuperclass; if (fromType->getClassOrBoundGenericClass()) fromSuperclass = fromType; else - fromSuperclass = fromType->getSuperclass(nullptr); + fromSuperclass = fromType->getSuperclass(); // Unless both types have a superclass bound, we have no further // information. diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 2af6e688b6c..24258f573e8 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -5254,7 +5254,7 @@ public: bool treatIUOResultAsError) { bool emittedError = false; Type plainParentTy = owningTy->adjustSuperclassMemberDeclType( - parentMember, member, parentMember->getInterfaceType(), &TC); + parentMember, member, parentMember->getInterfaceType()); const auto *parentTy = plainParentTy->castTo(); if (isa(parentMember)) parentTy = parentTy->getResult()->castTo(); @@ -5700,7 +5700,7 @@ public: // Check whether the types are identical. auto parentDeclTy = owningTy->adjustSuperclassMemberDeclType( - parentDecl, decl, parentDecl->getInterfaceType(), &TC); + parentDecl, decl, parentDecl->getInterfaceType()); parentDeclTy = parentDeclTy->getUnlabeledType(TC.Context); if (method) { // For methods, strip off the 'Self' type. @@ -5971,7 +5971,7 @@ public: } else if (auto property = dyn_cast_or_null(abstractStorage)) { auto propertyTy = property->getInterfaceType(); auto parentPropertyTy = superclass->adjustSuperclassMemberDeclType( - matchDecl, decl, matchDecl->getInterfaceType(), &TC); + matchDecl, decl, matchDecl->getInterfaceType()); if (!propertyTy->canOverride(parentPropertyTy, OverrideMatchMode::Strict, diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index 3e12e4bf59b..badb353a2bc 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -3142,7 +3142,7 @@ static CheckTypeWitnessResult checkTypeWitness(TypeChecker &tc, DeclContext *dc, AssociatedTypeDecl *assocType, Type type) { if (auto superclass = assocType->getSuperclass()) { - if (!superclass->isExactSuperclassOf(type, &tc)) + if (!superclass->isExactSuperclassOf(type)) return superclass->getAnyNominal(); } diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index c509dcfdee6..8f9910b9020 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -401,8 +401,7 @@ findDeclContextForType(TypeChecker &TC, } } else { // Get the substituted superclass type, if any. - superclass = resolver->resolveTypeOfContext(parentDC) - ->getSuperclass(nullptr); + superclass = resolver->resolveTypeOfContext(parentDC)->getSuperclass(); // Start with the type of the current context. auto fromNominal = parentDC->getAsNominalTypeOrNominalTypeExtensionContext(); @@ -426,7 +425,7 @@ findDeclContextForType(TypeChecker &TC, if (superclassDecl == ownerNominal) return std::make_tuple(superclass, true); - superclass = superclass->getSuperclass(nullptr); + superclass = superclass->getSuperclass(); } // Walk refined protocols. @@ -983,8 +982,10 @@ static Type diagnoseUnknownType(TypeChecker &tc, DeclContext *dc, } else { // Situation where class tries to inherit from itself, such // would produce an assertion when trying to lookup members of the class. - auto lazyResolver = tc.Context.getLazyResolver(); - if (auto superClass = parentType->getSuperclass(lazyResolver)) { + // + // FIXME: Handle this in a more principled way, since there are many + // similar checks. + if (auto superClass = parentType->getSuperclass()) { if (superClass->isEqual(parentType)) { auto decl = parentType->getAnyNominal(); if (decl) { @@ -2973,7 +2974,7 @@ Type TypeResolver::resolveCompositionType(CompositionTypeRepr *repr, } if (ty->isExistentialType()) { - if (auto superclassTy = ty->getSuperclass(nullptr)) + if (auto superclassTy = ty->getSuperclass()) if (checkSuperclass(tyR->getStartLoc(), superclassTy)) continue; @@ -3062,7 +3063,7 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module, // derived class as the parent type. if (auto *ownerClass = member->getDeclContext() ->getAsClassOrClassExtensionContext()) { - baseTy = baseTy->getSuperclassForDecl(ownerClass, this); + baseTy = baseTy->getSuperclassForDecl(ownerClass); } if (baseTy->is()) @@ -3101,7 +3102,7 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module, } Type TypeChecker::getSuperClassOf(Type type) { - return type->getSuperclass(this); + return type->getSuperclass(); } static void lookupAndAddLibraryTypes(TypeChecker &TC, diff --git a/tools/swift-ide-test/ModuleAPIDiff.cpp b/tools/swift-ide-test/ModuleAPIDiff.cpp index a9269445ef2..3be0f380bd2 100644 --- a/tools/swift-ide-test/ModuleAPIDiff.cpp +++ b/tools/swift-ide-test/ModuleAPIDiff.cpp @@ -83,10 +83,9 @@ generic-signature ::= GenericSignature: GenericParams: (ordered) - Name: - (Superclass: )? ConformanceRequirements: - Type: - Protocol: + ProtocolOrClass: SameTypeRequirements: - FirstType: SecondType: @@ -320,7 +319,6 @@ bool operator==(const NestedDecls &LHS, const NestedDecls &RHS) { struct GenericParam { Identifier Name; - Optional Superclass; }; struct ConformanceRequirement { @@ -507,7 +505,6 @@ template <> struct MappingTraits<::swift::sma::NestedDecls> { template <> struct MappingTraits<::swift::sma::GenericParam> { static void mapping(IO &io, ::swift::sma::GenericParam &ND) { io.mapRequired("Name", ND.Name); - io.mapOptional("Superclass", ND.Superclass); } }; @@ -745,21 +742,21 @@ public: for (auto *GTPT : GS->getGenericParams()) { sma::GenericParam ResultGP; ResultGP.Name = convertToIdentifier(GTPT->getName()); - if (auto SuperclassTy = GTPT->getSuperclass(nullptr)) { - ResultGP.Superclass = convertToTypeName(SuperclassTy); - } ResultGS.GenericParams.emplace_back(std::move(ResultGP)); } for (auto &Req : GS->getRequirements()) { switch (Req.getKind()) { case RequirementKind::Superclass: case RequirementKind::Conformance: - case RequirementKind::Layout: ResultGS.ConformanceRequirements.emplace_back( sma::ConformanceRequirement{ convertToTypeName(Req.getFirstType()), convertToTypeName(Req.getSecondType())}); break; + case RequirementKind::Layout: + // FIXME + assert(false && "Not implemented"); + break; case RequirementKind::SameType: ResultGS.SameTypeRequirements.emplace_back( sma::SameTypeRequirement{convertToTypeName(Req.getFirstType()),