Jean-Marc,
Am 23.11.2013 17:52, schrieb jean-marc Mercier:
A drawback is that the stack trace is inefficient, hardening the debugging. Thus it is better to set INLINE = 0 in dev phase.
yes; you should probably also set `TAILCALLS` to -1 if you want the stack trace to always be accurate. As BaseX performs tail-call optimization [1], the stack will otherwise never contain more than a fixed number (currently 256) of tail-call frames.
Could you be kind enough to point me out the link to your code at Basex repository ?
Sure, function inlining is triggered in StaticFuncCall [2] and DynFuncCall [3].
Motivation : I would like to try evaluating whether inlining recursive functions is possible or not. You are welcome to suggestions !
The hard part about inlining recursive functions is figuring out when to stop. As they have a call to themselves in the function body, each time you inline them at least one new call is inserted. This also means that unconditionally inlining recursive functions can send the compiler into an infinite loop.
Inlining is indeed possible for all functions for which we can guarantee that the number of replacements will be finite. I'm currently implementing this for `fn:fold-left`, `fn:fold-right` and `fn:for-each` (basically loop unrolling) when the sequence is short and known at compile time. It would definitely be possible to implement this for user-defined functions, too, but we'd need to identify (a subset of) the correct ones.
Another option would be to always inline recursive functions up to a fixed depth. This is conceptually simpler, but would bloat the syntax tree and mostly (?) not help much.
What are your ideas? Leo
[1] http://en.wikipedia.org/wiki/Tail_call [2] https://github.com/BaseXdb/basex/blob/next/basex-core/src/main/java/org/base... [3] https://github.com/BaseXdb/basex/blob/next/basex-core/src/main/java/org/base...