Write an optimizer that also checks correct usage of attributes

Registered by Eike on 2010-06-26

The code which is generated by the interpreter is quite inelegant, and it may contain semantic errors.

The optimizer should find illegal use of attributes.
It should remove superfluous variables, and dead code.
It should be able to reorder statements.

Blueprint information

Not started
Needs approval
Series goal:
Accepted for trunk
Not started
Milestone target:
milestone icon 0.4.1


Tests for correct semantics:
- What are the inputs/outputs of the code?
- Are all parameters/initial values/differentials assigned a value?
- Are there any assignments to variables that have the wrong role for writing
- Are any variables assigned twice (illegal)?
- The methods of a flat object must not use any data from outside of the flat

- Create missing assignments in 'if' statements
    - Makes creating all attributes at the beginnig of the function unnecessary
    - May remove problems with local variables
    - Maybe unnecessary when good dataflow analysis algoritm exists
- Remove variables:
    - All variables that are read only once
    - Variables that are never read.
    - Special attention needs to be payed to "if" statements.
- Remove statements that compute removed variables
- Reorder statements.
Algorithm could go backwards from the outputs.

- Local variables need special design:
    - True for variables and automatically created variables (See Bug #600786,
      Bug #597234)
    - They should not always need a value (Goes this away when missing variables
      in if statements are generated?), currently problematic for arameters.
    - They also should not automatically be stored.
- Inheritance of role needs to be more refined.
    - RoleStateVariable is not inherited. It should become: RoleVariable
    - RoleParameter can only be inherited in initial functions.
      Assignments to parameters re illegal in "dynamic" and "final".
    - Alternative: special role for local variables:
      They can get any AttributeRole as long as they are not stored
      but potentially optimized away.

The following libraries could be useful to implement these features:

- python-graph: a pure python library with graph data structure, algorithms, and visualization via Graphviz.

- Network X: a (pure python?) library with graph data structure, algorithms, and simple visualization. Maybe more complete than ``python-graph``.

- Igraph: library with many algorithms. Not pure Python.


Work Items

Dependency tree

* Blueprints in grey have been implemented.

This blueprint contains Public information 
Everyone can see this information.


No subscribers.