@@ -367,6 +367,8 @@ static ProtocolConformanceRef getBuiltinFunctionTypeConformance(
367
367
if (isBitwiseCopyableFunctionType (functionType))
368
368
return synthesizeConformance ();
369
369
break ;
370
+ case KnownProtocolKind::SendableMetatype:
371
+ return synthesizeConformance ();
370
372
default :
371
373
break ;
372
374
}
@@ -387,21 +389,22 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance(
387
389
case KnownProtocolKind::Sendable:
388
390
// Metatypes are generally Sendable, but under StrictSendableMetatypes we
389
391
// cannot assume that metatypes based on type parameters are Sendable.
392
+ // Therefore, check for conformance to SendableMetatype.
390
393
if (ctx.LangOpts .hasFeature (Feature::StrictSendableMetatypes)) {
391
- Type instanceType = metatypeType-> getInstanceType ();
392
-
393
- // If the instance type is a type parameter, it is not necessarily
394
- // Sendable. There will need to be a Sendable requirement.
395
- if (instanceType-> isTypeParameter ())
396
- break ;
397
-
398
- // If the instance type is an archetype or existential, check whether
399
- // it conforms to Sendable.
400
- // FIXME: If the requirement machine were to infer T.Type: Sendable
401
- // from T: Sendable, we wouldn't need this for archetypes.
402
- if (instanceType-> is <ArchetypeType>() ||
403
- instanceType-> isAnyExistentialType ()) {
404
- auto instanceConformance = lookupConformance ( instanceType, protocol );
394
+ auto sendableMetatypeProto =
395
+ ctx. getProtocol (KnownProtocolKind::SendableMetatype);
396
+ if (sendableMetatypeProto) {
397
+ Type instanceType = metatypeType-> getInstanceType ();
398
+
399
+ // If the instance type is a type parameter, it is not necessarily
400
+ // Sendable. There will need to be a Sendable requirement.
401
+ if (instanceType-> isTypeParameter ())
402
+ break ;
403
+
404
+ // If the instance type conforms to SendableMetatype, then its
405
+ // metatype is Sendable.
406
+ auto instanceConformance = lookupConformance (
407
+ instanceType, sendableMetatypeProto );
405
408
if (instanceConformance.isInvalid () ||
406
409
instanceConformance.hasMissingConformance ())
407
410
break ;
@@ -414,6 +417,7 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance(
414
417
case KnownProtocolKind::Copyable:
415
418
case KnownProtocolKind::Escapable:
416
419
case KnownProtocolKind::BitwiseCopyable:
420
+ case KnownProtocolKind::SendableMetatype:
417
421
return ProtocolConformanceRef (
418
422
ctx.getBuiltinConformance (type, protocol,
419
423
BuiltinConformanceKind::Synthesized));
@@ -433,6 +437,7 @@ getBuiltinBuiltinTypeConformance(Type type, const BuiltinType *builtinType,
433
437
if (auto kp = protocol->getKnownProtocolKind ()) {
434
438
switch (*kp) {
435
439
case KnownProtocolKind::Sendable:
440
+ case KnownProtocolKind::SendableMetatype:
436
441
case KnownProtocolKind::Copyable:
437
442
case KnownProtocolKind::Escapable: {
438
443
ASTContext &ctx = protocol->getASTContext ();
@@ -447,7 +452,8 @@ getBuiltinBuiltinTypeConformance(Type type, const BuiltinType *builtinType,
447
452
break ;
448
453
}
449
454
450
- // All other builtin types are Sendable, Copyable, and Escapable.
455
+ // All other builtin types are Sendable, SendableMetatype, Copyable, and
456
+ // Escapable.
451
457
return ProtocolConformanceRef (
452
458
ctx.getBuiltinConformance (type, protocol,
453
459
BuiltinConformanceKind::Synthesized));
@@ -616,6 +622,13 @@ LookupConformanceInModuleRequest::evaluate(
616
622
if (!nominal || isa<ProtocolDecl>(nominal))
617
623
return ProtocolConformanceRef::forMissingOrInvalid (type, protocol);
618
624
625
+ // All nominal types implicitly conform to SendableMetatype.
626
+ if (protocol->isSpecificProtocol (KnownProtocolKind::SendableMetatype)) {
627
+ return ProtocolConformanceRef (
628
+ ctx.getBuiltinConformance (type, protocol,
629
+ BuiltinConformanceKind::Synthesized));
630
+ }
631
+
619
632
// Expand conformances added by extension macros.
620
633
//
621
634
// FIXME: This expansion should only be done if the
0 commit comments