17
17
#ifndef SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
18
18
#define SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
19
19
20
+ #include " swift/Basic/OptionSet.h"
20
21
#include " swift/SIL/ApplySite.h"
21
22
#include " swift/SIL/DebugUtils.h"
22
23
#include " swift/SIL/MemAccessUtils.h"
26
27
namespace swift {
27
28
28
29
class VariableNameInferrer {
30
+ public:
31
+ enum class Flag {
32
+ // / If set then we should look through get and set accessors and infer their
33
+ // / name from self.
34
+ // /
35
+ // / DISCUSSION: This may not be the correct semantics for all name inference
36
+ // / since we may want to consider computed properties to be tied to self.
37
+ InferSelfThroughAllAccessors = 0x1 ,
38
+ };
39
+
40
+ using Options = OptionSet<Flag>;
41
+
42
+ private:
29
43
// / The stacklist that we use to process from use->
30
44
StackList<PointerUnion<SILInstruction *, SILValue>> variableNamePath;
31
45
@@ -37,10 +51,21 @@ class VariableNameInferrer {
37
51
// / The final string we computed.
38
52
SmallString<64 > &resultingString;
39
53
54
+ // / Options that control how we do our walk.
55
+ // /
56
+ // / Example: In certain cases we may want to impute self as a name for
57
+ // / computed getters/setters and in other cases we may not want to.
58
+ Options options;
59
+
40
60
public:
41
61
VariableNameInferrer (SILFunction *fn, SmallString<64 > &resultingString)
42
62
: variableNamePath(fn), resultingString(resultingString) {}
43
63
64
+ VariableNameInferrer (SILFunction *fn, Options options,
65
+ SmallString<64 > &resultingString)
66
+ : variableNamePath(fn), resultingString(resultingString),
67
+ options (options) {}
68
+
44
69
// / Attempts to infer a name from just uses of \p searchValue.
45
70
// /
46
71
// / Returns true if we found a name.
@@ -100,11 +125,16 @@ class VariableNameInferrer {
100
125
101
126
private:
102
127
void drainVariableNamePath ();
128
+ void popSingleVariableName ();
103
129
104
130
// / Finds the SILValue that either provides the direct debug information or
105
131
// / that has a debug_value user that provides the name of the value.
106
132
SILValue findDebugInfoProvidingValue (SILValue searchValue);
107
133
134
+ // / Do not call this directly. Used just to improve logging for
135
+ // / findDebugInfoProvidingValue.
136
+ SILValue findDebugInfoProvidingValueHelper (SILValue searchValue);
137
+
108
138
// / Given an initialized once allocation inst without a ValueDecl or a
109
139
// / DebugVariable provided name, attempt to find a root value from its
110
140
// / initialization.
0 commit comments