@@ -1688,6 +1688,52 @@ TypeConverter::convertExistentialMetatypeType(ExistentialMetatypeType *T) {
1688
1688
baseTI);
1689
1689
}
1690
1690
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
+
1691
1737
// / Emit protocol witness table pointers for the given protocol conformances,
1692
1738
// / passing each emitted witness table index into the given function body.
1693
1739
static void forEachProtocolWitnessTable (
@@ -1766,8 +1812,8 @@ Address irgen::emitOpenExistentialBox(IRGenFunction &IGF,
1766
1812
2 * IGF.IGM .getPointerSize ());
1767
1813
auto witness = IGF.Builder .CreateLoad (witnessAddr);
1768
1814
1769
- IGF. bindArchetype (openedArchetype, metadata, MetadataState::Complete,
1770
- witness);
1815
+ bindArchetype (IGF, openedArchetype, metadata, MetadataState::Complete,
1816
+ witness);
1771
1817
return box.getAddress ();
1772
1818
}
1773
1819
@@ -2093,8 +2139,8 @@ irgen::emitClassExistentialProjection(IRGenFunction &IGF,
2093
2139
baseTy,
2094
2140
sigFn,
2095
2141
/* allow artificial*/ false );
2096
- IGF. bindArchetype (openedArchetype, metadata, MetadataState::Complete,
2097
- wtables);
2142
+ bindArchetype (IGF, openedArchetype, metadata, MetadataState::Complete,
2143
+ wtables);
2098
2144
2099
2145
return value;
2100
2146
}
@@ -2143,8 +2189,8 @@ irgen::emitExistentialMetatypeProjection(IRGenFunction &IGF,
2143
2189
}
2144
2190
2145
2191
auto openedArchetype = cast<ArchetypeType>(targetType.getInstanceType ());
2146
- IGF. bindArchetype (openedArchetype, metatype, MetadataState::Complete,
2147
- wtables);
2192
+ bindArchetype (IGF, openedArchetype, metatype, MetadataState::Complete,
2193
+ wtables);
2148
2194
2149
2195
return value;
2150
2196
}
@@ -2484,8 +2530,8 @@ Address irgen::emitOpaqueBoxedExistentialProjection(
2484
2530
wtables.push_back (IGF.Builder .CreateLoad (wtableAddr));
2485
2531
}
2486
2532
2487
- IGF. bindArchetype (openedArchetype, metadata, MetadataState::Complete,
2488
- wtables);
2533
+ bindArchetype (IGF, openedArchetype, metadata, MetadataState::Complete,
2534
+ wtables);
2489
2535
}
2490
2536
2491
2537
return valueAddr;
@@ -2503,8 +2549,8 @@ Address irgen::emitOpaqueBoxedExistentialProjection(
2503
2549
for (unsigned i = 0 , n = layout.getNumTables (); i != n; ++i) {
2504
2550
wtables.push_back (layout.loadWitnessTable (IGF, base, i));
2505
2551
}
2506
- IGF. bindArchetype (openedArchetype, metadata, MetadataState::Complete,
2507
- wtables);
2552
+ bindArchetype (IGF, openedArchetype, metadata, MetadataState::Complete,
2553
+ wtables);
2508
2554
}
2509
2555
2510
2556
auto *projectFunc =
0 commit comments