@@ -1424,51 +1424,44 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14241424
14251425 B.setInsertionPoint (entryBlock);
14261426
1427- // If we're using a new enough deployment target, call swift_createExecutors()
1428- if (ctx.LangOpts .ExecutorFactory ) {
1429- if (!isCreateExecutorsFunctionAvailable (SGM)) {
1430- ctx.Diags .diagnose (SourceLoc (), diag::executor_factory_not_supported);
1431- } else {
1432- CanType factoryTy = SGM.getConfiguredExecutorFactory ()->getCanonicalType ();
1427+ // If we're using a new enough deployment target, and we can find a
1428+ // DefaultExecutorFactory type, call swift_createExecutors()
1429+ Type factoryNonCanTy = SGM.getConfiguredExecutorFactory ();
14331430
1434- if (!factoryTy) {
1435- ctx.Diags .diagnose (SourceLoc (), diag::cannot_find_executor_factory_type,
1436- *ctx.LangOpts .ExecutorFactory );
1437- }
1431+ if (isCreateExecutorsFunctionAvailable (SGM) && factoryNonCanTy) {
1432+ CanType factoryTy = factoryNonCanTy->getCanonicalType ();
14381433
1439- ProtocolDecl *executorFactoryProtocol
1440- = ctx.getProtocol (KnownProtocolKind::ExecutorFactory);
1441- auto conformance = lookupConformance (factoryTy, executorFactoryProtocol);
1434+ ProtocolDecl *executorFactoryProtocol
1435+ = ctx.getProtocol (KnownProtocolKind::ExecutorFactory);
1436+ auto conformance = lookupConformance (factoryTy, executorFactoryProtocol);
14421437
1443- if (conformance.isInvalid ()) {
1444- // If this type doesn't conform, ignore it and use the default factory
1445- SourceLoc loc = extractNearestSourceLoc (factoryTy);
1438+ if (conformance.isInvalid ()) {
1439+ // If this type doesn't conform, ignore it and use the default factory
1440+ SourceLoc loc = extractNearestSourceLoc (factoryTy);
14461441
1447- ctx.Diags .diagnose (loc, diag::executor_factory_must_conform,
1448- *ctx.LangOpts .ExecutorFactory );
1442+ ctx.Diags .diagnose (loc, diag::executor_factory_must_conform);
14491443
1450- factoryTy = SGM.getDefaultExecutorFactory ()->getCanonicalType ();
1451- conformance = lookupConformance (factoryTy, executorFactoryProtocol);
1444+ factoryTy = SGM.getDefaultExecutorFactory ()->getCanonicalType ();
1445+ conformance = lookupConformance (factoryTy, executorFactoryProtocol);
14521446
1453- assert (!conformance.isInvalid ());
1454- }
1447+ assert (!conformance.isInvalid ());
1448+ }
14551449
1456- FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors ();
1457- assert (createExecutorsFuncDecl
1458- && " Failed to find swift_createExecutors function decl" );
1459- SILFunction *createExecutorsSILFunc =
1460- SGM.getFunction (SILDeclRef (createExecutorsFuncDecl, SILDeclRef::Kind::Func),
1450+ FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors ();
1451+ assert (createExecutorsFuncDecl
1452+ && " Failed to find swift_createExecutors function decl" );
1453+ SILFunction *createExecutorsSILFunc =
1454+ SGM.getFunction (SILDeclRef (createExecutorsFuncDecl, SILDeclRef::Kind::Func),
14611455 NotForDefinition);
1462- SILValue createExecutorsFunc =
1463- B.createFunctionRefFor (moduleLoc, createExecutorsSILFunc);
1464- MetatypeType *factoryThickMetaTy
1465- = MetatypeType::get (factoryTy, MetatypeRepresentation::Thick);
1466- SILValue factorySILMetaTy
1467- = B.createMetatype (moduleLoc, getLoweredType (factoryThickMetaTy));
1468- auto ceSubs = SubstitutionMap::getProtocolSubstitutions (
1469- conformance.getProtocol (), factoryTy, conformance);
1470- B.createApply (moduleLoc, createExecutorsFunc, ceSubs, { factorySILMetaTy });
1471- }
1456+ SILValue createExecutorsFunc =
1457+ B.createFunctionRefFor (moduleLoc, createExecutorsSILFunc);
1458+ MetatypeType *factoryThickMetaTy
1459+ = MetatypeType::get (factoryTy, MetatypeRepresentation::Thick);
1460+ SILValue factorySILMetaTy
1461+ = B.createMetatype (moduleLoc, getLoweredType (factoryThickMetaTy));
1462+ auto ceSubs = SubstitutionMap::getProtocolSubstitutions (
1463+ conformance.getProtocol (), factoryTy, conformance);
1464+ B.createApply (moduleLoc, createExecutorsFunc, ceSubs, { factorySILMetaTy });
14721465 }
14731466
14741467 auto wrapCallArgs = [this , &moduleLoc](SILValue originalValue, FuncDecl *fd,
0 commit comments