<div dir="ltr"><div dir="ltr">On Thu, Oct 28, 2021 at 5:51 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Thu, 28 Oct 2021 at 17:06, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Thu, Oct 28, 2021 at 4:58 PM Richard Smith via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, 25 Oct 2021 at 01:57, chuanqi.xcq via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)">Hi all,</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)"><br></span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)"> Recently I am playing with C++20 modules and I found that the command line support of GCC</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)">is much better than Clang. Here is an example:</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)"><br></span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)">```C++</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)">// say_hello.cpp<br>module;<br>#include <iostream><br>#include <string_view><br>export module Hello;<br>export void SayHello<br> (std::string_view const &name)<br>{<br> std::cout << "Hello " << name << "!\n";<br>}</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)">// main.cpp<br>#include <string_view><br>import Hello;<br>int main() {<br> SayHello("world");<br> return 0;<br>}</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)">```</span></div><div style="clear:both"><span style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;color:rgb(0,0,0)"><br></span></div><div style="clear:both">To compile the example, in gcc we need:</div><div style="clear:both">```</div><div style="clear:both">g++ -std=c++20 -fmodules-ts <span style="color:rgb(0,0,0);font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">say_hello.cpp </span>main.cpp <br></div><div style="clear:both">```</div><div style="clear:both"><br></div><div style="clear:both">And in clang, we need:</div><div style="clear:both">```</div><div style="clear:both"><p style="margin:0px;font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:14px;line-height:normal;font-family:Helvetica;color:rgb(18,20,22)">clang++ -std=c++20 -fmodules-ts -Xclang -emit-module-interface -c say_hello.cpp -o Hello.pcm</p><p style="margin:0px;font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:14px;line-height:normal;font-family:Helvetica;color:rgb(18,20,22)">clang++ -std=c++20 -fmodules-ts -fprebuilt-module-path=. main.cpp say_hello.cpp</p></div><div style="clear:both">```</div></div></blockquote><div><br></div><div>Your point is well-taken. However, some part of the extra work required here is that you're not doing things in the expected way.</div><div><br></div><div>The above is not a correct way to enable C++20 modules in Clang: -fmodules-ts enables the old Modules TS mode, not C++20 modules. -std=c++20 is enough to enable C++20 modules.</div><div><br></div><div>For the '-Xclang -emit-module-interface' portion, what Clang expects is that files that define module interfaces are either named .cppm or are specified with -x c++-module. With that file type, you can use --precompile to produce a .pcm file (just like you'd use -E or -c to produce other kinds of output). For example:</div><div><br></div><div>clang++ -std=c++20 say_hello.cppm --precompile -o Hello.pcm</div><div><br></div><div>The above commands are also parsing say_hello.cpp twice. You can avoid that by using the precompiled form, say_hello.pcm, as a compilation input instead:</div><div><br></div><div>clang++ -std=c++20 -fprebuilt-module-path=. say_hello.pcm main.cpp</div><div><br></div><div>However, this is all based on a model where the PCM file contains a complete description of the input .cppm file, which is not a great model for us to use moving forward due to all the extra stuff ending up in the .pcm file. Currently, Clang lacks two important features here:<br></div><div><br></div><div>1) Produce a .pcm file and a .o file from a single compilation action.</div><div>2) Produce a .pcm file that contains only the information needed for an importer, not a complete description of the input.</div></div></div></blockquote><div><br>Ah, that's good to know - didn't know you were inclined/supportive of this direction (as the only way to build a module - or some mode that'd do it as two-step too?) - one of the previous counterarguments was that producing the .pcm without the .o unblocked consumers sooner/let the .o generation be done in parallel with those consumers. Is that generally known/considered to be too small of a benefit to be worth the build/support complexity compared to the minimal-pcm+.o in-one-go mode & its benefits (smaller .pcms)?<br></div></div></div></blockquote><div><br></div><div>I think it's likely there'll be reasonable build strategies that want to build a minimal PCM and a .o file with two separate actions (to maximize throughput in highly parallel builds), and there'll be reasonable build strategies that want to build them as part of the same action (to minimize total time in a build with less parallelism). I expect people will want both options to be available. The option that we currently provide -- producing a PCM file that can be used as an input to both .o generation and for import -- is probably not well aligned with what most build strategies will want.</div></div></div></blockquote><div><br>Reckon there just aren't enough savings in reusing the PCM for .o generation compared to parsing from scratch? Not enough to justify adding an extra intermediate file (a full pcm that gets consumed for .o generation and a slim pcm that gets consumed by uses). That we'll move away from complete pcms entirely to only minimal pcms? Fair enough. Good to know/think about.<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 dir="ltr"><div class="gmail_quote"><div><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 dir="ltr"><div class="gmail_quote"><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>We will of course need some command-line support for those features, and being compatible with GCC (which already provides these features) would likely make sense.</div><div><br></div><div>As for building and using modules in a single clang command, I agree that'd be nice to have, both for convenience and for GCC compatibility. But ideally this shouldn't depend on what order the files are specified in on the command line, which would require some kind of pre-scanning to find which modules are defined in which files so they can be processed in topological order. (Otherwise, specifying the files in the wrong order would presumably result in stale .pcm files getting used, which would seem quite user-hostile. I don't know if that's what you get from GCC or if it does better somehow.) That kind of prescan might be more complexity than we'd want in the compiler driver, though we can discuss that and figure out where we want to draw that line.</div><div><br></div><div>In any case, I'm hoping we get some clear guidance from SG15 that we can follow.</div><div><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><div style="clear:both">Yeah, in clang we need to another line to emit module interface explicitly and another option</div><div style="clear:both">to tell the prebuilt-module-path. And in GCC, this happens by default, when GCC find it is compiling</div><div style="clear:both">a c++20 module, it would generate the module interface automatically to the path:</div><div style="clear:both">```</div><div style="clear:both"><div style="color:rgb(0,0,0);font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;text-decoration:none">gcm.cache/filename.gcm</div></div><div style="clear:both">```</div><div style="clear:both">It would create `gcm.cache` in case it doesn't exist. </div><div style="clear:both"><br></div><div style="clear:both">And GCC would search prebuilt module interface in `gcm.cache` automatically.</div><div style="clear:both"><br></div><div style="clear:both">It looks much more friendly to me. The intention of this mail is to ask if you think it is the right direction</div><div style="clear:both">to make the clang's command line support for c++20 module more like GCC. The different I see now includes:</div><div style="clear:both">- Generate prebuilt module interface automatically. (And generate it to a specific directory automatically)</div><div style="clear:both">- Have a default value for <span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">prebuilt module path.</span></div><div style="clear:both"><span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline"><br></span></div><div style="clear:both"><span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">I am wondering if any one more familiar with the clang's command line and file system would love to </span></div><div style="clear:both"><span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">support this (I am not so familiar with it). <span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">Although It may take more time, </span>I would love to support if others are busy.</span></div><div style="clear:both"><span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline"><br></span></div><div style="clear:both"><span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">Thanks,</span></div><div style="clear:both"><span style="color:rgb(18,20,22);font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:0px;text-transform:none;background-color:rgb(255,255,255);text-decoration:none;float:none;display:inline">Chuanqi</span></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div></div>