Write an optimizer that also checks correct usage of attributes
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
Related branches
Related bugs
Sprints
Whiteboard
Tests for correct semantics:
- What are the inputs/outputs of the code?
- Are all parameters/initial values/
- Are there any assignments to variables that have the wrong role for writing
(illegal)?
- Are any variables assigned twice (illegal)?
- The methods of a flat object must not use any data from outside of the flat
object.
Optimizations:
- 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.
Issues:
- 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.
Libraries:
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.
http://
- Network X: a (pure python?) library with graph data structure, algorithms, and simple visualization. Maybe more complete than ``python-graph``.
http://
- Igraph: library with many algorithms. Not pure Python.
http://
Work Items
Dependency tree
* Blueprints in grey have been implemented.