micropython

TO_DO.txt

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