Skip to content

Commit a1df238

Browse files
committed
Associate @autoclosure only with parameter types
Mangled implicit closures shouldn't have `@autoclosure` flag associated with them, because their type is just a regular function type.
1 parent 6b62ac8 commit a1df238

File tree

10 files changed

+27
-22
lines changed

10 files changed

+27
-22
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class ASTMangler : public Mangler {
229229
void appendAnyGenericType(const GenericTypeDecl *decl);
230230

231231
void appendFunction(AnyFunctionType *fn, bool isFunctionMangling = false);
232-
void appendFunctionType(AnyFunctionType *fn);
232+
void appendFunctionType(AnyFunctionType *fn, bool isAutoClosure = false);
233233

234234
void appendFunctionSignature(AnyFunctionType *fn);
235235

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ void ASTMangler::appendFunction(AnyFunctionType *fn, bool isFunctionMangling) {
16931693
}
16941694
}
16951695

1696-
void ASTMangler::appendFunctionType(AnyFunctionType *fn) {
1696+
void ASTMangler::appendFunctionType(AnyFunctionType *fn, bool isAutoClosure) {
16971697
assert((DWARFMangling || fn->isCanonical()) &&
16981698
"expecting canonical types when not mangling for the debugger");
16991699

@@ -1715,7 +1715,7 @@ void ASTMangler::appendFunctionType(AnyFunctionType *fn) {
17151715
case AnyFunctionType::Representation::Thin:
17161716
return appendOperator("Xf");
17171717
case AnyFunctionType::Representation::Swift:
1718-
if (fn->isAutoClosure()) {
1718+
if (isAutoClosure) {
17191719
if (fn->isNoEscape())
17201720
return appendOperator("XK");
17211721
else
@@ -1799,7 +1799,12 @@ void ASTMangler::appendTypeList(Type listTy) {
17991799

18001800
void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
18011801
ParameterTypeFlags flags) {
1802-
appendType(elementType);
1802+
if (flags.isAutoClosure())
1803+
appendFunctionType(elementType->castTo<FunctionType>(),
1804+
/*isAutoClosure*/ true);
1805+
else
1806+
appendType(elementType);
1807+
18031808
switch (flags.getValueOwnership()) {
18041809
case ValueOwnership::Default:
18051810
/* nothing */

test/DebugInfo/autoclosure.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func &&&&&(lhs: Bool, rhs: @autoclosure () -> Bool) -> Bool {
2121
func call_me(_ input: Int64) -> Void {
2222
// rdar://problem/14627460
2323
// An autoclosure should have a line number in the debug info and a scope line of 0.
24-
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "$s11autoclosure7call_meyys5Int64VFSbyXKfu_",{{.*}} isLocal: true, isDefinition: true
24+
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "$s11autoclosure7call_meyys5Int64VFSbyXEfu_",{{.*}} isLocal: true, isDefinition: true
2525
// But not in the line table.
2626
// CHECK-DAG: ![[DBG]] = !DILocation(line: [[@LINE+1]],
2727
if input != 0 &&&&& ( get_truth (input * 2 + 1) > 0 ) {

test/Profiler/coverage_closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func foo() {
1616
// CHECK-LABEL: sil_coverage_map {{.*}}// f1 #1 ((Swift.Int32, Swift.Int32) -> Swift.Bool) -> Swift.Bool in coverage_closures.foo()
1717
// CHECK-NEXT: [[@LINE+1]]:55 -> {{.*}}:4 : 0
1818
func f1(_ closure : (Int32, Int32) -> Bool) -> Bool {
19-
// CHECK-LABEL: sil_coverage_map {{.*}}// implicit closure #1 : @autoclosure () throws -> Swift.Bool in f1
19+
// CHECK-LABEL: sil_coverage_map {{.*}}// implicit closure #1 () throws -> Swift.Bool in f1
2020
// CHECK-NEXT: [[@LINE+1]]:29 -> [[@LINE+1]]:42 : 0
2121
return closure(0, 1) && closure(1, 0)
2222
}
@@ -29,7 +29,7 @@ func foo() {
2929

3030
// CHECK-LABEL: sil_coverage_map {{.*}}// closure #3 (Swift.Int32, Swift.Int32) -> Swift.Bool in coverage_closures.foo()
3131
// CHECK-NEXT: [[@LINE+3]]:6 -> [[@LINE+3]]:48 : 0
32-
// CHECK-LABEL: sil_coverage_map {{.*}}// implicit closure #1 : @autoclosure () throws -> {{.*}} in coverage_closures.foo
32+
// CHECK-LABEL: sil_coverage_map {{.*}}// implicit closure #1 () throws -> {{.*}} in coverage_closures.foo
3333
// CHECK-NEXT: [[@LINE+1]]:36 -> [[@LINE+1]]:46 : 0
3434
f1 { left, right in left == 0 || right == 1 }
3535
}

test/Profiler/instrprof_operators.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func operators(a : Bool, b : Bool) {
2121
}
2222

2323
// CHECK: implicit closure
24-
// CHECK: %[[NAME:.*]] = string_literal utf8 "{{.*}}:$s19instrprof_operators0B01a1bySb_SbtFSbyKXKfu_"
24+
// CHECK: %[[NAME:.*]] = string_literal utf8 "{{.*}}:$s19instrprof_operators0B01a1bySb_SbtFSbyKXEfu_"
2525
// CHECK: %[[HASH:.*]] = integer_literal $Builtin.Int64,
2626
// CHECK: %[[NCOUNTS:.*]] = integer_literal $Builtin.Int32, 1
2727
// CHECK: %[[INDEX:.*]] = integer_literal $Builtin.Int32, 0
2828
// CHECK: builtin "int_instrprof_increment"(%[[NAME]] : {{.*}}, %[[HASH]] : {{.*}}, %[[NCOUNTS]] : {{.*}}, %[[INDEX]] : {{.*}})
2929
// CHECK-NOT: builtin "int_instrprof_increment"
3030

3131
// CHECK: implicit closure
32-
// CHECK: %[[NAME:.*]] = string_literal utf8 "{{.*}}:$s19instrprof_operators0B01a1bySb_SbtFSbyKXKfu0_"
32+
// CHECK: %[[NAME:.*]] = string_literal utf8 "{{.*}}:$s19instrprof_operators0B01a1bySb_SbtFSbyKXEfu0_"
3333
// CHECK: %[[HASH:.*]] = integer_literal $Builtin.Int64,
3434
// CHECK: %[[NCOUNTS:.*]] = integer_literal $Builtin.Int32, 1
3535
// CHECK: %[[INDEX:.*]] = integer_literal $Builtin.Int32, 0

test/SILGen/auto_closures.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Base {
3939
public class Sub : Base {
4040
// CHECK-LABEL: sil hidden @$s13auto_closures3SubC1xAA4BoolVvg : $@convention(method) (@guaranteed Sub) -> Bool {
4141
// CHECK: bb0([[SELF:%.*]] : @guaranteed $Sub):
42-
// CHECK: [[AUTOCLOSURE_FUNC:%.*]] = function_ref @$s13auto_closures3SubC1xAA4BoolVvgAFyXKfu_ : $@convention(thin) (@guaranteed Sub) -> Bool
42+
// CHECK: [[AUTOCLOSURE_FUNC:%.*]] = function_ref @$s13auto_closures3SubC1xAA4BoolVvgAFyXEfu_ : $@convention(thin) (@guaranteed Sub) -> Bool
4343
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
4444
// CHECK: [[AUTOCLOSURE:%.*]] = partial_apply [callee_guaranteed] [[AUTOCLOSURE_FUNC]]([[SELF_COPY]])
4545
// CHECK: [[CVT:%.*]] = convert_escape_to_noescape [not_guaranteed] [[AUTOCLOSURE]]
@@ -48,7 +48,7 @@ public class Sub : Base {
4848
// CHECK: return [[RET]] : $Bool
4949
// CHECK: }
5050

51-
// CHECK-LABEL: sil private [transparent] @$s13auto_closures3SubC1xAA4BoolVvgAFyXKfu_ : $@convention(thin) (@guaranteed Sub) -> Bool {
51+
// CHECK-LABEL: sil private [transparent] @$s13auto_closures3SubC1xAA4BoolVvgAFyXEfu_ : $@convention(thin) (@guaranteed Sub) -> Bool {
5252
// CHECK: [[SUPER:%[0-9]+]] = function_ref @$s13auto_closures4BaseC1xAA4BoolVvg : $@convention(method) (@guaranteed Base) -> Bool
5353
// CHECK: [[RET:%.*]] = apply [[SUPER]]({{%.*}})
5454
// CHECK: return [[RET]]
@@ -57,9 +57,9 @@ public class Sub : Base {
5757

5858
// CHECK-LABEL: sil hidden @$s13auto_closures20closureInAutoclosureyAA4BoolVAD_ADtF : $@convention(thin) (Bool, Bool) -> Bool {
5959
// CHECK: }
60-
// CHECK-LABEL: sil private [transparent] @$s13auto_closures20closureInAutoclosureyAA4BoolVAD_ADtFADyXKfu_ : $@convention(thin) (Bool, Bool) -> Bool {
60+
// CHECK-LABEL: sil private [transparent] @$s13auto_closures20closureInAutoclosureyAA4BoolVAD_ADtFADyXEfu_ : $@convention(thin) (Bool, Bool) -> Bool {
6161
// CHECK: }
62-
// CHECK-LABEL: sil private @$s13auto_closures20closureInAutoclosureyAA4BoolVAD_ADtFADyXKfu_A2DXEfU_ : $@convention(thin) (Bool, Bool) -> Bool {
62+
// CHECK-LABEL: sil private @$s13auto_closures20closureInAutoclosureyAA4BoolVAD_ADtFADyXEfu_A2DXEfU_ : $@convention(thin) (Bool, Bool) -> Bool {
6363
// CHECK: }
6464
func compareBool(_ lhs: Bool, _ rhs: Bool) -> Bool { return false_ }
6565
func testBool(_ x: Bool, _ pred: (Bool) -> Bool) -> Bool {

test/SILGen/closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class SuperSub : SuperBase {
602602
func f() {
603603
// CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@guaranteed SuperSub) -> () {
604604
// CHECK: bb0([[ARG:%.*]] : @guaranteed $SuperSub):
605-
// CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_2:\$s8closures8SuperSubC1fyyFyycfU_yyKXKfu_]] : $@convention(thin) (@guaranteed SuperSub) -> @error Error
605+
// CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_2:\$s8closures8SuperSubC1fyyFyycfU_yyKXEfu_]] : $@convention(thin) (@guaranteed SuperSub) -> @error Error
606606
// CHECK: [[ARG_COPY:%.*]] = copy_value [[ARG]]
607607
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [[INNER]]([[ARG_COPY]])
608608
// CHECK: [[CVT:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PA]]

test/SILGen/default_arguments.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func autocloseFile(x: @autoclosure () -> String = #file,
6060
y: @autoclosure () -> Int = #line) { }
6161
// CHECK-LABEL: sil hidden @$s17default_arguments17testAutocloseFileyyF
6262
func testAutocloseFile() {
63-
// CHECK-LABEL: sil private [transparent] @$s17default_arguments17testAutocloseFileyyFSSyXKfu_ : $@convention(thin) () -> @owned String
63+
// CHECK-LABEL: sil private [transparent] @$s17default_arguments17testAutocloseFileyyFSSyXEfu_ : $@convention(thin) () -> @owned String
6464
// CHECK: string_literal utf8{{.*}}default_arguments.swift
6565

66-
// CHECK-LABEL: sil private [transparent] @$s17default_arguments17testAutocloseFileyyFSiyXKfu0_ : $@convention(thin) () -> Int
66+
// CHECK-LABEL: sil private [transparent] @$s17default_arguments17testAutocloseFileyyFSiyXEfu0_ : $@convention(thin) () -> Int
6767
// CHECK: integer_literal $Builtin.IntLiteral, [[@LINE+1]]
6868
autocloseFile()
6969
}
@@ -92,7 +92,7 @@ func autoclosure(_: @autoclosure () -> ()) {}
9292
// CHECK: string_literal utf8 "testCallWithMagicLiterals()"
9393
// CHECK-LABEL: sil private @$s17default_arguments25testCallWithMagicLiteralsyyFyyXEfU_
9494
// CHECK: string_literal utf8 "testCallWithMagicLiterals()"
95-
// CHECK-LABEL: sil private [transparent] @$s17default_arguments25testCallWithMagicLiteralsyyFyyXKfu_
95+
// CHECK-LABEL: sil private [transparent] @$s17default_arguments25testCallWithMagicLiteralsyyFyyXEfu_
9696
// CHECK: string_literal utf8 "testCallWithMagicLiterals()"
9797
func testCallWithMagicLiterals() {
9898
testMagicLiterals()

test/SILGen/dynamic.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ public class Base {
444444
public class Sub : Base {
445445
// CHECK-LABEL: sil hidden @$s7dynamic3SubC1xSbvg : $@convention(method) (@guaranteed Sub) -> Bool {
446446
// CHECK: bb0([[SELF:%.*]] : @guaranteed $Sub):
447-
// CHECK: [[AUTOCLOSURE:%.*]] = function_ref @$s7dynamic3SubC1xSbvgSbyKXKfu_ : $@convention(thin) (@guaranteed Sub) -> (Bool, @error Error)
447+
// CHECK: [[AUTOCLOSURE:%.*]] = function_ref @$s7dynamic3SubC1xSbvgSbyKXEfu_ : $@convention(thin) (@guaranteed Sub) -> (Bool, @error Error)
448448
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
449449
// CHECK: = partial_apply [callee_guaranteed] [[AUTOCLOSURE]]([[SELF_COPY]])
450450
// CHECK: return {{%.*}} : $Bool
451451
// CHECK: } // end sil function '$s7dynamic3SubC1xSbvg'
452452

453-
// CHECK-LABEL: sil private [transparent] @$s7dynamic3SubC1xSbvgSbyKXKfu_ : $@convention(thin) (@guaranteed Sub) -> (Bool, @error Error) {
453+
// CHECK-LABEL: sil private [transparent] @$s7dynamic3SubC1xSbvgSbyKXEfu_ : $@convention(thin) (@guaranteed Sub) -> (Bool, @error Error) {
454454
// CHECK: bb0([[VALUE:%.*]] : @guaranteed $Sub):
455455
// CHECK: [[VALUE_COPY:%.*]] = copy_value [[VALUE]]
456456
// CHECK: [[CAST_VALUE_COPY:%.*]] = upcast [[VALUE_COPY]]
@@ -460,7 +460,7 @@ public class Sub : Base {
460460
// CHECK: = apply [[SUPER]]([[BORROWED_CAST_VALUE_COPY]])
461461
// CHECK: end_borrow [[BORROWED_CAST_VALUE_COPY]]
462462
// CHECK: destroy_value [[CAST_VALUE_COPY]]
463-
// CHECK: } // end sil function '$s7dynamic3SubC1xSbvgSbyKXKfu_'
463+
// CHECK: } // end sil function '$s7dynamic3SubC1xSbvgSbyKXEfu_'
464464
override var x: Bool { return false || super.x }
465465
}
466466

test/SILGen/mangling.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func instantiateGenericUnionConstructor<T>(_ t: T) {
9898
struct HasVarInit {
9999
static var state = true && false
100100
}
101-
// CHECK-LABEL: // function_ref implicit closure #1 : @autoclosure () throws -> Swift.Bool in variable initialization expression of static mangling.HasVarInit.state : Swift.Bool
102-
// CHECK-NEXT: function_ref @$s8mangling10HasVarInitV5stateSbvpZfiSbyKXKfu_
101+
// CHECK-LABEL: // function_ref implicit closure #1 () throws -> Swift.Bool in variable initialization expression of static mangling.HasVarInit.state : Swift.Bool
102+
// CHECK-NEXT: function_ref @$s8mangling10HasVarInitV5stateSbvpZfiSbyKXEfu_
103103

104104
// auto_closures should not collide with the equivalent non-auto_closure
105105
// function type.

0 commit comments

Comments
 (0)