Skip to content

SIL: Replace substitutionsChangeGenericTypeParameters() with isIdentity() check #73606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions include/swift/SIL/TypeSubstCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,31 +375,6 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
getOpValue(dfei->getOperand()), remappedDerivativeFnType));
}

/// One abstract function in the debug info can only have one set of variables
/// and types. This function determines whether applying the substitutions in
/// \p SubsMap on the generic signature \p Sig will change the generic type
/// parameters in the signature. This is used to decide whether it's necessary
/// to clone a unique copy of the function declaration with the substitutions
/// applied for the debug info.
static bool substitutionsChangeGenericTypeParameters(SubstitutionMap SubsMap,
GenericSignature Sig) {

// If there are no substitutions, just reuse
// the original decl.
if (SubsMap.empty())
return false;

bool Result = false;
Sig->forEachParam([&](GenericTypeParamType *ParamType, bool Canonical) {
if (!Canonical)
return;
if (!Type(ParamType).subst(SubsMap)->isEqual(ParamType))
Result = true;
});

return Result;
}

enum { ForInlining = true };
/// Helper function to clone the parent function of a SILDebugScope if
/// necessary when inlining said function into a new generic context.
Expand All @@ -420,7 +395,11 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
if (SubsMap.hasArchetypes())
SubsMap = SubsMap.mapReplacementTypesOutOfContext();

if (!substitutionsChangeGenericTypeParameters(SubsMap, RemappedSig))
// One abstract function in the debug info can only have one set of variables
// and types. We check if the function is called with non-identity substitutions
// to decide whether it's necessary to clone a unique copy of the function
// declaration with the substitutions applied for the debug info.
if (SubsMap.isIdentity())
return ParentFunction;

// Note that mapReplacementTypesOutOfContext() can't do anything for
Expand Down