Skip to content

[AST] NFC: Remove InitRetType #79422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8369,8 +8369,6 @@ class FuncDecl : public AbstractFunctionDecl {

TypeRepr *getResultTypeRepr() const { return FnRetType.getTypeRepr(); }

void setDeserializedResultTypeLoc(TypeLoc ResultTyR);

SourceRange getResultTypeSourceRange() const {
return FnRetType.getSourceRange();
}
Expand Down Expand Up @@ -8897,9 +8895,6 @@ 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,
Expand All @@ -8908,7 +8903,7 @@ class ConstructorDecl : public AbstractFunctionDecl {
TypeLoc thrownTy,
ParameterList *BodyParams,
GenericParamList *GenericParams,
DeclContext *Parent, TypeRepr *InitRetTy);
DeclContext *Parent);

static ConstructorDecl *
createImported(ASTContext &ctx, ClangNode clangNode, DeclName name,
Expand All @@ -8930,10 +8925,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
/// inserted at the end of the initializer by SILGen.
Expr *getSuperInitCall() { return CallToSuperInit; }
Expand Down
4 changes: 1 addition & 3 deletions lib/AST/Bridging/DeclBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,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);

Expand Down
16 changes: 2 additions & 14 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3994,8 +3994,6 @@ TypeRepr *ValueDecl::getResultTypeRepr() const {
returnRepr = SD->getElementTypeRepr();
} else if (auto *MD = dyn_cast<MacroDecl>(this)) {
returnRepr = MD->resultType.getTypeRepr();
} else if (auto *CD = dyn_cast<ConstructorDecl>(this)) {
returnRepr = CD->getResultTypeRepr();
}

return returnRepr;
Expand Down Expand Up @@ -10500,10 +10498,6 @@ void FuncDecl::setResultInterfaceType(Type type) {
std::move(type));
}

void FuncDecl::setDeserializedResultTypeLoc(TypeLoc ResultTyR) {
FnRetType = ResultTyR;
}

FuncDecl *FuncDecl::createImpl(ASTContext &Context,
SourceLoc StaticLoc,
StaticSpellingKind StaticSpelling,
Expand Down Expand Up @@ -10941,7 +10935,7 @@ ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
TypeLoc ThrownType,
ParameterList *BodyParams,
GenericParamList *GenericParams,
DeclContext *Parent, TypeRepr *ResultTyR)
DeclContext *Parent)
: AbstractFunctionDecl(DeclKind::Constructor, Parent, Name, ConstructorLoc,
Async, AsyncLoc, Throws, ThrowsLoc, ThrownType,
/*HasImplicitSelfDecl=*/true,
Expand All @@ -10952,7 +10946,6 @@ ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
if (BodyParams)
setParameters(BodyParams);

InitRetType = TypeLoc(ResultTyR);
Bits.ConstructorDecl.HasStubImplementation = 0;
Bits.ConstructorDecl.Failable = Failable;

Expand All @@ -10973,16 +10966,11 @@ ConstructorDecl *ConstructorDecl::createImported(
failable, failabilityLoc,
async, asyncLoc,
throws, throwsLoc, TypeLoc::withoutLoc(thrownType),
bodyParams, genericParams, parent,
/*LifetimeDependenceTypeRepr*/ nullptr);
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 ||
Expand Down
9 changes: 3 additions & 6 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3922,8 +3922,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();

Expand Down Expand Up @@ -6734,8 +6733,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));
Expand Down Expand Up @@ -7262,8 +7260,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
/*Throws=*/importedName.getErrorInfo().has_value(),
/*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(), bodyParams,
/*GenericParams=*/nullptr, const_cast<DeclContext *>(dc),
/*LifetimeDependentTypeRepr*/ nullptr);
/*GenericParams=*/nullptr, const_cast<DeclContext *>(dc));

addObjCAttribute(result, selector);
recordMemberInContext(dc, result);
Expand Down
9 changes: 3 additions & 6 deletions lib/ClangImporter/SwiftDeclSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,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->copyFormalAccessFrom(structDecl);

Expand Down Expand Up @@ -638,8 +637,7 @@ ConstructorDecl *SwiftDeclSynthesizer::createValueConstructor(
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
/*ThrownType=*/TypeLoc(), paramList,
/*GenericParams=*/nullptr, structDecl,
/*LifetimeDependentTypeRepr*/ nullptr);
/*GenericParams=*/nullptr, structDecl);

constructor->copyFormalAccessFrom(structDecl);

Expand Down Expand Up @@ -1286,8 +1284,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->copyFormalAccessFrom(enumDecl);
ctorDecl->setBodySynthesizer(synthesizeEnumRawValueConstructorBody, enumDecl);
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9849,7 +9849,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
isAsync, asyncLoc,
throwsLoc.isValid(), throwsLoc,
thrownTy, BodyParams, GenericParams,
CurDeclContext, FuncRetTy);
CurDeclContext);
CD->setImplicitlyUnwrappedOptional(IUO);
CD->attachParsedAttrs(Attributes);

Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,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();
Expand Down Expand Up @@ -827,8 +826,7 @@ createDesignatedInitOverride(ClassDecl *classDecl,
/*AsyncLoc=*/SourceLoc(),
/*Throws=*/superclassCtor->hasThrows(),
/*ThrowsLoc=*/SourceLoc(), TypeLoc::withoutLoc(thrownType), bodyParams,
genericParams, implCtx->getAsGenericContext(),
/*LifetimeDependentTypeRepr*/ nullptr);
genericParams, implCtx->getAsGenericContext());

ctor->setImplicit();

Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/DerivedConformanceCodingKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/DerivedConformanceRawRepresentable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,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);
Expand Down
3 changes: 1 addition & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3717,8 +3717,7 @@ class DeclDeserializer {
/*ThrowsLoc=*/SourceLoc(),
TypeLoc::withoutLoc(thrownType),
/*BodyParams=*/nullptr,
genericParams, parent,
nullptr);
genericParams, parent);
declOrOffset = ctor;

ctor->setGenericSignature(MF.getGenericSignature(genericSigID));
Expand Down