Skip to content

Commit 349d37a

Browse files
committed
[embedded] Start fencing parts of IRGen that are not compatible with embedded Swift.
1 parent 52cea42 commit 349d37a

9 files changed

+70
-4
lines changed

include/swift/IRGen/Linking.h

+22
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ enum class TypeMetadataAddress {
8585
FullMetadata,
8686
};
8787

88+
inline bool isEmbedded(CanType t) {
89+
return t->getASTContext().LangOpts.hasFeature(Feature::Embedded);
90+
}
91+
92+
inline bool isEmbedded(Decl *d) {
93+
return d->getASTContext().LangOpts.hasFeature(Feature::Embedded);
94+
}
95+
96+
inline bool isEmbedded(const ProtocolConformance *c) {
97+
return c->getType()->getASTContext().LangOpts.hasFeature(Feature::Embedded);
98+
}
99+
88100
/// A link entity is some sort of named declaration, combined with all
89101
/// the information necessary to distinguish specific implementations
90102
/// of the declaration from each other.
@@ -828,13 +840,15 @@ class LinkEntity {
828840
static LinkEntity forTypeMetadata(CanType concreteType,
829841
TypeMetadataAddress addr) {
830842
assert(!isObjCImplementation(concreteType));
843+
assert(!isEmbedded(concreteType));
831844
LinkEntity entity;
832845
entity.setForType(Kind::TypeMetadata, concreteType);
833846
entity.Data |= LINKENTITY_SET_FIELD(MetadataAddress, unsigned(addr));
834847
return entity;
835848
}
836849

837850
static LinkEntity forTypeMetadataPattern(NominalTypeDecl *decl) {
851+
assert(!isEmbedded(decl));
838852
LinkEntity entity;
839853
entity.setForDecl(Kind::TypeMetadataPattern, decl);
840854
return entity;
@@ -891,25 +905,29 @@ class LinkEntity {
891905

892906
static LinkEntity forNominalTypeDescriptor(NominalTypeDecl *decl) {
893907
assert(!isObjCImplementation(decl));
908+
assert(!isEmbedded(decl));
894909
LinkEntity entity;
895910
entity.setForDecl(Kind::NominalTypeDescriptor, decl);
896911
return entity;
897912
}
898913

899914
static LinkEntity forNominalTypeDescriptorRecord(NominalTypeDecl *decl) {
900915
assert(!isObjCImplementation(decl));
916+
assert(!isEmbedded(decl));
901917
LinkEntity entity;
902918
entity.setForDecl(Kind::NominalTypeDescriptorRecord, decl);
903919
return entity;
904920
}
905921

906922
static LinkEntity forOpaqueTypeDescriptor(OpaqueTypeDecl *decl) {
923+
assert(!isEmbedded(decl));
907924
LinkEntity entity;
908925
entity.setForDecl(Kind::OpaqueTypeDescriptor, decl);
909926
return entity;
910927
}
911928

912929
static LinkEntity forOpaqueTypeDescriptorRecord(OpaqueTypeDecl *decl) {
930+
assert(!isEmbedded(decl));
913931
LinkEntity entity;
914932
entity.setForDecl(Kind::OpaqueTypeDescriptorRecord, decl);
915933
return entity;
@@ -990,6 +1008,7 @@ class LinkEntity {
9901008
}
9911009

9921010
static LinkEntity forValueWitness(CanType concreteType, ValueWitness witness) {
1011+
assert(!isEmbedded(concreteType));
9931012
LinkEntity entity;
9941013
entity.Pointer = concreteType.getPointer();
9951014
entity.Data = LINKENTITY_SET_FIELD(Kind, unsigned(Kind::ValueWitness))
@@ -998,6 +1017,7 @@ class LinkEntity {
9981017
}
9991018

10001019
static LinkEntity forValueWitnessTable(CanType type) {
1020+
assert(!isEmbedded(type));
10011021
LinkEntity entity;
10021022
entity.setForType(Kind::ValueWitnessTable, type);
10031023
return entity;
@@ -1027,13 +1047,15 @@ class LinkEntity {
10271047
}
10281048

10291049
static LinkEntity forProtocolWitnessTable(const RootProtocolConformance *C) {
1050+
assert(!isEmbedded(C));
10301051
LinkEntity entity;
10311052
entity.setForProtocolConformance(Kind::ProtocolWitnessTable, C);
10321053
return entity;
10331054
}
10341055

10351056
static LinkEntity
10361057
forProtocolWitnessTablePattern(const ProtocolConformance *C) {
1058+
assert(!isEmbedded(C));
10371059
LinkEntity entity;
10381060
entity.setForProtocolConformance(Kind::ProtocolWitnessTablePattern, C);
10391061
return entity;

lib/IRGen/GenClass.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,10 @@ void IRGenModule::emitClassDecl(ClassDecl *D) {
10751075
assert(!IRGen.hasLazyMetadata(D));
10761076

10771077
// Emit the class metadata.
1078-
emitClassMetadata(*this, D, fragileLayout, resilientLayout);
1079-
emitFieldDescriptor(D);
1078+
if (!D->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
1079+
emitClassMetadata(*this, D, fragileLayout, resilientLayout);
1080+
emitFieldDescriptor(D);
1081+
}
10801082

10811083
IRGen.addClassForEagerInitialization(D);
10821084
IRGen.addBackDeployedObjCActorInitialization(D);

lib/IRGen/GenDecl.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,13 @@ void IRGenModule::emitGlobalLists() {
12391239
// Eagerly emit functions that are externally visible. Functions that are
12401240
// dynamic replacements must also be eagerly emitted.
12411241
static bool isLazilyEmittedFunction(SILFunction &f, SILModule &m) {
1242+
// Embedded Swift only emits specialized function, so don't emit genreic
1243+
// functions, even if they're externally visible.
1244+
if (f.getASTContext().LangOpts.hasFeature(Feature::Embedded) &&
1245+
f.getLoweredFunctionType()->getSubstGenericSignature()) {
1246+
return true;
1247+
}
1248+
12421249
if (f.isPossiblyUsedExternally())
12431250
return false;
12441251

@@ -1403,6 +1410,18 @@ deleteAndReenqueueForEmissionValuesDependentOnCanonicalPrespecializedMetadataRec
14031410
/// Emit any lazy definitions (of globals or functions or whatever
14041411
/// else) that we require.
14051412
void IRGenerator::emitLazyDefinitions() {
1413+
if (SIL.getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
1414+
// In embedded Swift, the compiler cannot emit any metadata, etc.
1415+
assert(LazyTypeMetadata.empty() &&
1416+
LazySpecializedTypeMetadataRecords.empty() &&
1417+
LazyTypeContextDescriptors.empty() &&
1418+
LazyOpaqueTypeDescriptors.empty() &&
1419+
LazyFunctionDefinitions.empty() &&
1420+
LazyCanonicalSpecializedMetadataAccessors.empty() &&
1421+
LazyMetadataAccessors.empty() &&
1422+
LazyWitnessTables.empty());
1423+
}
1424+
14061425
while (!LazyTypeMetadata.empty() ||
14071426
!LazySpecializedTypeMetadataRecords.empty() ||
14081427
!LazyTypeContextDescriptors.empty() ||

lib/IRGen/GenEnum.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7158,7 +7158,8 @@ const TypeInfo *TypeConverter::convertEnumType(TypeBase *key, CanType type,
71587158
}
71597159

71607160
void IRGenModule::emitEnumDecl(EnumDecl *theEnum) {
7161-
if (!IRGen.hasLazyMetadata(theEnum)) {
7161+
if (!IRGen.hasLazyMetadata(theEnum) &&
7162+
!theEnum->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
71627163
emitEnumMetadata(*this, theEnum);
71637164
emitFieldDescriptor(theEnum);
71647165
}

lib/IRGen/GenExistential.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,11 @@ static void forEachProtocolWitnessTable(
17801780
assert(protocols.size() == witnessConformances.size() &&
17811781
"mismatched protocol conformances");
17821782

1783+
// Don't emit witness tables in embedded Swift.
1784+
if (srcType->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
1785+
return;
1786+
}
1787+
17831788
for (unsigned i = 0, e = protocols.size(); i < e; ++i) {
17841789
assert(protocols[i] == witnessConformances[i].getRequirement());
17851790
auto table = emitWitnessTableRef(IGF, srcType, srcMetadataCache,

lib/IRGen/GenMeta.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,10 @@ static void eraseExistingTypeContextDescriptor(IRGenModule &IGM,
25682568
void irgen::emitLazyTypeContextDescriptor(IRGenModule &IGM,
25692569
NominalTypeDecl *type,
25702570
RequireMetadata_t requireMetadata) {
2571+
if (type->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
2572+
return;
2573+
}
2574+
25712575
eraseExistingTypeContextDescriptor(IGM, type);
25722576

25732577
bool hasLayoutString = false;
@@ -6466,6 +6470,10 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
64666470
void IRGenModule::emitProtocolDecl(ProtocolDecl *protocol) {
64676471
PrettyStackTraceDecl stackTraceRAII("emitting metadata for", protocol);
64686472

6473+
if (protocol->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
6474+
return;
6475+
}
6476+
64696477
// Marker protocols are never emitted.
64706478
if (protocol->isMarkerProtocol())
64716479
return;

lib/IRGen/GenProto.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,10 @@ static void addWTableTypeMetadata(IRGenModule &IGM,
23942394
}
23952395

23962396
void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
2397+
if (Context.LangOpts.hasFeature(Feature::Embedded)) {
2398+
return;
2399+
}
2400+
23972401
// Don't emit a witness table if it is a declaration.
23982402
if (wt->isDeclaration())
23992403
return;
@@ -3353,6 +3357,8 @@ llvm::Value *irgen::emitWitnessTableRef(IRGenFunction &IGF,
33533357
CanType srcType,
33543358
llvm::Value **srcMetadataCache,
33553359
ProtocolConformanceRef conformance) {
3360+
assert(!srcType->getASTContext().LangOpts.hasFeature(Feature::Embedded));
3361+
33563362
auto proto = conformance.getRequirement();
33573363
assert(Lowering::TypeConverter::protocolRequiresWitnessTable(proto)
33583364
&& "protocol does not have witness tables?!");

lib/IRGen/GenStruct.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,8 @@ const TypeInfo *irgen::getPhysicalStructFieldTypeInfo(IRGenModule &IGM,
15971597
}
15981598

15991599
void IRGenModule::emitStructDecl(StructDecl *st) {
1600-
if (!IRGen.hasLazyMetadata(st)) {
1600+
if (!IRGen.hasLazyMetadata(st) &&
1601+
!st->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
16011602
emitStructMetadata(*this, st);
16021603
emitFieldDescriptor(st);
16031604
}

lib/IRGen/MetadataRequest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3303,6 +3303,8 @@ llvm::Value *IRGenFunction::emitTypeMetadataRef(CanType type) {
33033303
MetadataResponse
33043304
IRGenFunction::emitTypeMetadataRef(CanType type,
33053305
DynamicMetadataRequest request) {
3306+
assert(!type->getASTContext().LangOpts.hasFeature(Feature::Embedded));
3307+
33063308
type = IGM.getRuntimeReifiedType(type);
33073309
// Look through any opaque types we're allowed to.
33083310
type = IGM.substOpaqueTypesWithUnderlyingTypes(type);

0 commit comments

Comments
 (0)