Skip to content

Commit 9773a3c

Browse files
authored
Merge pull request #42395 from xedin/result-builder-type
[BuilderTransform] Extract all builder related operations into `ResultBuilder` type
2 parents 2d2586e + 6bc6ded commit 9773a3c

File tree

2 files changed

+166
-124
lines changed

2 files changed

+166
-124
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,50 @@ enum class FreeTypeVariableBinding {
105105

106106
namespace constraints {
107107

108+
struct ResultBuilder {
109+
private:
110+
DeclContext *DC;
111+
/// An implicit variable that represents `Self` type of the result builder.
112+
VarDecl *BuilderSelf;
113+
Type BuilderType;
114+
llvm::SmallDenseMap<DeclName, bool> SupportedOps;
115+
116+
Identifier BuildOptionalId;
117+
118+
/// Counter used to give unique names to the variables that are
119+
/// created implicitly.
120+
unsigned VarCounter = 0;
121+
122+
public:
123+
ResultBuilder(ConstraintSystem *CS, DeclContext *DC, Type builderType);
124+
125+
DeclContext *getDeclContext() const { return DC; }
126+
127+
Type getType() const { return BuilderType; }
128+
129+
NominalTypeDecl *getBuilderDecl() const {
130+
return BuilderType->getAnyNominal();
131+
}
132+
133+
Identifier getBuildOptionalId() const { return BuildOptionalId; }
134+
135+
bool supports(Identifier fnBaseName, ArrayRef<Identifier> argLabels = {},
136+
bool checkAvailability = false);
137+
138+
bool supportsOptional() { return supports(getBuildOptionalId()); }
139+
140+
Expr *buildCall(SourceLoc loc, Identifier fnName,
141+
ArrayRef<Expr *> argExprs,
142+
ArrayRef<Identifier> argLabels) const;
143+
144+
/// Build an implicit variable in this context.
145+
VarDecl *buildVar(SourceLoc loc);
146+
147+
/// Build a reference to a given variable and mark it
148+
/// as located at a given source location.
149+
DeclRefExpr *buildVarRef(VarDecl *var, SourceLoc loc);
150+
};
151+
108152
/// Describes the algorithm to use for trailing closure matching.
109153
enum class TrailingClosureMatching {
110154
/// Match a trailing closure to the first parameter that appears to work.

0 commit comments

Comments
 (0)