Skip to content

Reimplement function builders as statement transformations. #29133

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

Merged
merged 12 commits into from
Jan 17, 2020
Merged
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
2 changes: 1 addition & 1 deletion include/swift/AST/ASTTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

SWIFT_TYPEID(AncestryFlags)
SWIFT_TYPEID(CtorInitializerKind)
SWIFT_TYPEID(FunctionBuilderClosurePreCheck)
SWIFT_TYPEID(FunctionBuilderBodyPreCheck)
SWIFT_TYPEID(GenericSignature)
SWIFT_TYPEID(ImplicitMemberAction)
SWIFT_TYPEID(ParamSpecifier)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/ASTTypeIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ConstructorDecl;
class CustomAttr;
class Decl;
class EnumDecl;
enum class FunctionBuilderClosurePreCheck : uint8_t;
enum class FunctionBuilderBodyPreCheck : uint8_t;
class GenericParamList;
class GenericSignature;
class GenericTypeParamType;
Expand Down
20 changes: 17 additions & 3 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3599,7 +3599,10 @@ class ClosureExpr : public AbstractClosureExpr {
/// the CaptureListExpr which would normally maintain this sort of
/// information about captured variables), we need to have some way to access
/// this information directly on the ClosureExpr.
VarDecl *CapturedSelfDecl;
///
/// The bit indicates whether this closure has had a function builder
/// applied to it.
llvm::PointerIntPair<VarDecl *, 1, bool> CapturedSelfDeclAndAppliedBuilder;

/// The location of the "throws", if present.
SourceLoc ThrowsLoc;
Expand All @@ -3624,7 +3627,8 @@ class ClosureExpr : public AbstractClosureExpr {
unsigned discriminator, DeclContext *parent)
: AbstractClosureExpr(ExprKind::Closure, Type(), /*Implicit=*/false,
discriminator, parent),
BracketRange(bracketRange), CapturedSelfDecl(capturedSelfDecl),
BracketRange(bracketRange),
CapturedSelfDeclAndAppliedBuilder(capturedSelfDecl, false),
ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc), InLoc(inLoc),
ExplicitResultType(explicitResultType), Body(nullptr) {
setParameterList(params);
Expand Down Expand Up @@ -3726,13 +3730,23 @@ class ClosureExpr : public AbstractClosureExpr {
bool hasEmptyBody() const;

/// VarDecl captured by this closure under the literal name \c self , if any.
VarDecl *getCapturedSelfDecl() const { return CapturedSelfDecl; }
VarDecl *getCapturedSelfDecl() const {
return CapturedSelfDeclAndAppliedBuilder.getPointer();
}

/// Whether this closure captures the \c self param in its body in such a
/// way that implicit \c self is enabled within its body (i.e. \c self is
/// captured non-weakly).
bool capturesSelfEnablingImplictSelf() const;

bool hasAppliedFunctionBuilder() const {
return CapturedSelfDeclAndAppliedBuilder.getInt();
}

void setAppliedFunctionBuilder(bool flag = true) {
CapturedSelfDeclAndAppliedBuilder.setInt(flag);
}

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::Closure;
}
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ class ValueWitnessRequest
void cacheResult(Witness value) const;
};

enum class FunctionBuilderClosurePreCheck : uint8_t {
enum class FunctionBuilderBodyPreCheck : uint8_t {
/// There were no problems pre-checking the closure.
Okay,

Expand All @@ -1763,7 +1763,7 @@ enum class FunctionBuilderClosurePreCheck : uint8_t {

class PreCheckFunctionBuilderRequest
: public SimpleRequest<PreCheckFunctionBuilderRequest,
FunctionBuilderClosurePreCheck(AnyFunctionRef),
FunctionBuilderBodyPreCheck(AnyFunctionRef),
CacheKind::Cached> {
public:
using SimpleRequest::SimpleRequest;
Expand All @@ -1772,7 +1772,7 @@ class PreCheckFunctionBuilderRequest
friend SimpleRequest;

// Evaluation.
llvm::Expected<FunctionBuilderClosurePreCheck>
llvm::Expected<FunctionBuilderBodyPreCheck>
evaluate(Evaluator &evaluator, AnyFunctionRef fn) const;

public:
Expand Down Expand Up @@ -2044,7 +2044,7 @@ AnyValue::Holder<GenericSignature>::equals(const HolderBase &other) const {
void simple_display(llvm::raw_ostream &out, Type value);
void simple_display(llvm::raw_ostream &out, const TypeRepr *TyR);
void simple_display(llvm::raw_ostream &out, ImplicitMemberAction action);
void simple_display(llvm::raw_ostream &out, FunctionBuilderClosurePreCheck pck);
void simple_display(llvm::raw_ostream &out, FunctionBuilderBodyPreCheck pck);

#define SWIFT_TYPEID_ZONE TypeChecker
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,15 +1122,15 @@ void ValueWitnessRequest::cacheResult(Witness type) const {
//----------------------------------------------------------------------------//

void swift::simple_display(llvm::raw_ostream &out,
FunctionBuilderClosurePreCheck value) {
FunctionBuilderBodyPreCheck value) {
switch (value) {
case FunctionBuilderClosurePreCheck::Okay:
case FunctionBuilderBodyPreCheck::Okay:
out << "okay";
break;
case FunctionBuilderClosurePreCheck::HasReturnStmt:
case FunctionBuilderBodyPreCheck::HasReturnStmt:
out << "has return statement";
break;
case FunctionBuilderClosurePreCheck::Error:
case FunctionBuilderBodyPreCheck::Error:
out << "error";
break;
}
Expand Down
Loading