@@ -97,6 +97,13 @@ class DeadFunctionAndGlobalElimination {
97
97
98
98
// / Checks is a function is alive, e.g. because it is visible externally.
99
99
bool isAnchorFunction (SILFunction *F) {
100
+ // In embedded Swift, (even public) generic functions *after serialization*
101
+ // cannot be used externally and are not anchors.
102
+ bool embedded = Module->getOptions ().EmbeddedSwift ;
103
+ bool generic = loweredFunctionHasGenericArguments (F);
104
+ bool isSerialized = Module->isSerialized ();
105
+ if (embedded && generic && isSerialized)
106
+ return false ;
100
107
101
108
// Functions that may be used externally cannot be removed.
102
109
if (F->isPossiblyUsedExternally ())
@@ -427,15 +434,7 @@ class DeadFunctionAndGlobalElimination {
427
434
findAnchorsInTables ();
428
435
429
436
for (SILFunction &F : *Module) {
430
- // In embedded Swift, generic functions, even public ones cannot be used
431
- // externally and are not anchors.
432
- bool embedded = Module->getOptions ().EmbeddedSwift ;
433
- bool generic = loweredFunctionHasGenericArguments (&F);
434
- bool isSerialized = Module->isSerialized ();
435
- bool ignoreAnchor =
436
- embedded && generic && isSerialized;
437
-
438
- if (isAnchorFunction (&F) && !ignoreAnchor) {
437
+ if (isAnchorFunction (&F)) {
439
438
LLVM_DEBUG (llvm::dbgs () << " anchor function: " << F.getName () <<" \n " );
440
439
ensureAlive (&F);
441
440
}
@@ -446,7 +445,7 @@ class DeadFunctionAndGlobalElimination {
446
445
[this ](SILFunction *targetFun) { ensureAlive (targetFun); });
447
446
448
447
bool retainBecauseFunctionIsNoOpt = !F.shouldOptimize ();
449
- if (embedded )
448
+ if (Module-> getOptions (). EmbeddedSwift )
450
449
retainBecauseFunctionIsNoOpt = false ;
451
450
452
451
if (retainBecauseFunctionIsNoOpt) {
0 commit comments