Skip to content

Commit be78127

Browse files
Merge pull request #85923 from aschwaighofer/embedded_existentials_requires_embedded
[embedded] Feature::EmbeddedExistentials requires Feature::Embedded
2 parents 0c0a98d + 4d87996 commit be78127

File tree

17 files changed

+73
-47
lines changed

17 files changed

+73
-47
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct Options {
4545
}
4646

4747
var enableEmbeddedSwiftExistentials: Bool {
48-
hasFeature(.EmbeddedExistentials)
48+
hasFeature(.Embedded) && hasFeature(.EmbeddedExistentials)
4949
}
5050

5151
var enableMergeableTraps: Bool {

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ ERROR(layout_string_instantiation_without_layout_strings,none,
572572

573573
ERROR(evolution_with_embedded,none,
574574
"Library evolution cannot be enabled with embedded Swift.", ())
575+
ERROR(embedded_existentials_without_embedded,none,
576+
"EmbeddedExistentials requires enabling embedded Swift.", ())
575577
ERROR(wmo_with_embedded,none,
576578
"Whole module optimization (wmo) must be enabled with embedded Swift.", ())
577579
ERROR(objc_with_embedded,none,

include/swift/IRGen/Linking.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ inline bool isEmbeddedWithoutEmbeddedExitentials(CanType t) {
9898
// expect for classes (both generic and non-generic), dynamic self, and
9999
// class-bound existentials.
100100
inline bool isMetadataAllowedInEmbedded(CanType t) {
101+
auto &langOpts = t->getASTContext().LangOpts;
101102
bool embeddedExistentials =
102-
t->getASTContext().LangOpts.hasFeature(Feature::EmbeddedExistentials);
103+
langOpts.hasFeature(Feature::EmbeddedExistentials) &&
104+
langOpts.hasFeature(Feature::Embedded);
103105

104106
if (isa<ClassType>(t) || isa<BoundGenericClassType>(t) ||
105107
isa<DynamicSelfType>(t)) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
18181818
}
18191819
Opts.BypassResilienceChecks |= Args.hasArg(OPT_bypass_resilience);
18201820

1821+
if (Opts.hasFeature(Feature::EmbeddedExistentials) &&
1822+
!Opts.hasFeature(Feature::Embedded)) {
1823+
Diags.diagnose(SourceLoc(), diag::embedded_existentials_without_embedded);
1824+
HadError = true;
1825+
}
18211826
if (Opts.hasFeature(Feature::Embedded)) {
18221827
Opts.UnavailableDeclOptimizationMode = UnavailableDeclOptimization::Complete;
18231828
Opts.DisableImplicitStringProcessingModuleImport = true;

lib/IRGen/ClassMetadataVisitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ template <class Impl> class ClassMetadataVisitor
7777
// The regular `layout` method can be used for layout tasks for which the
7878
// actual superclass pointer is not relevant.
7979
void layoutEmbedded(CanType classTy) {
80-
if (IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials))
80+
if (IGM.isEmbeddedWithExistentials())
8181
asImpl().addValueWitnessTable();
8282
asImpl().noteAddressPoint();
8383
asImpl().addEmbeddedSuperclass(classTy);
@@ -91,7 +91,7 @@ template <class Impl> class ClassMetadataVisitor
9191
"Adjustment index must be synchronized with this layout");
9292

9393
if (IGM.Context.LangOpts.hasFeature(Feature::Embedded)) {
94-
if (IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials))
94+
if (IGM.isEmbeddedWithExistentials())
9595
asImpl().addValueWitnessTable();
9696
asImpl().noteAddressPoint();
9797
asImpl().addSuperclass();

lib/IRGen/GenCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ llvm::Value *irgen::emitCheckedCast(IRGenFunction &IGF,
8888
llvm::Value *srcMetadata = nullptr;
8989

9090
// Embedded swift currently only supports existential -> concrete type casts.
91-
if (IGF.IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
91+
if (IGF.IGM.isEmbeddedWithExistentials()) {
9292
srcMetadata = llvm::ConstantPointerNull::get(IGF.IGM.TypeMetadataPtrTy);
9393
} else {
9494
srcMetadata = IGF.emitTypeMetadataRef(srcType);

lib/IRGen/GenClass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,18 +1051,17 @@ void IRGenModule::emitClassDecl(ClassDecl *D) {
10511051
auto &resilientLayout =
10521052
classTI.getClassLayout(*this, selfType, /*forBackwardDeployment=*/false);
10531053

1054-
auto isEmbeddedWithExistentials =
1055-
Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
1054+
auto hasEmbeddedWithExistentials = isEmbeddedWithExistentials();
10561055

10571056
// As a matter of policy, class metadata is never emitted lazily for now.
1058-
assert(isEmbeddedWithExistentials || !IRGen.hasLazyMetadata(D));
1057+
assert(hasEmbeddedWithExistentials || !IRGen.hasLazyMetadata(D));
10591058

10601059
// Emit the class metadata.
10611060
if (!D->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
10621061
emitClassMetadata(*this, D, fragileLayout, resilientLayout);
10631062
emitFieldDescriptor(D);
10641063
} else {
1065-
if (!isEmbeddedWithExistentials && !D->isGenericContext()) {
1064+
if (!hasEmbeddedWithExistentials && !D->isGenericContext()) {
10661065
emitEmbeddedClassMetadata(*this, D);
10671066
} else {
10681067
// We create all metadata lazily in embedded with existentials mode.

lib/IRGen/GenDecl.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,10 @@ bool IRGenerator::hasLazyMetadata(TypeDecl *type) {
15881588
auto found = HasLazyMetadata.find(type);
15891589
if (found != HasLazyMetadata.end())
15901590
return found->second;
1591-
1592-
if (SIL.getASTContext().LangOpts.hasFeature(Feature::EmbeddedExistentials) &&
1591+
auto &langOpts = SIL.getASTContext().LangOpts;
1592+
auto isEmbeddedWithExistentials = langOpts.hasFeature(Feature::Embedded) &&
1593+
langOpts.hasFeature(Feature::EmbeddedExistentials);
1594+
if (isEmbeddedWithExistentials &&
15931595
(isa<StructDecl>(type) || isa<EnumDecl>(type))) {
15941596
bool isGeneric = cast<NominalTypeDecl>(type)->isGenericContext();
15951597
HasLazyMetadata[type] = !isGeneric;
@@ -5308,8 +5310,7 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(
53085310

53095311
return cast<llvm::GlobalValue>(addr);
53105312
}
5311-
bool hasEmbeddedExistentials =
5312-
Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
5313+
bool hasEmbeddedExistentials = isEmbeddedWithExistentials();
53135314
auto entity =
53145315
(isPrespecialized &&
53155316
!irgen::isCanonicalInitializableTypeMetadataStaticallyAddressable(
@@ -5427,7 +5428,8 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
54275428

54285429
llvm::Type *defaultVarTy;
54295430
unsigned adjustmentIndex;
5430-
if (Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
5431+
auto hasEmbeddedExistentials = isEmbeddedWithExistentials();
5432+
if (hasEmbeddedExistentials) {
54315433
adjustmentIndex = 0;
54325434
defaultVarTy = EmbeddedExistentialsMetadataStructTy;
54335435
} else if (concreteType->isAny() || concreteType->isAnyObject() || concreteType->isVoid() || concreteType->is<TupleType>() || concreteType->is<BuiltinType>()) {
@@ -5474,15 +5476,15 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
54745476
}
54755477
}
54765478

5477-
if (Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
5479+
if (hasEmbeddedExistentials) {
54785480
if ((isa<StructDecl>(nominal) || isa<EnumDecl>(nominal)) &&
54795481
nominal->isGenericContext()) {
54805482
IRGen.noteUseOfSpecializedValueMetadata(concreteType);
54815483
}
54825484
}
54835485
}
54845486

5485-
if (Context.LangOpts.hasFeature(Feature::EmbeddedExistentials) &&
5487+
if (hasEmbeddedExistentials &&
54865488
(isa<TupleType>(concreteType) ||
54875489
isa<FunctionType>(concreteType))) {
54885490
IRGen.noteUseOfSpecializedValueMetadata(concreteType);

lib/IRGen/GenExistential.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ Address irgen::emitAllocateBoxedOpaqueExistentialBuffer(
23142314
if (fixedTI->getFixedPacking(IGF.IGM) == FixedPacking::OffsetZero) {
23152315
return valueTI.getAddressForPointer(IGF.Builder.CreateBitCast(
23162316
existentialBuffer.getAddress(), IGF.IGM.PtrTy));
2317-
} else if (IGF.IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
2317+
} else if (IGF.IGM.isEmbeddedWithExistentials()) {
23182318
llvm::Value *box, *address;
23192319
auto *metadata = existLayout.loadMetadataRef(IGF, existentialContainer);
23202320
IGF.emitAllocBoxCall(metadata, box, address);
@@ -2897,8 +2897,7 @@ static llvm::Function *getDestroyBoxedOpaqueExistentialBufferFunction(
28972897
Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy);
28982898
auto *reference = Builder.CreateLoad(Address(
28992899
referenceAddr, IGM.RefCountedPtrTy, buffer.getAlignment()));
2900-
if (IGF.IGM.Context.LangOpts
2901-
.hasFeature(Feature::EmbeddedExistentials)) {
2900+
if (IGF.IGM.isEmbeddedWithExistentials()) {
29022901
IGF.emitReleaseBox(reference);
29032902
} else
29042903
IGF.emitNativeStrongRelease(reference, IGF.getDefaultAtomicity());

lib/IRGen/GenMeta.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,7 +2973,7 @@ void irgen::emitLazyTypeContextDescriptor(IRGenModule &IGM,
29732973
void irgen::emitLazyTypeMetadata(IRGenModule &IGM, NominalTypeDecl *type) {
29742974
// Embedded existentials emit very spares metadata records and don't have type
29752975
// context descriptors.
2976-
if (!type->getASTContext().LangOpts.hasFeature(Feature::EmbeddedExistentials))
2976+
if (!IGM.isEmbeddedWithExistentials())
29772977
eraseExistingTypeContextDescriptor(IGM, type);
29782978

29792979
if (requiresForeignTypeMetadata(type)) {
@@ -4270,7 +4270,7 @@ namespace {
42704270
auto type = (Target->checkAncestry(AncestryFlags::ObjC)
42714271
? IGM.Context.getAnyObjectType()
42724272
: IGM.Context.TheNativeObjectType);
4273-
if (IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
4273+
if (IGM.isEmbeddedWithExistentials()) {
42744274
return irgen::emitValueWitnessTable(IGM, type, false, false);
42754275
}
42764276
auto wtable = IGM.getAddrOfValueWitnessTable(type);
@@ -5577,9 +5577,8 @@ void irgen::emitLazyClassMetadata(IRGenModule &IGM, CanType classTy) {
55775577
// Might already be emitted, skip if that's the case.
55785578
auto entity =
55795579
LinkEntity::forTypeMetadata(classTy, TypeMetadataAddress::AddressPoint);
5580-
5581-
auto isEmbeddedWithExistentials = IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
5582-
if (isEmbeddedWithExistentials) {
5580+
auto hasEmbeddedWithExistentials = IGM.isEmbeddedWithExistentials();
5581+
if (hasEmbeddedWithExistentials) {
55835582
entity = LinkEntity::forTypeMetadata(classTy, TypeMetadataAddress::FullMetadata);
55845583
}
55855584
auto *existingVar = cast<llvm::GlobalVariable>(
@@ -5588,7 +5587,7 @@ void irgen::emitLazyClassMetadata(IRGenModule &IGM, CanType classTy) {
55885587
return;
55895588
}
55905589

5591-
if (isEmbeddedWithExistentials) {
5590+
if (hasEmbeddedWithExistentials) {
55925591
emitEmbeddedClassMetadata(IGM, classTy->getClassOrBoundGenericClass());
55935592
return;
55945593
}
@@ -6225,8 +6224,7 @@ void irgen::emitStructMetadata(IRGenModule &IGM, StructDecl *structDecl) {
62256224

62266225
bool isPattern;
62276226
bool canBeConstant;
6228-
bool hasEmbeddedExistentialFeature =
6229-
IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
6227+
bool hasEmbeddedExistentialFeature = IGM.isEmbeddedWithExistentials();
62306228
if (structDecl->isGenericContext()) {
62316229
assert(!hasEmbeddedExistentialFeature);
62326230
GenericStructMetadataBuilder builder(IGM, structDecl, init);
@@ -6268,7 +6266,7 @@ void irgen::emitSpecializedGenericStructMetadata(IRGenModule &IGM, CanType type,
62686266
bool isPattern = false;
62696267

62706268
SpecializedGenericStructMetadataBuilder builder(IGM, type, decl, init);
6271-
if (IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
6269+
if (IGM.isEmbeddedWithExistentials()) {
62726270
builder.embeddedLayout();
62736271
} else {
62746272
builder.layout();
@@ -6315,7 +6313,7 @@ class TupleMetadataBuilder : public TupleMetadataVisitor<TupleMetadataBuilder> {
63156313
};
63166314
} // end anonymous namespace
63176315
void irgen::emitLazyTupleMetadata(IRGenModule &IGM, CanType tupleTy) {
6318-
assert(IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials));
6316+
assert(IGM.isEmbeddedWithExistentials());
63196317
assert(isa<TupleType>(tupleTy));
63206318

63216319
Type ty = tupleTy.getPointer();
@@ -6374,7 +6372,7 @@ class FunctionMetadataBuilder : public FunctionMetadataVisitor<FunctionMetadataB
63746372
} // end anonymous namespace
63756373

63766374
void irgen::emitLazyFunctionMetadata(IRGenModule &IGM, CanType funTy) {
6377-
assert(IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials));
6375+
assert(IGM.isEmbeddedWithExistentials());
63786376
assert(isa<FunctionType>(funTy));
63796377

63806378
Type ty = funTy.getPointer();
@@ -6771,8 +6769,7 @@ void irgen::emitEnumMetadata(IRGenModule &IGM, EnumDecl *theEnum) {
67716769

67726770
bool isPattern;
67736771
bool canBeConstant;
6774-
bool hasEmbeddedExistentialFeature =
6775-
IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
6772+
bool hasEmbeddedExistentialFeature = IGM.isEmbeddedWithExistentials();
67766773
if (theEnum->isGenericContext()) {
67776774
assert(!hasEmbeddedExistentialFeature);
67786775
GenericEnumMetadataBuilder builder(IGM, theEnum, init);
@@ -6813,7 +6810,8 @@ void irgen::emitSpecializedGenericEnumMetadata(IRGenModule &IGM, CanType type,
68136810
init.setPacked(true);
68146811

68156812
SpecializedGenericEnumMetadataBuilder builder(IGM, type, decl, init);
6816-
if (IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
6813+
6814+
if (IGM.isEmbeddedWithExistentials()) {
68176815
builder.embeddedLayout();
68186816
} else {
68196817
builder.layout();
@@ -7202,8 +7200,7 @@ void irgen::emitForeignTypeMetadata(IRGenModule &IGM, NominalTypeDecl *decl) {
72027200
auto init = builder.beginStruct();
72037201
init.setPacked(true);
72047202

7205-
auto isEmbedded =
7206-
IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
7203+
auto isEmbedded = IGM.isEmbeddedWithExistentials();
72077204

72087205
if (auto classDecl = dyn_cast<ClassDecl>(decl)) {
72097206
if (classDecl->isForeignReferenceType()) {

0 commit comments

Comments
 (0)