<div dir="ltr">It's worth carefully thinking about your design goals for this system. Particularly how much you value:<div> - predictability (isolation and debugging)</div><div> - efficiency (e.g. in terms of total CPU usage)<br><div> - scalability (often in tension with efficiency)</div></div><div><br></div><div><div>We've had some good experience with a mapreduce approach for cross-TU analysis, for dead-code analysis etc.</div><div>The idea is your analysis is composed of pure functions that run on a single TU.</div><div></div><div>e.g. for inline-function, this would be:</div><div> 1. [Prepare] analyze the TU containing the target function, this is a function (input spec, TU AST) -> function AST</div><div> 2. [Map] analyze every TU to find occurrences and compute edits, this is a function (TU AST, function AST) -> [(file, edit)]</div><div> 3. [Reduce] group by file and reconcile edits, this is a function (file, [edit]) -> edit</div><div><br></div><div>It trades off a bit of efficiency to be highly predictable (pure functions are easy to test, intermediate states can be saved for analysis, bugs are easily localizable to TUs) and scalable.</div></div><div>It does require your intermediate data to be serializable, but distributing over a network server does too. Having the "framework part" not be too opinionated about the form of this data gives some useful flexibility.</div><div><br></div><div>Compared to this, your ASTServer seems to sacrifice scalability and predictability for efficiency if I'm understanding it correctly, it's worth carefully considering whether this is the right tradeoff (e.g. it only makes sense if your analyses are often slow enough to be worth squeezing this efficiency out of, but fast enough that they don't need to be seriously distributed).</div><div><br></div><div>The Tooling libraries have fair support for Map steps, but none for Reduce and nothing very useful for stringing steps together. It's possible to bolt this stuff on but I regret that we haven't added it.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 29, 2020 at 10:15 AM Endre Fülöp <<a href="mailto:Endre.Fulop@sigmatechnology.se">Endre.Fulop@sigmatechnology.se</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="HU">
<div class="gmail-m_-3399173636269120719WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi!<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">In order to not overburden the previous discussion about Analyzer and Tooling, I would like to ask you opinions on a related but slightly orthogonal matter.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Gabor and I had a brainstorming session about the issues CTU analysis and compilation command handling (previous topic) brought up recently.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Note that these points are to be regarded as cursory expeditions into the hypothetical (at best).<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">The train of thought regarding CTU analysis had the following outline:<u></u><u></u></span></p>
<ul type="disc">
<li class="MsoNormal">
<span lang="EN-US">We need a tool that gets a `FunctionDecl` (the function which we would like to inline) and returns with an AST to its TU.<u></u><u></u></span></li><ul type="circle">
<li class="MsoNormal">
<span lang="EN-US">the fitting abstraction level of the result seems to be the TU level<u></u><u></u></span></li><li class="MsoNormal">
<span lang="EN-US">`externalDefMapping.txt` is just an implementation detail, actually we don't need that.<u></u><u></u></span></li></ul>
<li class="MsoNormal">
<span lang="EN-US">Let's call this tool `<b>ASTServer</b>`.<u></u><u></u></span></li><li class="MsoNormal">
<span lang="EN-US">ASTServer has some resemblance to `clangd`.<u></u><u></u></span></li><ul type="circle">
<li class="MsoNormal">
<span lang="EN-US">Works on the whole project<u></u><u></u></span></li><li class="MsoNormal">
<span lang="EN-US">Uses compilation DB<u></u><u></u></span></li><li class="MsoNormal">
<span lang="EN-US">Persists already parsed ASTs in its memory (up to a limit)<u></u><u></u></span></li><ul type="square">
<li class="MsoNormal">
<span lang="EN-US">(Cache eviction strategies? LRU?)<u></u><u></u></span></li></ul>
</ul>
<li class="MsoNormal">
<span lang="EN-US">The AST would be returned on a socket and in a serialized form (ASTReader/Writer).<u></u><u></u></span></li><ul type="circle">
<li class="MsoNormal">
<span lang="EN-US">could also work over the network, promoting distribution<u></u><u></u></span></li></ul>
<li class="MsoNormal">
<span lang="EN-US">We need another tool: `<b>clang-analyzer</b>` !!!<u></u><u></u></span></li><ul type="circle">
<li class="MsoNormal">
<span lang="EN-US">Actually we should have done this earlier<u></u><u></u></span></li><li class="MsoNormal">
<span lang="EN-US">Utilizes clang for analysis purposes<u></u><u></u></span></li><li class="MsoNormal">
<span lang="EN-US">Handles comm with `ASTServer`<u></u><u></u></span></li><ul type="square">
<li class="MsoNormal">
<span lang="EN-US">Caches ASTs from the server<u></u><u></u></span></li></ul>
</ul>
<li class="MsoNormal">
<span lang="EN-US">external orchestrator tool CodeChecker tool would launch ASTServer and then would call clang-analyzer tool for each TU, thus conducting the analysis.<u></u><u></u></span></li></ul>
<p class="MsoNormal"><span lang="EN-US">The reasoning behind the separation:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">The analyzer is a complex subsystem of Clang. The valid concern of clang binary growing out of proportion, and the increasing need for<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">tooling dependencies surfacing due to CTU analysis indicate the need reorganizing facilities.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">The point is further backed by the argument that a complex functionality of interprocess communication (over sockets in our example)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">is even less desirable inside the clang binary than binary size bloat.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Also the complexity of the whole solution could be distributed, and concerns of build system management, build configuration formats<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">can be separated from the analyzer itself (but allows for a wide variety of build-system vs analysis cooperation schemes to be implemented).<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Again, the scope of these ideas is not trivial to assess, and would probably require a considerable amount of effort,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">but I hope an open discussion would outline a solution that benefits the structure of the whole project.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Cheers,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Endre<u></u><u></u></span></p>
</div>
</div>

</blockquote></div>