@@ -1142,8 +1142,9 @@ void IRGenModule::emitGlobalLists() {
1142
1142
// Eagerly emit functions that are externally visible. Functions that are
1143
1143
// dynamic replacements must also be eagerly emitted.
1144
1144
static bool isLazilyEmittedFunction (SILFunction &f, SILModule &m) {
1145
- // Embedded Swift only emits specialized function, so don't emit generic
1146
- // functions, even if they're externally visible.
1145
+ // Embedded Swift only emits specialized function (except when they are
1146
+ // protocol witness methods). So don't emit generic functions, even if they're
1147
+ // externally visible.
1147
1148
if (f.getASTContext ().LangOpts .hasFeature (Feature::Embedded) &&
1148
1149
f.getLoweredFunctionType ()->getSubstGenericSignature ()) {
1149
1150
return true ;
@@ -1332,7 +1333,7 @@ void IRGenerator::emitLazyDefinitions() {
1332
1333
assert (LazyFieldDescriptors.empty ());
1333
1334
// LazyFunctionDefinitions are allowed, but they must not be generic
1334
1335
for (SILFunction *f : LazyFunctionDefinitions) {
1335
- assert (!f-> isGeneric ( ));
1336
+ assert (hasValidSignatureForEmbedded (f ));
1336
1337
}
1337
1338
assert (LazyWitnessTables.empty ());
1338
1339
assert (LazyCanonicalSpecializedMetadataAccessors.empty ());
@@ -1482,7 +1483,7 @@ void IRGenerator::addLazyFunction(SILFunction *f) {
1482
1483
1483
1484
// Embedded Swift doesn't expect any generic functions to be referenced.
1484
1485
if (SIL.getASTContext ().LangOpts .hasFeature (Feature::Embedded)) {
1485
- assert (!f-> isGeneric ( ));
1486
+ assert (hasValidSignatureForEmbedded (f ));
1486
1487
}
1487
1488
1488
1489
assert (!FinishedEmittingLazyDefinitions);
@@ -3472,6 +3473,24 @@ llvm::CallBase *swift::irgen::emitCXXConstructorCall(
3472
3473
return result;
3473
3474
}
3474
3475
3476
+ // For a SILFunction to be legal in Embedded Swift, it must be either
3477
+ // - non-generic
3478
+ // - generic with parameters thar are either
3479
+ // - fully specialized (concrete)
3480
+ // - a class-bound archetype (class-bound existential)
3481
+ bool swift::irgen::hasValidSignatureForEmbedded (SILFunction *f) {
3482
+ auto s = f->getLoweredFunctionType ()->getInvocationGenericSignature ();
3483
+ for (auto genParam : s.getGenericParams ()) {
3484
+ auto mappedParam = f->getGenericEnvironment ()->mapTypeIntoContext (genParam);
3485
+ if (auto archeTy = dyn_cast<ArchetypeType>(mappedParam)) {
3486
+ if (archeTy->requiresClass ())
3487
+ continue ;
3488
+ }
3489
+ return false ;
3490
+ }
3491
+ return true ;
3492
+ }
3493
+
3475
3494
StackProtectorMode IRGenModule::shouldEmitStackProtector (SILFunction *f) {
3476
3495
const SILOptions &opts = IRGen.SIL .getOptions ();
3477
3496
return (opts.EnableStackProtection && f->needsStackProtection ()) ?
@@ -4351,7 +4370,10 @@ static bool conformanceIsVisibleViaMetadata(
4351
4370
4352
4371
4353
4372
void IRGenModule::addProtocolConformance (ConformanceDescription &&record) {
4354
-
4373
+ if (Context.LangOpts .hasFeature (Feature::Embedded)) {
4374
+ return ;
4375
+ }
4376
+
4355
4377
emitProtocolConformance (record);
4356
4378
4357
4379
if (conformanceIsVisibleViaMetadata (record.conformance )) {
0 commit comments