Skip to content

Commit 10359ea

Browse files
committed
AST: Synthesize ExtensionDecls for conditional conformances of Builtin.TheTupleType to Sendable and Copyable
1 parent bae8e69 commit 10359ea

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6296,10 +6296,44 @@ BuiltinTupleDecl *ASTContext::getBuiltinTupleDecl() {
62966296
if (result)
62976297
return result;
62986298

6299-
result = new (*this) BuiltinTupleDecl(Id_TheTupleType,
6300-
TheBuiltinModule->getFiles()[0]);
6299+
auto *dc = TheBuiltinModule->getFiles()[0];
6300+
6301+
result = new (*this) BuiltinTupleDecl(Id_TheTupleType, dc);
63016302
result->setAccess(AccessLevel::Public);
63026303

6304+
// Cook up conditional conformances to Sendable and Copyable.
6305+
auto buildFakeExtension = [&](ProtocolDecl *proto) {
6306+
auto protoTy = proto->getDeclaredInterfaceType();
6307+
6308+
// extension Builtin.TheTupleType: P { ... }
6309+
SmallVector<InheritedEntry, 1> inherited;
6310+
inherited.emplace_back(TypeLoc::withoutLoc(protoTy));
6311+
auto *ext = ExtensionDecl::create(*this, SourceLoc(), nullptr,
6312+
AllocateCopy(inherited),
6313+
dc, nullptr);
6314+
6315+
// <each T where repeat each T: P>
6316+
auto genericSig = result->getGenericSignature();
6317+
auto params = genericSig.getGenericParams();
6318+
assert(params.size() == 1);
6319+
Requirement req(RequirementKind::Conformance, params[0], protoTy);
6320+
genericSig = GenericSignature::get(params, req);
6321+
ext->setGenericSignature(genericSig);
6322+
6323+
// Bind the extension.
6324+
evaluator.cacheOutput(ExtendedTypeRequest{ext},
6325+
result->getDeclaredInterfaceType());
6326+
ext->setExtendedNominal(result);
6327+
6328+
result->addExtension(ext);
6329+
};
6330+
6331+
if (auto *proto = getProtocol(KnownProtocolKind::Sendable))
6332+
buildFakeExtension(proto);
6333+
6334+
if (auto *proto = getProtocol(KnownProtocolKind::Copyable))
6335+
buildFakeExtension(proto);
6336+
63036337
return result;
63046338
}
63056339

0 commit comments

Comments
 (0)