Skip to content

Commit ceeb2c9

Browse files
committed
---
yaml --- r: 341701 b: refs/heads/rxwei-patch-1 c: 8117849 h: refs/heads/master i: 341699: f26fd4e
1 parent 1fc02ca commit ceeb2c9

12 files changed

+239
-221
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: 015b7c52660e4d0513e4679dc272ddbe9a1f319f
1018+
refs/heads/rxwei-patch-1: 8117849d46c35034cb3732aa1bd2f86b88e166e3
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/include/swift/AST/Decl.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,7 +5615,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
56155615
}
56165616

56175617
struct BodySynthesizer {
5618-
void (* Fn)(AbstractFunctionDecl *, void *);
5618+
std::pair<BraceStmt *, bool> (* Fn)(AbstractFunctionDecl *, void *);
56195619
void *Context;
56205620
};
56215621

@@ -5748,18 +5748,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57485748
/// have a body for this function.
57495749
///
57505750
/// \sa hasBody()
5751-
BraceStmt *getBody(bool canSynthesize = true) const {
5752-
if (canSynthesize && getBodyKind() == BodyKind::Synthesize) {
5753-
const_cast<AbstractFunctionDecl *>(this)->setBodyKind(BodyKind::None);
5754-
(Synthesizer.Fn)(const_cast<AbstractFunctionDecl *>(this),
5755-
Synthesizer.Context);
5756-
}
5757-
if (getBodyKind() == BodyKind::Parsed ||
5758-
getBodyKind() == BodyKind::TypeChecked) {
5759-
return Body;
5760-
}
5761-
return nullptr;
5762-
}
5751+
BraceStmt *getBody(bool canSynthesize = true) const;
5752+
57635753
void setBody(BraceStmt *S, BodyKind NewBodyKind = BodyKind::Parsed) {
57645754
assert(getBodyKind() != BodyKind::Skipped &&
57655755
"cannot set a body if it was skipped");
@@ -5784,8 +5774,12 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57845774
}
57855775

57865776
/// Note that parsing for the body was delayed.
5787-
void setBodySynthesizer(void (* fn)(AbstractFunctionDecl *, void *),
5788-
void *context = nullptr) {
5777+
///
5778+
/// The function should return the body statement and a flag indicating
5779+
/// whether that body is already type-checked.
5780+
void setBodySynthesizer(
5781+
std::pair<BraceStmt *, bool> (* fn)(AbstractFunctionDecl *, void *),
5782+
void *context = nullptr) {
57895783
assert(getBodyKind() == BodyKind::None);
57905784
Synthesizer = {fn, context};
57915785
setBodyKind(BodyKind::Synthesize);

branches/rxwei-patch-1/lib/AST/Decl.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6236,6 +6236,40 @@ bool AbstractFunctionDecl::argumentNameIsAPIByDefault() const {
62366236
return false;
62376237
}
62386238

6239+
BraceStmt *AbstractFunctionDecl::getBody(bool canSynthesize) const {
6240+
switch (getBodyKind()) {
6241+
case BodyKind::Deserialized:
6242+
case BodyKind::MemberwiseInitializer:
6243+
case BodyKind::None:
6244+
case BodyKind::Skipped:
6245+
return nullptr;
6246+
6247+
case BodyKind::Parsed:
6248+
case BodyKind::TypeChecked:
6249+
return Body;
6250+
6251+
case BodyKind::Unparsed:
6252+
// FIXME: Go parse now!
6253+
return nullptr;
6254+
6255+
case BodyKind::Synthesize: {
6256+
if (!canSynthesize)
6257+
return nullptr;
6258+
6259+
const_cast<AbstractFunctionDecl *>(this)->setBodyKind(BodyKind::None);
6260+
BraceStmt *body;
6261+
bool isTypeChecked;
6262+
6263+
auto mutableThis = const_cast<AbstractFunctionDecl *>(this);
6264+
std::tie(body, isTypeChecked) = (Synthesizer.Fn)(
6265+
mutableThis, Synthesizer.Context);
6266+
mutableThis->setBody(
6267+
body, isTypeChecked ? BodyKind::TypeChecked : BodyKind::Parsed);
6268+
return body;
6269+
}
6270+
}
6271+
}
6272+
62396273
SourceRange AbstractFunctionDecl::getBodySourceRange() const {
62406274
switch (getBodyKind()) {
62416275
case BodyKind::None:

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,7 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
536536
auto body = BraceStmt::create(C, SourceLoc(), {assign, ret}, SourceLoc(),
537537
/*implicit*/ true);
538538

539-
ctorDecl->setBody(body);
540-
ctorDecl->setBodyTypeCheckedIfPresent();
539+
ctorDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
541540

542541
return ctorDecl;
543542
}
@@ -612,8 +611,7 @@ static AccessorDecl *makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
612611
auto body = BraceStmt::create(C, SourceLoc(), ASTNode(ret), SourceLoc(),
613612
/*implicit*/ true);
614613

615-
getterDecl->setBody(body);
616-
getterDecl->setBodyTypeCheckedIfPresent();
614+
getterDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
617615

618616
return getterDecl;
619617
}
@@ -689,8 +687,7 @@ static AccessorDecl *makeStructRawValueGetter(
689687
auto body = BraceStmt::create(C, SourceLoc(), ASTNode(ret), SourceLoc(),
690688
/*implicit*/ true);
691689

692-
getterDecl->setBody(body);
693-
getterDecl->setBodyTypeCheckedIfPresent();
690+
getterDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
694691

695692
return getterDecl;
696693
}
@@ -848,8 +845,7 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
848845
auto ret = new (C) ReturnStmt(SourceLoc(), expr);
849846
auto body = BraceStmt::create(C, SourceLoc(), ASTNode(ret), SourceLoc(),
850847
/*implicit*/ true);
851-
getterDecl->setBody(body);
852-
getterDecl->setBodyTypeCheckedIfPresent();
848+
getterDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
853849
getterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
854850
}
855851

@@ -879,8 +875,7 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
879875

880876
auto body = BraceStmt::create(C, SourceLoc(), { assign }, SourceLoc(),
881877
/*implicit*/ true);
882-
setterDecl->setBody(body);
883-
setterDecl->setBodyTypeCheckedIfPresent();
878+
setterDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
884879
setterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
885880
}
886881

@@ -956,8 +951,7 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
956951
auto ret = new (C) ReturnStmt(SourceLoc(), reinterpreted);
957952
auto body = BraceStmt::create(C, SourceLoc(), ASTNode(ret), SourceLoc(),
958953
/*implicit*/ true);
959-
getterDecl->setBody(body);
960-
getterDecl->setBodyTypeCheckedIfPresent();
954+
getterDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
961955
getterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
962956
}
963957

@@ -1017,8 +1011,7 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
10171011

10181012
auto body = BraceStmt::create(C, SourceLoc(), { initialize }, SourceLoc(),
10191013
/*implicit*/ true);
1020-
setterDecl->setBody(body);
1021-
setterDecl->setBodyTypeCheckedIfPresent();
1014+
setterDecl->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
10221015
setterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
10231016
}
10241017

@@ -1282,8 +1275,7 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,
12821275
// Create the function body.
12831276
auto body = BraceStmt::create(context, SourceLoc(), {assign, ret},
12841277
SourceLoc());
1285-
constructor->setBody(body);
1286-
constructor->setBodyTypeCheckedIfPresent();
1278+
constructor->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
12871279

12881280
// We're done.
12891281
return constructor;
@@ -1401,8 +1393,7 @@ createValueConstructor(ClangImporter::Implementation &Impl,
14011393

14021394
// Create the function body.
14031395
auto body = BraceStmt::create(context, SourceLoc(), stmts, SourceLoc());
1404-
constructor->setBody(body);
1405-
constructor->setBodyTypeCheckedIfPresent();
1396+
constructor->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
14061397
}
14071398

14081399
// We're done.
@@ -1552,8 +1543,7 @@ static ConstructorDecl *createRawValueBridgingConstructor(
15521543
auto ret = new (ctx) ReturnStmt(SourceLoc(), result, /*Implicit=*/true);
15531544

15541545
auto body = BraceStmt::create(ctx, SourceLoc(), {assign, ret}, SourceLoc());
1555-
init->setBody(body);
1556-
init->setBodyTypeCheckedIfPresent();
1546+
init->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
15571547
}
15581548

15591549
return init;
@@ -1911,8 +1901,8 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
19111901

19121902
auto ret = new (C) ReturnStmt(SourceLoc(), domainDeclRef);
19131903
getterDecl->setBody(
1914-
BraceStmt::create(C, SourceLoc(), {ret}, SourceLoc(), isImplicit));
1915-
getterDecl->setBodyTypeCheckedIfPresent();
1904+
BraceStmt::create(C, SourceLoc(), {ret}, SourceLoc(), isImplicit),
1905+
AbstractFunctionDecl::BodyKind::TypeChecked);
19161906

19171907
return true;
19181908
}
@@ -8268,8 +8258,8 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
82688258
// Finally, set the body.
82698259
func->setBody(BraceStmt::create(C, SourceLoc(),
82708260
ASTNode(ret),
8271-
SourceLoc()));
8272-
func->setBodyTypeCheckedIfPresent();
8261+
SourceLoc()),
8262+
AbstractFunctionDecl::BodyKind::TypeChecked);
82738263
}
82748264

82758265
// Mark the function transparent so that we inline it away completely.

0 commit comments

Comments
 (0)