Skip to content

Commit f27369d

Browse files
committed
[BuilderTransform] Add contextual type to transformation information
This information would be used to decide whether conjunction that represents transformed closure should be delayed or not.
1 parent 55d0bbe commit f27369d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ struct AppliedBuilderTransform {
985985
/// converted. Opaque types should be unopened.
986986
Type bodyResultType;
987987

988+
/// If transform is applied to a closure, this type represents
989+
/// contextual type the closure is converted type (e.g. a parameter
990+
/// type or or pattern type).
991+
Type contextualType;
992+
988993
/// The version of the original body with result builder applied
989994
/// as AST transformation.
990995
NullablePtr<BraceStmt> transformedBody;
@@ -5727,7 +5732,7 @@ class ConstraintSystem {
57275732
Optional<TypeMatchResult>
57285733
matchResultBuilder(AnyFunctionRef fn, Type builderType, Type bodyResultType,
57295734
ConstraintKind bodyResultConstraintKind,
5730-
ConstraintLocatorBuilder locator);
5735+
Type contextualType, ConstraintLocatorBuilder locator);
57315736

57325737
/// Matches a wrapped or projected value parameter type to its backing
57335738
/// property wrapper type by applying the property wrapper.

lib/Sema/BuilderTransform.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,7 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
23412341

23422342
if (auto result = cs.matchResultBuilder(
23432343
func, builderType, resultContextType, resultConstraintKind,
2344+
/*contextualType=*/Type(),
23442345
cs.getConstraintLocator(func->getBody()))) {
23452346
if (result->isFailure())
23462347
return nullptr;
@@ -2428,6 +2429,7 @@ Optional<ConstraintSystem::TypeMatchResult>
24282429
ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
24292430
Type bodyResultType,
24302431
ConstraintKind bodyResultConstraintKind,
2432+
Type contextualType,
24312433
ConstraintLocatorBuilder locator) {
24322434
builderType = simplifyType(builderType);
24332435
auto builder = builderType->getAnyNominal();
@@ -2552,6 +2554,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
25522554

25532555
transformInfo.builderType = builderType;
25542556
transformInfo.bodyResultType = bodyResultType;
2557+
transformInfo.contextualType = contextualType;
25552558
transformInfo.transformedBody = transformedBody->second;
25562559

25572560
// Record the transformation.

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11037,7 +11037,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1103711037
if (resultBuilderType) {
1103811038
if (auto result = matchResultBuilder(
1103911039
closure, resultBuilderType, closureType->getResult(),
11040-
ConstraintKind::Conversion, locator)) {
11040+
ConstraintKind::Conversion, contextualType, locator)) {
1104111041
return result->isSuccess();
1104211042
}
1104311043
}

0 commit comments

Comments
 (0)