1 Low-Level Instructions and Macro Instructions
2 =============================================
3
4 Have contexts and values stored separately in memory. This involves eliminating DataValue
5 and storing attributes using two words.
6
7 Migrate macro instructions such as the *Index instructions to library code implemented
8 using low-level instructions.
9
10 Consider introducing classic machine level instructions (word addition, subtraction, and
11 so on) in order to implement all current RSVP instructions.
12
13 Move common code sequences to a library routine, such as the context checking that occurs
14 in functions and methods.
15
16 Dataflow Optimisations
17 ======================
18
19 Assignments, particularly now that no result register exists, may cause StoreTemp/LoadTemp
20 instruction pairs to be produced and these could be eliminated.
21
22 Class and Module Attribute Assignment
23 =====================================
24
25 Verify that the context information is correctly set, particularly for the unoptimised
26 cases.
27
28 Update docs/assignment.txt.
29
30 Prevent assignments within classes, such as method aliasing, from causing the source of an
31 assignment from being automatically generated. Instead, only external references should be
32 registered.
33
34 Prevent "from <module> import ..." statements from registering references to such local
35 aliases such that they cause the source of each alias to be automatically generated.
36
37 Consider attribute assignment observations, along with the possibility of class and module
38 attribute assignment.
39
40 (Note direct assignments as usual, indirect assignments via the attribute usage
41 mechanism. During attribute collection and inference, add assigned values to all
42 inferred targets.)
43
44 (Since class attributes can be assigned, StoreAttrIndex would no longer need to reject
45 static attributes, although this might still be necessary where attribute usage analysis
46 has not been performed.)
47
48 Potentially consider changing static attribute details to use object-relative offsets in
49 order to simplify the instruction implementations. This might allow us to eliminate the
50 static attribute flag for attributes in the object table, at least at run-time.
51
52 Dynamic Attribute Access
53 ========================
54
55 Consider explicit accessor initialisation:
56
57 attr = accessor("attr")
58 getattr(C, attr)
59
60 Attribute Usage
61 ===============
62
63 Loop entry points and other places where usage becomes more specific might be used as
64 places to impose guards. See tests/attribute_access_type_restriction_loop_list.py for an
65 example.
66
67 Consider attribute usage observations being suspended inside blocks where AttributeError
68 may be caught (although this doesn't anticipate such exceptions being caught outside a
69 function altogether).
70
71 Consider type deduction and its consequences where types belong to the same hierarchy
72 and where a guard could be generated for the most general type.
73
74 Consider permitting multiple class alternatives where the attributes are all identical.
75
76 Support class attribute positioning similar to instance attribute positioning, potentially
77 (for both) based on usage observations. For example, if __iter__ is used on two classes,
78 the class attribute could be exposed at a similar relative position to the class (and
79 potentially accessible using a LoadAttr-style instruction).
80
81 **** Constant attribute users need not maintain usage since they are already resolved. ****
82
83 Consider handling CallFunc in micropython.inspect in order to produce instances of specific classes.
84 Then, consider adding support for guard removal/verification where known instances are involved.
85 Consider handling branches of values within namespaces in order to support more precise value usage.
86
87 Frame Optimisations
88 ===================
89
90 Stack frame replacement where a local frame is unused after a call, such as in a tail call
91 situation.
92
93 Local assignment detection plus frame re-use. Example: slice.__init__ calls
94 xrange.__init__ with the same arguments which are unchanged in xrange.__init__. There is
95 therefore no need to build a new frame for this call, although in some cases the locals
96 frame might need expanding.
97
98 Reference tracking where objects associated with names are assigned to attributes of other
99 objects may assist in allocation optimisations. Recording whether an object referenced by
100 a name is assigned to an attribute, propagated to another name and assigned to an
101 attribute, or passed to another function or method might, if such observations were
102 combined, allow frame-based or temporary allocation to occur.
103
104 Inlining
105 ========
106
107 Where a function or method call can always be determined, the body of the target could be
108 inlined - copied into place - within the caller. If the target is only ever called by a
109 single caller it could be moved into place. This could enhance deductions based on
110 attribute usage since observations from the inlined function would be merged into the
111 caller.
112
113 Function Specialisation
114 =======================
115
116 Specialisation of certain functions, such as isinstance(x, cls) where cls is a known
117 constant.
118
119 Structure and Object Table Optimisations
120 ========================================
121
122 Fix object table entries for attributes not provided by any known object, or provide an
123 error, potentially overridden by options. For example, the augmented assignment methods
124 are not supported by the built-in objects and thus the operator module functions cause
125 the compilation to fail. Alternatively, just supply the methods since something has to do
126 so in the builtins.
127
128 Consider attribute merging where many attributes are just aliases for the same underlying
129 definition.
130
131 Consider references to defaults as occurring only within the context of a particular
132 function, thus eliminating default value classes if such functions are not themselves
133 invoked.
134
135 Scope Handling
136 ==============
137
138 Consider merging the InspectedModule.store tests with the scope conflict handling.
139
140 Consider labelling _scope on assignments and dealing with the assignment of removed
141 attributes, possibly removing the entire assignment, and distinguishing between such cases
142 and unknown names.
143
144 Check name origin where multiple branches could yield multiple scope interpretations:
145
146 ----
147 try:
148 set # built-in name
149 except NameError:
150 from sets import Set as set # local definition of name
151
152 set # could be confused by the local definition at run-time
153 ----
154
155 Object Coverage
156 ===============
157
158 Support __init__ traversal (and other implicit names) more effectively.
159
160 Other
161 =====
162
163 Support self attribute visualisation in the reports and/or provide a function or
164 annotations which can provide the eventual optimisation directly to such components.
165
166 Check context_value initialisation (avoiding or handling None effectively).
167
168 Consider better "macro" support where new expressions need to be generated and processed.
169
170 Detect TestIdentity results involving constants, potentially optimising status-affected
171 instructions:
172
173 TestIdentity(x, y) # where x is always y
174 JumpIfFalse(...) # would be removed (never false)
175 JumpIfTrue(...) # changed to Jump(...)
176
177 Status-affected blocks could be optimised away for such constant-related results.