Skip to content

Commit eec6cfe

Browse files
committed
---
yaml --- r: 341709 b: refs/heads/rxwei-patch-1 c: 9c17bb1 h: refs/heads/master i: 341707: cd70284
1 parent 92ae770 commit eec6cfe

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: d01e80f8200788d8f2f44c01b66f537b87909f03
1018+
refs/heads/rxwei-patch-1: 9c17bb1ffe0ba17eae40eb87454b84f685bdb091
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/lib/ClangImporter/ImportDecl.cpp

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,75 +1251,80 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,
12511251
return { getterDecl, setterDecl };
12521252
}
12531253

1254-
/// Create a default constructor that initializes a struct to zero.
1255-
static ConstructorDecl *
1256-
createDefaultConstructor(ClangImporter::Implementation &Impl,
1257-
StructDecl *structDecl) {
1258-
auto &context = Impl.SwiftContext;
1259-
1260-
auto emptyPL = ParameterList::createEmpty(context);
1261-
1262-
// Create the constructor.
1263-
DeclName name(context, DeclBaseName::createConstructor(), emptyPL);
1264-
auto constructor = new (context) ConstructorDecl(
1265-
name, structDecl->getLoc(), OTK_None, /*FailabilityLoc=*/SourceLoc(),
1266-
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), emptyPL,
1267-
/*GenericParams=*/nullptr, structDecl);
1268-
1269-
// Set the constructor's type.
1270-
constructor->computeType();
1271-
constructor->setValidationToChecked();
1272-
1273-
constructor->setAccess(AccessLevel::Public);
1274-
1275-
// Mark the constructor transparent so that we inline it away completely.
1276-
constructor->getAttrs().add(new (context) TransparentAttr(/*implicit*/ true));
1277-
1278-
if (Impl.hasFinishedTypeChecking())
1279-
return constructor;
1254+
/// Synthesize the body for an struct default initializer.
1255+
static std::pair<BraceStmt *, bool>
1256+
synthesizeStructDefaultConstructorBody(AbstractFunctionDecl *afd,
1257+
void *context) {
1258+
auto constructor = cast<ConstructorDecl>(afd);
1259+
ASTContext &ctx = constructor->getASTContext();
1260+
auto structDecl = static_cast<StructDecl *>(context);
12801261

12811262
// Use a builtin to produce a zero initializer, and assign it to self.
12821263

12831264
// Construct the left-hand reference to self.
12841265
auto *selfDecl = constructor->getImplicitSelfDecl();
1285-
Expr *lhs = new (context) DeclRefExpr(selfDecl,
1286-
DeclNameLoc(), /*Implicit=*/true);
1266+
Expr *lhs = new (ctx) DeclRefExpr(selfDecl, DeclNameLoc(), /*Implicit=*/true);
12871267
auto selfType = structDecl->getDeclaredInterfaceType();
12881268
lhs->setType(LValueType::get(selfType));
12891269

1290-
auto emptyTuple = TupleType::getEmpty(context);
1270+
auto emptyTuple = TupleType::getEmpty(ctx);
12911271

12921272
// Construct the right-hand call to Builtin.zeroInitializer.
1293-
Identifier zeroInitID = context.getIdentifier("zeroInitializer");
1273+
Identifier zeroInitID = ctx.getIdentifier("zeroInitializer");
12941274
auto zeroInitializerFunc =
1295-
cast<FuncDecl>(getBuiltinValueDecl(context, zeroInitID));
1275+
cast<FuncDecl>(getBuiltinValueDecl(ctx, zeroInitID));
12961276
SubstitutionMap subMap =
12971277
SubstitutionMap::get(zeroInitializerFunc->getGenericSignature(),
12981278
llvm::makeArrayRef(selfType), { });
12991279
ConcreteDeclRef concreteDeclRef(zeroInitializerFunc, subMap);
13001280
auto zeroInitializerRef =
1301-
new (context) DeclRefExpr(concreteDeclRef, DeclNameLoc(),
1302-
/*implicit*/ true);
1281+
new (ctx) DeclRefExpr(concreteDeclRef, DeclNameLoc(), /*implicit*/ true);
13031282
zeroInitializerRef->setType(FunctionType::get({}, selfType));
13041283

1305-
auto call = CallExpr::createImplicit(context, zeroInitializerRef, {}, {});
1284+
auto call = CallExpr::createImplicit(ctx, zeroInitializerRef, {}, {});
13061285
call->setType(selfType);
13071286
call->setThrows(false);
13081287

1309-
auto assign = new (context) AssignExpr(lhs, SourceLoc(), call,
1310-
/*implicit*/ true);
1288+
auto assign = new (ctx) AssignExpr(lhs, SourceLoc(), call, /*implicit*/ true);
13111289
assign->setType(emptyTuple);
13121290

1313-
auto result = TupleExpr::createEmpty(context, SourceLoc(), SourceLoc(),
1291+
auto result = TupleExpr::createEmpty(ctx, SourceLoc(), SourceLoc(),
13141292
/*Implicit=*/true);
13151293
result->setType(emptyTuple);
13161294

1317-
auto ret = new (context) ReturnStmt(SourceLoc(), result, /*Implicit=*/true);
1295+
auto ret = new (ctx) ReturnStmt(SourceLoc(), result, /*Implicit=*/true);
13181296

13191297
// Create the function body.
1320-
auto body = BraceStmt::create(context, SourceLoc(), {assign, ret},
1321-
SourceLoc());
1322-
constructor->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
1298+
auto body = BraceStmt::create(ctx, SourceLoc(), {assign, ret}, SourceLoc());
1299+
return { body, /*isTypeChecked=*/true };
1300+
}
1301+
1302+
/// Create a default constructor that initializes a struct to zero.
1303+
static ConstructorDecl *
1304+
createDefaultConstructor(ClangImporter::Implementation &Impl,
1305+
StructDecl *structDecl) {
1306+
auto &context = Impl.SwiftContext;
1307+
1308+
auto emptyPL = ParameterList::createEmpty(context);
1309+
1310+
// Create the constructor.
1311+
DeclName name(context, DeclBaseName::createConstructor(), emptyPL);
1312+
auto constructor = new (context) ConstructorDecl(
1313+
name, structDecl->getLoc(), OTK_None, /*FailabilityLoc=*/SourceLoc(),
1314+
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(), emptyPL,
1315+
/*GenericParams=*/nullptr, structDecl);
1316+
1317+
// Set the constructor's type.
1318+
constructor->computeType();
1319+
constructor->setValidationToChecked();
1320+
1321+
constructor->setAccess(AccessLevel::Public);
1322+
1323+
// Mark the constructor transparent so that we inline it away completely.
1324+
constructor->getAttrs().add(new (context) TransparentAttr(/*implicit*/ true));
1325+
1326+
constructor->setBodySynthesizer(synthesizeStructDefaultConstructorBody,
1327+
structDecl);
13231328

13241329
// We're done.
13251330
return constructor;

0 commit comments

Comments
 (0)