Skip to content

Commit 1d9981e

Browse files
authored
Merge pull request swiftlang#74249 from hamishknight/building-skip-6.0
[6.0] [Completion] Only skip result builder expressions in the same builder
2 parents 4a5d8c8 + 3fb58c3 commit 1d9981e

22 files changed

+67
-42
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class ResultBuilderTransform
7272
DeclContext *dc;
7373
ResultBuilder builder;
7474

75+
/// The source range of the body.
76+
SourceRange bodyRange;
77+
7578
/// The result type of this result builder body.
7679
Type ResultType;
7780

@@ -80,9 +83,9 @@ class ResultBuilderTransform
8083

8184
public:
8285
ResultBuilderTransform(ConstraintSystem &cs, DeclContext *dc,
83-
Type builderType, Type resultTy)
86+
SourceRange bodyRange, Type builderType, Type resultTy)
8487
: ctx(cs.getASTContext()), dc(dc), builder(cs, dc, builderType),
85-
ResultType(resultTy) {}
88+
bodyRange(bodyRange), ResultType(resultTy) {}
8689

8790
UnsupportedElt getUnsupportedElement() const { return FirstUnsupported; }
8891

@@ -238,12 +241,14 @@ class ResultBuilderTransform
238241
// buildBlock higher.
239242
buildBlockArguments.push_back(expr);
240243
} else if (ctx.CompletionCallback && expr->getSourceRange().isValid() &&
244+
containsIDEInspectionTarget(bodyRange, ctx.SourceMgr) &&
241245
!containsIDEInspectionTarget(expr->getSourceRange(),
242246
ctx.SourceMgr)) {
243-
// A statement that doesn't contain the code completion expression can't
244-
// influence the type of the code completion expression. Add a variable
245-
// for it that we can put into the buildBlock call but don't add the
246-
// expression itself into the transformed body to improve performance.
247+
// A top-level expression that doesn't contain the code completion
248+
// expression can't influence the type of the code completion expression
249+
// if they're in the same result builder. Add a variable for it that we
250+
// can put into the buildBlock call but don't add the expression itself
251+
// into the transformed body to improve performance.
247252
auto *resultVar = buildPlaceholderVar(expr->getStartLoc(), newBody);
248253
buildBlockArguments.push_back(
249254
builder.buildVarRef(resultVar, expr->getStartLoc()));
@@ -1176,6 +1181,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
11761181
// let's do it and cache the result.
11771182
if (!transformedBody) {
11781183
ResultBuilderTransform transform(*this, fn.getAsDeclContext(),
1184+
fn.getBody()->getSourceRange(),
11791185
builderType, bodyResultType);
11801186
auto *body = transform.apply(fn.getBody());
11811187

test/IDE/complete_actorisolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: concurrency
2-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -warn-concurrency
2+
// RUN: %batch-code-completion -warn-concurrency
33

44
class MyNonSendable {}
55
struct MySendable {}

test/IDE/complete_after_pattern_in_closure.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -enable-experimental-concurrency
1+
// RUN: %batch-code-completion -enable-experimental-concurrency
32

43
func makeURL(withExtension ext: Int?) -> Int? {
54
return nil

test/IDE/complete_annotation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-ide-test -batch-code-completion -code-completion-annotate-results -code-completion-sourcetext -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion -code-completion-annotate-results -code-completion-sourcetext
22

33
struct MyStruct {
44
init(x: Int) {}

test/IDE/complete_annotation_concurrency.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-ide-test -batch-code-completion -code-completion-annotate-results -code-completion-sourcetext -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion -code-completion-annotate-results -code-completion-sourcetext
32

43
// REQUIRES: concurrency
54

test/IDE/complete_call_pattern.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -disable-objc-attr-requires-foundation-module
1+
// RUN: %batch-code-completion -disable-objc-attr-requires-foundation-module
32

43
struct FooStruct {
54
init() {}

test/IDE/complete_concurrency_keyword.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -enable-experimental-concurrency
1+
// RUN: %batch-code-completion -enable-experimental-concurrency
22

33
// REQUIRES: concurrency
44

test/IDE/complete_diagnostics_concurrency.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// REQUIRES: concurrency
22

3-
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t/output -warn-concurrency
3+
// RUN: %batch-code-completion -warn-concurrency
54

65
func asyncFunc() async {}
76
func syncFunc() {}

test/IDE/complete_globalactorunsafe_strict.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -warn-concurrency
1+
// RUN: %batch-code-completion -warn-concurrency
22
// REQUIRES: concurrency
33

44
// SAFE_NOTREC: Begin completions, 2 items

test/IDE/complete_if_switch_expr.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -debug-forbid-typecheck-prefix FORBIDDEN -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion -debug-forbid-typecheck-prefix FORBIDDEN
32

43
enum E {
54
case e

0 commit comments

Comments
 (0)