<div dir="ltr">Thanks everyone for an interest. I really appreciate your help and I see your points. <div><br></div><div>To be able to release next version of ctai, I implemented a simplified example.</div><div><br></div><div>One more clarification Reid,</div><div>><span style="font-size:12.8px">My understanding is that constexpr functions were designed as a more convenient, readable, and efficient way to implement these kinds of metaprograms, so I suggest using them instead.</span></div><div><span style="font-size:12.8px">One of the assumptions during ctai implementation was to use template classes/structs everywhere, without constexpr functions and objects. There is a kind of stereotype that templates are difficult and I wanted to challenge myself with program like that. In fact, with constexpr functions/objects it would be too easy (:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks again,</span></div><div><span style="font-size:12.8px">Stryku</span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-05-02 18:16 GMT+02:00 Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, May 2, 2017 at 5:37 AM, mats petersson via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="m_-1129979958721840232h5"><span style="color:rgb(34,34,34)">The problem is that the compiler doesn't work anywhere like that currently, and I'm pretty sure you can't (with less than lots of months of effort, if it's at all possible) make it work like that.</span><br></div></div><div><br></div><div>Part of the reason for the compiler "not working like that" is that it does things in phases: It forms AST of the entire  program, then runs semantic analysis on the entire AST, and then runs the CodeGen on the entire AST. Oh, and debug info is generated alongside CodeGen, and knowing the types in debug symbols is probably useful [although I don't know how useful debuggers are in debugging Template Meta Programming code - not something I spend much time working on in general].<br></div></div></div></div></blockquote><div><br></div></span><div>This is mostly correct, but clang semantic analysis and IR generation actually happen incrementally after every top-level decl. Some things get deferred to end of TU, so that triggers further analysis and IR gen.</div><div><br></div><div>I'm pretty sure we can't do the "delete" steps Mateusz describes because we can't instantiate a template once and then throw away the instantiated specialization later. We have to keep it around in case something would reinstantiate it. The point of instantiation is pretty important in C++, so I don't think we would want to implement a mode that throws away implicit instantiations.</div><div><br></div><div>Finally, it's not practical to implement such a mode because we use a BumpPtrAllocator memory management strategy in ASTContext. That means AST nodes live until end of TU, and there is no infrastructure to free and re-allocate their memory.</div><div><br></div><div>My understanding is that constexpr functions were designed as a more convenient, readable, and efficient way to implement these kinds of metaprograms, so I suggest using them instead.</div></div></div></div>
</blockquote></div><br></div>