Skip to content

Files

Latest commit

 

History

History
37 lines (20 loc) · 1.46 KB

implementation.md

File metadata and controls

37 lines (20 loc) · 1.46 KB

One curiosity question I have it why the parsePrefix() and parseInfix() methods were written to return a function pointer, instead of writing them to simply take the (ParserSessionPtr, Token) arguments and compute the result directly. The function pointer seems like pure indirection (I didn't see any place where the returned function pointer wasn't immediately called.)

Just looking at the first example I saw:

auto P2 = prefixParselets[Tok.Tok.value()];
    
MUSTTAIL
return (P2->parsePrefix())(session, P2, Tok);

Are you asking why not just do:

return P2->parsePrefix(session, Tok);

?

This is because the current state-of-the-art for tail calls in Clang is that you cannot make a tail call from flat function to an instance method.

You can call flat function -> flat function and method instance -> method of same instance, but I think that's it.

But I later discovered that I am abusing the current tail-call technology and cannot actually use the [[clang::musttail]] stuff right now (see llvm/llvm-project#56435 that I filed)

If I made Tokens a lot smaller, I may be able to get away with not breaking anything at -O2 but I haven't done that yet.

So none of the tail-call stuff is even being used right now.

I wonder if it would be possible to do P2->parsePrefix(session, Tok) or similar if not compiling with MUSTTAIL.

I have no doubt that deep C++ magic involving std::bind or something may be technically possible.