ArkScript-lang / Ark

ArkScript is a small, fast, functional and scripting language for C++ projects
https://arkscript-lang.dev/
Mozilla Public License 2.0
599 stars 46 forks source link

Rewrite optimizer to have room for other optimizations #251

Open SuperFola opened 3 years ago

SuperFola commented 3 years ago

Currently the optimizer needs to read the AST 2*n times if it has n different optimizations to perform, which is highly inefficient.

We should be able to read the AST at most 2 times to perform all the optimizations.

PierrePharel commented 3 years ago

And how we can do it ?

SuperFola commented 3 years ago

I don't know yet

SuperFola commented 3 years ago

I'm coming back with some ideas and key points:

SuperFola commented 3 years ago

After some time spent thinking about this issue, I think I know how we can rewrite the optimizer

The new optimizer should be able to

Transformations won't be complex, only wrapping or unwrapping nodes in other nodes.


I suggest to update our nodes so that they use less memory, making them easier to copy (our nodes are big objects, which is bad because we instanciate them very often). It would be nice if we could remove the filename attribute and use a string_view, pointing to a string owned by the parser, but this will need to refactor the import method of the parser so that all the filenames are stored in the same instance (since each time we find an (import "x.ark") we instanciate a sub parser).