Skip to content
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

Delete remnants of dependsOn syntax for lifetime dependence #77030

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 5 additions & 13 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
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 @@ -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);

Expand Down
36 changes: 11 additions & 25 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3792,8 +3792,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 @@ -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;

Expand All @@ -10583,21 +10576,14 @@ ConstructorDecl *ConstructorDecl::createImported(
GenericParamList *genericParams, DeclContext *parent) {
void *declPtr = allocateMemoryForDecl<ConstructorDecl>(
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 ||
Expand Down
9 changes: 3 additions & 6 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<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 @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

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 @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3719,16 +3719,14 @@ class DeclDeserializer {
return thrownTypeOrError.takeError();
const auto thrownType = thrownTypeOrError.get();

auto ctor = MF.createDecl<ConstructorDecl>(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<ConstructorDecl>(
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));
Expand Down