Skip to content

Commit e96886a

Browse files
committed
[SIL] Honor @inlinable in resilient modules for enum exhaustivity
Otherwise, we'll generate inlinable code over a supposedly non-frozen enum that doesn't actually contain a 'default'.
1 parent 42ab996 commit e96886a

File tree

5 files changed

+499
-12
lines changed

5 files changed

+499
-12
lines changed

lib/SIL/SILInstructions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,9 @@ namespace {
14241424
EnumDecl *decl = enumType.getEnumOrBoundGenericEnum();
14251425
assert(decl && "switch_enum operand is not an enum");
14261426

1427-
// FIXME: Get expansion from SILFunction
1428-
if (!decl->isEffectivelyExhaustive(inst->getModule().getSwiftModule(),
1429-
ResilienceExpansion::Maximal)) {
1427+
const SILFunction *F = inst->getFunction();
1428+
if (!decl->isEffectivelyExhaustive(F->getModule().getSwiftModule(),
1429+
F->getResilienceExpansion())) {
14301430
return nullptr;
14311431
}
14321432

lib/SIL/SILVerifier.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,10 +3705,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
37053705
}
37063706

37073707
// If the select is non-exhaustive, we require a default.
3708-
// FIXME: Get the resilience expansion from the function.
37093708
bool isExhaustive =
37103709
eDecl->isEffectivelyExhaustive(F.getModule().getSwiftModule(),
3711-
ResilienceExpansion::Maximal);
3710+
F.getResilienceExpansion());
37123711
require((isExhaustive && unswitchedElts.empty()) || I->hasDefault(),
37133712
"nonexhaustive select_enum must have a default destination");
37143713
if (I->hasDefault()) {
@@ -3877,10 +3876,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
38773876
}
38783877

38793878
// If the switch is non-exhaustive, we require a default.
3880-
// FIXME: Get the resilience expansion from the function.
38813879
bool isExhaustive =
38823880
uDecl->isEffectivelyExhaustive(F.getModule().getSwiftModule(),
3883-
ResilienceExpansion::Maximal);
3881+
F.getResilienceExpansion());
38843882
require((isExhaustive && unswitchedElts.empty()) || SOI->hasDefault(),
38853883
"nonexhaustive switch_enum must have a default destination");
38863884
if (SOI->hasDefault()) {

lib/SILOptimizer/Transforms/SILCodeMotion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ void BBEnumTagDataflowState::handlePredCondSelectEnum(CondBranchInst *CondBr) {
317317
// know the true branch must be the other tag.
318318
if (EnumDecl *E = Operand->getType().getEnumOrBoundGenericEnum()) {
319319
// We can't do this optimization on non-exhaustive enums.
320-
// FIXME: Get resilience expansion from the function.
320+
const SILFunction *Fn = CondBr->getFunction();
321321
bool IsExhaustive =
322-
E->isEffectivelyExhaustive(CondBr->getModule().getSwiftModule(),
323-
ResilienceExpansion::Maximal);
322+
E->isEffectivelyExhaustive(Fn->getModule().getSwiftModule(),
323+
Fn->getResilienceExpansion());
324324
if (!IsExhaustive)
325325
return;
326326
// Look for a single other element on this enum.

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,10 +1583,9 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
15831583
EnumElementDecl *FirstElt = *Iter;
15841584

15851585
// We can't do this optimization on non-exhaustive enums.
1586-
// FIXME: Get the resilience expansion from the function.
15871586
bool IsExhaustive =
15881587
E->isEffectivelyExhaustive(Fn.getModule().getSwiftModule(),
1589-
ResilienceExpansion::Maximal);
1588+
Fn.getResilienceExpansion());
15901589

15911590
if (IsExhaustive
15921591
&& SEI->getNumCases() >= 1

0 commit comments

Comments
 (0)