Skip to content

Commit ffcafd7

Browse files
committed
fix the AST printer to stop omitting parens around "simple enough" parameter
lists.
1 parent 87db7b4 commit ffcafd7

37 files changed

+108
-97
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,8 +3734,19 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
37343734
};
37353735

37363736
printFunctionExtInfo(T->getExtInfo());
3737-
printWithParensIfNotSimple(T->getInput());
3738-
3737+
3738+
bool needsParens =
3739+
!isa<ParenType>(T->getInput().getPointer()) &&
3740+
!T->getInput()->is<TupleType>();
3741+
3742+
if (needsParens)
3743+
Printer << "(";
3744+
3745+
visit(T->getInput());
3746+
3747+
if (needsParens)
3748+
Printer << ")";
3749+
37393750
if (T->throws())
37403751
Printer << " " << tok::kw_throws;
37413752

test/Constraints/dictionary_literal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var b3 = [1 : 2.5]
4343
// <rdar://problem/22584076> QoI: Using array literal init with dictionary produces bogus error
4444

4545
// expected-note @+1 {{did you mean to use a dictionary literal instead?}}
46-
var _: Dictionary<String, (Int) -> Int>? = [ // expected-error {{contextual type 'Dictionary<String, (Int) -> Int>' (aka 'Dictionary<String, Int -> Int>') cannot be used with array literal}}
46+
var _: Dictionary<String, (Int) -> Int>? = [ // expected-error {{contextual type 'Dictionary<String, (Int) -> Int>' cannot be used with array literal}}
4747
"closure_1" as String, {(Int) -> Int in 0},
4848
"closure_2", {(Int) -> Int in 0}]
4949

test/IDE/complete_crashes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func flip<A, B, C>(_ f: A -> B -> C) -> B -> A -> C { }
132132
func rdar22688199() {
133133
let f = flip(curried)(#^RDAR_22688199^#
134134
}
135-
// FLIP_CURRIED: Pattern/ExprSpecific: ['(']{#b1: Int#}, {#b2: Int#})[#Int -> ()#]
135+
// FLIP_CURRIED: Pattern/ExprSpecific: ['(']{#b1: Int#}, {#b2: Int#})[#(Int) -> ()#]
136136

137137
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RDAR_22836263
138138
func rdar22836263() {

test/IDE/reconstruct_type_from_mangled_name.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func f1() {
4545

4646
s1ins.s1f1()
4747
// CHECK: type: Mystruct1
48-
// CHECK: type: Mystruct1 -> () -> Int
48+
// CHECK: type: (Mystruct1) -> () -> Int
4949

5050
if let ifletf1 = Int?(1) {
5151
// FIXME: lookup incorrect for if let binding.
@@ -65,21 +65,21 @@ class Myclass2 {
6565
arr1.append(1)
6666
// FIXME: missing append()
6767
// CHECK: dref: FAILURE for 'append' usr=s:FSa6appendFxT_
68-
// CHECK: type: @lvalue Array<Int> -> Int -> ()
68+
// CHECK: type: (@lvalue Array<Int>) -> (Int) -> ()
6969

7070
var arr2 : [Mystruct1]
7171
// CHECK: decl: var arr2: [Mystruct1]
7272
// CHECK: type: Array<Mystruct1>
7373

7474
arr2.append(Mystruct1())
75-
// CHECK: type: @lvalue Array<Mystruct1> -> Mystruct1 -> ()
75+
// CHECK: type: (@lvalue Array<Mystruct1>) -> (Mystruct1) -> ()
7676

7777
var arr3 : [Myclass1]
7878
// CHECK: decl: var arr3: [Myclass1]
7979
// CHECK: type: Array<Myclass1>
8080

8181
arr3.append(Myclass1())
82-
// CHECK: type: @lvalue Array<Myclass1> -> Myclass1 -> ()
82+
// CHECK: type: (@lvalue Array<Myclass1>) -> (Myclass1) -> ()
8383

8484
_ = Myclass2.init()
8585
// CHECK: dref: init()

test/NameBinding/name_lookup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ class ThisDerived1 : ThisBase1 {
223223
self.baseInstanceVar = 42 // expected-error {{member 'baseInstanceVar' cannot be used on type 'ThisDerived1'}}
224224
self.baseProp = 42 // expected-error {{member 'baseProp' cannot be used on type 'ThisDerived1'}}
225225
self.baseFunc0() // expected-error {{missing argument}}
226-
self.baseFunc0(ThisBase1())() // expected-error {{'(ThisBase1) -> () -> ()' is not convertible to 'ThisDerived1 -> () -> ()'}}
226+
self.baseFunc0(ThisBase1())() // expected-error {{'(ThisBase1) -> () -> ()' is not convertible to '(ThisDerived1) -> () -> ()'}}
227227

228228
self.baseFunc0(ThisDerived1())()
229229
self.baseFunc1(42) // expected-error {{cannot convert value of type 'Int' to expected argument type 'ThisBase1'}}
230-
self.baseFunc1(ThisBase1())(42) // expected-error {{'(ThisBase1) -> (Int) -> ()' is not convertible to 'ThisDerived1 -> (Int) -> ()'}}
230+
self.baseFunc1(ThisBase1())(42) // expected-error {{'(ThisBase1) -> (Int) -> ()' is not convertible to '(ThisDerived1) -> (Int) -> ()'}}
231231
self.baseFunc1(ThisDerived1())(42)
232232
self[0] = 42.0 // expected-error {{instance member 'subscript' cannot be used on type 'ThisDerived1'}}
233233
self.baseStaticVar = 42

test/SIL/Parser/overloaded_member.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bb0(%0 : $A, %1 : $X):
2727
store %5 to %2a : $*X
2828
%7 = load %2a : $*X
2929
strong_retain %7 : $X
30-
// CHECK: class_method [volatile] %{{[0-9]+}} : $X, #X.init!initializer.1.foreign : X.Type -> (a1: A, a2: A) -> X , $@convention(objc_method) (A, A, @owned X) -> @owned X
30+
// CHECK: class_method [volatile] %{{[0-9]+}} : $X, #X.init!initializer.1.foreign : (X.Type) -> (a1: A, a2: A) -> X , $@convention(objc_method) (A, A, @owned X) -> @owned X
3131
%9 = class_method [volatile] %7 : $X, #X.init!initializer.1.foreign : (X.Type) -> (a1: A, a2: A) -> X , $@convention(objc_method) (A, A, @owned X) -> @owned X
3232
%10 = load %3a : $*A
3333
%11 = load %3a : $*A

test/SILGen/addressors.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,20 @@ struct CArray<T> {
145145

146146
func id_int(_ i: Int32) -> Int32 { return i }
147147

148-
// CHECK-LABEL: sil hidden @_TF10addressors11test_carrayFRGVS_6CArrayFVs5Int32S1__S1_ : $@convention(thin) (@inout CArray<Int32 -> Int32>) -> Int32 {
149-
// CHECK: bb0([[ARRAY:%.*]] : $*CArray<Int32 -> Int32>):
148+
// CHECK-LABEL: sil hidden @_TF10addressors11test_carrayFRGVS_6CArrayFVs5Int32S1__S1_ : $@convention(thin) (@inout CArray<(Int32) -> Int32>) -> Int32 {
149+
// CHECK: bb0([[ARRAY:%.*]] : $*CArray<(Int32) -> Int32>):
150150
func test_carray(_ array: inout CArray<(Int32) -> Int32>) -> Int32 {
151151
// CHECK: [[T0:%.*]] = function_ref @_TFV10addressors6CArrayau9subscriptFSix :
152152
// CHECK: [[T1:%.*]] = apply [[T0]]<(Int32) -> Int32>({{%.*}}, [[ARRAY]])
153-
// CHECK: [[T2:%.*]] = struct_extract [[T1]] : $UnsafeMutablePointer<Int32 -> Int32>, #UnsafeMutablePointer._rawValue
153+
// CHECK: [[T2:%.*]] = struct_extract [[T1]] : $UnsafeMutablePointer<(Int32) -> Int32>, #UnsafeMutablePointer._rawValue
154154
// CHECK: [[T3:%.*]] = pointer_to_address [[T2]] : $Builtin.RawPointer to $*@callee_owned (@in Int32) -> @out Int32
155155
// CHECK: store {{%.*}} to [[T3]] :
156156
array[0] = id_int
157157

158158
// CHECK: [[T0:%.*]] = load [[ARRAY]]
159159
// CHECK: [[T1:%.*]] = function_ref @_TFV10addressors6CArraylu9subscriptFSix :
160160
// CHECK: [[T2:%.*]] = apply [[T1]]<(Int32) -> Int32>({{%.*}}, [[T0]])
161-
// CHECK: [[T3:%.*]] = struct_extract [[T2]] : $UnsafePointer<Int32 -> Int32>, #UnsafePointer._rawValue
161+
// CHECK: [[T3:%.*]] = struct_extract [[T2]] : $UnsafePointer<(Int32) -> Int32>, #UnsafePointer._rawValue
162162
// CHECK: [[T4:%.*]] = pointer_to_address [[T3]] : $Builtin.RawPointer to $*@callee_owned (@in Int32) -> @out Int32
163163
// CHECK: [[T5:%.*]] = load [[T4]]
164164
return array[1](5)

test/SILGen/cf.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ func useEmAll(_ model: CCMagnetismModel) {
2727
// CHECK: function_ref @CCRefrigeratorDestroy : $@convention(c) (@owned ImplicitlyUnwrappedOptional<CCRefrigerator>) -> ()
2828
CCRefrigeratorDestroy(clone)
2929

30-
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.refrigerator!1.foreign : CCMagnetismModel -> () -> Unmanaged<CCRefrigerator>! , $@convention(objc_method) (CCMagnetismModel) -> ImplicitlyUnwrappedOptional<Unmanaged<CCRefrigerator>>
30+
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.refrigerator!1.foreign : (CCMagnetismModel) -> () -> Unmanaged<CCRefrigerator>! , $@convention(objc_method) (CCMagnetismModel) -> ImplicitlyUnwrappedOptional<Unmanaged<CCRefrigerator>>
3131
let f0 = model.refrigerator()
3232

33-
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.getRefrigerator!1.foreign : CCMagnetismModel -> () -> CCRefrigerator! , $@convention(objc_method) (CCMagnetismModel) -> @autoreleased ImplicitlyUnwrappedOptional<CCRefrigerator>
33+
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.getRefrigerator!1.foreign : (CCMagnetismModel) -> () -> CCRefrigerator! , $@convention(objc_method) (CCMagnetismModel) -> @autoreleased ImplicitlyUnwrappedOptional<CCRefrigerator>
3434
let f1 = model.getRefrigerator()
3535

36-
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.takeRefrigerator!1.foreign : CCMagnetismModel -> () -> CCRefrigerator! , $@convention(objc_method) (CCMagnetismModel) -> @owned ImplicitlyUnwrappedOptional<CCRefrigerator>
36+
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.takeRefrigerator!1.foreign : (CCMagnetismModel) -> () -> CCRefrigerator! , $@convention(objc_method) (CCMagnetismModel) -> @owned ImplicitlyUnwrappedOptional<CCRefrigerator>
3737
let f2 = model.takeRefrigerator()
3838

39-
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.borrowRefrigerator!1.foreign : CCMagnetismModel -> () -> CCRefrigerator! , $@convention(objc_method) (CCMagnetismModel) -> @autoreleased ImplicitlyUnwrappedOptional<CCRefrigerator>
39+
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.borrowRefrigerator!1.foreign : (CCMagnetismModel) -> () -> CCRefrigerator! , $@convention(objc_method) (CCMagnetismModel) -> @autoreleased ImplicitlyUnwrappedOptional<CCRefrigerator>
4040
let f3 = model.borrowRefrigerator()
4141

42-
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.setRefrigerator!1.foreign : CCMagnetismModel -> (CCRefrigerator!) -> () , $@convention(objc_method) (ImplicitlyUnwrappedOptional<CCRefrigerator>, CCMagnetismModel) -> ()
42+
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.setRefrigerator!1.foreign : (CCMagnetismModel) -> (CCRefrigerator!) -> () , $@convention(objc_method) (ImplicitlyUnwrappedOptional<CCRefrigerator>, CCMagnetismModel) -> ()
4343
model.setRefrigerator(copy)
4444

45-
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.giveRefrigerator!1.foreign : CCMagnetismModel -> (CCRefrigerator!) -> () , $@convention(objc_method) (@owned ImplicitlyUnwrappedOptional<CCRefrigerator>, CCMagnetismModel) -> ()
45+
// CHECK: class_method [volatile] %0 : $CCMagnetismModel, #CCMagnetismModel.giveRefrigerator!1.foreign : (CCMagnetismModel) -> (CCRefrigerator!) -> () , $@convention(objc_method) (@owned ImplicitlyUnwrappedOptional<CCRefrigerator>, CCMagnetismModel) -> ()
4646
model.giveRefrigerator(copy)
4747

4848
// rdar://16846555

test/SILGen/complete_object_init.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class A {
1010
// CHECK: [[SELF:%[0-9]+]] = mark_uninitialized [delegatingself] [[PB]] : $*A
1111
// CHECK: store [[SELF_PARAM]] to [[SELF]] : $*A
1212
// CHECK: [[SELFP:%[0-9]+]] = load [[SELF]] : $*A
13-
// CHECK: [[INIT:%[0-9]+]] = class_method [[SELFP]] : $A, #A.init!initializer.1 : A.Type -> (x: X) -> A , $@convention(method) (X, @owned A) -> @owned A
13+
// CHECK: [[INIT:%[0-9]+]] = class_method [[SELFP]] : $A, #A.init!initializer.1 : (A.Type) -> (x: X) -> A , $@convention(method) (X, @owned A) -> @owned A
1414
// CHECK: [[X_INIT:%[0-9]+]] = function_ref @_TFV20complete_object_init1XC{{.*}} : $@convention(method) (@thin X.Type) -> X
1515
// CHECK: [[X_META:%[0-9]+]] = metatype $@thin X.Type
1616
// CHECK: [[X:%[0-9]+]] = apply [[X_INIT]]([[X_META]]) : $@convention(method) (@thin X.Type) -> X

test/SILGen/dynamic_init.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class C {
77
// CHECK-LABEL: sil hidden @_TF12dynamic_init15testDynamicInit
88
func testDynamicInit(cm: C.Type) {
99
// CHECK: bb0([[CM:%[0-9]+]] : $@thick C.Type):
10-
// CHECK: [[METHOD:%[0-9]+]] = class_method [[CM]] : $@thick C.Type, #C.init!allocator.1 : C.Type -> () -> C , $@convention(method) (@thick C.Type) -> @owned C
10+
// CHECK: [[METHOD:%[0-9]+]] = class_method [[CM]] : $@thick C.Type, #C.init!allocator.1 : (C.Type) -> () -> C , $@convention(method) (@thick C.Type) -> @owned C
1111
// CHECK: [[C_OBJ:%[0-9]+]] = apply [[METHOD]]([[CM]]) : $@convention(method) (@thick C.Type) -> @owned C
1212
// CHECK: strong_release [[C_OBJ]] : $C
1313
// CHECK: [[RESULT:%[0-9]+]] = tuple ()

0 commit comments

Comments
 (0)