Skip to content

Commit 7da4886

Browse files
committed
SILOptimizer: Use getNextDepth()/getMaxDepth()
1 parent 818f479 commit 7da4886

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,7 @@ void ExistentialTransform::convertExistentialArgTypesToGenericArgTypes(
277277
params.append(FTy->getParameters().begin(), FTy->getParameters().end());
278278

279279
/// Determine the existing generic parameter depth.
280-
int Depth = 0;
281-
if (OrigGenericSig != nullptr) {
282-
Depth = OrigGenericSig.getGenericParams().back()->getDepth() + 1;
283-
}
280+
int Depth = OrigGenericSig.getNextDepth();
284281

285282
/// Index of the Generic Parameter.
286283
int GPIdx = 0;
@@ -514,10 +511,7 @@ void ExistentialTransform::populateThunkBody() {
514511
}
515512
}
516513

517-
unsigned int OrigDepth = 0;
518-
if (F->getLoweredFunctionType()->isPolymorphic()) {
519-
OrigDepth = OrigCalleeGenericSig.getGenericParams().back()->getDepth() + 1;
520-
}
514+
unsigned int OrigDepth = OrigCalleeGenericSig.getNextDepth();
521515
SubstitutionMap OrigSubMap = F->getForwardingSubstitutionMap();
522516

523517
/// Create substitutions for Apply instructions.

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ getSubstitutionsForCallee(SILModule &module, CanSILFunctionType baseCalleeType,
410410
unsigned baseDepth = 0;
411411
SubstitutionMap baseSubMap;
412412
if (auto baseClassSig = baseClassDecl->getGenericSignatureOfContext()) {
413-
baseDepth = baseClassSig.getGenericParams().back()->getDepth() + 1;
413+
baseDepth = baseClassSig.getNextDepth();
414414

415415
// Compute the type of the base class, starting from the
416416
// derived class type and the type of the method's self
@@ -435,9 +435,7 @@ getSubstitutionsForCallee(SILModule &module, CanSILFunctionType baseCalleeType,
435435

436436
// Add generic parameters from the method itself, ignoring any generic
437437
// parameters from the derived class.
438-
unsigned origDepth = 0;
439-
if (auto calleeClassSig = calleeClassDecl->getGenericSignatureOfContext())
440-
origDepth = calleeClassSig.getGenericParams().back()->getDepth() + 1;
438+
unsigned origDepth = calleeClassDecl->getGenericSignature().getNextDepth();
441439

442440
auto baseCalleeSig = baseCalleeType->getInvocationGenericSignature();
443441

@@ -927,10 +925,8 @@ getWitnessMethodSubstitutions(
927925
// substitutions for the concrete type's generic parameters.
928926
auto baseSubMap = conformance->getSubstitutionMap();
929927

930-
unsigned baseDepth = 0;
931928
auto *rootConformance = conformance->getRootConformance();
932-
if (auto conformingTypeSig = rootConformance->getGenericSignature())
933-
baseDepth = conformingTypeSig.getGenericParams().back()->getDepth() + 1;
929+
unsigned baseDepth = rootConformance->getGenericSignature().getNextDepth();
934930

935931
// witnessThunkSig begins with the optional class 'Self', followed by the
936932
// generic parameters of the concrete conforming type, followed by the

0 commit comments

Comments
 (0)