Skip to content

Commit 1f7c2fa

Browse files
committed
[NFC] Clean up IRGen generic-requirements collection APIs
1 parent e7f6c8c commit 1f7c2fa

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,7 @@ void EmitPolymorphicArguments::emit(SubstitutionMap subs,
31723172
// For now, treat all archetypes independently.
31733173
enumerateUnfulfilledRequirements([&](GenericRequirement requirement) {
31743174
llvm::Value *requiredValue =
3175-
emitGenericRequirementFromSubstitutions(IGF, Generics, M,
3175+
emitGenericRequirementFromSubstitutions(IGF, Generics,
31763176
requirement, subs);
31773177
out.add(requiredValue);
31783178
});
@@ -3294,14 +3294,17 @@ NecessaryBindings NecessaryBindings::computeBindings(
32943294
/// that takes the (thick) parent metatype as an argument.
32953295
GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM,
32963296
NominalTypeDecl *typeDecl)
3297-
: TheDecl(typeDecl) {
3297+
: GenericTypeRequirements(IGM, typeDecl->getGenericSignatureOfContext()) {}
3298+
3299+
GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM,
3300+
GenericSignature ncGenerics) {
32983301
// We only need to do something here if the declaration context is
32993302
// somehow generic.
3300-
auto ncGenerics = typeDecl->getGenericSignatureOfContext();
33013303
if (!ncGenerics || ncGenerics->areAllParamsConcrete()) return;
33023304

33033305
// Construct a representative function type.
33043306
auto generics = ncGenerics.getCanonicalSignature();
3307+
Generics = generics;
33053308
auto fnType = SILFunctionType::get(generics, SILFunctionType::ExtInfo(),
33063309
SILCoroutineKind::None,
33073310
/*callee*/ ParameterConvention::Direct_Unowned,
@@ -3345,12 +3348,9 @@ void GenericTypeRequirements::emitInitOfBuffer(IRGenFunction &IGF,
33453348
Address buffer) {
33463349
if (Requirements.empty()) return;
33473350

3348-
auto generics =
3349-
TheDecl->getGenericSignatureOfContext().getCanonicalSignature();
3350-
auto &module = *TheDecl->getParentModule();
33513351
emitInitOfGenericRequirementsBuffer(IGF, Requirements, buffer,
33523352
[&](GenericRequirement requirement) {
3353-
return emitGenericRequirementFromSubstitutions(IGF, generics, module,
3353+
return emitGenericRequirementFromSubstitutions(IGF, Generics,
33543354
requirement, subs);
33553355
});
33563356
}
@@ -3383,7 +3383,6 @@ void irgen::emitInitOfGenericRequirementsBuffer(IRGenFunction &IGF,
33833383
llvm::Value *
33843384
irgen::emitGenericRequirementFromSubstitutions(IRGenFunction &IGF,
33853385
CanGenericSignature generics,
3386-
ModuleDecl &module,
33873386
GenericRequirement requirement,
33883387
SubstitutionMap subs) {
33893388
CanType depTy = requirement.TypeParameter;

lib/IRGen/GenericArguments.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ struct GenericArguments {
7373
}
7474

7575
void collect(IRGenFunction &IGF, CanType type) {
76-
auto *decl = type.getNominalOrBoundGenericNominal();
77-
GenericTypeRequirements requirements(IGF.IGM, decl);
78-
76+
auto decl = type.getNominalOrBoundGenericNominal();
7977
auto subs = type->getContextSubstitutionMap(IGF.IGM.getSwiftModule(), decl);
78+
collect(IGF, subs);
79+
}
80+
81+
void collect(IRGenFunction &IGF, SubstitutionMap subs) {
82+
GenericTypeRequirements requirements(IGF.IGM, subs.getGenericSignature());
83+
8084
requirements.enumerateFulfillments(
8185
IGF.IGM, subs,
8286
[&](unsigned reqtIndex, CanType type, ProtocolConformanceRef conf) {
@@ -87,7 +91,7 @@ struct GenericArguments {
8791
}
8892
});
8993

90-
collectTypes(IGF.IGM, decl);
94+
collectTypes(IGF.IGM, requirements);
9195
assert(Types.size() == Values.size());
9296
}
9397
};

lib/IRGen/GenericRequirement.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void enumerateGenericSignatureRequirements(CanGenericSignature signature,
6060
llvm::Value *
6161
emitGenericRequirementFromSubstitutions(IRGenFunction &IGF,
6262
CanGenericSignature signature,
63-
ModuleDecl &module,
6463
GenericRequirement requirement,
6564
SubstitutionMap subs);
6665

@@ -99,11 +98,12 @@ void bindFromGenericRequirementsBuffer(IRGenFunction &IGF,
9998
/// root conformances of the context established by the type, again minus
10099
/// anything fulfillable from its parent type metadata).
101100
class GenericTypeRequirements {
102-
NominalTypeDecl *TheDecl;
103101
llvm::SmallVector<GenericRequirement, 4> Requirements;
102+
CanGenericSignature Generics;
104103

105104
public:
106105
GenericTypeRequirements(IRGenModule &IGM, NominalTypeDecl *decl);
106+
GenericTypeRequirements(IRGenModule &IGM, GenericSignature sig);
107107

108108
/// Return the layout chunks.
109109
ArrayRef<GenericRequirement> getRequirements() const {

lib/IRGen/IRGenSIL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6473,8 +6473,7 @@ void IRGenSILFunction::visitKeyPathInst(swift::KeyPathInst *I) {
64736473
emitInitOfGenericRequirementsBuffer(*this, requirements, argsBuf,
64746474
[&](GenericRequirement reqt) -> llvm::Value * {
64756475
return emitGenericRequirementFromSubstitutions(*this, sig,
6476-
*IGM.getSwiftModule(),
6477-
reqt, subs);
6476+
reqt, subs);
64786477
});
64796478
}
64806479

0 commit comments

Comments
 (0)