Merge pull request #85551 from aschwaighofer/wip_embedded_exit

Preliminary support for existential in embedded Swift
This commit is contained in:
Arnold Schwaighofer
2025-11-18 15:10:40 -05:00
committed by GitHub
21 changed files with 721 additions and 45 deletions

View File

@@ -89,11 +89,18 @@ enum class TypeMetadataAddress {
inline bool isEmbedded(CanType t) {
return t->getASTContext().LangOpts.hasFeature(Feature::Embedded);
}
inline bool isEmbeddedWithoutEmbeddedExitentials(CanType t) {
auto &langOpts = t->getASTContext().LangOpts;
return langOpts.hasFeature(Feature::Embedded) &&
!langOpts.hasFeature(Feature::EmbeddedExistentials);
}
// Metadata is not generated and not allowed to be referenced in Embedded Swift,
// expect for classes (both generic and non-generic), dynamic self, and
// class-bound existentials.
inline bool isMetadataAllowedInEmbedded(CanType t) {
bool embeddedExistentials =
t->getASTContext().LangOpts.hasFeature(Feature::EmbeddedExistentials);
if (isa<ClassType>(t) || isa<BoundGenericClassType>(t) ||
isa<DynamicSelfType>(t)) {
return true;
@@ -106,6 +113,9 @@ inline bool isMetadataAllowedInEmbedded(CanType t) {
if (archeTy->requiresClass())
return true;
}
if (embeddedExistentials)
return true;
return false;
}
@@ -117,6 +127,11 @@ inline bool isEmbedded(const ProtocolConformance *c) {
return c->getType()->getASTContext().LangOpts.hasFeature(Feature::Embedded);
}
inline bool isEmbeddedWithoutEmbeddedExitentials(const ProtocolConformance *c) {
return isEmbedded(c) && !c->getType()->getASTContext().
LangOpts.hasFeature(Feature::EmbeddedExistentials);
}
/// A link entity is some sort of named declaration, combined with all
/// the information necessary to distinguish specific implementations
/// of the declaration from each other.
@@ -1098,7 +1113,7 @@ public:
}
static LinkEntity forValueWitnessTable(CanType type) {
assert(!isEmbedded(type));
assert(!isEmbeddedWithoutEmbeddedExitentials(type));
LinkEntity entity;
entity.setForType(Kind::ValueWitnessTable, type);
return entity;
@@ -1128,7 +1143,7 @@ public:
}
static LinkEntity forProtocolWitnessTable(const ProtocolConformance *C) {
if (isEmbedded(C)) {
if (isEmbeddedWithoutEmbeddedExitentials(C)) {
assert(C->getProtocol()->requiresClass());
}

View File

@@ -236,6 +236,14 @@ FUNCTION(NativeStrongReleaseDirect, Swift, swift_releaseDirect, SwiftDirectRR_CC
EFFECT(RuntimeEffect::RefCounting, RuntimeEffect::Deallocating),
UNKNOWN_MEMEFFECTS)
// void swift_releaseBox(void *ptr);
FUNCTION(ReleaseBox, Swift, swift_releaseBox, C_CC, AlwaysAvailable,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind),
EFFECT(RuntimeEffect::RefCounting, RuntimeEffect::Deallocating),
UNKNOWN_MEMEFFECTS)
// void *swift_retain_n(void *ptr, int32_t n);
FUNCTION(NativeStrongRetainN, Swift, swift_retain_n, C_CC, AlwaysAvailable,
RETURNS(RefCountedPtrTy),