From 2e4ad65889f5beffb48d06593b2daa3f3d2dda41 Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 20 Mar 2023 11:54:47 -0400 Subject: [PATCH] [NFC] Change forEachFunctionParam to only ignore the final orig parameter and not also drop a subst parameter. This turned out to be more convenient for certain clients (e.g. SILGenPoly) than requiring the full subst param list to be passed in. These clients want to process the subst param list separately, and dropping self early can be convenient for that. The only fundamental reason we need this flag is for working with the orig type, so just use it for that; clients that need to use this feature can reasonably be expected to cooperate. --- include/swift/SIL/AbstractionPatternGenerators.h | 2 +- lib/SIL/IR/AbstractionPattern.cpp | 13 +++++-------- lib/SIL/IR/SILFunctionType.cpp | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/swift/SIL/AbstractionPatternGenerators.h b/include/swift/SIL/AbstractionPatternGenerators.h index 3e0bfc410d7..b0cbd0624f4 100644 --- a/include/swift/SIL/AbstractionPatternGenerators.h +++ b/include/swift/SIL/AbstractionPatternGenerators.h @@ -81,7 +81,7 @@ class FunctionParamGenerator { public: FunctionParamGenerator(AbstractionPattern origFunctionType, AnyFunctionType::CanParamArrayRef substParams, - bool ignoreFinalParam); + bool ignoreFinalOrigParam); /// Is the traversal finished? If so, none of the getters below /// are allowed to be called. diff --git a/lib/SIL/IR/AbstractionPattern.cpp b/lib/SIL/IR/AbstractionPattern.cpp index cce631cca68..b66c784e9a9 100644 --- a/lib/SIL/IR/AbstractionPattern.cpp +++ b/lib/SIL/IR/AbstractionPattern.cpp @@ -1203,7 +1203,7 @@ unsigned AbstractionPattern::getNumFunctionParams() const { void AbstractionPattern:: forEachFunctionParam(AnyFunctionType::CanParamArrayRef substParams, - bool ignoreFinalParam, + bool ignoreFinalOrigParam, llvm::function_ref handleExpansion) const { - FunctionParamGenerator generator(*this, substParams, ignoreFinalParam); + FunctionParamGenerator generator(*this, substParams, ignoreFinalOrigParam); for (; !generator.isFinished(); generator.advance()) { if (generator.isPackExpansion()) { @@ -1239,7 +1239,7 @@ forEachFunctionParam(AnyFunctionType::CanParamArrayRef substParams, FunctionParamGenerator::FunctionParamGenerator( AbstractionPattern origFunctionType, AnyFunctionType::CanParamArrayRef substParams, - bool ignoreFinalParam) + bool ignoreFinalOrigParam) : origFunctionType(origFunctionType), allSubstParams(substParams) { origFunctionTypeIsOpaque = (origFunctionType.isTypeParameterOrOpaqueArchetype() || @@ -1249,11 +1249,8 @@ FunctionParamGenerator::FunctionParamGenerator( numOrigParams = allSubstParams.size(); } else { numOrigParams = origFunctionType.getNumFunctionParams(); - } - - if (ignoreFinalParam) { - allSubstParams = allSubstParams.drop_back(); - numOrigParams--; + if (ignoreFinalOrigParam) + numOrigParams--; } if (!isFinished()) loadParameter(); diff --git a/lib/SIL/IR/SILFunctionType.cpp b/lib/SIL/IR/SILFunctionType.cpp index f3b8c873848..38638269b6f 100644 --- a/lib/SIL/IR/SILFunctionType.cpp +++ b/lib/SIL/IR/SILFunctionType.cpp @@ -1569,7 +1569,8 @@ private: maybeAddForeignParameters(); // Process all the non-self parameters. - origType.forEachFunctionParam(params, hasSelf, + origType.forEachFunctionParam(params.drop_back(hasSelf ? 1 : 0), + /*ignore final orig param*/ hasSelf, [&](unsigned origParamIndex, unsigned substParamIndex, ParameterTypeFlags origFlags, AbstractionPattern origParamType,