Skip to content

Commit 1e8ce52

Browse files
committed
SIL: Strip [serialized] flag from functions even at -Onone
While the comment is correct to state that this won't enable any new optimizations with -Onone, it does enable IRGen's lazy function emission, which is important for 'reasync' functions, which we don't want to emit at all even at -Onone. This fixes debug stdlib builds with the new reasync versions of the &&, || and ?? operators.
1 parent 95d3944 commit 1e8ce52

32 files changed

+262
-244
lines changed

lib/SILOptimizer/UtilityPasses/SerializeSILPass.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,9 @@ class SerializeSILPass : public SILModuleTransform {
451451
!M.getOptions().CrossModuleOptimization)
452452
return;
453453

454-
// Mark all reachable functions as "anchors" so that they are not
455-
// removed later by the dead function elimination pass. This
456-
// is required, because clients may reference any of the
457-
// serialized functions or anything referenced from them. Therefore,
458-
// to avoid linker errors, the object file of the current module should
459-
// contain all the symbols which were alive at the time of serialization.
460454
LLVM_DEBUG(llvm::dbgs() << "Serializing SILModule in SerializeSILPass\n");
461455
M.serialize();
462456

463-
// If we are not optimizing, do not strip the [serialized] flag. We *could*
464-
// do this since after serializing [serialized] is irrelevent. But this
465-
// would incur an unnecessary compile time cost since if we are not
466-
// optimizing we are not going to perform any sort of DFE.
467-
if (!getOptions().shouldOptimize())
468-
return;
469457
removeSerializedFlagFromAllFunctions(M);
470458
}
471459
};

test/AutoDiff/SILOptimizer/differentiation_subset_parameters_thunk.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func genericInoutIndirectCaller<T: Differentiable, U: Differentiable>(
8181
return inoutIndirectCaller(x, y, z)
8282
}
8383

84-
// CHECK-LABEL: sil shared [transparent] [serialized] [thunk] @$sSdSfSdSfIegnrrr_TJSpSSSpSrSUSP : $@convention(thin) (@in_guaranteed Double, @guaranteed @callee_guaranteed (@in_guaranteed Double) -> (@out Float, @out Double, @out Float)) -> (@out Float, @out Float) {
84+
// CHECK-LABEL: sil shared [transparent] [thunk] @$sSdSfSdSfIegnrrr_TJSpSSSpSrSUSP : $@convention(thin) (@in_guaranteed Double, @guaranteed @callee_guaranteed (@in_guaranteed Double) -> (@out Float, @out Double, @out Float)) -> (@out Float, @out Float) {
8585
// CHECK: bb0(%0 : $*Float, %1 : $*Float, %2 : $*Double, %3 : $@callee_guaranteed (@in_guaranteed Double) -> (@out Float, @out Double, @out Float)):
8686
// CHECK: %4 = alloc_stack $Double
8787
// CHECK: %5 = apply %3(%0, %4, %1, %2) : $@callee_guaranteed (@in_guaranteed Double) -> (@out Float, @out Double, @out Float)
@@ -91,7 +91,7 @@ func genericInoutIndirectCaller<T: Differentiable, U: Differentiable>(
9191
// CHECK: return %8 : $()
9292
// CHECK: }
9393

94-
// CHECK-LABEL: sil shared [transparent] [serialized] [thunk] @$s13TangentVector16_Differentiation14DifferentiablePQy_AaDQzAaDQy0_Ieglrr_TJSpSSSpSrSSUP : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : Differentiable, τ_0_1 : Differentiable, τ_0_2 : Differentiable> (@inout τ_0_1.TangentVector, @guaranteed @callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)) -> @out τ_0_0.TangentVector {
94+
// CHECK-LABEL: sil shared [transparent] [thunk] @$s13TangentVector16_Differentiation14DifferentiablePQy_AaDQzAaDQy0_Ieglrr_TJSpSSSpSrSSUP : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : Differentiable, τ_0_1 : Differentiable, τ_0_2 : Differentiable> (@inout τ_0_1.TangentVector, @guaranteed @callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)) -> @out τ_0_0.TangentVector {
9595
// CHECK: bb0(%0 : $*τ_0_0.TangentVector, %1 : $*τ_0_1.TangentVector, %2 : $@callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)):
9696
// CHECK: %3 = alloc_stack $τ_0_2.TangentVector
9797
// CHECK: %4 = apply %2(%0, %3, %1) : $@callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)
@@ -101,7 +101,7 @@ func genericInoutIndirectCaller<T: Differentiable, U: Differentiable>(
101101
// CHECK: return %7 : $()
102102
// CHECK: }
103103

104-
// CHECK-LABEL: sil shared [transparent] [serialized] [thunk] @$s13TangentVector16_Differentiation14DifferentiablePQy_AaDQzAaDQy0_Ieglrr_TJSpSSSpSrUSUP : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : Differentiable, τ_0_1 : Differentiable, τ_0_2 : Differentiable> (@inout τ_0_1.TangentVector, @guaranteed @callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)) -> () {
104+
// CHECK-LABEL: sil shared [transparent] [thunk] @$s13TangentVector16_Differentiation14DifferentiablePQy_AaDQzAaDQy0_Ieglrr_TJSpSSSpSrUSUP : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : Differentiable, τ_0_1 : Differentiable, τ_0_2 : Differentiable> (@inout τ_0_1.TangentVector, @guaranteed @callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)) -> () {
105105
// CHECK: bb0(%0 : $*τ_0_1.TangentVector, %1 : $@callee_guaranteed (@inout τ_0_1.TangentVector) -> (@out τ_0_0.TangentVector, @out τ_0_2.TangentVector)):
106106
// CHECK: %2 = alloc_stack $τ_0_0.TangentVector
107107
// CHECK: %3 = alloc_stack $τ_0_2.TangentVector

test/ClangImporter/const_and_pure.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ func testit() {
88
normal_function()
99
}
1010

11-
// CHECK: sil [serializable] [readnone] [clang const_function] @const_function : $@convention(c) () -> ()
12-
// CHECK: sil [serializable] [readonly] [clang pure_function] @pure_function : $@convention(c) () -> ()
13-
// CHECK: sil [serializable] [clang normal_function] @normal_function : $@convention(c) () -> ()
11+
// CHECK: sil [readnone] [clang const_function] @const_function : $@convention(c) () -> ()
12+
// CHECK: sil [readonly] [clang pure_function] @pure_function : $@convention(c) () -> ()
13+
// CHECK: sil [clang normal_function] @normal_function : $@convention(c) () -> ()
1414

1515

test/ClangImporter/enum-error.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,30 @@ func testError() {
4545
} catch {}
4646

4747
#elseif ASQEXPR
48-
// ASQEXPR: sil_witness_table shared [serialized] TestError: _BridgedStoredNSError module __ObjC
48+
// ASQEXPR: sil_witness_table shared TestError: _BridgedStoredNSError module __ObjC
4949
let wasTestError = testErrorNSError as? TestError; wasTestError
5050

5151
#elseif ASBANGEXPR
52-
// ASBANGEXPR: sil_witness_table shared [serialized] TestError: _BridgedStoredNSError module __ObjC
52+
// ASBANGEXPR: sil_witness_table shared TestError: _BridgedStoredNSError module __ObjC
5353
let terr2 = testErrorNSError as! TestError; terr2
5454

5555
#elseif ISEXPR
56-
// ISEXPR: sil_witness_table shared [serialized] TestError: _BridgedStoredNSError module __ObjC
56+
// ISEXPR: sil_witness_table shared TestError: _BridgedStoredNSError module __ObjC
5757
if (testErrorNSError is TestError) {
5858
print("true")
5959
} else {
6060
print("false")
6161
}
6262

6363
#elseif CATCHIS
64-
// CATCHIS: sil_witness_table shared [serialized] TestError: _BridgedStoredNSError module __ObjC
64+
// CATCHIS: sil_witness_table shared TestError: _BridgedStoredNSError module __ObjC
6565
do {
6666
throw TestError(.TETwo)
6767
} catch is TestError {
6868
} catch {}
6969

7070
#elseif CATCHAS
71-
// CATCHAS: sil_witness_table shared [serialized] TestError: _BridgedStoredNSError module __ObjC
71+
// CATCHAS: sil_witness_table shared TestError: _BridgedStoredNSError module __ObjC
7272
do {
7373
throw TestError(.TETwo)
7474
} catch let err as TestError {
@@ -83,8 +83,8 @@ func testError() {
8383
let _ : TestError = dyncast(testErrorNSError)
8484

8585
#elseif EXHAUSTIVE
86-
// CHECK: sil_witness_table shared [serialized] TestError: _BridgedStoredNSError module __ObjC
87-
// CHECK: sil_witness_table shared [serialized] ExhaustiveError: _BridgedStoredNSError module __ObjC
86+
// CHECK: sil_witness_table shared TestError: _BridgedStoredNSError module __ObjC
87+
// CHECK: sil_witness_table shared ExhaustiveError: _BridgedStoredNSError module __ObjC
8888
let terr = getErr()
8989
switch (terr) { case .TENone, .TEOne, .TETwo: break }
9090
// EXHAUSTIVE: [[@LINE-1]]:{{.+}}: warning: switch covers known cases, but 'TestError.Code' may have additional unknown values

test/ClangImporter/static_inline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// RUN: %FileCheck < %t/static_inline.sil %s
77
// RUN: %target-swift-frontend -parse-as-library -module-name=static_inline -O -emit-ir %t/static_inline.sil -enable-objc-interop -import-objc-header %S/Inputs/static_inline.h | %FileCheck --check-prefix=CHECK-IR %s
88

9-
// CHECK: sil shared [serializable] [clang c_inline_func] @c_inline_func : $@convention(c) (Int32) -> Int32
9+
// CHECK: sil shared [clang c_inline_func] @c_inline_func : $@convention(c) (Int32) -> Int32
1010

1111
// CHECK-IR-LABEL: define{{.*}} i32 @"$s13static_inline6testit1xs5Int32VAE_tF"(i32 %0)
1212
// CHECK-IR: = add {{.*}}, 27

test/IRGen/alwaysEmitIntoClient.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -O | %FileCheck %s --check-prefix=OPTIMIZED
2+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
3+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=NEGATIVE
4+
// RUN: %target-swift-frontend -emit-ir -primary-file %s | %FileCheck %s --check-prefix=PRIMARY
5+
6+
// Make sure that @_alwaysEmitIntoClient functions are lazily
7+
// emitted in WMO builds.
8+
9+
// Both functions are eliminated in optimized builds; the first is inlined
10+
// into the caller, and the second is eliminated since it was never called.
11+
12+
// OPTIMIZED-NOT: define weak_odr hidden swiftcc void @"$s20alwaysEmitIntoClient18referencedFunctionyyF"() {{.*}} {
13+
// OPTIMIZED-NOT: define weak_odr hidden swiftcc void @"$s20alwaysEmitIntoClient20unreferencedFunctionyyF"() {{.*}} {
14+
15+
// The unreferenced function should be eliminated in an unoptimized WMO
16+
// build too, since it was never referenced from inside the module.
17+
18+
// CHECK-LABEL: define linkonce_odr hidden swiftcc void @"$s20alwaysEmitIntoClient18referencedFunctionyyF"() {{.*}} {
19+
// NEGATIVE-NOT: define linkonce_odr hidden swiftcc void @"$s20alwaysEmitIntoClient20unreferencedFunctionyyF"() {{.*}} {
20+
21+
// In non-WMO mode, both functions must be emitted since they could be
22+
// referenced from other translation units.
23+
24+
// PRIMARY-LABEL: define weak_odr hidden swiftcc void @"$s20alwaysEmitIntoClient18referencedFunctionyyF"() {{.*}} {
25+
// PRIMARY-LABEL: define weak_odr hidden swiftcc void @"$s20alwaysEmitIntoClient20unreferencedFunctionyyF"() {{.*}} {
26+
27+
@_alwaysEmitIntoClient public func referencedFunction() {}
28+
@_alwaysEmitIntoClient public func unreferencedFunction() {}
29+
30+
public func referencesFunction() {
31+
referencedFunction()
32+
}

test/IRGen/opaque_result_type_debug.swift

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
// RUN: %target-swift-frontend -enable-library-evolution -disable-availability-checking -g -emit-ir -enable-anonymous-context-mangled-names %s | %FileCheck %s
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -enable-library-evolution -disable-availability-checking -emit-module -emit-module-path %t/opaque_result_type_debug_other.swiftmodule -module-name opaque_result_type_debug_other -enable-anonymous-context-mangled-names %s -DLIBRARY
3+
// RUN: %target-swift-frontend -disable-availability-checking -g -emit-ir -enable-anonymous-context-mangled-names %s -DCLIENT -I %t | %FileCheck %s
4+
5+
#if LIBRARY
26

37
public protocol P {}
48
extension Int: P {}
59

6-
// CHECK: [[DEFINER_NAME:@.*]] = {{.*}}constant [{{[0-9]+}} x i8] c"$s24opaque_result_type_debug3fooQryF\00"
7-
// CHECK: @"$s24opaque_result_type_debug3fooQryFMXX" = {{.*}}constant{{.*}} [[DEFINER_NAME]]
8-
// CHECK: @"$s24opaque_result_type_debug3fooQryFQOMQ" = {{.*}}constant{{.*}} @"$s24opaque_result_type_debug3fooQryFMXX"
9-
1010
public func foo() -> some P {
1111
return 0
1212
}
1313

14-
// CHECK: [[DEFINER_NAME:@.*]] = {{.*}}constant [{{[0-9]+}} x i8] c"$s24opaque_result_type_debug4propQrvp\00"
15-
// CHECK: @"$s24opaque_result_type_debug4propQrvpMXX" = {{.*}}constant{{.*}} [[DEFINER_NAME]]
16-
// CHECK: @"$s24opaque_result_type_debug4propQrvpQOMQ" = {{.*}}constant{{.*}} @"$s24opaque_result_type_debug4propQrvpMXX"
17-
1814
public var prop: some P {
1915
return 0
2016
}
2117

22-
// CHECK: [[DEFINER_NAME:@.*]] = {{.*}}constant [{{[0-9]+}} x i8] c"$s24opaque_result_type_debug3FooVQrycip\00"
23-
// CHECK: @"$s24opaque_result_type_debug3FooVQrycipMXX" = {{.*}}constant{{.*}} [[DEFINER_NAME]]
24-
// CHECK: @"$s24opaque_result_type_debug3FooVQrycipQOMQ" = {{.*}}constant{{.*}} @"$s24opaque_result_type_debug3FooVQrycipMXX"
25-
2618
public struct Foo {
2719
public init() {}
2820
public subscript() -> some P {
2921
return 0
3022
}
3123
}
3224

33-
// CHECK: @"\01l_type_metadata_table" = {{.*}} @"$s24opaque_result_type_debug3fooQryFQOMQ"
25+
#else
26+
27+
import opaque_result_type_debug_other
3428

3529
@_silgen_name("use") public func use<T: P>(_: T)
3630

@@ -51,11 +45,13 @@ public func bar<T: P>(genericValue: T) {
5145
use(opaqueSubValue)
5246
}
5347

54-
// CHECK-DAG: ![[OPAQUE_TYPE:[0-9]+]] = !DICompositeType({{.*}} name: "$s24opaque_result_type_debug3fooQryFQOyQo_D"
48+
#endif
49+
50+
// CHECK-DAG: ![[OPAQUE_TYPE:[0-9]+]] = !DICompositeType({{.*}} name: "$s30opaque_result_type_debug_other3fooQryFQOyQo_D"
5551
// CHECK-DAG: ![[LET_OPAQUE_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[OPAQUE_TYPE]])
56-
// CHECK-DAG: ![[OPAQUE_PROP_TYPE:[0-9]+]] = !DICompositeType({{.*}} name: "$s24opaque_result_type_debug4propQrvpQOyQo_D"
52+
// CHECK-DAG: ![[OPAQUE_PROP_TYPE:[0-9]+]] = !DICompositeType({{.*}} name: "$s30opaque_result_type_debug_other4propQrvpQOyQo_D"
5753
// CHECK-DAG: ![[LET_OPAQUE_PROP_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[OPAQUE_PROP_TYPE]])
58-
// CHECK-DAG: ![[OPAQUE_SUB_TYPE:[0-9]+]] = !DICompositeType({{.*}} name: "$s24opaque_result_type_debug3FooVQrycipQOy_Qo_D"
54+
// CHECK-DAG: ![[OPAQUE_SUB_TYPE:[0-9]+]] = !DICompositeType({{.*}} name: "$s30opaque_result_type_debug_other3FooVQrycipQOy_Qo_D"
5955
// CHECK-DAG: ![[LET_OPAQUE_SUB_TYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[OPAQUE_SUB_TYPE]])
6056
// CHECK-DAG: {{![0-9]+}} = !DILocalVariable(name: "opaqueValue",{{.*}} type: ![[LET_OPAQUE_TYPE]])
6157
// CHECK-DAG: {{![0-9]+}} = !DILocalVariable(name: "opaquePropValue",{{.*}} type: ![[LET_OPAQUE_PROP_TYPE]])

test/IRGen/opaque_result_type_substitution.swift

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -25,141 +25,9 @@ public func usePair<T, V>(_ t: T, _ v: V) {
2525
print(p)
2626
}
2727

28-
protocol P { }
29-
30-
struct C<S : Hashable> {
31-
struct Inner {}
32-
33-
init(_ s: S) { }
34-
35-
func getInner() -> Inner {
36-
return Inner()
37-
}
38-
}
39-
40-
struct O<T> {
41-
var t: T
42-
43-
init(_ t: T) {
44-
self.t = t
45-
}
46-
}
47-
48-
struct M<T, V> : P {
49-
init(_ f: T, _ s: V) {
50-
}
51-
52-
func foobar() -> some P {
53-
return self
54-
}
55-
}
56-
57-
public func test2<S : Hashable, T, V>(_ s: S, _ t: T, _ v: V) {
58-
var x = M(C(s).getInner(), t)
59-
let q = x.foobar()
60-
let u = x.foobar()
61-
let y = O(q)
62-
print(y)
63-
}
64-
6528
// CHECK-LABEL: define{{.*}} swiftcc void @"$s31opaque_result_type_substitution7usePairyyx_q_tr0_lF"({{.*}}, %swift.type* %T, %swift.type* %V)
6629
// CHECK: [[PAIR_TV:%.*]] = call swiftcc %swift.metadata_response @"$s31opaque_result_type_substitution4PairVMa"({{.*}}, %swift.type* %T, %swift.type* %V)
6730
// CHECK: [[MD:%.*]] = extractvalue %swift.metadata_response [[PAIR_TV]], 0
6831
// CHECK: [[PAIR_OPAQUE:%.*]] = call swiftcc %swift.metadata_response @"$s31opaque_result_type_substitution4PairVMa"({{.*}}, %swift.type* [[MD]], %swift.type* [[MD]])
6932
// CHECK: [[MD2:%.*]] = extractvalue %swift.metadata_response [[PAIR_OPAQUE]], 0
70-
// CHECK: call {{.*}}* @"$s31opaque_result_type_substitution4PairVyAC6foobarQryFQOyxq__Qo_AEGr0_lWOh"({{.*}}, %swift.type* {{.*}}, %swift.type* [[MD2]])
71-
72-
public protocol Thing { }
73-
74-
public struct Thingy : Thing {}
75-
76-
public protocol KeyProto {
77-
associatedtype Value
78-
}
79-
80-
extension KeyProto {
81-
public static func transform3<T : Thing>(
82-
_ transform: @escaping (A<Self>) -> T)
83-
-> some Thing {
84-
return Thingy()
85-
}
86-
}
87-
88-
public struct A<Key : KeyProto> {}
89-
90-
extension A {
91-
public func transform2<T>(_ transform: @escaping (Key.Value) -> T) -> Thingy {
92-
return Thingy()
93-
}
94-
}
95-
96-
struct AKey : KeyProto {
97-
typealias Value = Int
98-
}
99-
100-
extension Thing {
101-
public func transform<K>(key _: K.Type = K.self, transform: @escaping (inout K) -> Void) -> some Thing {
102-
return Thingy()
103-
}
104-
}
105-
106-
struct OutterThing<Content : Thing> : Thing {
107-
let content: Content
108-
109-
init(_ c: Content) {
110-
self.content = c
111-
}
112-
113-
var body: some Thing {
114-
return AKey.transform3 { y in
115-
y.transform2 { i in
116-
self.content.transform(
117-
key: Thingy.self) { value in }
118-
}
119-
}
120-
}
121-
}
122-
123-
public protocol W {}
124-
125-
struct Key : W {}
126-
127-
extension W {
128-
public static func transform(_ transform: @escaping (P1<Self>) -> ()) -> some W {
129-
return Key()
130-
}
131-
}
132-
133-
public struct P1<Key : W> { }
134-
135-
extension P1 {
136-
public func transform2<T>(_ transform: @escaping (Key) -> T) { }
137-
}
138-
139-
public struct T<Content> : W {
140-
public init(content : ()->Content) {}
141-
}
142-
143-
public struct Content<Content> : W {
144-
public init(content: Content) {}
145-
}
146-
147-
extension W {
148-
func moo() -> some W {
149-
return Content(content: self)
150-
}
151-
}
152-
153-
struct Test<Label : W> {
154-
var label: Label
155-
// This function used to crash.
156-
var dontCrash: some W {
157-
return Key.transform { y in
158-
y.transform2 { i in
159-
T() {
160-
return self.label
161-
}.moo()
162-
}
163-
}
164-
}
165-
}
33+
// CHECK: call {{.*}}* @"$s31opaque_result_type_substitution4PairVyACyxq_GADGr0_lWOh"({{.*}}, %swift.type* {{.*}}, %swift.type* [[MD2]])

0 commit comments

Comments
 (0)