Skip to content

Commit

Permalink
[SE-0289] Finish renaming source code, tests to "result builders"
Browse files Browse the repository at this point in the history
  • Loading branch information
DougGregor committed Oct 21, 2020
1 parent 0d568a9 commit 6d41524
Show file tree
Hide file tree
Showing 49 changed files with 314 additions and 315 deletions.
2 changes: 1 addition & 1 deletion include/swift/AST/ASTTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SWIFT_TYPEID(AncestryFlags)
SWIFT_TYPEID(BodyInitKind)
SWIFT_TYPEID(BodyInitKindAndExpr)
SWIFT_TYPEID(CtorInitializerKind)
SWIFT_TYPEID(FunctionBuilderBodyPreCheck)
SWIFT_TYPEID(ResultBuilderBodyPreCheck)
SWIFT_TYPEID(GenericSignature)
SWIFT_TYPEID(ImplicitImportList)
SWIFT_TYPEID(ImplicitMemberAction)
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 @@ -35,7 +35,7 @@ class CustomAttr;
class Decl;
class EnumDecl;
class FuncDecl;
enum class FunctionBuilderBodyPreCheck : uint8_t;
enum class ResultBuilderBodyPreCheck : uint8_t;
class GenericParamList;
class GenericSignature;
class GenericTypeParamType;
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2403,11 +2403,11 @@ class ValueDecl : public Decl {

/// Retrieve the attribute associating this declaration with a
/// result builder, if there is one.
CustomAttr *getAttachedFunctionBuilder() const;
CustomAttr *getAttachedResultBuilder() const;

/// Retrieve the @functionBuilder type attached to this declaration,
/// Retrieve the @resultBuilder type attached to this declaration,
/// if there is one.
Type getFunctionBuilderType() const;
Type getResultBuilderType() const;

/// If this value or its backing storage is annotated
/// @_dynamicReplacement(for: ...), compute the original declaration
Expand Down
10 changes: 5 additions & 5 deletions include/swift/AST/EducationalNotes.def
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ EDUCATIONAL_NOTES(unlabeled_trailing_closure_deprecated,
"trailing-closure-matching.md")

EDUCATIONAL_NOTES(result_builder_static_buildblock,
"function-builder-methods.md")
"result-builder-methods.md")
EDUCATIONAL_NOTES(result_builder_missing_limited_availability,
"function-builder-methods.md")
"result-builder-methods.md")
EDUCATIONAL_NOTES(result_builder_missing_build_optional,
"function-builder-methods.md")
"result-builder-methods.md")
EDUCATIONAL_NOTES(result_builder_missing_build_either,
"function-builder-methods.md")
"result-builder-methods.md")
EDUCATIONAL_NOTES(result_builder_missing_build_array,
"function-builder-methods.md")
"result-builder-methods.md")

#undef EDUCATIONAL_NOTES
42 changes: 21 additions & 21 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,8 @@ void simple_display(llvm::raw_ostream &out, ResilienceExpansion value);

/// Request the custom attribute which attaches a result builder to the
/// given declaration.
class AttachedFunctionBuilderRequest :
public SimpleRequest<AttachedFunctionBuilderRequest,
class AttachedResultBuilderRequest :
public SimpleRequest<AttachedResultBuilderRequest,
CustomAttr *(ValueDecl *),
RequestFlags::Cached> {
public:
Expand All @@ -758,8 +758,8 @@ class AttachedFunctionBuilderRequest :

/// Request the result builder type attached to the given declaration,
/// if any.
class FunctionBuilderTypeRequest :
public SimpleRequest<FunctionBuilderTypeRequest,
class ResultBuilderTypeRequest :
public SimpleRequest<ResultBuilderTypeRequest,
Type(ValueDecl *),
RequestFlags::Cached> {
public:
Expand Down Expand Up @@ -1960,7 +1960,7 @@ class ValueWitnessRequest
void cacheResult(Witness value) const;
};

struct PreCheckFunctionBuilderDescriptor {
struct PreCheckResultBuilderDescriptor {
AnyFunctionRef Fn;
bool SuppressDiagnostics;

Expand All @@ -1972,35 +1972,35 @@ struct PreCheckFunctionBuilderDescriptor {
BraceStmt *Body;

public:
PreCheckFunctionBuilderDescriptor(AnyFunctionRef Fn, bool suppressDiagnostics)
PreCheckResultBuilderDescriptor(AnyFunctionRef Fn, bool suppressDiagnostics)
: Fn(Fn), SuppressDiagnostics(suppressDiagnostics), Body(Fn.getBody()) {}

friend llvm::hash_code
hash_value(const PreCheckFunctionBuilderDescriptor &owner) {
hash_value(const PreCheckResultBuilderDescriptor &owner) {
return llvm::hash_combine(owner.Fn, owner.Body);
}

friend bool operator==(const PreCheckFunctionBuilderDescriptor &lhs,
const PreCheckFunctionBuilderDescriptor &rhs) {
friend bool operator==(const PreCheckResultBuilderDescriptor &lhs,
const PreCheckResultBuilderDescriptor &rhs) {
return lhs.Fn == rhs.Fn && lhs.Body == rhs.Body;
}

friend bool operator!=(const PreCheckFunctionBuilderDescriptor &lhs,
const PreCheckFunctionBuilderDescriptor &rhs) {
friend bool operator!=(const PreCheckResultBuilderDescriptor &lhs,
const PreCheckResultBuilderDescriptor &rhs) {
return !(lhs == rhs);
}

friend SourceLoc extractNearestSourceLoc(PreCheckFunctionBuilderDescriptor d) {
friend SourceLoc extractNearestSourceLoc(PreCheckResultBuilderDescriptor d) {
return extractNearestSourceLoc(d.Fn);
}

friend void simple_display(llvm::raw_ostream &out,
const PreCheckFunctionBuilderDescriptor &d) {
const PreCheckResultBuilderDescriptor &d) {
simple_display(out, d.Fn);
}
};

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

Expand All @@ -2011,10 +2011,10 @@ enum class FunctionBuilderBodyPreCheck : uint8_t {
HasReturnStmt,
};

class PreCheckFunctionBuilderRequest
: public SimpleRequest<PreCheckFunctionBuilderRequest,
FunctionBuilderBodyPreCheck(
PreCheckFunctionBuilderDescriptor),
class PreCheckResultBuilderRequest
: public SimpleRequest<PreCheckResultBuilderRequest,
ResultBuilderBodyPreCheck(
PreCheckResultBuilderDescriptor),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
Expand All @@ -2023,8 +2023,8 @@ class PreCheckFunctionBuilderRequest
friend SimpleRequest;

// Evaluation.
FunctionBuilderBodyPreCheck
evaluate(Evaluator &evaluator, PreCheckFunctionBuilderDescriptor owner) const;
ResultBuilderBodyPreCheck
evaluate(Evaluator &evaluator, PreCheckResultBuilderDescriptor owner) const;

public:
// Separate caching.
Expand Down Expand Up @@ -2759,7 +2759,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, FunctionBuilderBodyPreCheck pck);
void simple_display(llvm::raw_ostream &out, ResultBuilderBodyPreCheck pck);

#define SWIFT_TYPEID_ZONE TypeChecker
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SWIFT_REQUEST(TypeChecker, AbstractGenericSignatureRequest,
SmallVector<GenericTypeParamType *, 2>,
SmallVector<Requirement, 2>),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, AttachedFunctionBuilderRequest,
SWIFT_REQUEST(TypeChecker, AttachedResultBuilderRequest,
CustomAttr *(ValueDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, AttachedPropertyWrapperTypeRequest,
Type(VarDecl *, unsigned), Cached, NoLocationInfo)
Expand Down Expand Up @@ -81,7 +81,7 @@ SWIFT_REQUEST(TypeChecker, ExistentialTypeSupportedRequest,
bool(ProtocolDecl *), SeparatelyCached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ExtendedTypeRequest, Type(ExtensionDecl *), Cached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, FunctionBuilderTypeRequest, Type(ValueDecl *),
SWIFT_REQUEST(TypeChecker, ResultBuilderTypeRequest, Type(ValueDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, IsAsyncHandlerRequest, bool(FuncDecl *),
Cached, NoLocationInfo)
Expand Down Expand Up @@ -249,8 +249,8 @@ SWIFT_REQUEST(TypeChecker, HasUserDefinedDesignatedInitRequest,
bool(NominalTypeDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, HasMemberwiseInitRequest,
bool(StructDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PreCheckFunctionBuilderRequest,
FunctionBuilderClosurePreCheck(PreCheckFunctionBuilderDescriptor),
SWIFT_REQUEST(TypeChecker, PreCheckResultBuilderRequest,
ResultBuilderBodyPreCheck(PreCheckResultBuilderDescriptor),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ResolveImplicitMemberRequest,
evaluator::SideEffect(NominalTypeDecl *, ImplicitMemberAction),
Expand Down
27 changes: 13 additions & 14 deletions include/swift/Sema/CSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ enum class FixKind : uint8_t {
DefaultGenericArgument,

/// Skip any unhandled constructs that occur within a closure argument that
/// matches up with a
/// parameter that has a result builder.
SkipUnhandledConstructInFunctionBuilder,
/// matches up with a parameter that has a result builder.
SkipUnhandledConstructInResultBuilder,

/// Allow invalid reference to a member declared as `mutating`
/// when base is an r-value type.
Expand Down Expand Up @@ -278,7 +277,7 @@ enum class FixKind : uint8_t {
AllowKeyPathWithoutComponents,

/// Ignore result builder body which fails `pre-check` call.
IgnoreInvalidFunctionBuilderBody,
IgnoreInvalidResultBuilderBody,

/// Resolve type of `nil` by providing a contextual type.
SpecifyContextualTypeForNil,
Expand Down Expand Up @@ -1500,19 +1499,19 @@ class DefaultGenericArgument final : public ConstraintFix {
ConstraintLocator *locator);
};

class SkipUnhandledConstructInFunctionBuilder final : public ConstraintFix {
class SkipUnhandledConstructInResultBuilder final : public ConstraintFix {
public:
using UnhandledNode = llvm::PointerUnion<Stmt *, Decl *>;

private:
UnhandledNode unhandled;
NominalTypeDecl *builder;

SkipUnhandledConstructInFunctionBuilder(ConstraintSystem &cs,
SkipUnhandledConstructInResultBuilder(ConstraintSystem &cs,
UnhandledNode unhandled,
NominalTypeDecl *builder,
ConstraintLocator *locator)
: ConstraintFix(cs, FixKind::SkipUnhandledConstructInFunctionBuilder,
: ConstraintFix(cs, FixKind::SkipUnhandledConstructInResultBuilder,
locator),
unhandled(unhandled), builder(builder) { }

Expand All @@ -1523,7 +1522,7 @@ class SkipUnhandledConstructInFunctionBuilder final : public ConstraintFix {

bool diagnose(const Solution &solution, bool asNote = false) const override;

static SkipUnhandledConstructInFunctionBuilder *
static SkipUnhandledConstructInResultBuilder *
create(ConstraintSystem &cs, UnhandledNode unhandledNode,
NominalTypeDecl *builder, ConstraintLocator *locator);
};
Expand Down Expand Up @@ -1997,17 +1996,17 @@ class AllowKeyPathWithoutComponents final : public ConstraintFix {
ConstraintLocator *locator);
};

class IgnoreInvalidFunctionBuilderBody final : public ConstraintFix {
class IgnoreInvalidResultBuilderBody final : public ConstraintFix {
enum class ErrorInPhase {
PreCheck,
ConstraintGeneration,
};

ErrorInPhase Phase;

IgnoreInvalidFunctionBuilderBody(ConstraintSystem &cs, ErrorInPhase phase,
IgnoreInvalidResultBuilderBody(ConstraintSystem &cs, ErrorInPhase phase,
ConstraintLocator *locator)
: ConstraintFix(cs, FixKind::IgnoreInvalidFunctionBuilderBody, locator),
: ConstraintFix(cs, FixKind::IgnoreInvalidResultBuilderBody, locator),
Phase(phase) {}

public:
Expand All @@ -2021,18 +2020,18 @@ class IgnoreInvalidFunctionBuilderBody final : public ConstraintFix {
return diagnose(*commonFixes.front().first);
}

static IgnoreInvalidFunctionBuilderBody *
static IgnoreInvalidResultBuilderBody *
duringPreCheck(ConstraintSystem &cs, ConstraintLocator *locator) {
return create(cs, ErrorInPhase::PreCheck, locator);
}

static IgnoreInvalidFunctionBuilderBody *
static IgnoreInvalidResultBuilderBody *
duringConstraintGeneration(ConstraintSystem &cs, ConstraintLocator *locator) {
return create(cs, ErrorInPhase::ConstraintGeneration, locator);
}

private:
static IgnoreInvalidFunctionBuilderBody *
static IgnoreInvalidResultBuilderBody *
create(ConstraintSystem &cs, ErrorInPhase phase, ConstraintLocator *locator);
};

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Sema/ConstraintLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
bool isForOptionalTry() const;

/// Determine whether this locator is for a result builder body result type.
bool isForFunctionBuilderBodyResult() const;
bool isForResultBuilderBodyResult() const;

/// Determine whether this locator points directly to a given expression.
template <typename E> bool directlyAt() const {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Sema/ConstraintLocatorPathElts.def
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SIMPLE_LOCATOR_PATH_ELT(FunctionArgument)
SIMPLE_LOCATOR_PATH_ELT(FunctionResult)

/// The result type of a result builder body.
SIMPLE_LOCATOR_PATH_ELT(FunctionBuilderBodyResult)
SIMPLE_LOCATOR_PATH_ELT(ResultBuilderBodyResult)

/// A generic argument.
/// FIXME: Add support for named generic arguments?
Expand Down
20 changes: 10 additions & 10 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SemaTest;
// so they could be made friends of ConstraintSystem.
namespace TypeChecker {

Optional<BraceStmt *> applyFunctionBuilderBodyTransform(FuncDecl *func,
Optional<BraceStmt *> applyResultBuilderBodyTransform(FuncDecl *func,
Type builderType);

Optional<constraints::SolutionApplicationTarget>
Expand Down Expand Up @@ -1186,7 +1186,7 @@ class Solution {

/// The set of functions that have been transformed by a result builder.
llvm::MapVector<AnyFunctionRef, AppliedBuilderTransform>
functionBuilderTransformed;
resultBuilderTransformed;

/// Simplify the given type by substituting all occurrences of
/// type variables for their fixed types.
Expand Down Expand Up @@ -1300,8 +1300,8 @@ class Solution {
/// Retrieve the builder transform that was applied to this function, if any.
const AppliedBuilderTransform *getAppliedBuilderTransform(
AnyFunctionRef fn) const {
auto known = functionBuilderTransformed.find(fn);
return known != functionBuilderTransformed.end()
auto known = resultBuilderTransformed.find(fn);
return known != resultBuilderTransformed.end()
? &known->second
: nullptr;
}
Expand Down Expand Up @@ -2130,7 +2130,7 @@ class ConstraintSystem {
///
/// Tracking this information is useful to avoid producing duplicate
/// diagnostics when result builder has multiple overloads.
llvm::SmallDenseSet<AnyFunctionRef> InvalidFunctionBuilderBodies;
llvm::SmallDenseSet<AnyFunctionRef> InvalidResultBuilderBodies;

/// Maps node types used within all portions of the constraint
/// system, instead of directly using the types on the
Expand Down Expand Up @@ -2220,7 +2220,7 @@ class ConstraintSystem {

/// The set of functions that have been transformed by a result builder.
std::vector<std::pair<AnyFunctionRef, AppliedBuilderTransform>>
functionBuilderTransformed;
resultBuilderTransformed;

/// Cache of the effects any closures visited.
llvm::SmallDenseMap<ClosureExpr *, FunctionType::ExtInfo, 4> closureEffectsCache;
Expand Down Expand Up @@ -2687,7 +2687,7 @@ class ConstraintSystem {

unsigned numFavoredConstraints;

unsigned numFunctionBuilderTransformed;
unsigned numResultBuilderTransformed;

/// The length of \c ResolvedOverloads.
unsigned numResolvedOverloads;
Expand Down Expand Up @@ -2759,7 +2759,7 @@ class ConstraintSystem {

// FIXME: Perhaps these belong on ConstraintSystem itself.
friend Optional<BraceStmt *>
swift::TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *func,
swift::TypeChecker::applyResultBuilderBodyTransform(FuncDecl *func,
Type builderType);

friend Optional<SolutionApplicationTarget>
Expand Down Expand Up @@ -4607,7 +4607,7 @@ class ConstraintSystem {
///
/// \returns \c None when the result builder cannot be applied at all,
/// otherwise the result of applying the result builder.
Optional<TypeMatchResult> matchFunctionBuilder(
Optional<TypeMatchResult> matchResultBuilder(
AnyFunctionRef fn, Type builderType, Type bodyResultType,
ConstraintKind bodyResultConstraintKind,
ConstraintLocatorBuilder locator);
Expand Down Expand Up @@ -6002,7 +6002,7 @@ std::string describeGenericType(ValueDecl *GP, bool includeName = false);
/// type-checked version.
///
/// \returns the transformed body
BraceStmt *applyFunctionBuilderTransform(
BraceStmt *applyResultBuilderTransform(
const constraints::Solution &solution,
constraints::AppliedBuilderTransform applied,
BraceStmt *body,
Expand Down
Loading

0 comments on commit 6d41524

Please sign in to comment.