Skip to content

Commit aa5db25

Browse files
committed
[variable-name-utils] Move destructure and function arg to the new string ref representation.
1 parent 1e2fb39 commit aa5db25

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

lib/SILOptimizer/Utils/VariableNameUtils.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -507,23 +507,24 @@ SILValue VariableNameInferrer::findDebugInfoProvidingValueHelper(
507507

508508
if (auto *dti = dyn_cast_or_null<DestructureTupleInst>(
509509
searchValue->getDefiningInstruction())) {
510-
// Append searchValue, so we can find the specific tuple index.
511-
variableNamePath.push_back(searchValue);
510+
variableNamePath.push_back(
511+
getStringRefForIndex(*dti->getIndexOfResult(searchValue)));
512512
searchValue = dti->getOperand();
513513
continue;
514514
}
515515

516516
if (auto *dsi = dyn_cast_or_null<DestructureStructInst>(
517517
searchValue->getDefiningInstruction())) {
518-
// Append searchValue, so we can find the specific struct field.
519-
variableNamePath.push_back(searchValue);
518+
unsigned index = *dsi->getIndexOfResult(searchValue);
519+
variableNamePath.push_back(
520+
getNameFromDecl(dsi->getStructDecl()->getStoredProperties()[index]));
520521
searchValue = dsi->getOperand();
521522
continue;
522523
}
523524

524525
if (auto *fArg = dyn_cast<SILFunctionArgument>(searchValue)) {
525-
if (fArg->getDecl()) {
526-
variableNamePath.push_back({fArg});
526+
if (auto *decl = fArg->getDecl()) {
527+
variableNamePath.push_back(decl->getBaseName().userFacingName());
527528
return fArg;
528529
}
529530
}
@@ -687,29 +688,6 @@ void VariableNameInferrer::popSingleVariableName() {
687688
return;
688689
}
689690

690-
if (std::holds_alternative<SILValue>(next)) {
691-
auto value = std::get<SILValue>(next);
692-
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
693-
resultingString += fArg->getDecl()->getBaseName().userFacingName();
694-
return;
695-
}
696-
697-
if (auto *dti = dyn_cast_or_null<DestructureTupleInst>(
698-
value->getDefiningInstruction())) {
699-
llvm::raw_svector_ostream stream(resultingString);
700-
stream << *dti->getIndexOfResult(value);
701-
return;
702-
}
703-
704-
if (auto *dsi = dyn_cast_or_null<DestructureStructInst>(
705-
value->getDefiningInstruction())) {
706-
unsigned index = *dsi->getIndexOfResult(value);
707-
resultingString +=
708-
getNameFromDecl(dsi->getStructDecl()->getStoredProperties()[index]);
709-
return;
710-
}
711-
}
712-
713691
resultingString += "<unknown decl>";
714692
}
715693

0 commit comments

Comments
 (0)