@@ -91,7 +91,7 @@ static void getVariableNameForValue(SILValue value2,
91
91
// operand.
92
92
StackList<llvm::PointerUnion<SILInstruction *, SILValue>> variableNamePath (
93
93
value2->getFunction ());
94
- while (true ) {
94
+ while (searchValue ) {
95
95
if (auto *allocInst = dyn_cast<AllocationInst>(searchValue)) {
96
96
// If the instruction itself doesn't carry any variable info, see whether
97
97
// it's copied from another place that does.
@@ -130,18 +130,44 @@ static void getVariableNameForValue(SILValue value2,
130
130
variableNamePath.push_back ({fArg });
131
131
break ;
132
132
}
133
-
134
- if ( auto bai = dyn_cast_or_null<BeginApplyInst>(searchValue-> getDefiningInstruction ())) {
133
+
134
+ auto getNamePathComponentFromCallee = [&](FullApplySite call) -> llvm::Optional<SILValue> {
135
135
// Use the name of the property being accessed if we can get to it.
136
- if (isa<FunctionRefBaseInst>(bai-> getCallee ())
137
- || isa<MethodInst>(bai-> getCallee ())) {
138
- variableNamePath.push_back (bai-> getCallee ()->getDefiningInstruction ());
136
+ if (isa<FunctionRefBaseInst>(call. getCallee ())
137
+ || isa<MethodInst>(call. getCallee ())) {
138
+ variableNamePath.push_back (call. getCallee ()->getDefiningInstruction ());
139
139
// Try to name the base of the property if this is a method.
140
- if (bai->getSubstCalleeType ()->hasSelfParam ()) {
141
- searchValue = bai->getSelfArgument ();
142
- continue ;
140
+ if (call.getSubstCalleeType ()->hasSelfParam ()) {
141
+ return call.getSelfArgument ();
143
142
} else {
144
- break ;
143
+ return SILValue ();
144
+ }
145
+ }
146
+ return llvm::None;
147
+ };
148
+
149
+ // Read or modify accessor.
150
+ if (auto bai = dyn_cast_or_null<BeginApplyInst>(searchValue->getDefiningInstruction ())) {
151
+ if (auto selfParam = getNamePathComponentFromCallee (bai)) {
152
+ searchValue = *selfParam;
153
+ continue ;
154
+ }
155
+ }
156
+
157
+ // Addressor accessor.
158
+ if (auto ptrToAddr = dyn_cast<PointerToAddressInst>(stripAccessMarkers (searchValue))) {
159
+ // The addressor can either produce the raw pointer itself or an `UnsafePointer` stdlib type wrapping it.
160
+ ApplyInst *addressorInvocation;
161
+ if (auto structExtract = dyn_cast<StructExtractInst>(ptrToAddr->getOperand ())) {
162
+ addressorInvocation = dyn_cast<ApplyInst>(structExtract->getOperand ());
163
+ } else {
164
+ addressorInvocation = dyn_cast<ApplyInst>(ptrToAddr->getOperand ());
165
+ }
166
+
167
+ if (addressorInvocation) {
168
+ if (auto selfParam = getNamePathComponentFromCallee (addressorInvocation)) {
169
+ searchValue = *selfParam;
170
+ continue ;
145
171
}
146
172
}
147
173
}
0 commit comments