Wiki tutorial outdated?
vladimmi opened this issue · comments
I'm currently reading through tutorial in wiki and this part looks wrong:
There is a catch, though: testing different memoization implementations, the most efficient one was found to be D's built-in associative arrays, which is what is used by Pegged right now. But AAs do not work at compile-time. So right now, memoization is disabled at compile-time even with the Memoization.yes option to allow Pegged parsers to function at compile-time.
Found at the end of https://github.com/PhilippeSigaud/Pegged/wiki/Memoization
As far as I can see, AAs do work at compile-time, like this: https://run.dlang.io/is/zWXVfC
Also, quick search through pegged code didnt lead to place with such forced disabling.
Memoization happens at https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/grammar.d#L538 and https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/grammar.d#L578, both of which are located in the else
block of if(__ctfe)
at https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/grammar.d#L521. So, memoization does indeed not happen at compile-time currently, so the wiki is correct in that regard.
I am not sure what aspect of AA does or didn't work at compile-time. I do know that AAs use a different implementation at compile time, but that shouldn't be an issue. There is also the alternative of https://dlang.org/phobos/std_container_rbtree.html. So maybe memoization at compile-time could be made to work nowadays, but I am not sure. I have added a few words in the wiki to soften that statement.