paul@472 | 1 | Name usage types: as parameters, as base classes, as callables. This potentially restricts
|
paul@472 | 2 | attribute usage effects because names mentioned as base classes are not propagated and
|
paul@472 | 3 | made freely available for use in attribute accesses.
|
paul@472 | 4 |
|
paul@419 | 5 | Low-Level Instructions and Macro Instructions
|
paul@419 | 6 | =============================================
|
paul@419 | 7 |
|
paul@429 | 8 | Have contexts and values stored separately in memory. This involves eliminating DataValue
|
paul@429 | 9 | and storing attributes using two words.
|
paul@429 | 10 |
|
paul@419 | 11 | Migrate macro instructions such as the *Index instructions to library code implemented
|
paul@419 | 12 | using low-level instructions.
|
paul@419 | 13 |
|
paul@419 | 14 | Consider introducing classic machine level instructions (word addition, subtraction, and
|
paul@419 | 15 | so on) in order to implement all current RSVP instructions.
|
paul@419 | 16 |
|
paul@450 | 17 | Move common code sequences to a library routine, such as the context checking that occurs
|
paul@450 | 18 | in functions and methods.
|
paul@450 | 19 |
|
paul@464 | 20 | Dataflow Optimisations
|
paul@464 | 21 | ======================
|
paul@450 | 22 |
|
paul@464 | 23 | Assignments, particularly now that no result register exists, may cause StoreTemp/LoadTemp
|
paul@464 | 24 | instruction pairs to be produced and these could be eliminated.
|
paul@450 | 25 |
|
paul@417 | 26 | Class and Module Attribute Assignment
|
paul@417 | 27 | =====================================
|
paul@417 | 28 |
|
paul@557 | 29 | Allow unrestricted class and module assignment (but not new external binding of
|
paul@557 | 30 | attributes), eliminating run-time checks on object types in instructions like
|
paul@557 | 31 | StoreAttrIndex. This may involve less specific objects being identified during inspection.
|
paul@557 | 32 |
|
paul@568 | 33 | Potentially re-evaluate class bases in order to see if they are non-constant.
|
paul@568 | 34 |
|
paul@417 | 35 | Verify that the context information is correctly set, particularly for the unoptimised
|
paul@417 | 36 | cases.
|
paul@417 | 37 |
|
paul@417 | 38 | Update docs/assignment.txt.
|
paul@417 | 39 |
|
paul@431 | 40 | Prevent assignments within classes, such as method aliasing, from causing the source of an
|
paul@431 | 41 | assignment from being automatically generated. Instead, only external references should be
|
paul@431 | 42 | registered.
|
paul@431 | 43 |
|
paul@431 | 44 | Prevent "from <module> import ..." statements from registering references to such local
|
paul@431 | 45 | aliases such that they cause the source of each alias to be automatically generated.
|
paul@431 | 46 |
|
paul@419 | 47 | Consider attribute assignment observations, along with the possibility of class and module
|
paul@419 | 48 | attribute assignment.
|
paul@419 | 49 |
|
paul@419 | 50 | (Note direct assignments as usual, indirect assignments via the attribute usage
|
paul@419 | 51 | mechanism. During attribute collection and inference, add assigned values to all
|
paul@419 | 52 | inferred targets.)
|
paul@419 | 53 |
|
paul@419 | 54 | (Since class attributes can be assigned, StoreAttrIndex would no longer need to reject
|
paul@419 | 55 | static attributes, although this might still be necessary where attribute usage analysis
|
paul@419 | 56 | has not been performed.)
|
paul@419 | 57 |
|
paul@419 | 58 | Potentially consider changing static attribute details to use object-relative offsets in
|
paul@419 | 59 | order to simplify the instruction implementations. This might allow us to eliminate the
|
paul@419 | 60 | static attribute flag for attributes in the object table, at least at run-time.
|
paul@419 | 61 |
|
paul@413 | 62 | Dynamic Attribute Access
|
paul@413 | 63 | ========================
|
paul@413 | 64 |
|
paul@425 | 65 | Consider explicit accessor initialisation:
|
paul@425 | 66 |
|
paul@425 | 67 | attr = accessor("attr")
|
paul@425 | 68 | getattr(C, attr)
|
paul@413 | 69 |
|
paul@394 | 70 | Attribute Usage
|
paul@394 | 71 | ===============
|
paul@394 | 72 |
|
paul@498 | 73 | To consider: is it useful to distinguish between attribute name sets when the same names
|
paul@498 | 74 | are mentioned, but where one path through the code sets different values on attributes
|
paul@498 | 75 | than another? The _attrtypes collapses observations in order to make a list of object
|
paul@498 | 76 | types for a name, and the final set of names leading to such type deductions might be a
|
paul@498 | 77 | useful annotation to be added alongside _attrcombined.
|
paul@498 | 78 |
|
paul@575 | 79 | Update the reports to group identical sets of attribute names.
|
paul@575 | 80 |
|
paul@498 | 81 | Interface/Type Generalisation
|
paul@498 | 82 | -----------------------------
|
paul@498 | 83 |
|
paul@480 | 84 | Consolidate interface observations by taking all cached table accesses and determining
|
paul@480 | 85 | which usage patterns lead to the same types. For example, if full usage of {a, b} and
|
paul@480 | 86 | {a, b, c} leads to A and B in both cases, either {a, b} can be considered as partial usage
|
paul@480 | 87 | of the complete interface {a, b, c}, or the latter can be considered as an
|
paul@480 | 88 | overspecification of the former.
|
paul@480 | 89 |
|
paul@364 | 90 | Consider type deduction and its consequences where types belong to the same hierarchy
|
paul@364 | 91 | and where a guard could be generated for the most general type.
|
paul@364 | 92 |
|
paul@364 | 93 | Consider permitting multiple class alternatives where the attributes are all identical.
|
paul@364 | 94 |
|
paul@360 | 95 | Support class attribute positioning similar to instance attribute positioning, potentially
|
paul@360 | 96 | (for both) based on usage observations. For example, if __iter__ is used on two classes,
|
paul@360 | 97 | the class attribute could be exposed at a similar relative position to the class (and
|
paul@360 | 98 | potentially accessible using a LoadAttr-style instruction).
|
paul@360 | 99 |
|
paul@394 | 100 | **** Constant attribute users need not maintain usage since they are already resolved. ****
|
paul@394 | 101 |
|
paul@498 | 102 | Self-related Usage
|
paul@498 | 103 | ------------------
|
paul@498 | 104 |
|
paul@498 | 105 | Perform attribute usage on attributes of self as names, potentially combining observations
|
paul@498 | 106 | across methods.
|
paul@498 | 107 |
|
paul@498 | 108 | Additional Guards
|
paul@498 | 109 | -----------------
|
paul@498 | 110 |
|
paul@498 | 111 | Consider handling branches of values within namespaces in order to support more precise value usage.
|
paul@498 | 112 |
|
paul@498 | 113 | Loop entry points and other places where usage becomes more specific might be used as
|
paul@498 | 114 | places to impose guards. See tests/attribute_access_type_restriction_loop_list.py for an
|
paul@498 | 115 | example. (Such information is already shown in the reports.)
|
paul@498 | 116 |
|
paul@498 | 117 | Strict Interfaces/Types
|
paul@498 | 118 | -----------------------
|
paul@498 | 119 |
|
paul@498 | 120 | Make the gathering of usage parameterisable according to the optimisation level so that a
|
paul@498 | 121 | choice can be made between control-flow-dependent observations and the simple collection
|
paul@498 | 122 | of all attributes used with a name (producing a more static interface observation).
|
paul@498 | 123 |
|
paul@498 | 124 | AttributeError
|
paul@498 | 125 | --------------
|
paul@498 | 126 |
|
paul@504 | 127 | Consider attribute usage observations being suspended or optional inside blocks where
|
paul@504 | 128 | AttributeError may be caught (although this doesn't anticipate such exceptions being
|
paul@504 | 129 | caught outside a function altogether). For example:
|
paul@504 | 130 |
|
paul@504 | 131 | y = a.y
|
paul@504 | 132 | try:
|
paul@504 | 133 | z = a.z # z is an optional attribute
|
paul@504 | 134 | except AttributeError:
|
paul@504 | 135 | z = None
|
paul@498 | 136 |
|
paul@498 | 137 | Instantiation Deduction
|
paul@498 | 138 | -----------------------
|
paul@498 | 139 |
|
paul@394 | 140 | Consider handling CallFunc in micropython.inspect in order to produce instances of specific classes.
|
paul@503 | 141 | Then, consider adding support for guard removal/verification where known instances are involved. For
|
paul@503 | 142 | example:
|
paul@503 | 143 |
|
paul@503 | 144 | l = []
|
paul@503 | 145 | l.append(123) # type deductions are filtered using instantiation knowledge
|
paul@394 | 146 |
|
paul@394 | 147 | Frame Optimisations
|
paul@394 | 148 | ===================
|
paul@394 | 149 |
|
paul@394 | 150 | Stack frame replacement where a local frame is unused after a call, such as in a tail call
|
paul@394 | 151 | situation.
|
paul@394 | 152 |
|
paul@394 | 153 | Local assignment detection plus frame re-use. Example: slice.__init__ calls
|
paul@394 | 154 | xrange.__init__ with the same arguments which are unchanged in xrange.__init__. There is
|
paul@419 | 155 | therefore no need to build a new frame for this call, although in some cases the locals
|
paul@419 | 156 | frame might need expanding.
|
paul@419 | 157 |
|
paul@456 | 158 | Reference tracking where objects associated with names are assigned to attributes of other
|
paul@456 | 159 | objects may assist in allocation optimisations. Recording whether an object referenced by
|
paul@456 | 160 | a name is assigned to an attribute, propagated to another name and assigned to an
|
paul@456 | 161 | attribute, or passed to another function or method might, if such observations were
|
paul@456 | 162 | combined, allow frame-based or temporary allocation to occur.
|
paul@456 | 163 |
|
paul@472 | 164 | Instantiation
|
paul@472 | 165 | =============
|
paul@472 | 166 |
|
paul@472 | 167 | Specific instances could be produced, providing type information and acting somewhat like
|
paul@472 | 168 | classes during inspection.
|
paul@472 | 169 |
|
paul@419 | 170 | Inlining
|
paul@419 | 171 | ========
|
paul@419 | 172 |
|
paul@419 | 173 | Where a function or method call can always be determined, the body of the target could be
|
paul@419 | 174 | inlined - copied into place - within the caller. If the target is only ever called by a
|
paul@456 | 175 | single caller it could be moved into place. This could enhance deductions based on
|
paul@456 | 176 | attribute usage since observations from the inlined function would be merged into the
|
paul@456 | 177 | caller.
|
paul@394 | 178 |
|
paul@394 | 179 | Function Specialisation
|
paul@394 | 180 | =======================
|
paul@394 | 181 |
|
paul@394 | 182 | Specialisation of certain functions, such as isinstance(x, cls) where cls is a known
|
paul@394 | 183 | constant.
|
paul@394 | 184 |
|
paul@394 | 185 | Structure and Object Table Optimisations
|
paul@394 | 186 | ========================================
|
paul@394 | 187 |
|
paul@394 | 188 | Fix object table entries for attributes not provided by any known object, or provide an
|
paul@394 | 189 | error, potentially overridden by options. For example, the augmented assignment methods
|
paul@394 | 190 | are not supported by the built-in objects and thus the operator module functions cause
|
paul@394 | 191 | the compilation to fail. Alternatively, just supply the methods since something has to do
|
paul@394 | 192 | so in the builtins.
|
paul@394 | 193 |
|
paul@394 | 194 | Consider attribute merging where many attributes are just aliases for the same underlying
|
paul@394 | 195 | definition.
|
paul@394 | 196 |
|
paul@349 | 197 | Consider references to defaults as occurring only within the context of a particular
|
paul@349 | 198 | function, thus eliminating default value classes if such functions are not themselves
|
paul@349 | 199 | invoked.
|
paul@349 | 200 |
|
paul@394 | 201 | Scope Handling
|
paul@394 | 202 | ==============
|
paul@394 | 203 |
|
paul@394 | 204 | Consider merging the InspectedModule.store tests with the scope conflict handling.
|
paul@394 | 205 |
|
paul@343 | 206 | Consider labelling _scope on assignments and dealing with the assignment of removed
|
paul@343 | 207 | attributes, possibly removing the entire assignment, and distinguishing between such cases
|
paul@343 | 208 | and unknown names.
|
paul@343 | 209 |
|
paul@342 | 210 | Check name origin where multiple branches could yield multiple scope interpretations:
|
paul@342 | 211 |
|
paul@504 | 212 | try:
|
paul@504 | 213 | set # built-in name
|
paul@504 | 214 | except NameError:
|
paul@504 | 215 | from sets import Set as set # local definition of name
|
paul@342 | 216 |
|
paul@504 | 217 | set # could be confused by the local definition at run-time
|
paul@342 | 218 |
|
paul@394 | 219 | Object Coverage
|
paul@394 | 220 | ===============
|
paul@394 | 221 |
|
paul@332 | 222 | Support __init__ traversal (and other implicit names) more effectively.
|
paul@332 | 223 |
|
paul@499 | 224 | Importing Modules
|
paul@499 | 225 | =================
|
paul@499 | 226 |
|
paul@499 | 227 | Consider supporting relative imports, even though this is arguably a misfeature.
|
paul@499 | 228 |
|
paul@394 | 229 | Other
|
paul@394 | 230 | =====
|
paul@394 | 231 |
|
paul@482 | 232 | Consider a separate annotation phase where deductions are added to the AST for the
|
paul@482 | 233 | benefit of both the reporting and code generation phases.
|
paul@482 | 234 |
|
paul@332 | 235 | Check context_value initialisation (avoiding or handling None effectively).
|
paul@332 | 236 |
|
paul@342 | 237 | Consider better "macro" support where new expressions need to be generated and processed.
|
paul@402 | 238 |
|
paul@402 | 239 | Detect TestIdentity results involving constants, potentially optimising status-affected
|
paul@402 | 240 | instructions:
|
paul@402 | 241 |
|
paul@402 | 242 | TestIdentity(x, y) # where x is always y
|
paul@402 | 243 | JumpIfFalse(...) # would be removed (never false)
|
paul@402 | 244 | JumpIfTrue(...) # changed to Jump(...)
|
paul@402 | 245 |
|
paul@402 | 246 | Status-affected blocks could be optimised away for such constant-related results.
|