From b25c4665e4f3d8a6f247c8277daf87783a37fd88 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Mon, 18 May 2020 23:26:10 +0300 Subject: [PATCH] GenericSignatureImpl, #31712: Plug remaining relevant methods with type param. assertions --- include/swift/AST/GenericSignature.h | 4 ++-- lib/AST/GenericSignature.cpp | 9 +++++---- lib/AST/SubstitutionMap.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/swift/AST/GenericSignature.h b/include/swift/AST/GenericSignature.h index 4d347fae5b9d8..271e07899698f 100644 --- a/include/swift/AST/GenericSignature.h +++ b/include/swift/AST/GenericSignature.h @@ -329,12 +329,12 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final /// Determine whether the given dependent type is equal to a concrete type. bool isConcreteType(Type type) const; - /// Return the concrete type that the given dependent type is constrained to, + /// Return the concrete type that the given type parameter is constrained to, /// or the null Type if it is not the subject of a concrete same-type /// constraint. Type getConcreteType(Type type) const; - /// Return the layout constraint that the given dependent type is constrained + /// Return the layout constraint that the given type parameter is constrained /// to, or the null LayoutConstraint if it is not the subject of layout /// constraint. LayoutConstraint getLayoutConstraint(Type type) const; diff --git a/lib/AST/GenericSignature.cpp b/lib/AST/GenericSignature.cpp index ade97c2355846..a1a36e38096a4 100644 --- a/lib/AST/GenericSignature.cpp +++ b/lib/AST/GenericSignature.cpp @@ -428,7 +428,7 @@ Type GenericSignatureImpl::getSuperclassBound(Type type) const { /// required to conform. GenericSignature::RequiredProtocols GenericSignatureImpl::getRequiredProtocols(Type type) const { - if (!type->isTypeParameter()) return { }; + assert(type->isTypeParameter() && "Expected a type parameter"); auto &builder = *getGenericSignatureBuilder(); auto equivClass = @@ -479,11 +479,11 @@ bool GenericSignatureImpl::isConcreteType(Type type) const { return bool(getConcreteType(type)); } -/// Return the concrete type that the given dependent type is constrained to, +/// Return the concrete type that the given type parameter is constrained to, /// or the null Type if it is not the subject of a concrete same-type /// constraint. Type GenericSignatureImpl::getConcreteType(Type type) const { - if (!type->isTypeParameter()) return Type(); + assert(type->isTypeParameter() && "Expected a type parameter"); auto &builder = *getGenericSignatureBuilder(); auto equivClass = @@ -496,7 +496,8 @@ Type GenericSignatureImpl::getConcreteType(Type type) const { } LayoutConstraint GenericSignatureImpl::getLayoutConstraint(Type type) const { - if (!type->isTypeParameter()) return LayoutConstraint(); + assert(type->isTypeParameter() && + "Only type parameters can have layout constraints"); auto &builder = *getGenericSignatureBuilder(); auto equivClass = diff --git a/lib/AST/SubstitutionMap.cpp b/lib/AST/SubstitutionMap.cpp index 61d4695a4d9db..074e432f4893c 100644 --- a/lib/AST/SubstitutionMap.cpp +++ b/lib/AST/SubstitutionMap.cpp @@ -271,7 +271,7 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const { // The generic parameter may have been made concrete by the generic signature, // substitute into the concrete type. - if (auto concreteType = genericSig->getConcreteType(genericParam)){ + if (auto concreteType = genericSig->getConcreteType(genericParam)) { // Set the replacement type to an error, to block infinite recursion. replacementType = ErrorType::get(concreteType);