mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Remove a few calls to addSynthesizedDecl()
This commit is contained in:
@@ -838,12 +838,14 @@ static Expr *synthesizeCopyWithZoneCall(Expr *Val, VarDecl *VD,
|
|||||||
auto DSCE = new (Ctx) DotSyntaxCallExpr(DRE, SourceLoc(), Val);
|
auto DSCE = new (Ctx) DotSyntaxCallExpr(DRE, SourceLoc(), Val);
|
||||||
DSCE->setImplicit();
|
DSCE->setImplicit();
|
||||||
DSCE->setType(copyMethodType);
|
DSCE->setType(copyMethodType);
|
||||||
|
DSCE->setThrows(false);
|
||||||
|
|
||||||
Expr *Nil = new (Ctx) NilLiteralExpr(SourceLoc(), /*implicit*/true);
|
Expr *Nil = new (Ctx) NilLiteralExpr(SourceLoc(), /*implicit*/true);
|
||||||
Nil->setType(copyMethodType->getParams()[0].getParameterType());
|
Nil->setType(copyMethodType->getParams()[0].getParameterType());
|
||||||
|
|
||||||
Expr *Call = CallExpr::createImplicit(Ctx, DSCE, { Nil }, { Ctx.Id_with });
|
auto *Call = CallExpr::createImplicit(Ctx, DSCE, { Nil }, { Ctx.Id_with });
|
||||||
Call->setType(copyMethodType->getResult());
|
Call->setType(copyMethodType->getResult());
|
||||||
|
Call->setThrows(false);
|
||||||
|
|
||||||
TypeLoc ResultTy;
|
TypeLoc ResultTy;
|
||||||
ResultTy.setType(VD->getType());
|
ResultTy.setType(VD->getType());
|
||||||
@@ -1308,11 +1310,13 @@ static void synthesizeObservedSetterBody(AccessorDecl *Set,
|
|||||||
auto *SelfDRE = buildSelfReference(SelfDecl, SelfAccessorKind::Peer,
|
auto *SelfDRE = buildSelfReference(SelfDecl, SelfAccessorKind::Peer,
|
||||||
IsSelfLValue, Ctx);
|
IsSelfLValue, Ctx);
|
||||||
SelfDRE = maybeWrapInOutExpr(SelfDRE, Ctx);
|
SelfDRE = maybeWrapInOutExpr(SelfDRE, Ctx);
|
||||||
Callee = new (Ctx) DotSyntaxCallExpr(Callee, SourceLoc(), SelfDRE);
|
auto *DSCE = new (Ctx) DotSyntaxCallExpr(Callee, SourceLoc(), SelfDRE);
|
||||||
|
|
||||||
if (auto funcType = type->getAs<FunctionType>())
|
if (auto funcType = type->getAs<FunctionType>())
|
||||||
type = funcType->getResult();
|
type = funcType->getResult();
|
||||||
Callee->setType(type);
|
DSCE->setType(type);
|
||||||
|
DSCE->setThrows(false);
|
||||||
|
Callee = DSCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *Call = CallExpr::createImplicit(Ctx, Callee, { ValueDRE },
|
auto *Call = CallExpr::createImplicit(Ctx, Callee, { ValueDRE },
|
||||||
@@ -1320,6 +1324,7 @@ static void synthesizeObservedSetterBody(AccessorDecl *Set,
|
|||||||
if (auto funcType = type->getAs<FunctionType>())
|
if (auto funcType = type->getAs<FunctionType>())
|
||||||
type = funcType->getResult();
|
type = funcType->getResult();
|
||||||
Call->setType(type);
|
Call->setType(type);
|
||||||
|
Call->setThrows(false);
|
||||||
|
|
||||||
SetterBody.push_back(Call);
|
SetterBody.push_back(Call);
|
||||||
};
|
};
|
||||||
@@ -1884,8 +1889,6 @@ void swift::triggerAccessorSynthesis(TypeChecker &TC,
|
|||||||
|
|
||||||
if (!accessor->hasBody()) {
|
if (!accessor->hasBody()) {
|
||||||
accessor->setBodySynthesizer(&synthesizeAccessorBody);
|
accessor->setBodySynthesizer(&synthesizeAccessorBody);
|
||||||
|
|
||||||
TC.Context.addSynthesizedDecl(accessor);
|
|
||||||
TC.DeclsToFinalize.insert(accessor);
|
TC.DeclsToFinalize.insert(accessor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2386,9 +2389,10 @@ static void synthesizeStubBody(AbstractFunctionDecl *fn, void *) {
|
|||||||
column->setType(uintType);
|
column->setType(uintType);
|
||||||
column->setBuiltinInitializer(uintInit);
|
column->setBuiltinInitializer(uintInit);
|
||||||
|
|
||||||
Expr *call = CallExpr::createImplicit(
|
auto *call = CallExpr::createImplicit(
|
||||||
ctx, ref, { className, initName, file, line, column }, {});
|
ctx, ref, { className, initName, file, line, column }, {});
|
||||||
call->setType(ctx.getNeverType());
|
call->setType(ctx.getNeverType());
|
||||||
|
call->setThrows(false);
|
||||||
|
|
||||||
SmallVector<ASTNode, 2> stmts;
|
SmallVector<ASTNode, 2> stmts;
|
||||||
stmts.push_back(call);
|
stmts.push_back(call);
|
||||||
@@ -2601,10 +2605,11 @@ static void synthesizeDesignatedInitOverride(AbstractFunctionDecl *fn,
|
|||||||
auto *superclassCtorRefExpr =
|
auto *superclassCtorRefExpr =
|
||||||
new (ctx) DotSyntaxCallExpr(ctorRefExpr, SourceLoc(), superRef, type);
|
new (ctx) DotSyntaxCallExpr(ctorRefExpr, SourceLoc(), superRef, type);
|
||||||
superclassCtorRefExpr->setIsSuper(true);
|
superclassCtorRefExpr->setIsSuper(true);
|
||||||
|
superclassCtorRefExpr->setThrows(false);
|
||||||
|
|
||||||
auto *bodyParams = ctor->getParameters();
|
auto *bodyParams = ctor->getParameters();
|
||||||
auto ctorArgs = buildArgumentForwardingExpr(bodyParams->getArray(), ctx);
|
auto ctorArgs = buildArgumentForwardingExpr(bodyParams->getArray(), ctx);
|
||||||
Expr *superclassCallExpr =
|
auto *superclassCallExpr =
|
||||||
CallExpr::create(ctx, superclassCtorRefExpr, ctorArgs,
|
CallExpr::create(ctx, superclassCtorRefExpr, ctorArgs,
|
||||||
superclassCtor->getFullName().getArgumentNames(), { },
|
superclassCtor->getFullName().getArgumentNames(), { },
|
||||||
/*hasTrailingClosure=*/false, /*implicit=*/true);
|
/*hasTrailingClosure=*/false, /*implicit=*/true);
|
||||||
@@ -2612,15 +2617,16 @@ static void synthesizeDesignatedInitOverride(AbstractFunctionDecl *fn,
|
|||||||
if (auto *funcTy = type->getAs<FunctionType>())
|
if (auto *funcTy = type->getAs<FunctionType>())
|
||||||
type = funcTy->getResult();
|
type = funcTy->getResult();
|
||||||
superclassCallExpr->setType(type);
|
superclassCallExpr->setType(type);
|
||||||
|
superclassCallExpr->setThrows(superclassCtor->hasThrows());
|
||||||
|
|
||||||
|
Expr *expr = superclassCallExpr;
|
||||||
|
|
||||||
if (superclassCtor->hasThrows()) {
|
if (superclassCtor->hasThrows()) {
|
||||||
superclassCallExpr = new (ctx) TryExpr(SourceLoc(), superclassCallExpr,
|
expr = new (ctx) TryExpr(SourceLoc(), expr, type, /*implicit=*/true);
|
||||||
type, /*implicit=*/true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *rebindSelfExpr =
|
auto *rebindSelfExpr =
|
||||||
new (ctx) RebindSelfInConstructorExpr(superclassCallExpr,
|
new (ctx) RebindSelfInConstructorExpr(expr, selfDecl);
|
||||||
selfDecl);
|
|
||||||
|
|
||||||
SmallVector<ASTNode, 2> stmts;
|
SmallVector<ASTNode, 2> stmts;
|
||||||
stmts.push_back(rebindSelfExpr);
|
stmts.push_back(rebindSelfExpr);
|
||||||
|
|||||||
@@ -5480,7 +5480,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
|
|||||||
validateDecl(classDecl);
|
validateDecl(classDecl);
|
||||||
if (auto ctor = createDesignatedInitOverride(
|
if (auto ctor = createDesignatedInitOverride(
|
||||||
*this, classDecl, superclassCtor, kind)) {
|
*this, classDecl, superclassCtor, kind)) {
|
||||||
Context.addSynthesizedDecl(ctor);
|
|
||||||
classDecl->addMember(ctor);
|
classDecl->addMember(ctor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5657,11 +5656,14 @@ void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
|
|||||||
// Add the constructor.
|
// Add the constructor.
|
||||||
decl->addMember(ctor);
|
decl->addMember(ctor);
|
||||||
|
|
||||||
// Create an empty body for the default constructor. The type-check of the
|
// Create an empty body for the default constructor.
|
||||||
// constructor body will introduce default initializations of the members.
|
SmallVector<ASTNode, 1> stmts;
|
||||||
ctor->setBody(BraceStmt::create(Context, SourceLoc(), { }, SourceLoc()));
|
stmts.push_back(new (Context) ReturnStmt(decl->getLoc(), nullptr));
|
||||||
|
ctor->setBody(BraceStmt::create(Context, SourceLoc(), stmts, SourceLoc()));
|
||||||
|
ctor->setBodyTypeCheckedIfPresent();
|
||||||
|
|
||||||
// Make sure we type check the constructor later.
|
// FIXME: This is still needed so that DI can check captures for
|
||||||
|
// initializer expressions. Rethink that completely.
|
||||||
Context.addSynthesizedDecl(ctor);
|
Context.addSynthesizedDecl(ctor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user