grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.47k stars 310 forks source link

Code generation determinism #926

Open Gui-Yom opened 11 months ago

Gui-Yom commented 11 months ago

Currently, faust generates independent computation graph nodes in an unspecified order. This causes generated code to vary between runs.

I suspect this has to do with the way graph nodes are stored, e.g., using things such as : std::set<CodeLoop*>. Pointer values change between runs and as such, set ordering isn't stable between runs neither.

Then I may be completely mistaken about this, as I'm not particularly proficient with C++. But this seems like a good reason as to why sometimes struct fields and code loops are reordered between runs.

I might try to fix this in a PR in the following days.

sletz commented 11 months ago

We indeed have non-determinism in the compiler, basically because pointers are use as keys in the hash-consing system in tlib and possibly other places.

Fixed the non-determinism is certainly welcome, since if would also allow to have better automatic tests at several place in the compilation chain, up to the final code. But it was not so easy todo.