Skip to content

Commit 38e6420

Browse files
committed
[NFC] SIL: TypeDependentOperandCollector uses ctx.
Take a SILInstructionContext instead of a SILFunction because the latter isn't always available.
1 parent c64d56c commit 38e6420

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

lib/SIL/IR/SILInstructions.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TypeDependentOperandCollector {
7070
}
7171

7272
void addTo(SmallVectorImpl<SILValue> &typeDependentOperands,
73-
SILFunction &f);
73+
SILInstructionContext context);
7474
};
7575

7676
}
@@ -113,15 +113,18 @@ void TypeDependentOperandCollector::collect(SubstitutionMap subs) {
113113
/// Given that we've collected a set of type dependencies, add operands
114114
/// for those dependencies to the given vector.
115115
void TypeDependentOperandCollector::addTo(SmallVectorImpl<SILValue> &operands,
116-
SILFunction &F) {
116+
SILInstructionContext context) {
117117
for (GenericEnvironment *genericEnv : genericEnvs) {
118-
SILValue def = F.getModule().getLocalGenericEnvironmentDef(genericEnv, &F);
119-
assert(def->getFunction() == &F &&
118+
SILValue def = context.getModule().getLocalGenericEnvironmentDef(
119+
genericEnv, context.getFunction());
120+
assert(def->getFunction() == context.getFunction() &&
120121
"def of local environment is in wrong function");
121122
operands.push_back(def);
122123
}
123-
if (hasDynamicSelf)
124-
operands.push_back(F.getDynamicSelfMetadata());
124+
if (hasDynamicSelf) {
125+
assert(context.getFunction());
126+
operands.push_back(context.getFunction()->getDynamicSelfMetadata());
127+
}
125128
}
126129

127130
/// Collects all root local archetypes from a type and a substitution list, and
@@ -130,12 +133,22 @@ void TypeDependentOperandCollector::addTo(SmallVectorImpl<SILValue> &operands,
130133
/// of corresponding operands for the instruction being formed, because we need
131134
/// to reserve enough memory for these operands.
132135
template <class... Sources>
133-
static void collectTypeDependentOperands(
134-
SmallVectorImpl<SILValue> &typeDependentOperands,
135-
SILFunction &F, Sources &&... sources) {
136+
static void
137+
collectTypeDependentOperands(SmallVectorImpl<SILValue> &typeDependentOperands,
138+
SILInstructionContext context,
139+
Sources &&...sources) {
136140
TypeDependentOperandCollector collector;
137141
collector.collectAll(std::forward<Sources>(sources)...);
138-
collector.addTo(typeDependentOperands, F);
142+
collector.addTo(typeDependentOperands, context);
143+
}
144+
145+
template <class... Sources>
146+
static void
147+
collectTypeDependentOperands(SmallVectorImpl<SILValue> &typeDependentOperands,
148+
SILFunction &function, Sources &&...sources) {
149+
collectTypeDependentOperands(typeDependentOperands,
150+
SILInstructionContext::forFunction(function),
151+
std::forward<Sources>(sources)...);
139152
}
140153

141154
//===----------------------------------------------------------------------===//
@@ -2493,7 +2506,7 @@ OpenPackElementInst *OpenPackElementInst::create(
24932506
PackType *packSubstitution) {
24942507
collector.collect(packSubstitution->getCanonicalType());
24952508
});
2496-
collector.addTo(typeDependentOperands, F);
2509+
collector.addTo(typeDependentOperands, SILInstructionContext::forFunction(F));
24972510

24982511
SILType type = SILType::getSILTokenType(F.getASTContext());
24992512

0 commit comments

Comments
 (0)