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