micropython

TO_DO.txt

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