Skip to content

Commit 1d9981e

Browse files
authored
Merge pull request #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

test/IDE/complete_implicit_last_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 -enable-experimental-feature ImplicitLastExprResults -debug-forbid-typecheck-prefix FORBIDDEN -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion -enable-experimental-feature ImplicitLastExprResults -debug-forbid-typecheck-prefix FORBIDDEN
32

43
// Experimental feature requires asserts
54
// REQUIRES: asserts

test/IDE/complete_member_basetypes.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 -module-name "Mod"
1+
// RUN: %batch-code-completion -module-name "Mod"
32

43
protocol BaseP1 {}
54
protocol BaseP2 {}

test/IDE/complete_optionset.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 -plugin-path %swift-plugin-dir
1+
// RUN: %batch-code-completion -plugin-path %swift-plugin-dir
32

43
// REQUIRES: swift_swift_parser
54

test/IDE/complete_rdar126168123.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: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion
32

43
// rdar://126168123
54

test/IDE/complete_rdar127154780.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %batch-code-completion
2+
3+
// rdar://127154780 - Make sure we provide completions on variables that rely
4+
// on result builders being solved.
5+
6+
@resultBuilder
7+
enum Builder {
8+
static func buildBlock<T>(_ x: T) -> T { x }
9+
}
10+
11+
struct S {}
12+
13+
struct R<T> {
14+
init(@Builder _: () -> T) {}
15+
}
16+
17+
extension R where T == S {
18+
func bar() {}
19+
}
20+
21+
func foo() {
22+
let r = R() {
23+
S()
24+
}
25+
r.#^COMPLETE1?check=COMPLETE^#
26+
27+
let fn = {
28+
let r = R() {
29+
S()
30+
}
31+
r.#^COMPLETE2?check=COMPLETE^#
32+
}
33+
}
34+
// COMPLETE-DAG: Keyword[self]/CurrNominal: self[#R<S>#]; name=self
35+
// COMPLETE-DAG: Decl[InstanceMethod]/CurrNominal: bar()[#Void#]; name=bar()

test/IDE/complete_rdar63965160.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: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion
32

43
protocol View {}
54

test/IDE/complete_rdar94369218.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-complete-inits-in-postfix-expr -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion -code-complete-inits-in-postfix-expr
32

43
protocol MyProto {
54
init(value: String)

test/IDE/complete_subtype_overload.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: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion
32

43
class C {
54
static func cMethod() -> C {}

test/IDE/complete_then_stmt.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 -enable-experimental-feature ThenStatements -debug-forbid-typecheck-prefix FORBIDDEN -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion -enable-experimental-feature ThenStatements -debug-forbid-typecheck-prefix FORBIDDEN
32

43
// Experimental feature requires asserts
54
// REQUIRES: asserts

test/IDE/complete_type_relation_any_some.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: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck --completion-output-dir %t
1+
// RUN: %batch-code-completion
32

43
protocol Shape {}
54

test/IDE/complete_typerelation.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
// SE-0353
54
struct ConstraintedExistentialTest {

test/IDE/complete_unresolved_members.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 %S/Inputs/EnumFromOtherFile.swift -filecheck %raw-FileCheck -completion-output-dir %t
1+
// RUN: %batch-code-completion %S/Inputs/EnumFromOtherFile.swift
32

43
// NOCRASH: Token
54

0 commit comments

Comments
 (0)