Skip to content

Commit df95485

Browse files
authored
Merge pull request swiftlang#31826 from theblixguy/fix/SR-12821
[TBDGen] Fix symbol mismatch for enum case constructors
2 parents d1816ae + b6b1dec commit df95485

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
233233

234234
// Native function-local declarations have shared linkage.
235235
// FIXME: @objc declarations should be too, but we currently have no way
236-
// of marking them "used" other than making them external.
236+
// of marking them "used" other than making them external.
237237
ValueDecl *d = getDecl();
238238
DeclContext *moduleContext = d->getDeclContext();
239239
while (!moduleContext->isModuleScopeContext()) {
@@ -335,6 +335,10 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
335335
}
336336
}
337337

338+
if (isEnumElement()) {
339+
limit = Limit::OnDemand;
340+
}
341+
338342
auto effectiveAccess = d->getEffectiveAccess();
339343

340344
// Private setter implementations for an internal storage declaration should

lib/TBDGen/TBDGen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ void TBDGenVisitor::addConformances(const IterableDeclContext *IDC) {
498498
addSymbolIfNecessary(reqtAccessor, witnessAccessor);
499499
});
500500
} else if (isa<EnumElementDecl>(witnessDecl)) {
501-
addSymbolIfNecessary(valueReq, witnessDecl);
501+
auto getter = storage->getSynthesizedAccessor(AccessorKind::Get);
502+
addSymbolIfNecessary(getter, witnessDecl);
502503
}
503504
}
504505
});
@@ -1018,13 +1019,12 @@ void TBDGenVisitor::visitProtocolDecl(ProtocolDecl *PD) {
10181019

10191020
void TBDGenVisitor::visitEnumDecl(EnumDecl *ED) {
10201021
visitNominalTypeDecl(ED);
1021-
1022-
if (!ED->isResilient())
1023-
return;
10241022
}
10251023

10261024
void TBDGenVisitor::visitEnumElementDecl(EnumElementDecl *EED) {
1027-
addSymbol(LinkEntity::forEnumCase(EED));
1025+
if (EED->getParentEnum()->isResilient())
1026+
addSymbol(LinkEntity::forEnumCase(EED));
1027+
10281028
if (auto *PL = EED->getParameterList())
10291029
visitDefaultArguments(EED, PL);
10301030
}

test/SILGen/protocol_enum_witness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum AnotherBar: AnotherFoo {
2626
// CHECK-NEXT: return [[TUPLE]] : $()
2727
// CHECK-END: }
2828

29-
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar {
29+
// CHECK-LABEL: sil shared [transparent] [ossa] @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar {
3030
// CHECK: bb0({{%.*}} : $@thin Bar.Type):
3131
// CHECK-NEXT: [[CASE:%.*]] = enum $Bar, #Bar.button!enumelt
3232
// CHECK-NEXT: return [[CASE]] : $Bar
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// REQUIRES: VENDOR=apple
2+
// RUN: %target-swift-frontend -emit-ir -enable-testing -o/dev/null -module-name test -validate-tbd-against-ir=all %s
3+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -module-name test -validate-tbd-against-ir=all %s
4+
5+
protocol ProtoInternal {
6+
static var bar1: Self { get }
7+
static func bar2(arg: Int) -> Self
8+
}
9+
10+
enum EnumInternal: ProtoInternal {
11+
case bar1
12+
case bar2(arg: Int)
13+
}
14+
15+
public protocol ProtoPublic {
16+
static var bar3: Self { get }
17+
static func bar4(arg: Int) -> Self
18+
}
19+
20+
public enum EnumPublic: ProtoPublic {
21+
case bar3
22+
case bar4(arg: Int)
23+
}

0 commit comments

Comments
 (0)