Skip to content

[6.0] [Completion] Only skip result builder expressions in the same builder #74249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class ResultBuilderTransform
DeclContext *dc;
ResultBuilder builder;

/// The source range of the body.
SourceRange bodyRange;

/// The result type of this result builder body.
Type ResultType;

Expand All @@ -80,9 +83,9 @@ class ResultBuilderTransform

public:
ResultBuilderTransform(ConstraintSystem &cs, DeclContext *dc,
Type builderType, Type resultTy)
SourceRange bodyRange, Type builderType, Type resultTy)
: ctx(cs.getASTContext()), dc(dc), builder(cs, dc, builderType),
ResultType(resultTy) {}
bodyRange(bodyRange), ResultType(resultTy) {}

UnsupportedElt getUnsupportedElement() const { return FirstUnsupported; }

Expand Down Expand Up @@ -238,12 +241,14 @@ class ResultBuilderTransform
// buildBlock higher.
buildBlockArguments.push_back(expr);
} else if (ctx.CompletionCallback && expr->getSourceRange().isValid() &&
containsIDEInspectionTarget(bodyRange, ctx.SourceMgr) &&
!containsIDEInspectionTarget(expr->getSourceRange(),
ctx.SourceMgr)) {
// A statement that doesn't contain the code completion expression can't
// influence the type of the code completion expression. Add a variable
// for it that we can put into the buildBlock call but don't add the
// expression itself into the transformed body to improve performance.
// A top-level expression that doesn't contain the code completion
// expression can't influence the type of the code completion expression
// if they're in the same result builder. Add a variable for it that we
// can put into the buildBlock call but don't add the expression itself
// into the transformed body to improve performance.
auto *resultVar = buildPlaceholderVar(expr->getStartLoc(), newBody);
buildBlockArguments.push_back(
builder.buildVarRef(resultVar, expr->getStartLoc()));
Expand Down Expand Up @@ -1176,6 +1181,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
// let's do it and cache the result.
if (!transformedBody) {
ResultBuilderTransform transform(*this, fn.getAsDeclContext(),
fn.getBody()->getSourceRange(),
builderType, bodyResultType);
auto *body = transform.apply(fn.getBody());

Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_actorisolation.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: concurrency
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -warn-concurrency
// RUN: %batch-code-completion -warn-concurrency

class MyNonSendable {}
struct MySendable {}
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_after_pattern_in_closure.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -enable-experimental-concurrency
// RUN: %batch-code-completion -enable-experimental-concurrency

func makeURL(withExtension ext: Int?) -> Int? {
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_annotation.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// RUN: %batch-code-completion -code-completion-annotate-results -code-completion-sourcetext

struct MyStruct {
init(x: Int) {}
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_annotation_concurrency.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %batch-code-completion -code-completion-annotate-results -code-completion-sourcetext

// REQUIRES: concurrency

Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_call_pattern.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -disable-objc-attr-requires-foundation-module
// RUN: %batch-code-completion -disable-objc-attr-requires-foundation-module

struct FooStruct {
init() {}
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_concurrency_keyword.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -enable-experimental-concurrency
// RUN: %batch-code-completion -enable-experimental-concurrency

// REQUIRES: concurrency

Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_diagnostics_concurrency.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: concurrency

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

func asyncFunc() async {}
func syncFunc() {}
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_globalactorunsafe_strict.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -warn-concurrency
// RUN: %batch-code-completion -warn-concurrency
// REQUIRES: concurrency

// SAFE_NOTREC: Begin completions, 2 items
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_if_switch_expr.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -debug-forbid-typecheck-prefix FORBIDDEN -filecheck %raw-FileCheck -completion-output-dir %t
// RUN: %batch-code-completion -debug-forbid-typecheck-prefix FORBIDDEN

enum E {
case e
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_implicit_last_expr.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %batch-code-completion -enable-experimental-feature ImplicitLastExprResults -debug-forbid-typecheck-prefix FORBIDDEN

// Experimental feature requires asserts
// REQUIRES: asserts
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_member_basetypes.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -module-name "Mod"
// RUN: %batch-code-completion -module-name "Mod"

protocol BaseP1 {}
protocol BaseP2 {}
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_optionset.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -plugin-path %swift-plugin-dir
// RUN: %batch-code-completion -plugin-path %swift-plugin-dir

// REQUIRES: swift_swift_parser

Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_rdar126168123.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
// RUN: %batch-code-completion

// rdar://126168123

Expand Down
35 changes: 35 additions & 0 deletions test/IDE/complete_rdar127154780.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %batch-code-completion

// rdar://127154780 - Make sure we provide completions on variables that rely
// on result builders being solved.

@resultBuilder
enum Builder {
static func buildBlock<T>(_ x: T) -> T { x }
}

struct S {}

struct R<T> {
init(@Builder _: () -> T) {}
}

extension R where T == S {
func bar() {}
}

func foo() {
let r = R() {
S()
}
r.#^COMPLETE1?check=COMPLETE^#

let fn = {
let r = R() {
S()
}
r.#^COMPLETE2?check=COMPLETE^#
}
}
// COMPLETE-DAG: Keyword[self]/CurrNominal: self[#R<S>#]; name=self
// COMPLETE-DAG: Decl[InstanceMethod]/CurrNominal: bar()[#Void#]; name=bar()
3 changes: 1 addition & 2 deletions test/IDE/complete_rdar63965160.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
// RUN: %batch-code-completion

protocol View {}

Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_rdar94369218.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -code-complete-inits-in-postfix-expr -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
// RUN: %batch-code-completion -code-complete-inits-in-postfix-expr

protocol MyProto {
init(value: String)
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_subtype_overload.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
// RUN: %batch-code-completion

class C {
static func cMethod() -> C {}
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_then_stmt.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %batch-code-completion -enable-experimental-feature ThenStatements -debug-forbid-typecheck-prefix FORBIDDEN

// Experimental feature requires asserts
// REQUIRES: asserts
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_type_relation_any_some.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck --completion-output-dir %t
// RUN: %batch-code-completion

protocol Shape {}

Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_typerelation.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -disable-objc-attr-requires-foundation-module
// RUN: %batch-code-completion -disable-objc-attr-requires-foundation-module

// SE-0353
struct ConstraintedExistentialTest {
Expand Down
3 changes: 1 addition & 2 deletions test/IDE/complete_unresolved_members.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s %S/Inputs/EnumFromOtherFile.swift -filecheck %raw-FileCheck -completion-output-dir %t
// RUN: %batch-code-completion %S/Inputs/EnumFromOtherFile.swift

// NOCRASH: Token

Expand Down