Skip to content

Commit 5ce8406

Browse files
committed
SIL: Enum case constructors are fragile if the enum is public or @_versioned
1 parent b83bb7d commit 5ce8406

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SIL/SILDeclRef.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,16 @@ bool SILDeclRef::isFragile() const {
499499
DeclContext *dc;
500500
if (auto closure = getAbstractClosureExpr())
501501
dc = closure->getLocalContext();
502-
else
502+
else {
503503
dc = getDecl()->getInnermostDeclContext();
504504

505+
// Enum case constructors are serialized if the enum is @_versioned
506+
// or public.
507+
if (isEnumElement())
508+
if (cast<EnumDecl>(dc)->getEffectiveAccess() >= Accessibility::Public)
509+
return true;
510+
}
511+
505512
// This is stupid
506513
return (dc->getResilienceExpansion() == ResilienceExpansion::Minimal);
507514
}

test/SILGen/inlineable_attribute.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ public class MyCls {
2424
// CHECK-LABEL: sil [fragile] @_T020inlineable_attribute5MyClsCfD : $@convention(method) (@owned MyCls) -> ()
2525
@_inlineable deinit {}
2626
}
27+
28+
// Make sure enum case constructors for public and versioned enums are
29+
// [fragile].
30+
@_versioned enum MyEnum {
31+
case c(MySt)
32+
}
33+
34+
// CHECK-LABEL: sil shared [transparent] [fragile] [thunk] @_T020inlineable_attribute6MyEnumO1cAcA0C2StVcACmFTc : $@convention(thin) (@thin MyEnum.Type) -> @owned @callee_owned (MySt) -> MyEnum
35+
36+
@_inlineable public func referencesMyEnum() {
37+
_ = MyEnum.c
38+
}

0 commit comments

Comments
 (0)