@@ -1142,8 +1142,9 @@ void IRGenModule::emitGlobalLists() {
11421142// Eagerly emit functions that are externally visible. Functions that are
11431143// dynamic replacements must also be eagerly emitted.
11441144static 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.
11471148 if (f.getASTContext ().LangOpts .hasFeature (Feature::Embedded) &&
11481149 f.getLoweredFunctionType ()->getSubstGenericSignature ()) {
11491150 return true ;
@@ -1332,7 +1333,7 @@ void IRGenerator::emitLazyDefinitions() {
13321333 assert (LazyFieldDescriptors.empty ());
13331334 // LazyFunctionDefinitions are allowed, but they must not be generic
13341335 for (SILFunction *f : LazyFunctionDefinitions) {
1335- assert (!f-> isGeneric ( ));
1336+ assert (hasValidSignatureForEmbedded (f ));
13361337 }
13371338 assert (LazyWitnessTables.empty ());
13381339 assert (LazyCanonicalSpecializedMetadataAccessors.empty ());
@@ -1482,7 +1483,7 @@ void IRGenerator::addLazyFunction(SILFunction *f) {
14821483
14831484 // Embedded Swift doesn't expect any generic functions to be referenced.
14841485 if (SIL.getASTContext ().LangOpts .hasFeature (Feature::Embedded)) {
1485- assert (!f-> isGeneric ( ));
1486+ assert (hasValidSignatureForEmbedded (f ));
14861487 }
14871488
14881489 assert (!FinishedEmittingLazyDefinitions);
@@ -3472,6 +3473,24 @@ llvm::CallBase *swift::irgen::emitCXXConstructorCall(
34723473 return result;
34733474}
34743475
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+
34753494StackProtectorMode IRGenModule::shouldEmitStackProtector (SILFunction *f) {
34763495 const SILOptions &opts = IRGen.SIL .getOptions ();
34773496 return (opts.EnableStackProtection && f->needsStackProtection ()) ?
@@ -4351,7 +4370,10 @@ static bool conformanceIsVisibleViaMetadata(
43514370
43524371
43534372void IRGenModule::addProtocolConformance (ConformanceDescription &&record) {
4354-
4373+ if (Context.LangOpts .hasFeature (Feature::Embedded)) {
4374+ return ;
4375+ }
4376+
43554377 emitProtocolConformance (record);
43564378
43574379 if (conformanceIsVisibleViaMetadata (record.conformance )) {
0 commit comments