From 8afff6169956e2f363621cc578427939fc6f2b08 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 29 Jun 2023 19:18:28 -0400 Subject: [PATCH] AST: Replace TypeArrayView with ArrayRef This basically undoes 3da6fe9c0d48, which in hindsight was wrong. There were no other usages of TypeArrayView anywhere else except for GenericSignature::getGenericParams(), and it was almost never what you want, so callers had to convert back and forth to an ArrayRef. Remove it. --- include/swift/AST/Decl.h | 4 +-- include/swift/AST/GenericEnvironment.h | 2 +- include/swift/AST/GenericParamKey.h | 2 +- include/swift/AST/GenericSignature.h | 34 +++++++++--------- include/swift/AST/Type.h | 11 ------ include/swift/AST/Types.h | 4 +-- lib/AST/ASTContext.cpp | 20 +++-------- lib/AST/ASTPrinter.cpp | 12 +++---- lib/AST/Decl.cpp | 2 +- lib/AST/GenericEnvironment.cpp | 4 +-- lib/AST/GenericSignature.cpp | 36 ++++++++++++------- lib/AST/ParameterPack.cpp | 11 +++--- lib/AST/RequirementMachine/Diagnostics.cpp | 6 ++-- .../GenericSignatureQueries.cpp | 12 +++---- lib/AST/RequirementMachine/InterfaceType.cpp | 8 ++--- lib/AST/RequirementMachine/PropertyMap.cpp | 4 +-- lib/AST/RequirementMachine/PropertyMap.h | 10 +++--- .../RequirementMachine/RequirementBuilder.cpp | 6 ++-- .../RequirementMachine/RequirementMachine.cpp | 6 ++-- .../RequirementMachine/RequirementMachine.h | 19 +++++----- .../RequirementMachineRequests.cpp | 2 +- lib/AST/RequirementMachine/RewriteSystem.h | 4 +-- lib/Sema/TypeCheckGeneric.cpp | 4 +-- lib/Sema/TypeCheckProtocol.cpp | 3 +- lib/Sema/TypeChecker.h | 2 +- lib/SymbolGraphGen/JSON.cpp | 2 +- lib/SymbolGraphGen/JSON.h | 2 +- 27 files changed, 111 insertions(+), 121 deletions(-) diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 2ea9a088d6e15..478db907d017d 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -1358,7 +1358,7 @@ class GenericContext : private _GenericContext, public DeclContext { GenericEnvironment *getGenericEnvironment() const; /// Retrieve the innermost generic parameter types. - TypeArrayView getInnermostGenericParamTypes() const; + ArrayRef getInnermostGenericParamTypes() const; /// Retrieve the generic requirements. ArrayRef getGenericRequirements() const; @@ -3148,7 +3148,7 @@ class OpaqueTypeDecl final : /// Retrieve the generic parameters that represent the opaque types described by this opaque /// type declaration. - TypeArrayView getOpaqueGenericParams() const { + ArrayRef getOpaqueGenericParams() const { return OpaqueInterfaceGenericSignature.getInnermostGenericParams(); } diff --git a/include/swift/AST/GenericEnvironment.h b/include/swift/AST/GenericEnvironment.h index b1e01edccc941..810103630b4a1 100644 --- a/include/swift/AST/GenericEnvironment.h +++ b/include/swift/AST/GenericEnvironment.h @@ -177,7 +177,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final Kind getKind() const { return SignatureAndKind.getInt(); } - TypeArrayView getGenericParams() const; + ArrayRef getGenericParams() const; /// Retrieve the existential type for an opened existential environment. Type getOpenedExistentialType() const; diff --git a/include/swift/AST/GenericParamKey.h b/include/swift/AST/GenericParamKey.h index 7d9215fe1d93c..70f525e6407eb 100644 --- a/include/swift/AST/GenericParamKey.h +++ b/include/swift/AST/GenericParamKey.h @@ -93,7 +93,7 @@ struct GenericParamKey { /// Find the index that this key would have into an array of /// generic type parameters - unsigned findIndexIn(TypeArrayView genericParams) const; + unsigned findIndexIn(ArrayRef genericParams) const; }; } // end namespace swift diff --git a/include/swift/AST/GenericSignature.h b/include/swift/AST/GenericSignature.h index cea9d293435cf..f70e1472e774e 100644 --- a/include/swift/AST/GenericSignature.h +++ b/include/swift/AST/GenericSignature.h @@ -34,6 +34,7 @@ class ProtocolConformanceRef; class ProtocolType; class SubstitutionMap; class GenericEnvironment; +class GenericTypeParamType; namespace rewriting { class RequirementMachine; @@ -118,16 +119,13 @@ class GenericSignature { static GenericSignature get(ArrayRef params, ArrayRef requirements, bool isKnownCanonical = false); - static GenericSignature get(TypeArrayView params, - ArrayRef requirements, - bool isKnownCanonical = false); /// Produce a new generic signature which drops all of the marker /// protocol conformance requirements associated with this one. GenericSignature withoutMarkerProtocols() const; public: - static ASTContext &getASTContext(TypeArrayView params, + static ASTContext &getASTContext(ArrayRef params, ArrayRef requirements); public: @@ -164,7 +162,7 @@ class GenericSignature { void Profile(llvm::FoldingSetNodeID &id) const; static void Profile(llvm::FoldingSetNodeID &ID, - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements); public: using RequiredProtocols = SmallVector; @@ -191,13 +189,13 @@ class GenericSignature { public: /// Retrieve the generic parameters. - TypeArrayView getGenericParams() const; + ArrayRef getGenericParams() const; /// Retrieve the innermost generic parameters. /// /// Given a generic signature for a nested generic type, produce an /// array of the generic parameters for the innermost generic type. - TypeArrayView getInnermostGenericParams() const; + ArrayRef getInnermostGenericParams() const; /// Retrieve the requirements. ArrayRef getRequirements() const; @@ -240,7 +238,7 @@ class CanGenericSignature : public GenericSignature { /// Create a new generic signature with the given type parameters and /// requirements, first canonicalizing the types. static CanGenericSignature - getCanonical(TypeArrayView params, + getCanonical(ArrayRef params, ArrayRef requirements); public: @@ -267,7 +265,8 @@ class CanGenericSignature : public GenericSignature { /// The underlying implementation of generic signatures. class alignas(1 << TypeAlignInBits) GenericSignatureImpl final : public llvm::FoldingSetNode, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend class ASTContext; friend GenericSignature; friend TrailingObjects; @@ -286,14 +285,14 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final void *operator new(size_t Bytes) = delete; void operator delete(void *Data) = delete; - size_t numTrailingObjects(OverloadToken) const { + size_t numTrailingObjects(OverloadToken) const { return NumGenericParams; } size_t numTrailingObjects(OverloadToken) const { return NumRequirements; } - GenericSignatureImpl(TypeArrayView params, + GenericSignatureImpl(ArrayRef params, ArrayRef requirements, bool isKnownCanonical); @@ -326,6 +325,9 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final /// concrete. bool areAllParamsConcrete() const; + /// Check if the generic signature has a parameter pack. + bool hasParameterPack() const; + /// Compute the number of conformance requirements in this signature. unsigned getNumConformanceRequirements() const { unsigned result = 0; @@ -470,7 +472,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final Type getDependentUpperBounds(Type type) const; static void Profile(llvm::FoldingSetNodeID &ID, - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements); void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const; @@ -483,16 +485,16 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final friend CanGenericSignature; /// Retrieve the generic parameters. - TypeArrayView getGenericParams() const { - return TypeArrayView( - {getTrailingObjects(), NumGenericParams}); + ArrayRef getGenericParams() const { + return ArrayRef( + {getTrailingObjects(), NumGenericParams}); } /// Retrieve the innermost generic parameters. /// /// Given a generic signature for a nested generic type, produce an /// array of the generic parameters for the innermost generic type. - TypeArrayView getInnermostGenericParams() const; + ArrayRef getInnermostGenericParams() const; /// Retrieve the requirements. ArrayRef getRequirements() const { diff --git a/include/swift/AST/Type.h b/include/swift/AST/Type.h index 63a058950ce39..681f6987e7bb5 100644 --- a/include/swift/AST/Type.h +++ b/include/swift/AST/Type.h @@ -663,17 +663,6 @@ inline CanTypeWrapper dyn_cast_or_null(CanTypeWrapper

type) { return CanTypeWrapper(dyn_cast_or_null(type.getPointer())); } -template -inline T *staticCastHelper(const Type &Ty) { - // The constructor of the ArrayRef must guarantee this invariant. - // XXX -- We use reinterpret_cast instead of static_cast so that files - // can avoid including Types.h if they want to. - return reinterpret_cast(Ty.getPointer()); -} -/// TypeArrayView allows arrays of 'Type' to have a static type. -template -using TypeArrayView = ArrayRefView; } // end namespace swift namespace llvm { diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 03932d2884f40..428705af2cfdb 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -3786,7 +3786,7 @@ class GenericFunctionType final : public AnyFunctionType, } /// Retrieve the generic parameters of this polymorphic function type. - TypeArrayView getGenericParams() const; + ArrayRef getGenericParams() const; /// Retrieve the requirements of this polymorphic function type. ArrayRef getRequirements() const; @@ -6859,7 +6859,7 @@ class PackType final : public TypeBase, public llvm::FoldingSetNode, static PackType *getSingletonPackExpansion(Type packParameter); static SmallVector getExpandedGenericArgs( - TypeArrayView params, + ArrayRef params, ArrayRef args); public: diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 15551c01cedf2..4bdf1e3132fc3 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4376,7 +4376,7 @@ GenericTypeParamType *GenericTypeParamType::get(bool isParameterPack, return result; } -TypeArrayView +ArrayRef GenericFunctionType::getGenericParams() const { return Signature.getGenericParams(); } @@ -5071,7 +5071,7 @@ SubstitutionMap::Storage *SubstitutionMap::Storage::get( } void GenericSignatureImpl::Profile(llvm::FoldingSetNodeID &ID, - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements) { for (auto p : genericParams) ID.AddPointer(p); @@ -5086,19 +5086,8 @@ void GenericSignatureImpl::Profile(llvm::FoldingSetNodeID &ID, } } -GenericSignature -GenericSignature::get(ArrayRef params, - ArrayRef requirements, - bool isKnownCanonical) { - SmallVector paramTypes; - for (auto param : params) - paramTypes.push_back(param); - auto paramsView = TypeArrayView(paramTypes); - return get(paramsView, requirements, isKnownCanonical); -} - GenericSignature -GenericSignature::get(TypeArrayView params, +GenericSignature::get(ArrayRef params, ArrayRef requirements, bool isKnownCanonical) { assert(!params.empty()); @@ -5128,7 +5117,8 @@ GenericSignature::get(TypeArrayView params, // Allocate and construct the new signature. size_t bytes = - GenericSignatureImpl::template totalSizeToAlloc( + GenericSignatureImpl::template totalSizeToAlloc< + GenericTypeParamType *, Requirement>( params.size(), requirements.size()); void *mem = ctx.Allocate(bytes, alignof(GenericSignatureImpl)); auto *newSig = diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 58aa406391c30..9f9b1eb285916 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -910,11 +910,11 @@ class PrintAST : public ASTVisitor { printGenericSignature(GenericSignature genericSig, unsigned flags, llvm::function_ref filter); void printSingleDepthOfGenericSignature( - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements, unsigned flags, llvm::function_ref filter); void printSingleDepthOfGenericSignature( - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements, bool &isFirstReq, unsigned flags, llvm::function_ref filter); void printRequirement(const Requirement &req); @@ -1641,7 +1641,7 @@ void PrintAST::printGenericSignature( } void PrintAST::printSingleDepthOfGenericSignature( - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements, unsigned flags, llvm::function_ref filter) { bool isFirstReq = true; @@ -1650,7 +1650,7 @@ void PrintAST::printSingleDepthOfGenericSignature( } void PrintAST::printSingleDepthOfGenericSignature( - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements, bool &isFirstReq, unsigned flags, llvm::function_ref filter) { bool printParams = (flags & PrintParams); @@ -1692,7 +1692,7 @@ void PrintAST::printSingleDepthOfGenericSignature( /// Separate the explicit generic parameters from the implicit, opaque /// generic parameters. We only print the former. - TypeArrayView opaqueGenericParams; + ArrayRef opaqueGenericParams; for (unsigned index : indices(genericParams)) { auto gpDecl = genericParams[index]->getDecl(); if (!gpDecl) @@ -5728,7 +5728,7 @@ class TypePrinter : public TypeVisitor { } void printGenericArgs(ASTContext &ctx, - TypeArrayView params, + ArrayRef params, ArrayRef args) { printGenericArgs(PackType::getExpandedGenericArgs(params, args)); } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index ba2d4efcd7218..76a43b3439e6d 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1219,7 +1219,7 @@ GenericContext::GenericContext(DeclContextKind Kind, DeclContext *Parent, } } -TypeArrayView +ArrayRef GenericContext::getInnermostGenericParamTypes() const { return getGenericSignature().getInnermostGenericParams(); } diff --git a/lib/AST/GenericEnvironment.cpp b/lib/AST/GenericEnvironment.cpp index 142fdcc405434..29cab73dd25f1 100644 --- a/lib/AST/GenericEnvironment.cpp +++ b/lib/AST/GenericEnvironment.cpp @@ -98,7 +98,7 @@ ArrayRef GenericEnvironment::getOpenedPackParams() const { return ArrayRef(begin, getNumOpenedPackParams()); } -TypeArrayView +ArrayRef GenericEnvironment::getGenericParams() const { return getGenericSignature().getGenericParams(); } @@ -152,7 +152,7 @@ namespace { struct FindOpenedElementParam { ArrayRef openedPacks; - TypeArrayView packElementParams; + ArrayRef packElementParams; FindOpenedElementParam(const GenericEnvironment *env, ArrayRef openedPacks) diff --git a/lib/AST/GenericSignature.cpp b/lib/AST/GenericSignature.cpp index 6fde0c9387f06..b0af8625d92b6 100644 --- a/lib/AST/GenericSignature.cpp +++ b/lib/AST/GenericSignature.cpp @@ -45,12 +45,12 @@ void ConformancePath::dump() const { } GenericSignatureImpl::GenericSignatureImpl( - TypeArrayView params, + ArrayRef params, ArrayRef requirements, bool isKnownCanonical) : NumGenericParams(params.size()), NumRequirements(requirements.size()), CanonicalSignatureOrASTContext() { std::uninitialized_copy(params.begin(), params.end(), - getTrailingObjects()); + getTrailingObjects()); std::uninitialized_copy(requirements.begin(), requirements.end(), getTrailingObjects()); @@ -75,7 +75,7 @@ GenericSignatureImpl::GenericSignatureImpl( &GenericSignature::getASTContext(params, requirements); } -TypeArrayView +ArrayRef GenericSignatureImpl::getInnermostGenericParams() const { const auto params = getGenericParams(); @@ -168,8 +168,17 @@ bool GenericSignatureImpl::areAllParamsConcrete() const { return numConcreteGenericParams == getGenericParams().size(); } +bool GenericSignatureImpl::hasParameterPack() const { + for (auto *paramTy : getGenericParams()) { + if (paramTy->isParameterPack()) + return true; + } + + return false; +} + ASTContext &GenericSignature::getASTContext( - TypeArrayView params, + ArrayRef params, ArrayRef requirements) { // The params and requirements cannot both be empty. if (!params.empty()) @@ -179,9 +188,9 @@ ASTContext &GenericSignature::getASTContext( } /// Retrieve the generic parameters. -TypeArrayView GenericSignature::getGenericParams() const { +ArrayRef GenericSignature::getGenericParams() const { return isNull() - ? TypeArrayView{} + ? ArrayRef() : getPointer()->getGenericParams(); } @@ -189,9 +198,9 @@ TypeArrayView GenericSignature::getGenericParams() const { /// /// Given a generic signature for a nested generic type, produce an /// array of the generic parameters for the innermost generic type. -TypeArrayView GenericSignature::getInnermostGenericParams() const { +ArrayRef GenericSignature::getInnermostGenericParams() const { return isNull() - ? TypeArrayView{} + ? ArrayRef() : getPointer()->getInnermostGenericParams(); } @@ -224,7 +233,7 @@ bool GenericSignatureImpl::isCanonical() const { } CanGenericSignature -CanGenericSignature::getCanonical(TypeArrayView params, +CanGenericSignature::getCanonical(ArrayRef params, ArrayRef requirements) { // Canonicalize the parameters and requirements. SmallVector canonicalParams; @@ -529,8 +538,9 @@ bool GenericSignatureImpl::isValidTypeParameter(Type type) const { ArrayRef> CanGenericSignature::getGenericParams() const { - auto params = this->GenericSignature::getGenericParams().getOriginalArray(); - auto base = static_cast*>( + auto params = + this->GenericSignature::getGenericParams(); + auto base = reinterpret_cast *>( params.data()); return {base, params.size()}; } @@ -572,7 +582,7 @@ SmallVector GenericSignatureImpl::getShapeClasses() const { } unsigned GenericParamKey::findIndexIn( - TypeArrayView genericParams) const { + ArrayRef genericParams) const { // For depth 0, we have random access. We perform the extra checking so that // we can return if (Depth == 0 && Index < genericParams.size() && @@ -735,7 +745,7 @@ void GenericSignature::Profile(llvm::FoldingSetNodeID &id) const { } void GenericSignature::Profile(llvm::FoldingSetNodeID &ID, - TypeArrayView genericParams, + ArrayRef genericParams, ArrayRef requirements) { return GenericSignatureImpl::Profile(ID, genericParams, requirements); } diff --git a/lib/AST/ParameterPack.cpp b/lib/AST/ParameterPack.cpp index 7638c7ef4f34b..8d234183c8729 100644 --- a/lib/AST/ParameterPack.cpp +++ b/lib/AST/ParameterPack.cpp @@ -351,14 +351,13 @@ SmallVector BoundGenericType::getExpandedGenericArgs() { // It would be nicer to use genericSig.getInnermostGenericParams() here, // but that triggers a request cycle if we're in the middle of computing // the generic signature already. - SmallVector params; + SmallVector params; for (auto *paramDecl : getDecl()->getGenericParams()->getParams()) { - params.push_back(paramDecl->getDeclaredInterfaceType()); + params.push_back(paramDecl->getDeclaredInterfaceType() + ->castTo()); } - return PackType::getExpandedGenericArgs( - TypeArrayView(params), - getGenericArgs()); + return PackType::getExpandedGenericArgs(params, getGenericArgs()); } /// Foo => Pack{T..., Int, String} @@ -374,7 +373,7 @@ SmallVector TypeAliasType::getExpandedGenericArgs() { /// Pack{T, Pack{Int, String}} => {T..., Int, String} SmallVector -PackType::getExpandedGenericArgs(TypeArrayView params, +PackType::getExpandedGenericArgs(ArrayRef params, ArrayRef args) { SmallVector wrappedArgs; diff --git a/lib/AST/RequirementMachine/Diagnostics.cpp b/lib/AST/RequirementMachine/Diagnostics.cpp index 5dc484b8b3ae6..91c920b55c060 100644 --- a/lib/AST/RequirementMachine/Diagnostics.cpp +++ b/lib/AST/RequirementMachine/Diagnostics.cpp @@ -405,7 +405,7 @@ void RewriteSystem::computeRedundantRequirementDiagnostics( static Requirement getRequirementForDiagnostics(Type subject, Symbol property, const PropertyMap &map, - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &prefix) { switch (property.getKind()) { case Symbol::Kind::ConcreteType: { @@ -439,7 +439,7 @@ getRequirementForDiagnostics(Type subject, Symbol property, void RewriteSystem::computeConflictingRequirementDiagnostics( SmallVectorImpl &errors, SourceLoc signatureLoc, const PropertyMap &propertyMap, - TypeArrayView genericParams) { + ArrayRef genericParams) { for (auto pair : ConflictingRules) { const auto &firstRule = getRule(pair.first); const auto &secondRule = getRule(pair.second); @@ -476,7 +476,7 @@ void RewriteSystem::computeConflictingRequirementDiagnostics( void RewriteSystem::computeRecursiveRequirementDiagnostics( SmallVectorImpl &errors, SourceLoc signatureLoc, const PropertyMap &propertyMap, - TypeArrayView genericParams) { + ArrayRef genericParams) { for (unsigned ruleID : RecursiveRules) { const auto &rule = getRule(ruleID); diff --git a/lib/AST/RequirementMachine/GenericSignatureQueries.cpp b/lib/AST/RequirementMachine/GenericSignatureQueries.cpp index 43174d16baae0..326c7d1729ca1 100644 --- a/lib/AST/RequirementMachine/GenericSignatureQueries.cpp +++ b/lib/AST/RequirementMachine/GenericSignatureQueries.cpp @@ -49,7 +49,7 @@ using namespace rewriting; GenericSignature::LocalRequirements RequirementMachine::getLocalRequirements( Type depType, - TypeArrayView genericParams) const { + ArrayRef genericParams) const { auto term = Context.getMutableTermForType(depType->getCanonicalType(), /*proto=*/nullptr); System.simplify(term); @@ -158,7 +158,7 @@ RequirementMachine::getRequiredProtocols(Type depType) const { Type RequirementMachine:: getSuperclassBound(Type depType, - TypeArrayView genericParams) const { + ArrayRef genericParams) const { auto term = Context.getMutableTermForType(depType->getCanonicalType(), /*proto=*/nullptr); System.simplify(term); @@ -198,7 +198,7 @@ bool RequirementMachine::isConcreteType(Type depType, /// `Self` generic parameter here. Type RequirementMachine:: getConcreteType(Type depType, - TypeArrayView genericParams, + ArrayRef genericParams, const ProtocolDecl *proto) const { auto term = Context.getMutableTermForType(depType->getCanonicalType(), proto); @@ -359,7 +359,7 @@ static Type substPrefixType(Type type, unsigned suffixLength, Type prefixType, /// as well, and so on. Type RequirementMachine::getReducedType( Type type, - TypeArrayView genericParams) const { + ArrayRef genericParams) const { return type.transformRec([&](Type t) -> llvm::Optional { if (!t->hasTypeParameter()) @@ -739,7 +739,7 @@ RequirementMachine::getReducedShapeTerm(Type type) const { } Type RequirementMachine::getReducedShape(Type type, - TypeArrayView genericParams) const { + ArrayRef genericParams) const { if (!type->isParameterPack()) return Type(); @@ -759,7 +759,7 @@ void RequirementMachine::verify(const MutableTerm &term) const { // generic parameter. if (term.begin()->getKind() == Symbol::Kind::GenericParam) { auto *genericParam = term.begin()->getGenericParam(); - TypeArrayView genericParams = getGenericParams(); + auto genericParams = getGenericParams(); auto found = std::find_if(genericParams.begin(), genericParams.end(), [&](GenericTypeParamType *otherType) { diff --git a/lib/AST/RequirementMachine/InterfaceType.cpp b/lib/AST/RequirementMachine/InterfaceType.cpp index 54b0f40a3c2e6..b5db0d8b8396b 100644 --- a/lib/AST/RequirementMachine/InterfaceType.cpp +++ b/lib/AST/RequirementMachine/InterfaceType.cpp @@ -241,7 +241,7 @@ AssociatedTypeDecl *PropertyBag::getAssociatedType(Identifier name) { /// Compute the interface type for a range of symbols. static Type getTypeForSymbolRange(const Symbol *begin, const Symbol *end, - TypeArrayView genericParams, + ArrayRef genericParams, const PropertyMap &map) { auto &ctx = map.getRewriteContext(); Type result; @@ -391,12 +391,12 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end, } Type PropertyMap::getTypeForTerm(Term term, - TypeArrayView genericParams) const { + ArrayRef genericParams) const { return getTypeForSymbolRange(term.begin(), term.end(), genericParams, *this); } Type PropertyMap::getTypeForTerm(const MutableTerm &term, - TypeArrayView genericParams) const { + ArrayRef genericParams) const { return getTypeForSymbolRange(term.begin(), term.end(), genericParams, *this); } @@ -474,7 +474,7 @@ RewriteContext::getRelativeTermForType(CanType typeWitness, /// RewriteSystemBuilder::getConcreteSubstitutionSchema(). Type PropertyMap::getTypeFromSubstitutionSchema( Type schema, ArrayRef substitutions, - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &prefix) const { assert(!schema->isTypeParameter() && "Must have a concrete type here"); diff --git a/lib/AST/RequirementMachine/PropertyMap.cpp b/lib/AST/RequirementMachine/PropertyMap.cpp index 1a84696d48561..4183536c00fd9 100644 --- a/lib/AST/RequirementMachine/PropertyMap.cpp +++ b/lib/AST/RequirementMachine/PropertyMap.cpp @@ -158,7 +158,7 @@ PropertyBag::getPrefixAfterStrippingKey(const MutableTerm &lookupTerm) const { /// /// Asserts if this property bag does not have a superclass bound. Type PropertyBag::getSuperclassBound( - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &lookupTerm, const PropertyMap &map) const { MutableTerm prefix = getPrefixAfterStrippingKey(lookupTerm); @@ -179,7 +179,7 @@ Type PropertyBag::getSuperclassBound( /// /// Asserts if this property bag is not concrete. Type PropertyBag::getConcreteType( - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &lookupTerm, const PropertyMap &map) const { MutableTerm prefix = getPrefixAfterStrippingKey(lookupTerm); diff --git a/lib/AST/RequirementMachine/PropertyMap.h b/lib/AST/RequirementMachine/PropertyMap.h index d8f38b9810155..ff180a0ae7c4e 100644 --- a/lib/AST/RequirementMachine/PropertyMap.h +++ b/lib/AST/RequirementMachine/PropertyMap.h @@ -123,7 +123,7 @@ class PropertyBag { } Type getSuperclassBound( - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &lookupTerm, const PropertyMap &map) const; @@ -136,7 +136,7 @@ class PropertyBag { } Type getConcreteType( - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &lookupTerm, const PropertyMap &map) const; @@ -227,15 +227,15 @@ class PropertyMap { ////////////////////////////////////////////////////////////////////////////// Type getTypeForTerm(Term term, - TypeArrayView genericParams) const; + ArrayRef genericParams) const; Type getTypeForTerm(const MutableTerm &term, - TypeArrayView genericParams) const; + ArrayRef genericParams) const; Type getTypeFromSubstitutionSchema( Type schema, ArrayRef substitutions, - TypeArrayView genericParams, + ArrayRef genericParams, const MutableTerm &prefix) const; private: diff --git a/lib/AST/RequirementMachine/RequirementBuilder.cpp b/lib/AST/RequirementMachine/RequirementBuilder.cpp index a06085fb4d834..fc68f91b378cf 100644 --- a/lib/AST/RequirementMachine/RequirementBuilder.cpp +++ b/lib/AST/RequirementMachine/RequirementBuilder.cpp @@ -133,7 +133,7 @@ class RequirementBuilder { // Input parameters. const RewriteSystem &System; const PropertyMap ⤅ - TypeArrayView GenericParams; + ArrayRef GenericParams; bool ReconstituteSugar; bool Debug; @@ -147,7 +147,7 @@ class RequirementBuilder { std::vector Aliases; RequirementBuilder(const RewriteSystem &system, const PropertyMap &map, - TypeArrayView genericParams, + ArrayRef genericParams, bool reconstituteSugar) : System(system), Map(map), GenericParams(genericParams), @@ -380,7 +380,7 @@ void RequirementMachine::buildRequirementsFromRules( ArrayRef requirementRules, ArrayRef typeAliasRules, - TypeArrayView genericParams, + ArrayRef genericParams, bool reconstituteSugar, std::vector &reqs, std::vector &aliases) const { diff --git a/lib/AST/RequirementMachine/RequirementMachine.cpp b/lib/AST/RequirementMachine/RequirementMachine.cpp index 7995ccc515410..a2a3d02a66747 100644 --- a/lib/AST/RequirementMachine/RequirementMachine.cpp +++ b/lib/AST/RequirementMachine/RequirementMachine.cpp @@ -366,7 +366,7 @@ RequirementMachine::initWithProtocolWrittenRequirements( // For RequirementMachine::verify() when called by generic signature queries; // We have a single valid generic parameter at depth 0, index 0. - Params.push_back(component[0]->getSelfInterfaceType()); + Params.push_back(component[0]->getSelfInterfaceType()->castTo()); if (Dump) { llvm::dbgs() << "Adding protocols"; @@ -557,8 +557,8 @@ void RequirementMachine::dump(llvm::raw_ostream &out) const { } else { out << "fresh signature <"; for (auto paramTy : Params) { - out << " " << paramTy; - if (paramTy->castTo()->isParameterPack()) + out << " " << Type(paramTy); + if (paramTy->isParameterPack()) out << "…"; } out << " >"; diff --git a/lib/AST/RequirementMachine/RequirementMachine.h b/lib/AST/RequirementMachine/RequirementMachine.h index 948f6bc9b883c..2b18eaa5fbf92 100644 --- a/lib/AST/RequirementMachine/RequirementMachine.h +++ b/lib/AST/RequirementMachine/RequirementMachine.h @@ -55,7 +55,7 @@ class RequirementMachine final { friend class swift::InferredGenericSignatureRequest; CanGenericSignature Sig; - SmallVector Params; + SmallVector Params; RewriteContext &Context; RewriteSystem System; @@ -123,14 +123,13 @@ class RequirementMachine final { void buildRequirementsFromRules( ArrayRef requirementRules, ArrayRef typeAliasRules, - TypeArrayView genericParams, + ArrayRef genericParams, bool reconstituteSugar, std::vector &reqs, std::vector &aliases) const; - TypeArrayView getGenericParams() const { - return TypeArrayView( - ArrayRef(Params)); + ArrayRef getGenericParams() const { + return Params; } public: @@ -140,22 +139,22 @@ class RequirementMachine final { // RequirementMachine instance; instead, call the corresponding methods on // GenericSignature, which lazily create a RequirementMachine for you. GenericSignature::LocalRequirements getLocalRequirements(Type depType, - TypeArrayView genericParams) const; + ArrayRef genericParams) const; bool requiresClass(Type depType) const; LayoutConstraint getLayoutConstraint(Type depType) const; bool requiresProtocol(Type depType, const ProtocolDecl *proto) const; GenericSignature::RequiredProtocols getRequiredProtocols(Type depType) const; Type getSuperclassBound(Type depType, - TypeArrayView genericParams) const; + ArrayRef genericParams) const; bool isConcreteType(Type depType, const ProtocolDecl *proto=nullptr) const; Type getConcreteType(Type depType, - TypeArrayView genericParams, + ArrayRef genericParams, const ProtocolDecl *proto=nullptr) const; bool areReducedTypeParametersEqual(Type depType1, Type depType2) const; bool isReducedType(Type type) const; Type getReducedType(Type type, - TypeArrayView genericParams) const; + ArrayRef genericParams) const; bool isValidTypeParameter(Type type) const; ConformancePath getConformancePath(Type type, ProtocolDecl *protocol); TypeDecl *lookupNestedType(Type depType, Identifier name) const; @@ -165,7 +164,7 @@ class RequirementMachine final { public: Type getReducedShape(Type type, - TypeArrayView genericParams) const; + ArrayRef genericParams) const; bool haveSameShape(Type type1, Type type2) const; diff --git a/lib/AST/RequirementMachine/RequirementMachineRequests.cpp b/lib/AST/RequirementMachine/RequirementMachineRequests.cpp index b974d21ca7aa8..857ff39e4a3b5 100644 --- a/lib/AST/RequirementMachine/RequirementMachineRequests.cpp +++ b/lib/AST/RequirementMachine/RequirementMachineRequests.cpp @@ -152,7 +152,7 @@ static void splitConcreteEquivalenceClasses( ArrayRef requirements, const ProtocolDecl *proto, const RequirementMachine *machine, - TypeArrayView genericParams, + ArrayRef genericParams, SmallVectorImpl &splitRequirements, unsigned &attempt) { bool debug = machine->getDebugOptions().contains( diff --git a/lib/AST/RequirementMachine/RewriteSystem.h b/lib/AST/RequirementMachine/RewriteSystem.h index ad3e342131689..a89c0300ca2ea 100644 --- a/lib/AST/RequirementMachine/RewriteSystem.h +++ b/lib/AST/RequirementMachine/RewriteSystem.h @@ -235,12 +235,12 @@ class RewriteSystem final { void computeConflictingRequirementDiagnostics(SmallVectorImpl &errors, SourceLoc signatureLoc, const PropertyMap &map, - TypeArrayView genericParams); + ArrayRef genericParams); void computeRecursiveRequirementDiagnostics(SmallVectorImpl &errors, SourceLoc signatureLoc, const PropertyMap &map, - TypeArrayView genericParams); + ArrayRef genericParams); private: struct CriticalPair { diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp index f2e6ecf75e57f..8afea7922ae08 100644 --- a/lib/Sema/TypeCheckGeneric.cpp +++ b/lib/Sema/TypeCheckGeneric.cpp @@ -819,7 +819,7 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator, /// substitutions that will have been applied to these types. /// These are used to produce the "parameter = argument" bindings in the test. static std::string gatherGenericParamBindingsText( - ArrayRef types, TypeArrayView genericParams, + ArrayRef types, ArrayRef genericParams, TypeSubstitutionFn substitutions) { llvm::SmallPtrSet knownGenericParams; for (auto type : types) { @@ -870,7 +870,7 @@ static std::string gatherGenericParamBindingsText( void TypeChecker::diagnoseRequirementFailure( const CheckGenericArgumentsResult::RequirementFailureInfo &reqFailureInfo, SourceLoc errorLoc, SourceLoc noteLoc, Type targetTy, - TypeArrayView genericParams, + ArrayRef genericParams, TypeSubstitutionFn substitutions, ModuleDecl *module) { assert(errorLoc.isValid() && noteLoc.isValid()); diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index 6b023834d2b62..17b7b4dce2065 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -5061,7 +5061,8 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() { if (result == CheckGenericArgumentsResult::RequirementFailure) { TypeChecker::diagnoseRequirementFailure( result.getRequirementFailureInfo(), Loc, Loc, - proto->getDeclaredInterfaceType(), {proto->getSelfInterfaceType()}, + proto->getDeclaredInterfaceType(), + {proto->getSelfInterfaceType()->castTo()}, QuerySubstitutionMap{substitutions}, module); } diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h index 5d701126de1ea..740e7fbd20a3b 100644 --- a/lib/Sema/TypeChecker.h +++ b/lib/Sema/TypeChecker.h @@ -515,7 +515,7 @@ void checkShadowedGenericParams(GenericContext *dc); void diagnoseRequirementFailure( const CheckGenericArgumentsResult::RequirementFailureInfo &reqFailureInfo, SourceLoc errorLoc, SourceLoc noteLoc, Type targetTy, - TypeArrayView genericParams, + ArrayRef genericParams, TypeSubstitutionFn substitutions, ModuleDecl *module); /// Check the given generic parameter substitutions against the given diff --git a/lib/SymbolGraphGen/JSON.cpp b/lib/SymbolGraphGen/JSON.cpp index cb0aeed5cb400..8b33aa666691a 100644 --- a/lib/SymbolGraphGen/JSON.cpp +++ b/lib/SymbolGraphGen/JSON.cpp @@ -170,7 +170,7 @@ void swift::symbolgraphgen::serialize(const ModuleDecl &Module, void swift::symbolgraphgen::filterGenericParams( - TypeArrayView GenericParams, + ArrayRef GenericParams, SmallVectorImpl &FilteredParams, SubstitutionMap SubMap) { diff --git a/lib/SymbolGraphGen/JSON.h b/lib/SymbolGraphGen/JSON.h index 2c87bec6e5132..268d8c59f9752 100644 --- a/lib/SymbolGraphGen/JSON.h +++ b/lib/SymbolGraphGen/JSON.h @@ -46,7 +46,7 @@ void serialize(const swift::GenericTypeParamType *Param, llvm::json::OStream &OS void serialize(const ModuleDecl &M, llvm::json::OStream &OS, llvm::Triple Target); void filterGenericParams( - TypeArrayView GenericParams, + ArrayRef GenericParams, SmallVectorImpl &FilteredParams, SubstitutionMap SubMap = {});