Skip to content

Commit 527fb5d

Browse files
committed
SIL: Enum protocol witness thunks should be [serializable]
1 parent 93f22cd commit 527fb5d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ IsSerialized_t SILDeclRef::isSerialized() const {
531531
if (d->getEffectiveAccess() < AccessLevel::Public)
532532
return IsNotSerialized;
533533

534+
// Enum element constructors are serializable if the enum is
535+
// @usableFromInline or public.
536+
if (isEnumElement())
537+
return IsSerializable;
538+
534539
// 'read' and 'modify' accessors synthesized on-demand are serialized if
535540
// visible outside the module.
536541
if (auto fn = dyn_cast<FuncDecl>(d))
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
// RUN: %target-swift-emit-silgen %s -enable-library-evolution
23

3-
protocol Foo {
4+
public protocol Foo {
45
static var button: Self { get }
56
}
67

7-
enum Bar: Foo {
8+
public enum Bar: Foo {
89
case button
910
}
1011

11-
protocol AnotherFoo {
12+
public protocol AnotherFoo {
1213
static func bar(arg: Int) -> Self
1314
}
1415

15-
enum AnotherBar: AnotherFoo {
16+
public enum AnotherBar: AnotherFoo {
1617
case bar(arg: Int)
1718
}
1819

19-
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21protocol_enum_witness3BarOAA3FooA2aDP6buttonxvgZTW : $@convention(witness_method: Foo) (@thick Bar.Type) -> @out Bar {
20+
// CHECK-LABEL: sil shared [transparent] [serialized] [thunk] [ossa] @$s21protocol_enum_witness3BarOAA3FooA2aDP6buttonxvgZTW : $@convention(witness_method: Foo) (@thick Bar.Type) -> @out Bar {
2021
// CHECK: bb0([[BAR:%.*]] : $*Bar, [[BAR_TYPE:%.*]] : $@thick Bar.Type):
2122
// CHECK-NEXT: [[META_TYPE:%.*]] = metatype $@thin Bar.Type
2223
// CHECK: [[REF:%.*]] = function_ref @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar
@@ -26,13 +27,13 @@ enum AnotherBar: AnotherFoo {
2627
// CHECK-NEXT: return [[TUPLE]] : $()
2728
// CHECK-END: }
2829

29-
// CHECK-LABEL: sil shared [transparent] [ossa] @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar {
30+
// CHECK-LABEL: sil shared [transparent] [serializable] [ossa] @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar {
3031
// CHECK: bb0({{%.*}} : $@thin Bar.Type):
3132
// CHECK-NEXT: [[CASE:%.*]] = enum $Bar, #Bar.button!enumelt
3233
// CHECK-NEXT: return [[CASE]] : $Bar
3334
// CHECK-END: }
3435

35-
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21protocol_enum_witness10AnotherBarOAA0D3FooA2aDP3bar3argxSi_tFZTW : $@convention(witness_method: AnotherFoo) (Int, @thick AnotherBar.Type) -> @out AnotherBar {
36+
// CHECK-LABEL: sil shared [transparent] [serialized] [thunk] [ossa] @$s21protocol_enum_witness10AnotherBarOAA0D3FooA2aDP3bar3argxSi_tFZTW : $@convention(witness_method: AnotherFoo) (Int, @thick AnotherBar.Type) -> @out AnotherBar {
3637
// CHECK: bb0([[ANOTHER_BAR:%.*]] : $*AnotherBar, [[INT_ARG:%.*]] : $Int, [[ANOTHER_BAR_TYPE:%.*]] : $@thick AnotherBar.Type):
3738
// CHECK-NEXT: [[META_TYPE:%.*]] = metatype $@thin AnotherBar.Type
3839
// CHECK: [[REF:%.*]] = function_ref @$s21protocol_enum_witness10AnotherBarO3baryACSi_tcACmF : $@convention(method) (Int, @thin AnotherBar.Type) -> AnotherBar
@@ -42,8 +43,8 @@ enum AnotherBar: AnotherFoo {
4243
// CHECK-NEXT: return [[TUPLE]] : $()
4344
// CHECK-END: }
4445

45-
// CHECK-LABEL: sil_witness_table hidden Bar: Foo module protocol_enum_witness {
46+
// CHECK-LABEL: sil_witness_table [serialized] Bar: Foo module protocol_enum_witness {
4647
// CHECK: method #Foo.button!getter: <Self where Self : Foo> (Self.Type) -> () -> Self : @$s21protocol_enum_witness3BarOAA3FooA2aDP6buttonxvgZTW
4748

48-
// CHECK-LABEL: sil_witness_table hidden AnotherBar: AnotherFoo module protocol_enum_witness {
49+
// CHECK-LABEL: sil_witness_table [serialized] AnotherBar: AnotherFoo module protocol_enum_witness {
4950
// CHECK: method #AnotherFoo.bar: <Self where Self : AnotherFoo> (Self.Type) -> (Int) -> Self : @$s21protocol_enum_witness10AnotherBarOAA0D3FooA2aDP3bar3argxSi_tFZTW

0 commit comments

Comments
 (0)