Skip to content

Commit 0039b28

Browse files
committed
[variable-name-inference] Eliminate the old value representation and just use StringRef.
1 parent 98fd04c commit 0039b28

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

include/swift/SILOptimizer/Utils/VariableNameUtils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ class VariableNameInferrer {
112112
///
113113
/// Has to be a small vector since we push/pop the last segment start. This
114114
/// lets us speculate when processing phis.
115-
VariableNamePathArray<std::variant<SILInstruction *, SILValue, StringRef>, 4>
116-
variableNamePath;
115+
VariableNamePathArray<StringRef, 4> variableNamePath;
117116

118117
/// The root value of our string.
119118
///
@@ -216,7 +215,6 @@ class VariableNameInferrer {
216215

217216
private:
218217
void drainVariableNamePath();
219-
void popSingleVariableName();
220218

221219
/// Finds the SILValue that either provides the direct debug information or
222220
/// that has a debug_value user that provides the name of the value.

lib/SILOptimizer/Utils/VariableNameUtils.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@ SILValue VariableNameInferrer::getRootValueForTemporaryAllocation(
281281

282282
SILValue
283283
VariableNameInferrer::findDebugInfoProvidingValue(SILValue searchValue) {
284+
// NOTE: This should only return a non-empty SILValue if we actually have a
285+
// full path (including base name) in the variable name path.
284286
if (!searchValue)
285287
return SILValue();
288+
286289
LLVM_DEBUG(llvm::dbgs() << "Searching for debug info providing value for: "
287290
<< searchValue);
288291
ValueSet valueSet(searchValue->getFunction());
@@ -668,24 +671,13 @@ StringRef VariableNameInferrer::getNameFromDecl(Decl *d) {
668671
return UnknownDeclString;
669672
}
670673

671-
void VariableNameInferrer::popSingleVariableName() {
672-
auto next = variableNamePath.pop_back_val();
673-
674-
if (std::holds_alternative<StringRef>(next)) {
675-
resultingString += std::get<StringRef>(next);
676-
return;
677-
}
678-
679-
resultingString += UnknownDeclString;
680-
}
681-
682674
void VariableNameInferrer::drainVariableNamePath() {
683675
if (variableNamePath.empty())
684676
return;
685677

686678
// Walk backwards, constructing our string.
687679
while (true) {
688-
popSingleVariableName();
680+
resultingString += variableNamePath.pop_back_val();
689681

690682
if (variableNamePath.empty())
691683
return;

0 commit comments

Comments
 (0)