Skip to content

Commit 331f4a5

Browse files
committed
IRGen: Hollow out NecessaryBindings
This removes the "optimization" where a function type, metatype or tuple type was split up into structural components, because it seems that in general we need this structural type metadata again. Similarly, this no longer tries to split up dependent concrete conformances and instead passes the witness table in the context. This makes the context larger potentially, but it avoids calls to metadata access functions and swift_getWitnessTable() every time the closure is invoked.
1 parent b154a0b commit 331f4a5

13 files changed

+162
-293
lines changed

include/swift/IRGen/GenericRequirement.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class GenericRequirement {
7676
}
7777

7878
static GenericRequirement forShape(CanType type) {
79-
assert(!isa<PackType>(type));
8079
assert(type->isParameterPack() || isa<PackArchetypeType>(type));
8180
return GenericRequirement(Kind::Shape, type, nullptr);
8281
}
@@ -92,7 +91,6 @@ class GenericRequirement {
9291
}
9392

9493
static GenericRequirement forMetadata(CanType type) {
95-
assert(!isa<PackType>(type));
9694
auto kind = ((type->isParameterPack() ||
9795
isa<PackArchetypeType>(type))
9896
? Kind::MetadataPack : Kind::Metadata);
@@ -110,7 +108,6 @@ class GenericRequirement {
110108
}
111109

112110
static GenericRequirement forWitnessTable(CanType type, ProtocolDecl *proto) {
113-
assert(!isa<PackType>(type));
114111
auto kind = ((type->isParameterPack() ||
115112
isa<PackArchetypeType>(type))
116113
? Kind::WitnessTablePack

lib/IRGen/GenArchetype.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ withOpaqueTypeGenericArgs(IRGenFunction &IGF,
441441
opaqueDecl->getGenericSignature().getCanonicalSignature(),
442442
[&](GenericRequirement reqt) {
443443
auto arg = emitGenericRequirementFromSubstitutions(
444-
IGF, reqt, archetype->getSubstitutions(),
445-
MetadataState::Abstract);
444+
IGF, reqt, MetadataState::Abstract,
445+
archetype->getSubstitutions());
446446
args.push_back(arg);
447447
types.push_back(args.back()->getType());
448448
});

lib/IRGen/GenKeyPath.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ bindPolymorphicArgumentsFromComponentIndices(IRGenFunction &IGF,
8989
args =
9090
IGF.Builder.CreateInBoundsGEP(IGF.IGM.Int8Ty, args, genericArgsOffset);
9191
}
92+
9293
bindFromGenericRequirementsBuffer(
9394
IGF, requirements,
9495
Address(args, IGF.IGM.Int8Ty, IGF.IGM.getPointerAlignment()),
95-
MetadataState::Complete, [&](CanType t) {
96-
return genericEnv->mapTypeIntoContext(t)->getCanonicalType();
97-
});
96+
MetadataState::Complete, genericEnv->getForwardingSubstitutionMap());
9897
}
9998

10099
static llvm::Function *
@@ -295,9 +294,7 @@ getLayoutFunctionForComputedComponent(IRGenModule &IGM,
295294
bindFromGenericRequirementsBuffer(
296295
IGF, requirements,
297296
Address(args, IGM.Int8Ty, IGF.IGM.getPointerAlignment()),
298-
MetadataState::Complete, [&](CanType t) {
299-
return genericEnv->mapTypeIntoContext(t)->getCanonicalType();
300-
});
297+
MetadataState::Complete, genericEnv->getForwardingSubstitutionMap());
301298
}
302299

303300
// Run through the captured index types to determine the size and alignment
@@ -583,9 +580,7 @@ getInitializerForComputedComponent(IRGenModule &IGM,
583580
bindFromGenericRequirementsBuffer(
584581
IGF, requirements,
585582
Address(src, IGM.Int8Ty, IGF.IGM.getPointerAlignment()),
586-
MetadataState::Complete, [&](CanType t) {
587-
return genericEnv->mapTypeIntoContext(t)->getCanonicalType();
588-
});
583+
MetadataState::Complete, genericEnv->getForwardingSubstitutionMap());
589584

590585
} else {
591586
offset = llvm::ConstantInt::get(IGM.SizeTy, 0);

lib/IRGen/GenMeta.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,11 +2318,10 @@ namespace {
23182318
bindFromGenericRequirementsBuffer(
23192319
IGF, requirements,
23202320
Address(bindingsBufPtr, IGM.Int8Ty, IGM.getPointerAlignment()),
2321-
MetadataState::Complete, [&](CanType t) {
2322-
return genericEnv ? genericEnv->mapTypeIntoContext(t)
2323-
->getCanonicalType()
2324-
: t;
2325-
});
2321+
MetadataState::Complete,
2322+
(genericEnv
2323+
? genericEnv->getForwardingSubstitutionMap()
2324+
: SubstitutionMap()));
23262325
}
23272326

23282327
SmallVector<llvm::BasicBlock *, 4> conditionalTypes;

0 commit comments

Comments
 (0)