Skip to content

Commit b4e80cf

Browse files
committed
[Constraint graph] Enable one-way constraints in function builders.
Enable one-way constraints by default for function builders, finishing rdar://problem/50150793.
1 parent e77b040 commit b4e80cf

File tree

9 files changed

+43
-20
lines changed

9 files changed

+43
-20
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace swift {
213213
unsigned SolverShrinkUnsolvedThreshold = 10;
214214

215215
/// Enable one-way constraints in function builders.
216-
bool FunctionBuilderOneWayConstraints = false;
216+
bool FunctionBuilderOneWayConstraints = true;
217217

218218
/// Disable the shrink phase of the expression type checker.
219219
bool SolverDisableShrink = false;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ def enable_function_builder_one_way_constraints : Flag<["-"],
408408
"enable-function-builder-one-way-constraints">,
409409
HelpText<"Enable one-way constraints in the function builder transformation">;
410410

411+
def disable_function_builder_one_way_constraints : Flag<["-"],
412+
"disable-function-builder-one-way-constraints">,
413+
HelpText<"Disable one-way constraints in the function builder transformation">;
414+
411415
def solver_disable_shrink :
412416
Flag<["-"], "solver-disable-shrink">,
413417
HelpText<"Disable the shrink phase of expression type checking">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
441441

442442
if (Args.getLastArg(OPT_solver_disable_shrink))
443443
Opts.SolverDisableShrink = true;
444-
if (Args.getLastArg(OPT_enable_function_builder_one_way_constraints))
445-
Opts.FunctionBuilderOneWayConstraints = true;
444+
Opts.FunctionBuilderOneWayConstraints =
445+
Args.hasFlag(OPT_enable_function_builder_one_way_constraints,
446+
OPT_disable_function_builder_one_way_constraints,
447+
/*Default=*/true);
446448

447449
if (const Arg *A = Args.getLastArg(OPT_value_recursion_threshold)) {
448450
unsigned threshold;

test/Constraints/function_builder.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,20 @@ struct TagAccepter<Tag> {
276276
}
277277

278278
func testAcceptColorTagged(b: Bool, i: Int, s: String, d: Double) {
279+
// FIXME: When we support buildExpression, drop the "Color" prefix
279280
// CHECK: Tagged<
280281
acceptColorTagged {
281-
i.tag(.red)
282-
s.tag(.green)
283-
d.tag(.blue)
282+
i.tag(Color.red)
283+
s.tag(Color.green)
284+
d.tag(Color.blue)
284285
}
285286

287+
// FIXME: When we support buildExpression, drop the "Color" prefix
286288
// CHECK: Tagged<
287289
TagAccepter<Color>.acceptTagged {
288-
i.tag(.red)
289-
s.tag(.green)
290-
d.tag(.blue)
290+
i.tag(Color.red)
291+
s.tag(Color.green)
292+
d.tag(Color.blue)
291293
}
292294

293295
// CHECK: Tagged<

test/IDE/complete_function_builder.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_TOP | %FileCheck %s -check-prefix=IN_CLOSURE_TOP
22
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_NONTOP | %FileCheck %s -check-prefix=IN_CLOSURE_TOP
3-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_COLOR_CONTEXT | %FileCheck %s -check-prefix=IN_CLOSURE_COLOR_CONTEXT
4-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_COLOR_CONTEXT_DOT | %FileCheck %s -check-prefix=IN_CLOSURE_COLOR_CONTEXT_DOT
5-
6-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXTUAL_TYPE_1 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
7-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXTUAL_TYPE_2 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
8-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXTUAL_TYPE_3 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
9-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXTUAL_TYPE_4 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
10-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXTUAL_TYPE_5 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_INVALID
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=IN_CLOSURE_COLOR_CONTEXT | %FileCheck %s -check-prefix=IN_CLOSURE_COLOR_CONTEXT
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=IN_CLOSURE_COLOR_CONTEXT_DOT | %FileCheck %s -check-prefix=IN_CLOSURE_COLOR_CONTEXT_DOT
5+
6+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=CONTEXTUAL_TYPE_1 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=CONTEXTUAL_TYPE_2 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
8+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=CONTEXTUAL_TYPE_3 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
9+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=CONTEXTUAL_TYPE_4 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_VALID
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-function-builder-one-way-constraints -code-completion-token=CONTEXTUAL_TYPE_5 | %FileCheck %s -check-prefix=CONTEXTUAL_TYPE_INVALID
1111

1212
struct Tagged<Tag, Entity> {
1313
let tag: Tag

test/SourceKit/CursorInfo/function_builder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func acceptColorTagged<Result>(@TaggedBuilder<Color> body: (Color) -> Result) {
3939
func testAcceptColorTagged(i: Int, s: String) {
4040
acceptColorTagged { color in
4141
i.tag(color)
42-
s.tag(.green)
42+
s.tag(Color.green)
4343
}
4444
}
4545

test/decl/var/function_builders.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@ var globalWithEmptyImplicitGetter: Int {}
2424
// expected-error@-1 {{computed property must have accessors specified}}
2525
// expected-error@-3 {{function builder attribute 'Maker' can only be applied to a variable if it defines a getter}}
2626

27+
// FIXME: extra diagnostics
2728
@Maker
28-
var globalWithEmptyExplicitGetter: Int { get {} } // expected-error {{ype 'Maker' has no member 'buildBlock'}}
29+
var globalWithEmptyExplicitGetter: Int { get {} } // expected-error{{type 'Maker' has no member 'buildBlock'}}
30+
// expected-error@-1 {{cannot convert return expression of type 'Any' to return type 'Int'}}
2931

3032
@Maker
3133
var globalWithSingleGetter: Int { 0 } // expected-error {{ype 'Maker' has no member 'buildBlock'}}
34+
// expected-error@-1 {{cannot convert return expression of type 'Any' to return type 'Int'}}
3235

3336
@Maker
3437
var globalWithMultiGetter: Int { 0; 0 } // expected-error {{ype 'Maker' has no member 'buildBlock'}}
38+
// expected-error@-1 {{cannot convert return expression of type 'Any' to return type 'Int'}}
3539

3640
@Maker
3741
func globalFunction() {} // expected-error {{ype 'Maker' has no member 'buildBlock'}}
42+
// expected-error@-1 {{unexpected non-void return value in void function}}
3843

3944
@Maker
4045
func globalFunctionWithFunctionParam(fn: () -> ()) {} // expected-error {{ype 'Maker' has no member 'buildBlock'}}
46+
// expected-error@-1 {{unexpected non-void return value in void function}}
4147

4248
func makerParam(@Maker
4349
fn: () -> ()) {}

test/multifile/function_builder_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -typecheck %S/Inputs/function_builder_definition.swift -primary-file %s
22

3-
func test0() -> (Int, Float, String) {
3+
func test0() -> (Int, Double, String) {
44
return tuplify {
55
17
66
3.14159

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ static llvm::cl::opt<bool>
309309
EnableSourceImport("enable-source-import", llvm::cl::Hidden,
310310
llvm::cl::cat(Category), llvm::cl::init(false));
311311

312+
static llvm::cl::opt<bool>
313+
DisableFunctionBuilderOneWayConstraints(
314+
"disable-function-builder-one-way-constraints",
315+
llvm::cl::desc("Disable one-way constraints in function builders"),
316+
llvm::cl::cat(Category),
317+
llvm::cl::init(false));
318+
312319
static llvm::cl::opt<bool>
313320
SkipDeinit("skip-deinit",
314321
llvm::cl::desc("Whether to skip printing destructors"),
@@ -3319,6 +3326,8 @@ int main(int argc, char *argv[]) {
33193326
options::ImportObjCHeader;
33203327
InitInvok.getLangOptions().EnableAccessControl =
33213328
!options::DisableAccessControl;
3329+
InitInvok.getLangOptions().FunctionBuilderOneWayConstraints =
3330+
!options::DisableFunctionBuilderOneWayConstraints;
33223331
InitInvok.getLangOptions().CodeCompleteInitsInPostfixExpr |=
33233332
options::CodeCompleteInitsInPostfixExpr;
33243333
InitInvok.getLangOptions().CodeCompleteCallPatternHeuristics |=

0 commit comments

Comments
 (0)