CozySynthesizer / cozy

The collection synthesizer
https://cozy.uwplse.org
Apache License 2.0
209 stars 18 forks source link

Investigate explicit iteration primitives #117

Open Calvin-L opened 4 years ago

Calvin-L commented 4 years ago

This text was copied from #116 and improved slightly.

This enhancement describes a change that may or may not be an improvement. We will need to investigate whether it actually helps.

Cozy is very sloppy about when it iterates over a collection and when it constructs a new collection. The code generation step decides when to do which one, and the cost model has to know about which choice will be made in which situation.

For quite some time I have been considering pushing this difficult tradeoff to the synthesis engine. To do this, the synthesis engine will need to know the difference between an iterative operation and an in-memory collection. Here's more or less how it would look:

There are probably some other details I'm forgetting, but those points capture the gist of it. The effect of this change would be that Cozy's synthesizer reasons about when to use iteration. There would be fewer choices for the code generator to make. Hopefully there would also be better alignment between the cost model and the code generator.