Skip to content

Commit 0d1e507

Browse files
committed
IRGen: Clean up some crusty old code
1 parent 8d8fdb7 commit 0d1e507

File tree

4 files changed

+28
-69
lines changed

4 files changed

+28
-69
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,8 +2586,7 @@ void irgen::emitLazyTypeContextDescriptor(IRGenModule &IGM,
25862586
eraseExistingTypeContextDescriptor(IGM, type);
25872587

25882588
bool hasLayoutString = false;
2589-
auto lowered = getLoweredTypeInPrimaryContext(
2590-
IGM, type->getDeclaredType()->getCanonicalType());
2589+
auto lowered = getLoweredTypeInPrimaryContext(IGM, type);
25912590
auto &ti = IGM.getTypeInfo(lowered);
25922591
auto *typeLayoutEntry =
25932592
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);
@@ -3131,8 +3130,7 @@ namespace {
31313130
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
31323131
!IGM.getOptions().EnableLayoutStringValueWitnesses)
31333132
return nullptr;
3134-
auto lowered = getLoweredTypeInPrimaryContext(
3135-
IGM, Target->getDeclaredType()->getCanonicalType());
3133+
auto lowered = getLoweredTypeInPrimaryContext(IGM, Target);
31363134
auto &ti = IGM.getTypeInfo(lowered);
31373135
auto *typeLayoutEntry =
31383136
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);
@@ -3792,8 +3790,7 @@ namespace {
37923790
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
37933791
!IGM.getOptions().EnableLayoutStringValueWitnesses)
37943792
return nullptr;
3795-
auto lowered = getLoweredTypeInPrimaryContext(
3796-
IGM, Target->getDeclaredType()->getCanonicalType());
3793+
auto lowered = getLoweredTypeInPrimaryContext(IGM, Target);
37973794
auto &ti = IGM.getTypeInfo(lowered);
37983795
auto *typeLayoutEntry =
37993796
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);
@@ -5042,8 +5039,7 @@ namespace {
50425039
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
50435040
!IGM.getOptions().EnableLayoutStringValueWitnesses)
50445041
return nullptr;
5045-
auto lowered = getLoweredTypeInPrimaryContext(
5046-
IGM, Target->getDeclaredType()->getCanonicalType());
5042+
auto lowered = getLoweredTypeInPrimaryContext(IGM, Target);
50475043
auto &ti = IGM.getTypeInfo(lowered);
50485044
auto *typeLayoutEntry =
50495045
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);
@@ -5136,10 +5132,8 @@ namespace {
51365132
getValueWitnessTableForGenericValueType(IRGenModule &IGM,
51375133
NominalTypeDecl *decl,
51385134
bool &dependent) {
5139-
CanType unboundType
5140-
= decl->getDeclaredType()->getCanonicalType();
5141-
5142-
dependent = hasDependentValueWitnessTable(IGM, unboundType);
5135+
dependent = hasDependentValueWitnessTable(IGM, decl);
5136+
CanType unboundType = decl->getDeclaredType()->getCanonicalType();
51435137
return emitValueWitnessTable(IGM, unboundType, dependent,
51445138
/*relative reference*/ true);
51455139
}
@@ -5461,8 +5455,7 @@ namespace {
54615455
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
54625456
!IGM.getOptions().EnableLayoutStringValueWitnesses)
54635457
return nullptr;
5464-
auto lowered = getLoweredTypeInPrimaryContext(
5465-
IGM, Target->getDeclaredType()->getCanonicalType());
5458+
auto lowered = getLoweredTypeInPrimaryContext(IGM, Target);
54665459
auto &ti = IGM.getTypeInfo(lowered);
54675460
auto *typeLayoutEntry =
54685461
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);

lib/IRGen/GenReflection.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,19 +1079,20 @@ void IRGenModule::emitBuiltinTypeMetadataRecord(CanType builtinType) {
10791079

10801080
class MultiPayloadEnumDescriptorBuilder : public ReflectionMetadataBuilder {
10811081
CanType type;
1082+
CanType typeInContext;
10821083
const FixedTypeInfo *ti;
10831084

10841085
public:
10851086
MultiPayloadEnumDescriptorBuilder(IRGenModule &IGM,
10861087
const NominalTypeDecl *nominalDecl)
10871088
: ReflectionMetadataBuilder(IGM) {
10881089
type = nominalDecl->getDeclaredType()->getCanonicalType();
1089-
ti = &cast<FixedTypeInfo>(IGM.getTypeInfoForUnlowered(
1090-
nominalDecl->getDeclaredTypeInContext()->getCanonicalType()));
1090+
typeInContext = nominalDecl->getDeclaredTypeInContext()->getCanonicalType();
1091+
ti = &cast<FixedTypeInfo>(IGM.getTypeInfoForUnlowered(typeInContext));
10911092
}
10921093

10931094
void layout() override {
1094-
auto &strategy = getEnumImplStrategy(IGM, getFormalTypeInPrimaryContext(type));
1095+
auto &strategy = getEnumImplStrategy(IGM, typeInContext);
10951096
bool isMPE = strategy.getElementsWithPayload().size() > 1;
10961097
assert(isMPE && "Cannot emit Multi-Payload Enum data for an enum that doesn't have multiple payloads");
10971098

lib/IRGen/GenValueWitness.cpp

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -386,54 +386,22 @@ static Address getArgAsBuffer(IRGenFunction &IGF,
386386
getFixedBufferAlignment(IGF.IGM));
387387
}
388388

389-
static CanType getFormalTypeInContext(CanType abstractType, DeclContext *dc) {
390-
// Map the parent of any non-generic nominal type.
391-
if (auto nominalType = dyn_cast<NominalType>(abstractType)) {
392-
// If it doesn't have a parent, or the parent doesn't need remapping,
393-
// do nothing.
394-
auto abstractParentType = nominalType.getParent();
395-
if (!abstractParentType) return abstractType;
396-
auto parentType = getFormalTypeInContext(abstractParentType, dc);
397-
if (abstractParentType == parentType) return abstractType;
398-
399-
// Otherwise, rebuild the type.
400-
return CanType(NominalType::get(nominalType->getDecl(), parentType,
401-
nominalType->getDecl()->getASTContext()));
402-
403-
// Map unbound types into their defining context.
404-
} else if (auto ugt = dyn_cast<UnboundGenericType>(abstractType)) {
405-
return dc->mapTypeIntoContext(ugt->getDecl()->getDeclaredInterfaceType())
406-
->getCanonicalType();
407-
408-
// Everything else stays the same.
409-
} else {
410-
return abstractType;
389+
/// Don't add new callers of this, it doesn't make any sense.
390+
static CanType getFormalTypeInPrimaryContext(CanType abstractType) {
391+
auto *nominal = abstractType.getAnyNominal();
392+
if (abstractType->isEqual(nominal->getDeclaredType())) {
393+
return nominal->mapTypeIntoContext(nominal->getDeclaredInterfaceType())
394+
->getCanonicalType();
411395
}
412-
}
413396

414-
/// Given an abstract type --- a type possibly expressed in terms of
415-
/// unbound generic types --- return the formal type within the type's
416-
/// primary defining context.
417-
CanType irgen::getFormalTypeInPrimaryContext(CanType abstractType) {
418-
if (auto nominal = abstractType.getAnyNominal())
419-
return getFormalTypeInContext(abstractType, nominal);
397+
assert(!abstractType->hasUnboundGenericType());
420398
return abstractType;
421399
}
422400

423401
SILType irgen::getLoweredTypeInPrimaryContext(IRGenModule &IGM,
424-
CanType abstractType) {
425-
if (auto boundGenericType = dyn_cast<BoundGenericType>(abstractType)) {
426-
CanType concreteFormalType = getFormalTypeInPrimaryContext(abstractType);
427-
428-
auto concreteLoweredType = IGM.getLoweredType(concreteFormalType);
429-
const auto *boundConcreteTI = &IGM.getTypeInfo(concreteLoweredType);
430-
auto packing = boundConcreteTI->getFixedPacking(IGM);
431-
432-
abstractType =
433-
boundGenericType->getDecl()->getDeclaredType()->getCanonicalType();
434-
}
435-
CanType concreteFormalType = getFormalTypeInPrimaryContext(abstractType);
436-
402+
NominalTypeDecl *type) {
403+
CanType concreteFormalType = type->mapTypeIntoContext(
404+
type->getDeclaredInterfaceType())->getCanonicalType();
437405
return IGM.getLoweredType(concreteFormalType);
438406
}
439407

@@ -1191,8 +1159,9 @@ static void addValueWitnesses(IRGenModule &IGM, ConstantStructBuilder &B,
11911159
/// True if a type has a generic-parameter-dependent value witness table.
11921160
/// Currently, this is true if the size and/or alignment of the type is
11931161
/// dependent on its generic parameters.
1194-
bool irgen::hasDependentValueWitnessTable(IRGenModule &IGM, CanType ty) {
1195-
return !IGM.getTypeInfoForUnlowered(getFormalTypeInPrimaryContext(ty)).isFixedSize();
1162+
bool irgen::hasDependentValueWitnessTable(IRGenModule &IGM, NominalTypeDecl *decl) {
1163+
auto ty = decl->mapTypeIntoContext(decl->getDeclaredInterfaceType());
1164+
return !IGM.getTypeInfoForUnlowered(ty).isFixedSize();
11961165
}
11971166

11981167
static void addValueWitnessesForAbstractType(IRGenModule &IGM,
@@ -1364,7 +1333,8 @@ ConstantReference irgen::emitValueWitnessTable(IRGenModule &IGM,
13641333
// We should never be making a pattern if the layout isn't fixed.
13651334
// The reverse can be true for types whose layout depends on
13661335
// resilient types.
1367-
assert((!isPattern || hasDependentValueWitnessTable(IGM, abstractType)) &&
1336+
assert((!isPattern || hasDependentValueWitnessTable(
1337+
IGM, abstractType->getAnyNominal())) &&
13681338
"emitting VWT pattern for fixed-layout type");
13691339

13701340
ConstantInitBuilder builder(IGM);

lib/IRGen/GenValueWitness.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace irgen {
3636
/// True if a type has a generic-parameter-dependent value witness table.
3737
/// Currently, this is true if the size and/or alignment of the type is
3838
/// dependent on its generic parameters.
39-
bool hasDependentValueWitnessTable(IRGenModule &IGM, CanType ty);
39+
bool hasDependentValueWitnessTable(IRGenModule &IGM, NominalTypeDecl *decl);
4040

4141
/// Emit a value-witness table for the given type.
4242
///
@@ -47,13 +47,8 @@ namespace irgen {
4747
bool isPattern,
4848
bool relativeReference);
4949

50-
/// Given an abstract type --- a type possibly expressed in terms of
51-
/// unbound generic types --- return the formal type within the type's
52-
/// primary defining context.
53-
CanType getFormalTypeInPrimaryContext(CanType abstractType);
54-
5550
SILType getLoweredTypeInPrimaryContext(IRGenModule &IGM,
56-
CanType abstractType);
51+
NominalTypeDecl *type);
5752
}
5853
}
5954

0 commit comments

Comments
 (0)