Skip to content

Commit 5be83fe

Browse files
committed
---
yaml --- r: 341711 b: refs/heads/rxwei-patch-1 c: 55f619b h: refs/heads/master i: 341709: eec6cfe 341707: cd70284 341703: 89a87f1 341695: 2266551
1 parent e1f839e commit 5be83fe

File tree

3 files changed

+58
-50
lines changed

3 files changed

+58
-50
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: 4d4059e20255bfa137bf7a197cd8d48fe94179cb
1018+
refs/heads/rxwei-patch-1: 55f619ba8124c24ec03ae1d9223fd34827603028
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: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,60 +1557,72 @@ static void makeStructRawValued(
15571557
Impl.RawTypes[structDecl] = underlyingType;
15581558
}
15591559

1560+
/// Synthesizer callback for a raw value bridging constructor body.
1561+
static std::pair<BraceStmt *, bool>
1562+
synthesizeRawValueBridgingConstructorBody(AbstractFunctionDecl *afd,
1563+
void *context) {
1564+
auto init = cast<ConstructorDecl>(afd);
1565+
VarDecl *storedRawValue = static_cast<VarDecl *>(context);
1566+
1567+
ASTContext &ctx = init->getASTContext();
1568+
1569+
auto selfDecl = init->getImplicitSelfDecl();
1570+
auto storedType = storedRawValue->getInterfaceType();
1571+
1572+
// Construct left-hand side.
1573+
Expr *lhs = new (ctx) DeclRefExpr(selfDecl, DeclNameLoc(),
1574+
/*Implicit=*/true);
1575+
lhs->setType(LValueType::get(selfDecl->getType()));
1576+
1577+
lhs = new (ctx) MemberRefExpr(lhs, SourceLoc(), storedRawValue,
1578+
DeclNameLoc(), /*Implicit=*/true,
1579+
AccessSemantics::DirectToStorage);
1580+
lhs->setType(LValueType::get(storedType));
1581+
1582+
// Construct right-hand side.
1583+
// FIXME: get the parameter from the init, and plug it in here.
1584+
auto *paramDecl = init->getParameters()->get(0);
1585+
auto *paramRef = new (ctx) DeclRefExpr(
1586+
paramDecl, DeclNameLoc(), /*Implicit=*/true);
1587+
paramRef->setType(paramDecl->getType());
1588+
1589+
Expr *rhs = paramRef;
1590+
if (!storedRawValue->getInterfaceType()->isEqual(paramDecl->getType())) {
1591+
auto bridge = new (ctx) BridgeToObjCExpr(paramRef, storedType);
1592+
bridge->setType(storedType);
1593+
1594+
auto coerce = new (ctx) CoerceExpr(bridge, SourceLoc(),
1595+
{nullptr, storedType});
1596+
coerce->setType(storedType);
1597+
1598+
rhs = coerce;
1599+
}
1600+
1601+
// Add assignment.
1602+
auto assign = new (ctx) AssignExpr(lhs, SourceLoc(), rhs,
1603+
/*Implicit=*/true);
1604+
assign->setType(TupleType::getEmpty(ctx));
1605+
1606+
auto result = TupleExpr::createEmpty(ctx, SourceLoc(), SourceLoc(),
1607+
/*Implicit=*/true);
1608+
auto ret = new (ctx) ReturnStmt(SourceLoc(), result, /*Implicit=*/true);
1609+
1610+
auto body = BraceStmt::create(ctx, SourceLoc(), {assign, ret}, SourceLoc());
1611+
return { body, /*isTypeChecked=*/true };
1612+
}
1613+
15601614
/// Create a rawValue-ed constructor that bridges to its underlying storage.
15611615
static ConstructorDecl *createRawValueBridgingConstructor(
15621616
ClangImporter::Implementation &Impl, StructDecl *structDecl,
15631617
VarDecl *computedRawValue, VarDecl *storedRawValue, bool wantLabel,
15641618
bool wantBody) {
1565-
auto &ctx = Impl.SwiftContext;
15661619
auto init = createValueConstructor(Impl, structDecl, computedRawValue,
15671620
/*wantCtorParamNames=*/wantLabel,
15681621
/*wantBody=*/false);
15691622
// Insert our custom init body
15701623
if (wantBody) {
1571-
auto selfDecl = init->getImplicitSelfDecl();
1572-
auto storedType = storedRawValue->getInterfaceType();
1573-
1574-
// Construct left-hand side.
1575-
Expr *lhs = new (ctx) DeclRefExpr(selfDecl, DeclNameLoc(),
1576-
/*Implicit=*/true);
1577-
lhs->setType(LValueType::get(selfDecl->getType()));
1578-
1579-
lhs = new (ctx) MemberRefExpr(lhs, SourceLoc(), storedRawValue,
1580-
DeclNameLoc(), /*Implicit=*/true,
1581-
AccessSemantics::DirectToStorage);
1582-
lhs->setType(LValueType::get(storedType));
1583-
1584-
// Construct right-hand side.
1585-
// FIXME: get the parameter from the init, and plug it in here.
1586-
auto *paramDecl = init->getParameters()->get(0);
1587-
auto *paramRef = new (ctx) DeclRefExpr(
1588-
paramDecl, DeclNameLoc(), /*Implicit=*/true);
1589-
paramRef->setType(paramDecl->getType());
1590-
1591-
Expr *rhs = paramRef;
1592-
if (!storedRawValue->getInterfaceType()->isEqual(paramDecl->getType())) {
1593-
auto bridge = new (ctx) BridgeToObjCExpr(paramRef, storedType);
1594-
bridge->setType(storedType);
1595-
1596-
auto coerce = new (ctx) CoerceExpr(bridge, SourceLoc(),
1597-
{nullptr, storedType});
1598-
coerce->setType(storedType);
1599-
1600-
rhs = coerce;
1601-
}
1602-
1603-
// Add assignment.
1604-
auto assign = new (ctx) AssignExpr(lhs, SourceLoc(), rhs,
1605-
/*Implicit=*/true);
1606-
assign->setType(TupleType::getEmpty(ctx));
1607-
1608-
auto result = TupleExpr::createEmpty(ctx, SourceLoc(), SourceLoc(),
1609-
/*Implicit=*/true);
1610-
auto ret = new (ctx) ReturnStmt(SourceLoc(), result, /*Implicit=*/true);
1611-
1612-
auto body = BraceStmt::create(ctx, SourceLoc(), {assign, ret}, SourceLoc());
1613-
init->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
1624+
init->setBodySynthesizer(synthesizeRawValueBridgingConstructorBody,
1625+
storedRawValue);
16141626
}
16151627

16161628
return init;
@@ -1681,7 +1693,7 @@ static void makeStructRawValuedWithBridge(
16811693
if (makeUnlabeledValueInit)
16821694
unlabeledCtor = createRawValueBridgingConstructor(
16831695
Impl, structDecl, computedVar, storedVar,
1684-
/*wantLabel*/ false, /*wantBody*/!Impl.hasFinishedTypeChecking());
1696+
/*wantLabel*/ false, /*wantBody*/true);
16851697

16861698
if (unlabeledCtor)
16871699
structDecl->addMember(unlabeledCtor);

branches/rxwei-patch-1/lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
11681168
"already have a type resolver");
11691169
typeResolver.setPointerAndInt(newResolver, true);
11701170
}
1171-
bool hasBegunTypeChecking() const { return typeResolver.getInt(); }
1172-
bool hasFinishedTypeChecking() const {
1173-
return hasBegunTypeChecking() && !getTypeResolver();
1174-
}
11751171

11761172
/// Allocate a new delayed conformance ID with the given set of
11771173
/// conformances.

0 commit comments

Comments
 (0)