Skip to content

Commit 8bfc18b

Browse files
committed
Generalize the operation to get an opened environment for value
operations on a type
1 parent 81d9e68 commit 8bfc18b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/SILGen/SILGenFunction.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,12 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
25322532
return SGM.getAccessorDeclRef(accessor, F.getResilienceExpansion());
25332533
}
25342534

2535+
/// Given a lowered pack expansion type, produce a generic environment
2536+
/// sufficient for doing value operations on it and map the type into
2537+
/// the environment.
2538+
std::pair<GenericEnvironment*, SILType>
2539+
createOpenedElementValueEnvironment(SILType packExpansionTy);
2540+
25352541
/// Emit a dynamic loop over a single pack-expansion component of a pack.
25362542
///
25372543
/// \param formalPackType - a pack type with the right shape for the

lib/SILGen/SILGenPack.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,10 @@ static bool isPatternInvariantToExpansion(CanType patternType,
270270
});
271271
}
272272

273-
static std::pair<GenericEnvironment*, SILType>
274-
deriveOpenedElementTypeForPackExpansion(SILGenModule &SGM,
275-
CanPackExpansionType expansion) {
273+
std::pair<GenericEnvironment*, SILType>
274+
SILGenFunction::createOpenedElementValueEnvironment(SILType expansionTy) {
275+
auto expansion = expansionTy.castTo<PackExpansionType>();
276+
276277
// If the pattern type is invariant to the expansion, we don't need
277278
// to open anything.
278279
auto countArchetype = cast<PackArchetypeType>(expansion.getCountType());
@@ -300,10 +301,9 @@ void SILGenFunction::emitPartialDestroyPack(SILLocation loc, SILValue packAddr,
300301
unsigned componentIndex,
301302
SILValue limitWithinComponent) {
302303
auto packTy = packAddr->getType().castTo<SILPackType>();
303-
auto packExpansionTy =
304-
cast<PackExpansionType>(packTy->getElementType(componentIndex));
305304

306-
auto result = deriveOpenedElementTypeForPackExpansion(SGM, packExpansionTy);
305+
auto result = createOpenedElementValueEnvironment(
306+
packTy->getSILElementType(componentIndex));
307307
auto elementEnv = result.first;
308308
auto elementTy = result.second;
309309

@@ -322,11 +322,8 @@ void SILGenFunction::emitPartialDestroyTuple(SILLocation loc,
322322
CanPackType inducedPackType,
323323
unsigned componentIndex,
324324
SILValue limitWithinComponent) {
325-
auto tupleTy = tupleAddr->getType().castTo<TupleType>();
326-
auto packExpansionTy =
327-
cast<PackExpansionType>(tupleTy.getElementType(componentIndex));
328-
329-
auto result = deriveOpenedElementTypeForPackExpansion(SGM, packExpansionTy);
325+
auto result = createOpenedElementValueEnvironment(
326+
tupleAddr->getType().getTupleElementType(componentIndex));
330327
auto elementEnv = result.first;
331328
auto elementTy = result.second;
332329

0 commit comments

Comments
 (0)