diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 1e76c4c79179f..262c915834573 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -8689,18 +8689,12 @@ class ConstructorDecl : public AbstractFunctionDecl { /// inserted at the end of the initializer by SILGen. Expr *CallToSuperInit = nullptr; - /// Valid when lifetime dependence specifiers are present. - TypeLoc InitRetType; - public: - ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc, - bool Failable, SourceLoc FailabilityLoc, - bool Async, SourceLoc AsyncLoc, - bool Throws, SourceLoc ThrowsLoc, - TypeLoc thrownTy, - ParameterList *BodyParams, - GenericParamList *GenericParams, - DeclContext *Parent, TypeRepr *InitRetTy); + ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc, bool Failable, + SourceLoc FailabilityLoc, bool Async, SourceLoc AsyncLoc, + bool Throws, SourceLoc ThrowsLoc, TypeLoc thrownTy, + ParameterList *BodyParams, GenericParamList *GenericParams, + DeclContext *Parent); static ConstructorDecl * createImported(ASTContext &ctx, ClangNode clangNode, DeclName name, @@ -8722,8 +8716,6 @@ class ConstructorDecl : public AbstractFunctionDecl { /// Get the interface type of the initializing constructor. Type getInitializerInterfaceType(); - TypeRepr *getResultTypeRepr() const { return InitRetType.getTypeRepr(); } - void setDeserializedResultTypeLoc(TypeLoc ResultTyR); /// Get the typechecked call to super.init expression, which needs to be diff --git a/lib/AST/Bridging/DeclBridging.cpp b/lib/AST/Bridging/DeclBridging.cpp index ebab691aa0ef7..4ae777e1043c5 100644 --- a/lib/AST/Bridging/DeclBridging.cpp +++ b/lib/AST/Bridging/DeclBridging.cpp @@ -280,13 +280,11 @@ BridgedConstructorDecl BridgedConstructorDecl_createParsed( auto throwsLoc = cThrowsLoc.unbridged(); auto failabilityMarkLoc = cFailabilityMarkLoc.unbridged(); // FIXME: rethrows - // TODO: Handle LifetimeDependentReturnTypeRepr here. auto *decl = new (context) ConstructorDecl( declName, cInitKeywordLoc.unbridged(), failabilityMarkLoc.isValid(), failabilityMarkLoc, asyncLoc.isValid(), asyncLoc, throwsLoc.isValid(), throwsLoc, thrownType.unbridged(), parameterList, - genericParams.unbridged(), cDeclContext.unbridged(), - /*InitRetTy*/ nullptr); + genericParams.unbridged(), cDeclContext.unbridged()); decl->setTrailingWhereClause(genericWhereClause.unbridged()); decl->setImplicitlyUnwrappedOptional(isIUO); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 698bf79231ead..72858c9290744 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3792,8 +3792,6 @@ TypeRepr *ValueDecl::getResultTypeRepr() const { returnRepr = SD->getElementTypeRepr(); } else if (auto *MD = dyn_cast(this)) { returnRepr = MD->resultType.getTypeRepr(); - } else if (auto *CD = dyn_cast(this)) { - returnRepr = CD->getResultTypeRepr(); } return returnRepr; @@ -10551,23 +10549,18 @@ bool FuncDecl::isMainTypeMainMethod() const { ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc, bool Failable, SourceLoc FailabilityLoc, - bool Async, SourceLoc AsyncLoc, - bool Throws, SourceLoc ThrowsLoc, - TypeLoc ThrownType, + bool Async, SourceLoc AsyncLoc, bool Throws, + SourceLoc ThrowsLoc, TypeLoc ThrownType, ParameterList *BodyParams, GenericParamList *GenericParams, - DeclContext *Parent, TypeRepr *ResultTyR) - : AbstractFunctionDecl(DeclKind::Constructor, Parent, Name, ConstructorLoc, - Async, AsyncLoc, Throws, ThrowsLoc, ThrownType, - /*HasImplicitSelfDecl=*/true, - GenericParams), - FailabilityLoc(FailabilityLoc), - SelfDecl(nullptr) -{ + DeclContext *Parent) + : AbstractFunctionDecl(DeclKind::Constructor, Parent, Name, ConstructorLoc, + Async, AsyncLoc, Throws, ThrowsLoc, ThrownType, + /*HasImplicitSelfDecl=*/true, GenericParams), + FailabilityLoc(FailabilityLoc), SelfDecl(nullptr) { if (BodyParams) setParameters(BodyParams); - InitRetType = TypeLoc(ResultTyR); Bits.ConstructorDecl.HasStubImplementation = 0; Bits.ConstructorDecl.Failable = Failable; @@ -10583,21 +10576,14 @@ ConstructorDecl *ConstructorDecl::createImported( GenericParamList *genericParams, DeclContext *parent) { void *declPtr = allocateMemoryForDecl( ctx, sizeof(ConstructorDecl), true); - auto ctor = ::new (declPtr) - ConstructorDecl(name, constructorLoc, - failable, failabilityLoc, - async, asyncLoc, - throws, throwsLoc, TypeLoc::withoutLoc(thrownType), - bodyParams, genericParams, parent, - /*LifetimeDependenceTypeRepr*/ nullptr); + auto ctor = ::new (declPtr) ConstructorDecl( + name, constructorLoc, failable, failabilityLoc, async, asyncLoc, throws, + throwsLoc, TypeLoc::withoutLoc(thrownType), bodyParams, genericParams, + parent); ctor->setClangNode(clangNode); return ctor; } -void ConstructorDecl::setDeserializedResultTypeLoc(TypeLoc ResultTyR) { - InitRetType = ResultTyR; -} - bool ConstructorDecl::isObjCZeroParameterWithLongSelector() const { // The initializer must have a single, non-empty argument name. if (getName().getArgumentNames().size() != 1 || diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 574968bb49f60..98b6e07dd76a6 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -3792,8 +3792,7 @@ namespace { /*failable=*/false, /*FailabilityLoc=*/SourceLoc(), /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), - /*ThrownType=*/TypeLoc(), bodyParams, genericParams, dc, - /*LifetimeDependentTypeRepr*/ nullptr); + /*ThrownType=*/TypeLoc(), bodyParams, genericParams, dc); } else { auto resultTy = importedType.getType(); @@ -6456,8 +6455,7 @@ Decl *SwiftDeclConverter::importGlobalAsInitializer( /*FailabilityLoc=*/SourceLoc(), /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), - parameterList, /*GenericParams=*/nullptr, dc, - /*LifetimeDependentTypeRepr*/ nullptr); + parameterList, /*GenericParams=*/nullptr, dc); result->setImplicitlyUnwrappedOptional(isIUO); result->getASTContext().evaluator.cacheOutput(InitKindRequest{result}, std::move(initKind)); @@ -6971,8 +6969,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor( /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/importedName.getErrorInfo().has_value(), /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), bodyParams, - /*GenericParams=*/nullptr, const_cast(dc), - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, const_cast(dc)); addObjCAttribute(result, selector); recordMemberInContext(dc, result); diff --git a/lib/ClangImporter/SwiftDeclSynthesizer.cpp b/lib/ClangImporter/SwiftDeclSynthesizer.cpp index aaeb12df1ad4c..6faf50e92b02d 100644 --- a/lib/ClangImporter/SwiftDeclSynthesizer.cpp +++ b/lib/ClangImporter/SwiftDeclSynthesizer.cpp @@ -494,8 +494,7 @@ SwiftDeclSynthesizer::createDefaultConstructor(NominalTypeDecl *structDecl) { /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), emptyPL, - /*GenericParams=*/nullptr, structDecl, - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, structDecl); constructor->setAccess(AccessLevel::Public); @@ -625,8 +624,7 @@ ConstructorDecl *SwiftDeclSynthesizer::createValueConstructor( /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), paramList, - /*GenericParams=*/nullptr, structDecl, - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, structDecl); constructor->setAccess(AccessLevel::Public); @@ -1273,8 +1271,7 @@ SwiftDeclSynthesizer::makeEnumRawValueConstructor(EnumDecl *enumDecl) { /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), paramPL, - /*GenericParams=*/nullptr, enumDecl, - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, enumDecl); ctorDecl->setImplicit(); ctorDecl->setAccess(AccessLevel::Public); ctorDecl->setBodySynthesizer(synthesizeEnumRawValueConstructorBody, enumDecl); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 75d36133c60b2..b96ed93862c70 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -10025,12 +10025,10 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) { diagnoseWhereClauseInGenericParamList(GenericParams); - auto *CD = new (Context) ConstructorDecl(FullName, ConstructorLoc, - Failable, FailabilityLoc, - isAsync, asyncLoc, - throwsLoc.isValid(), throwsLoc, - thrownTy, BodyParams, GenericParams, - CurDeclContext, FuncRetTy); + auto *CD = new (Context) + ConstructorDecl(FullName, ConstructorLoc, Failable, FailabilityLoc, + isAsync, asyncLoc, throwsLoc.isValid(), throwsLoc, + thrownTy, BodyParams, GenericParams, CurDeclContext); CD->setImplicitlyUnwrappedOptional(IUO); CD->getAttrs() = Attributes; diff --git a/lib/Sema/CodeSynthesis.cpp b/lib/Sema/CodeSynthesis.cpp index 7273b296d8067..e6090d3e23d00 100644 --- a/lib/Sema/CodeSynthesis.cpp +++ b/lib/Sema/CodeSynthesis.cpp @@ -331,8 +331,7 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl, /*Failable=*/false, /*FailabilityLoc=*/SourceLoc(), /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), - /*ThrownType=*/TypeLoc(), paramList, /*GenericParams=*/nullptr, decl, - /*LifetimeDependentTypeRepr*/ nullptr); + /*ThrownType=*/TypeLoc(), paramList, /*GenericParams=*/nullptr, decl); // Mark implicit. ctor->setImplicit(); @@ -827,8 +826,7 @@ createDesignatedInitOverride(ClassDecl *classDecl, /*AsyncLoc=*/SourceLoc(), /*Throws=*/superclassCtor->hasThrows(), /*ThrowsLoc=*/SourceLoc(), TypeLoc::withoutLoc(thrownType), bodyParams, - genericParams, implCtx, - /*LifetimeDependentTypeRepr*/ nullptr); + genericParams, implCtx); ctor->setImplicit(); diff --git a/lib/Sema/DerivedConformanceCodable.cpp b/lib/Sema/DerivedConformanceCodable.cpp index fea79f9ab346a..f543b62affd77 100644 --- a/lib/Sema/DerivedConformanceCodable.cpp +++ b/lib/Sema/DerivedConformanceCodable.cpp @@ -1889,8 +1889,7 @@ static ValueDecl *deriveDecodable_init(DerivedConformance &derived) { /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/true, SourceLoc(), /*ThrownType=*/TypeLoc(), paramList, - /*GenericParams=*/nullptr, conformanceDC, - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, conformanceDC); initDecl->setImplicit(); initDecl->setSynthesized(); diff --git a/lib/Sema/DerivedConformanceCodingKey.cpp b/lib/Sema/DerivedConformanceCodingKey.cpp index 5f7393d58fee9..07d5f4fd4478b 100644 --- a/lib/Sema/DerivedConformanceCodingKey.cpp +++ b/lib/Sema/DerivedConformanceCodingKey.cpp @@ -132,8 +132,7 @@ static ValueDecl *deriveInitDecl(DerivedConformance &derived, Type paramType, /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), paramList, - /*GenericParams=*/nullptr, parentDC, - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, parentDC); initDecl->setImplicit(); diff --git a/lib/Sema/DerivedConformanceRawRepresentable.cpp b/lib/Sema/DerivedConformanceRawRepresentable.cpp index b750049420d67..9604ac364e649 100644 --- a/lib/Sema/DerivedConformanceRawRepresentable.cpp +++ b/lib/Sema/DerivedConformanceRawRepresentable.cpp @@ -432,8 +432,7 @@ deriveRawRepresentable_init(DerivedConformance &derived) { /*Async=*/false, /*AsyncLoc=*/SourceLoc(), /*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), paramList, - /*GenericParams=*/nullptr, parentDC, - /*LifetimeDependentTypeRepr*/ nullptr); + /*GenericParams=*/nullptr, parentDC); initDecl->setImplicit(); initDecl->setBodySynthesizer(&deriveBodyRawRepresentable_init); diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index cd865456d99b4..33773cb98b411 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -3719,16 +3719,14 @@ class DeclDeserializer { return thrownTypeOrError.takeError(); const auto thrownType = thrownTypeOrError.get(); - auto ctor = MF.createDecl(name, SourceLoc(), isFailable, - /*FailabilityLoc=*/SourceLoc(), - /*Async=*/async, - /*AsyncLoc=*/SourceLoc(), - /*Throws=*/throws, - /*ThrowsLoc=*/SourceLoc(), - TypeLoc::withoutLoc(thrownType), - /*BodyParams=*/nullptr, - genericParams, parent, - nullptr); + auto ctor = MF.createDecl( + name, SourceLoc(), isFailable, + /*FailabilityLoc=*/SourceLoc(), + /*Async=*/async, + /*AsyncLoc=*/SourceLoc(), + /*Throws=*/throws, + /*ThrowsLoc=*/SourceLoc(), TypeLoc::withoutLoc(thrownType), + /*BodyParams=*/nullptr, genericParams, parent); declOrOffset = ctor; ctor->setGenericSignature(MF.getGenericSignature(genericSigID));