Skip to content

Commit fffe129

Browse files
committed
[Constraint system] Generalize record of transformed function builders.
1 parent dfda7ac commit fffe129

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ class AnyFunctionRef {
208208
llvm_unreachable("unexpected AnyFunctionRef representation");
209209
}
210210

211+
friend bool operator==(AnyFunctionRef lhs, AnyFunctionRef rhs) {
212+
return lhs.TheFunction == rhs.TheFunction;
213+
}
214+
215+
friend bool operator!=(AnyFunctionRef lhs, AnyFunctionRef rhs) {
216+
return lhs.TheFunction != rhs.TheFunction;
217+
}
218+
211219
private:
212220
ArrayRef<AnyFunctionType::Yield>
213221
getYieldResultsImpl(SmallVectorImpl<AnyFunctionType::Yield> &buffer,

lib/Sema/BuilderTransform.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,13 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
604604

605605
// Record the transformation.
606606
assert(std::find_if(
607-
builderTransformedClosures.begin(),
608-
builderTransformedClosures.end(),
609-
[&](const std::pair<ClosureExpr *, AppliedBuilderTransform> &elt) {
607+
functionBuilderTransformed.begin(),
608+
functionBuilderTransformed.end(),
609+
[&](const std::pair<AnyFunctionRef, AppliedBuilderTransform> &elt) {
610610
return elt.first == closure;
611-
}) == builderTransformedClosures.end() &&
611+
}) == functionBuilderTransformed.end() &&
612612
"already transformed this closure along this path!?!");
613-
builderTransformedClosures.push_back(
613+
functionBuilderTransformed.push_back(
614614
std::make_pair(closure,
615615
AppliedBuilderTransform{builderType, singleExpr}));
616616

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7041,9 +7041,8 @@ namespace {
70417041
// If this closure had a function builder applied, rewrite it to a
70427042
// closure with a single expression body containing the builder
70437043
// invocations.
7044-
auto builder =
7045-
Rewriter.solution.builderTransformedClosures.find(closure);
7046-
if (builder != Rewriter.solution.builderTransformedClosures.end()) {
7044+
auto builder = Rewriter.solution.functionBuilderTransformed.find(closure);
7045+
if (builder != Rewriter.solution.functionBuilderTransformed.end()) {
70477046
auto singleExpr = builder->second.singleExpr;
70487047
auto returnStmt = new (ctx) ReturnStmt(
70497048
singleExpr->getStartLoc(), singleExpr, /*implicit=*/true);

lib/Sema/CSSolver.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ Solution ConstraintSystem::finalize() {
171171
for (auto &e : CheckedConformances)
172172
solution.Conformances.push_back({e.first, e.second});
173173

174-
for (const auto &transformed : builderTransformedClosures) {
174+
for (const auto &transformed : functionBuilderTransformed) {
175175
auto known =
176-
solution.builderTransformedClosures.find(transformed.first);
177-
if (known != solution.builderTransformedClosures.end()) {
176+
solution.functionBuilderTransformed.find(transformed.first);
177+
if (known != solution.functionBuilderTransformed.end()) {
178178
assert(known->second.singleExpr == transformed.second.singleExpr);
179179
}
180-
solution.builderTransformedClosures.insert(transformed);
180+
solution.functionBuilderTransformed.insert(transformed);
181181
}
182182

183183
return solution;
@@ -241,8 +241,8 @@ void ConstraintSystem::applySolution(const Solution &solution) {
241241
for (auto &conformance : solution.Conformances)
242242
CheckedConformances.push_back(conformance);
243243

244-
for (const auto &transformed : solution.builderTransformedClosures) {
245-
builderTransformedClosures.push_back(transformed);
244+
for (const auto &transformed : solution.functionBuilderTransformed) {
245+
functionBuilderTransformed.push_back(transformed);
246246
}
247247

248248
// Register any fixes produced along this path.
@@ -436,7 +436,7 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
436436
numCheckedConformances = cs.CheckedConformances.size();
437437
numDisabledConstraints = cs.solverState->getNumDisabledConstraints();
438438
numFavoredConstraints = cs.solverState->getNumFavoredConstraints();
439-
numBuilderTransformedClosures = cs.builderTransformedClosures.size();
439+
numFunctionBuilderTransformed = cs.functionBuilderTransformed.size();
440440
numResolvedOverloads = cs.ResolvedOverloads.size();
441441

442442
PreviousScore = cs.CurrentScore;
@@ -503,7 +503,7 @@ ConstraintSystem::SolverScope::~SolverScope() {
503503
truncate(cs.CheckedConformances, numCheckedConformances);
504504

505505
/// Remove any builder transformed closures.
506-
truncate(cs.builderTransformedClosures, numBuilderTransformedClosures);
506+
truncate(cs.functionBuilderTransformed, numFunctionBuilderTransformed);
507507

508508
// Reset the previous score.
509509
cs.CurrentScore = PreviousScore;

lib/Sema/ConstraintSystem.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,9 @@ class Solution {
823823
std::vector<std::pair<ConstraintLocator *, ProtocolConformanceRef>>
824824
Conformances;
825825

826-
/// The set of closures that have been transformed by a function builder.
827-
llvm::MapVector<ClosureExpr *, AppliedBuilderTransform>
828-
builderTransformedClosures;
826+
/// The set of functions that have been transformed by a function builder.
827+
llvm::MapVector<AnyFunctionRef, AppliedBuilderTransform>
828+
functionBuilderTransformed;
829829

830830
/// Simplify the given type by substituting all occurrences of
831831
/// type variables for their fixed types.
@@ -1341,9 +1341,9 @@ class ConstraintSystem {
13411341
std::vector<std::pair<ConstraintLocator *, ProtocolConformanceRef>>
13421342
CheckedConformances;
13431343

1344-
/// The set of closures that have been transformed by a function builder.
1345-
std::vector<std::pair<ClosureExpr *, AppliedBuilderTransform>>
1346-
builderTransformedClosures;
1344+
/// The set of functions that have been transformed by a function builder.
1345+
std::vector<std::pair<AnyFunctionRef, AppliedBuilderTransform>>
1346+
functionBuilderTransformed;
13471347

13481348
public:
13491349
/// The locators of \c Defaultable constraints whose defaults were used.
@@ -1840,7 +1840,7 @@ class ConstraintSystem {
18401840

18411841
unsigned numFavoredConstraints;
18421842

1843-
unsigned numBuilderTransformedClosures;
1843+
unsigned numFunctionBuilderTransformed;
18441844

18451845
/// The length of \c ResolvedOverloads.
18461846
unsigned numResolvedOverloads;

0 commit comments

Comments
 (0)