1.1 --- a/README.txt Tue Jan 22 01:08:08 2008 +0100
1.2 +++ b/README.txt Thu Jan 24 01:38:08 2008 +0100
1.3 @@ -171,9 +171,53 @@
1.4 Optimisations
1.5 =============
1.6
1.7 +Constant Attributes
1.8 +-------------------
1.9 +
1.10 Where attributes of modules, classes and instances are only set once and are
1.11 effectively constant, it should be possible to circumvent the attribute lookup
1.12 -mechanism and to directly reference the attribute value. This may only be of
1.13 -relevance where the values are modules, classes or functions, and it may be
1.14 -difficult to detect eligible attributes on instances due to the need for some
1.15 -kind of type inference or abstract execution.
1.16 +mechanism and to directly reference the attribute value. This technique may
1.17 +only be considered applicable in the following cases for "container" objects:
1.18 +
1.19 + 1. For modules, provided that assignments to module attributes are only
1.20 + permitted within the module itself either at the top-level or via names
1.21 + declared as globals. Thus, the following would not be permitted:
1.22 +
1.23 + another_module.this_module.attr = value
1.24 +
1.25 + (Where this_module is a reference to the current module.)
1.26 +
1.27 + 2. For classes, provided that assignments to class attributes are only
1.28 + permitted within the class definition, outside methods. This would mean
1.29 + that classes would be "sealed" at definition time (like functions).
1.30 +
1.31 +Unlike the property of function locals that they may only sensibly be accessed
1.32 +within the function in which they reside, these cases demand additional
1.33 +controls or assumptions on or about access to the stored data. Meanwhile, it
1.34 +would be difficult to detect eligible attributes on arbitrary instances due to
1.35 +the need for some kind of type inference or abstract execution.
1.36 +
1.37 +Where (1) and (2) apply, any attribute with only one recorded assignment on it
1.38 +can be considered a constant attribute and this eligible for this
1.39 +optimisation, the consequence of which would be the replacement of a
1.40 +LoadAttrIndex instruction (which needs to look up an attribute using the
1.41 +run-time details of the "container" and the compile-time details of the
1.42 +attribute) with a LoadAttr instruction.
1.43 +
1.44 +Constant Attribute Values
1.45 +-------------------------
1.46 +
1.47 +Where an attribute value is itself constant and be used either in an operation
1.48 +accessing its own attributes, or in an invocation, the value can be directly
1.49 +inspected for optimisations or employed in the generated code. For the
1.50 +attribute values themselves, only objects of a constant nature may be
1.51 +considered suitable for this particular optimisation:
1.52 +
1.53 + * Functions
1.54 + * Classes
1.55 + * Modules
1.56 + * Instances defined as constant literals
1.57 +
1.58 +This is because arbitrary objects (such as most instances) have no
1.59 +well-defined form before run-time and cannot be investigated further at
1.60 +compile-time or have a representation inserted into the generated code.