Skip to content

Commit ccd1106

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. (cherry picked from commit b4e80cf)
1 parent efe8863 commit ccd1106

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
@@ -208,7 +208,7 @@ namespace swift {
208208
unsigned SolverShrinkUnsolvedThreshold = 10;
209209

210210
/// Enable one-way constraints in function builders.
211-
bool FunctionBuilderOneWayConstraints = false;
211+
bool FunctionBuilderOneWayConstraints = true;
212212

213213
/// Disable the shrink phase of the expression type checker.
214214
bool SolverDisableShrink = false;

include/swift/Option/FrontendOptions.td

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

401+
def disable_function_builder_one_way_constraints : Flag<["-"],
402+
"disable-function-builder-one-way-constraints">,
403+
HelpText<"Disable one-way constraints in the function builder transformation">;
404+
401405
def solver_disable_shrink :
402406
Flag<["-"], "solver-disable-shrink">,
403407
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
@@ -419,8 +419,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
419419

420420
if (Args.getLastArg(OPT_solver_disable_shrink))
421421
Opts.SolverDisableShrink = true;
422-
if (Args.getLastArg(OPT_enable_function_builder_one_way_constraints))
423-
Opts.FunctionBuilderOneWayConstraints = true;
422+
Opts.FunctionBuilderOneWayConstraints =
423+
Args.hasFlag(OPT_enable_function_builder_one_way_constraints,
424+
OPT_disable_function_builder_one_way_constraints,
425+
/*Default=*/true);
424426

425427
if (const Arg *A = Args.getLastArg(OPT_value_recursion_threshold)) {
426428
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
@@ -308,6 +308,13 @@ static llvm::cl::opt<bool>
308308
EnableSourceImport("enable-source-import", llvm::cl::Hidden,
309309
llvm::cl::cat(Category), llvm::cl::init(false));
310310

311+
static llvm::cl::opt<bool>
312+
DisableFunctionBuilderOneWayConstraints(
313+
"disable-function-builder-one-way-constraints",
314+
llvm::cl::desc("Disable one-way constraints in function builders"),
315+
llvm::cl::cat(Category),
316+
llvm::cl::init(false));
317+
311318
static llvm::cl::opt<bool>
312319
SkipDeinit("skip-deinit",
313320
llvm::cl::desc("Whether to skip printing destructors"),
@@ -3295,6 +3302,8 @@ int main(int argc, char *argv[]) {
32953302
options::ImportObjCHeader;
32963303
InitInvok.getLangOptions().EnableAccessControl =
32973304
!options::DisableAccessControl;
3305+
InitInvok.getLangOptions().FunctionBuilderOneWayConstraints =
3306+
!options::DisableFunctionBuilderOneWayConstraints;
32983307
InitInvok.getLangOptions().CodeCompleteInitsInPostfixExpr |=
32993308
options::CodeCompleteInitsInPostfixExpr;
33003309
InitInvok.getLangOptions().CodeCompleteCallPatternHeuristics |=

0 commit comments

Comments
 (0)