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