Skip to content

Commit 8d8fdb7

Browse files
committed
IRGen: Make bindArchetype() a static helper in GenExistential.cpp to discourage future use
1 parent a892b91 commit 8d8fdb7

File tree

3 files changed

+56
-63
lines changed

3 files changed

+56
-63
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -363,51 +363,6 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
363363
return OpaqueArchetypeTypeInfo::create(storageType, abiAccessible);
364364
}
365365

366-
static void setMetadataRef(IRGenFunction &IGF,
367-
ArchetypeType *archetype,
368-
llvm::Value *metadata,
369-
MetadataState metadataState) {
370-
assert(metadata->getType() == IGF.IGM.TypeMetadataPtrTy);
371-
IGF.setUnscopedLocalTypeMetadata(CanType(archetype),
372-
MetadataResponse::forBounded(metadata, metadataState));
373-
}
374-
375-
static void setWitnessTable(IRGenFunction &IGF,
376-
ArchetypeType *archetype,
377-
unsigned protocolIndex,
378-
llvm::Value *wtable) {
379-
assert(wtable->getType() == IGF.IGM.WitnessTablePtrTy);
380-
assert(protocolIndex < archetype->getConformsTo().size());
381-
auto protocol = archetype->getConformsTo()[protocolIndex];
382-
IGF.setUnscopedLocalTypeData(CanType(archetype),
383-
LocalTypeDataKind::forAbstractProtocolWitnessTable(protocol),
384-
wtable);
385-
}
386-
387-
/// Inform IRGenFunction that the given archetype has the given value
388-
/// witness value within this scope.
389-
void IRGenFunction::bindArchetype(ArchetypeType *archetype,
390-
llvm::Value *metadata,
391-
MetadataState metadataState,
392-
ArrayRef<llvm::Value*> wtables) {
393-
// Set the metadata pointer.
394-
setTypeMetadataName(IGM, metadata, CanType(archetype));
395-
setMetadataRef(*this, archetype, metadata, metadataState);
396-
397-
// Set the protocol witness tables.
398-
399-
unsigned wtableI = 0;
400-
for (unsigned i = 0, e = archetype->getConformsTo().size(); i != e; ++i) {
401-
auto proto = archetype->getConformsTo()[i];
402-
if (!Lowering::TypeConverter::protocolRequiresWitnessTable(proto))
403-
continue;
404-
auto wtable = wtables[wtableI++];
405-
setProtocolWitnessTableName(IGM, wtable, CanType(archetype), proto);
406-
setWitnessTable(*this, archetype, i, wtable);
407-
}
408-
assert(wtableI == wtables.size());
409-
}
410-
411366
llvm::Value *irgen::emitDynamicTypeOfOpaqueArchetype(IRGenFunction &IGF,
412367
Address addr,
413368
SILType type) {

lib/IRGen/GenExistential.cpp

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,52 @@ TypeConverter::convertExistentialMetatypeType(ExistentialMetatypeType *T) {
16881688
baseTI);
16891689
}
16901690

1691+
static void setMetadataRef(IRGenFunction &IGF,
1692+
ArchetypeType *archetype,
1693+
llvm::Value *metadata,
1694+
MetadataState metadataState) {
1695+
assert(metadata->getType() == IGF.IGM.TypeMetadataPtrTy);
1696+
IGF.setUnscopedLocalTypeMetadata(CanType(archetype),
1697+
MetadataResponse::forBounded(metadata, metadataState));
1698+
}
1699+
1700+
static void setWitnessTable(IRGenFunction &IGF,
1701+
ArchetypeType *archetype,
1702+
unsigned protocolIndex,
1703+
llvm::Value *wtable) {
1704+
assert(wtable->getType() == IGF.IGM.WitnessTablePtrTy);
1705+
assert(protocolIndex < archetype->getConformsTo().size());
1706+
auto protocol = archetype->getConformsTo()[protocolIndex];
1707+
IGF.setUnscopedLocalTypeData(CanType(archetype),
1708+
LocalTypeDataKind::forAbstractProtocolWitnessTable(protocol),
1709+
wtable);
1710+
}
1711+
1712+
/// Inform IRGenFunction that the given archetype has the given value
1713+
/// witness value within this scope.
1714+
static void bindArchetype(IRGenFunction &IGF,
1715+
ArchetypeType *archetype,
1716+
llvm::Value *metadata,
1717+
MetadataState metadataState,
1718+
ArrayRef<llvm::Value*> wtables) {
1719+
// Set the metadata pointer.
1720+
setTypeMetadataName(IGF.IGM, metadata, CanType(archetype));
1721+
setMetadataRef(IGF, archetype, metadata, metadataState);
1722+
1723+
// Set the protocol witness tables.
1724+
1725+
unsigned wtableI = 0;
1726+
for (unsigned i = 0, e = archetype->getConformsTo().size(); i != e; ++i) {
1727+
auto proto = archetype->getConformsTo()[i];
1728+
if (!Lowering::TypeConverter::protocolRequiresWitnessTable(proto))
1729+
continue;
1730+
auto wtable = wtables[wtableI++];
1731+
setProtocolWitnessTableName(IGF.IGM, wtable, CanType(archetype), proto);
1732+
setWitnessTable(IGF, archetype, i, wtable);
1733+
}
1734+
assert(wtableI == wtables.size());
1735+
}
1736+
16911737
/// Emit protocol witness table pointers for the given protocol conformances,
16921738
/// passing each emitted witness table index into the given function body.
16931739
static void forEachProtocolWitnessTable(
@@ -1766,8 +1812,8 @@ Address irgen::emitOpenExistentialBox(IRGenFunction &IGF,
17661812
2 * IGF.IGM.getPointerSize());
17671813
auto witness = IGF.Builder.CreateLoad(witnessAddr);
17681814

1769-
IGF.bindArchetype(openedArchetype, metadata, MetadataState::Complete,
1770-
witness);
1815+
bindArchetype(IGF, openedArchetype, metadata, MetadataState::Complete,
1816+
witness);
17711817
return box.getAddress();
17721818
}
17731819

@@ -2093,8 +2139,8 @@ irgen::emitClassExistentialProjection(IRGenFunction &IGF,
20932139
baseTy,
20942140
sigFn,
20952141
/*allow artificial*/ false);
2096-
IGF.bindArchetype(openedArchetype, metadata, MetadataState::Complete,
2097-
wtables);
2142+
bindArchetype(IGF, openedArchetype, metadata, MetadataState::Complete,
2143+
wtables);
20982144

20992145
return value;
21002146
}
@@ -2143,8 +2189,8 @@ irgen::emitExistentialMetatypeProjection(IRGenFunction &IGF,
21432189
}
21442190

21452191
auto openedArchetype = cast<ArchetypeType>(targetType.getInstanceType());
2146-
IGF.bindArchetype(openedArchetype, metatype, MetadataState::Complete,
2147-
wtables);
2192+
bindArchetype(IGF, openedArchetype, metatype, MetadataState::Complete,
2193+
wtables);
21482194

21492195
return value;
21502196
}
@@ -2484,8 +2530,8 @@ Address irgen::emitOpaqueBoxedExistentialProjection(
24842530
wtables.push_back(IGF.Builder.CreateLoad(wtableAddr));
24852531
}
24862532

2487-
IGF.bindArchetype(openedArchetype, metadata, MetadataState::Complete,
2488-
wtables);
2533+
bindArchetype(IGF, openedArchetype, metadata, MetadataState::Complete,
2534+
wtables);
24892535
}
24902536

24912537
return valueAddr;
@@ -2503,8 +2549,8 @@ Address irgen::emitOpaqueBoxedExistentialProjection(
25032549
for (unsigned i = 0, n = layout.getNumTables(); i != n; ++i) {
25042550
wtables.push_back(layout.loadWitnessTable(IGF, base, i));
25052551
}
2506-
IGF.bindArchetype(openedArchetype, metadata, MetadataState::Complete,
2507-
wtables);
2552+
bindArchetype(IGF, openedArchetype, metadata, MetadataState::Complete,
2553+
wtables);
25082554
}
25092555

25102556
auto *projectFunc =

lib/IRGen/IRGenFunction.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,6 @@ class IRGenFunction {
561561
public:
562562
void emitFakeExplosion(const TypeInfo &type, Explosion &explosion);
563563

564-
//--- Declaration emission -----------------------------------------------------
565-
public:
566-
567-
void bindArchetype(ArchetypeType *type,
568-
llvm::Value *metadata,
569-
MetadataState metadataState,
570-
ArrayRef<llvm::Value*> wtables);
571-
572564
//--- Type emission ------------------------------------------------------------
573565
public:
574566
/// Look up a local type metadata reference, returning a null response

0 commit comments

Comments
 (0)