Skip to content

Commit 818f479

Browse files
committed
AST: Use getNextDepth()/getMaxDepth()
1 parent cb66dab commit 818f479

File tree

6 files changed

+13
-24
lines changed

6 files changed

+13
-24
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5884,11 +5884,8 @@ CanGenericSignature ASTContext::getSingleGenericParameterSignature() const {
58845884

58855885
Type OpenedArchetypeType::getSelfInterfaceTypeFromContext(GenericSignature parentSig,
58865886
ASTContext &ctx) {
5887-
unsigned depth = 0;
5888-
if (!parentSig.getGenericParams().empty())
5889-
depth = parentSig.getGenericParams().back()->getDepth() + 1;
58905887
return GenericTypeParamType::get(/*isParameterPack=*/ false,
5891-
/*depth=*/ depth, /*index=*/ 0,
5888+
parentSig.getNextDepth(), /*index=*/ 0,
58925889
ctx);
58935890
}
58945891

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,7 @@ void ASTMangler::appendContextualInverses(const GenericTypeDecl *contextDecl,
27482748
parts.params = std::nullopt;
27492749

27502750
// The depth of parameters for this extension is +1 of the extended signature.
2751-
parts.initialParamDepth = sig.getGenericParams().back()->getDepth() + 1;
2751+
parts.initialParamDepth = sig.getNextDepth();
27522752

27532753
appendModule(module, alternateModuleName);
27542754
appendGenericSignatureParts(sig, parts);
@@ -3391,7 +3391,7 @@ void ASTMangler::gatherGenericSignatureParts(GenericSignature sig,
33913391
} else {
33923392
inverseReqs.clear();
33933393
}
3394-
base.setDepth(canSig.getGenericParams().back()->getDepth());
3394+
base.setDepth(canSig->getMaxDepth());
33953395

33963396
unsigned &initialParamDepth = parts.initialParamDepth;
33973397
auto &genericParams = parts.params;
@@ -3412,7 +3412,7 @@ void ASTMangler::gatherGenericSignatureParts(GenericSignature sig,
34123412

34133413
// The signature depth starts above the depth of the context signature.
34143414
if (!contextSig.getGenericParams().empty()) {
3415-
initialParamDepth = contextSig.getGenericParams().back()->getDepth() + 1;
3415+
initialParamDepth = contextSig.getNextDepth();
34163416
}
34173417

34183418
// If both signatures have exactly the same requirements, ignoring
@@ -4760,11 +4760,10 @@ static std::optional<unsigned> getEnclosingTypeGenericDepth(const Decl *decl) {
47604760
if (!typeDecl)
47614761
return std::nullopt;
47624762

4763-
auto genericParams = typeDecl->getGenericParams();
4764-
if (!genericParams)
4763+
if (!typeDecl->isGeneric())
47654764
return std::nullopt;
47664765

4767-
return genericParams->getParams().back()->getDepth();
4766+
return typeDecl->getGenericSignature()->getMaxDepth();
47684767
}
47694768

47704769
ASTMangler::BaseEntitySignature::BaseEntitySignature(const Decl *decl)

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,10 +1807,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
18071807
auto *DC = Current->getInnermostDeclContext()->getInnermostTypeContext();
18081808
M = DC->getParentModule();
18091809
subMap = CurrentType->getContextSubstitutionMap(M, DC);
1810-
if (!subMap.empty()) {
1811-
typeContextDepth = subMap.getGenericSignature()
1812-
.getGenericParams().back()->getDepth() + 1;
1813-
}
1810+
typeContextDepth = subMap.getGenericSignature().getNextDepth();
18141811
}
18151812
}
18161813

@@ -7075,7 +7072,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
70757072

70767073
// The element archetypes are at a depth one past the max depth
70777074
// of the base signature.
7078-
unsigned elementDepth = params.back()->getDepth() + 1;
7075+
unsigned elementDepth = sig.getNextDepth();
70797076

70807077
// Transform the archetype's interface type to be based on the
70817078
// corresponding non-canonical type parameter.

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ArrayRef<GenericTypeParamType *>
7979
GenericSignatureImpl::getInnermostGenericParams() const {
8080
const auto params = getGenericParams();
8181

82-
const unsigned maxDepth = params.back()->getDepth();
82+
const unsigned maxDepth = getMaxDepth();
8383
if (params.front()->getDepth() == maxDepth)
8484
return params;
8585

lib/AST/RequirementEnvironment.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,9 @@ RequirementEnvironment::RequirementEnvironment(
7777

7878
// Calculate the depth at which the requirement's generic parameters
7979
// appear in the witness thunk signature.
80-
unsigned depth = 0;
81-
if (covariantSelf) {
80+
unsigned depth = conformanceSig.getNextDepth();
81+
if (covariantSelf)
8282
++depth;
83-
}
84-
if (conformanceSig) {
85-
depth += conformanceSig.getGenericParams().back()->getDepth() + 1;
86-
}
8783

8884
// Build a substitution map to replace the protocol's \c Self and the type
8985
// parameters of the requirement into a combined context that provides the

lib/AST/SubstitutionMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ OverrideSubsInfo::OverrideSubsInfo(const NominalTypeDecl *baseNominal,
578578
DerivedParams(derivedParams) {
579579

580580
if (auto baseNominalSig = baseNominal->getGenericSignature()) {
581-
BaseDepth = baseNominalSig.getGenericParams().back()->getDepth() + 1;
581+
BaseDepth = baseNominalSig.getNextDepth();
582582

583583
auto *genericEnv = derivedNominal->getGenericEnvironment();
584584
auto derivedNominalTy = derivedNominal->getDeclaredInterfaceType();
@@ -602,7 +602,7 @@ OverrideSubsInfo::OverrideSubsInfo(const NominalTypeDecl *baseNominal,
602602
}
603603

604604
if (auto derivedNominalSig = derivedNominal->getGenericSignature())
605-
OrigDepth = derivedNominalSig.getGenericParams().back()->getDepth() + 1;
605+
OrigDepth = derivedNominalSig.getNextDepth();
606606
}
607607

608608
Type QueryOverrideSubs::operator()(SubstitutableType *type) const {

0 commit comments

Comments
 (0)