Skip to content

Commit b1c90fe

Browse files
committed
[CS] Sink closure property wrapper application into applySolution
We need to make sure property wrappers are applied before `checkParameterList`.
1 parent 2d6a38b commit b1c90fe

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8883,7 +8883,8 @@ namespace {
88838883
rewriteFunction(closure);
88848884

88858885
if (AnyFunctionRef(closure).hasExternalPropertyWrapperParameters()) {
8886-
return Action::SkipNode(rewriteClosure(closure));
8886+
return Action::SkipNode(Rewriter.buildSingleCurryThunk(
8887+
closure, closure, Rewriter.cs.getConstraintLocator(closure)));
88878888
}
88888889

88898890
return Action::SkipNode(closure);
@@ -8935,49 +8936,6 @@ namespace {
89358936
std::optional<SyntacticElementTarget>
89368937
rewriteTarget(SyntacticElementTarget target);
89378938

8938-
AutoClosureExpr *rewriteClosure(ClosureExpr *closure) {
8939-
auto &solution = Rewriter.solution;
8940-
8941-
// Apply types to synthesized property wrapper vars.
8942-
for (auto *param : *closure->getParameters()) {
8943-
if (!param->hasAttachedPropertyWrapper())
8944-
continue;
8945-
8946-
// Set the interface type of each property wrapper synthesized var
8947-
auto *backingVar = param->getPropertyWrapperBackingProperty();
8948-
auto backingType =
8949-
solution.simplifyType(solution.getType(backingVar))->mapTypeOutOfContext();
8950-
backingVar->setInterfaceType(backingType);
8951-
8952-
if (auto *projectionVar = param->getPropertyWrapperProjectionVar()) {
8953-
projectionVar->setInterfaceType(
8954-
solution.simplifyType(solution.getType(projectionVar))->mapTypeOutOfContext());
8955-
}
8956-
8957-
auto *wrappedValueVar = param->getPropertyWrapperWrappedValueVar();
8958-
auto wrappedValueType =
8959-
solution.simplifyType(solution.getType(wrappedValueVar))->mapTypeOutOfContext();
8960-
wrappedValueVar->setInterfaceType(wrappedValueType->getWithoutSpecifierType());
8961-
8962-
if (param->hasImplicitPropertyWrapper()) {
8963-
if (wrappedValueType->is<LValueType>())
8964-
wrappedValueVar->setImplInfo(StorageImplInfo::getMutableComputed());
8965-
8966-
// Add an explicit property wrapper attribute, which is needed for
8967-
// synthesizing the accessors.
8968-
auto &context = wrappedValueVar->getASTContext();
8969-
auto *typeExpr = TypeExpr::createImplicit(backingType, context);
8970-
auto *attr = CustomAttr::create(context, SourceLoc(), typeExpr, /*implicit=*/true);
8971-
wrappedValueVar->getAttrs().add(attr);
8972-
}
8973-
}
8974-
8975-
TypeChecker::checkParameterList(closure->getParameters(), closure);
8976-
8977-
return Rewriter.buildSingleCurryThunk(
8978-
closure, closure, Rewriter.cs.getConstraintLocator(closure));
8979-
}
8980-
89818939
/// Rewrite the function for the given solution.
89828940
///
89838941
/// \returns true if an error occurred.

lib/Sema/CSSyntacticElement.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,46 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
25232523
};
25242524
} // namespace
25252525

2526+
static void applySolutionToClosurePropertyWrappers(ClosureExpr *closure,
2527+
const Solution &solution) {
2528+
for (auto *param : *closure->getParameters()) {
2529+
if (!param->hasAttachedPropertyWrapper())
2530+
continue;
2531+
2532+
// Set the interface type of each property wrapper synthesized var
2533+
auto *backingVar = param->getPropertyWrapperBackingProperty();
2534+
auto backingType = solution.simplifyType(solution.getType(backingVar))
2535+
->mapTypeOutOfContext();
2536+
backingVar->setInterfaceType(backingType);
2537+
2538+
if (auto *projectionVar = param->getPropertyWrapperProjectionVar()) {
2539+
projectionVar->setInterfaceType(
2540+
solution.simplifyType(solution.getType(projectionVar))
2541+
->mapTypeOutOfContext());
2542+
}
2543+
2544+
auto *wrappedValueVar = param->getPropertyWrapperWrappedValueVar();
2545+
auto wrappedValueType =
2546+
solution.simplifyType(solution.getType(wrappedValueVar))
2547+
->mapTypeOutOfContext();
2548+
wrappedValueVar->setInterfaceType(
2549+
wrappedValueType->getWithoutSpecifierType());
2550+
2551+
if (param->hasImplicitPropertyWrapper()) {
2552+
if (wrappedValueType->is<LValueType>())
2553+
wrappedValueVar->setImplInfo(StorageImplInfo::getMutableComputed());
2554+
2555+
// Add an explicit property wrapper attribute, which is needed for
2556+
// synthesizing the accessors.
2557+
auto &context = wrappedValueVar->getASTContext();
2558+
auto *typeExpr = TypeExpr::createImplicit(backingType, context);
2559+
auto *attr =
2560+
CustomAttr::create(context, SourceLoc(), typeExpr, /*implicit=*/true);
2561+
wrappedValueVar->getAttrs().add(attr);
2562+
}
2563+
}
2564+
}
2565+
25262566
SolutionApplicationToFunctionResult ConstraintSystem::applySolution(
25272567
Solution &solution, AnyFunctionRef fn,
25282568
DeclContext *&currentDC,
@@ -2553,6 +2593,8 @@ SolutionApplicationToFunctionResult ConstraintSystem::applySolution(
25532593
if (closure->hasExplicitResultType()) {
25542594
closure->setExplicitResultType(closureFnType->getResult());
25552595
}
2596+
2597+
applySolutionToClosurePropertyWrappers(closure, solution);
25562598
}
25572599

25582600
// Enter the context of the function before performing any additional

0 commit comments

Comments
 (0)