[IRGen] Adopt reference storage type meta-programming macros

This commit also fixes reference storage extra inhabitant bugs.
This commit is contained in:
David Zarzycki
2018-05-20 19:11:49 -04:00
parent b91bde4d14
commit 057bbb366a
26 changed files with 2040 additions and 2333 deletions

View File

@@ -2255,23 +2255,15 @@ namespace {
// object.
auto &C = IGF.IGM.Context;
CanType referent;
switch (type->getOwnership()) {
case ReferenceOwnership::Strong:
llvm_unreachable("shouldn't be a ReferenceStorageType");
case ReferenceOwnership::Weak:
referent = type.getReferentType().getOptionalObjectType();
break;
case ReferenceOwnership::Unmanaged:
case ReferenceOwnership::Unowned:
referent = type.getReferentType();
break;
}
CanType referent = type.getReferentType();
CanType underlyingTy = referent;
if (auto Ty = referent.getOptionalObjectType())
underlyingTy = Ty;
// Reference storage types with witness tables need open-coded layouts.
// TODO: Maybe we could provide prefabs for 1 witness table.
if (referent.isExistentialType()) {
auto layout = referent.getExistentialLayout();
if (underlyingTy.isExistentialType()) {
auto layout = underlyingTy.getExistentialLayout();
for (auto *protoTy : layout.getProtocols()) {
auto *protoDecl = protoTy->getDecl();
if (IGF.getSILTypes().protocolRequiresWitnessTable(protoDecl))
@@ -2290,7 +2282,7 @@ namespace {
}
CanType valueWitnessReferent;
switch (getReferenceCountingForType(IGF.IGM, referent)) {
switch (getReferenceCountingForType(IGF.IGM, underlyingTy)) {
case ReferenceCounting::Unknown:
case ReferenceCounting::Block:
case ReferenceCounting::ObjC:
@@ -2311,7 +2303,7 @@ namespace {
// Get the reference storage type of the builtin object whose value
// witness we can borrow.
if (type->getOwnership() == ReferenceOwnership::Weak)
if (referent->getOptionalObjectType())
valueWitnessReferent = OptionalType::get(valueWitnessReferent)
->getCanonicalType();