<div dir="ltr">Hi,<div><br></div><div>should we submit this CL, adding the option to prepend classes and struct fully qualified names with "::"?</div><div><br></div><div>This can then allow people to slowly switch to the new function, and I can close my fix/close my bug in CLIF. I can do more on this CL if it is needed, but I would like to be sure this will get submitted and I will not waste my time, and know exactly what you want me to do.</div><div><br></div><div>Possible options include:</div><div>- adding the full context, with the bug, in the CL description</div><div>- adding documentation on `getFullyQualifiedName` expliciting in which context the bug can occur</div><div>- adding a FullyQualifiedTypePrinter() that will take an AST or a TypePolicy, and set the correct fields, so one can do QualType.getAsString(FullyQualifiedTypePrinter(ast)) to replace the hereabove one.</div><div>- add some tests, but I do not know where and how.</div><div><br></div><div>When this few lines are submitted, I can update google3 for clang, and I can start changing some internal occurrences, and finally fix the CLIF bug.</div><div><br></div><div>Thanks!</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 11:19 PM Jean-Baptiste Lespiau <<a href="mailto:jblespiau@google.com">jblespiau@google.com</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 dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 11:11 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</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 dir="ltr"><div dir="ltr">On Tue, May 12, 2020 at 12:40 PM Jean-Baptiste Lespiau <<a href="mailto:jblespiau@google.com" target="_blank">jblespiau@google.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">Hi,<div><br></div><div>thanks for your answer.</div><div><br></div><div>Just a few remarks:</div><div><br></div><div>1. I imagine that we cannot know if people are using getFullyQualifiedName. In particular, people could have developed their own internal tools, thus we cannot be aware of all callers. I do not know Clang's policy, but can we delete or completely change a function without deprecating it first?</div></div></blockquote><div><br>The LLVM project offers little/no API guarantees - potentially/especially for a function with no use in-tree. But, yes, as Googlers we'd be encouraged not to commit an API change knowing this might cause widespread internal breakage without a plan/pre-emptively fixing things.<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> I was imagining that the process was to deprecate it, document the case where it can be incorrect, and that in a next release it gets deleted/replaced (or someone steps up to fix it).</div></div></blockquote><div><br>Sometimes deprecation is used - certain APIs have a lot of out of tree surface area <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>2. As example of different behaviors:</div><div>(a) the qual_type.getAsString() will print implementation namespace details (e.g. ::std<b>::__u</b>::variant instead of std::variant).</div></div></blockquote><div><br></div><div>Yep, that's probably not ideal for most source generating use cases.</div><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>(b) It will also display default template arguments, e.g.</div><div>template <T = void></div><div>class MyClass</div><div>is printed as MyClass (I think) in getFullyQualifiedName, while getAsString() will use MyClass<void>.</div></div></blockquote><div><br>That seems better/correct - did CLIF actually want/rely on/benefit from the old behavior of only printing the template name?<br></div></div></div></blockquote><div> </div><div>I did check to replace all of the getFullyQualifiedName in CLIF with the new version: it worked like a charm. The error messages are just changed accordingly (so they will have longer types). </div><div>And the generated code was also less verbose.</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>(c) the example of the nested template argument above.</div></div></blockquote><div><br>Which seems just wrong/inconsistent/not-behaving-to-spec to me - I don't imagine any caller actually wanted that behavior?<br></div></div></div></blockquote><div><br></div><div>I agree. </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><br></div><div>At the end,what matters is that getAsString() is semantically always correct, even if it can be overly verbose.</div></div></blockquote><div><br></div><div>The presence of inline namespaces is about the only bit I'd find a touch questionable. (Hopefully Sam can chime in on some of that)</div></div></div></blockquote><div><br></div><div>Me too, I would be curious if it is easy to remove. </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> I tried to fix getFullyQualifiedName, but I do not understand its code.</div><div><br></div><div>3. When the goal we want to reach has been decided, there is also the question on how to transition from the current state to the next state, and who can help with that. To be way clearer, I won't be able to fix all of Google internal usage of this function (I am not at all working on Clang, Clif, or any tools, I just hit the bug and decided to look into it, and it happened that I found a fix). Thus, if we can do the changes using iterative steps, such as</div><div>(a) add the new "::" prefix configuration,</div><div>(b) Deprecate/document the fact that getFullyQualifiedName has a bug, and people should move to use qual_type.getAsString(Policy) instead, using "FullyQualifiedName" and "GlobalScopeQualifiedName". We can for example provide :</div></div></blockquote><div><br></div><div>It'd still fall to one of us Googlers to clean this all up inside Google - since we build with -Werror, it's not like folks'll just get soft encouragement to migrate away from the API, either the warning will be on and their build will be broken (in which case we'll probably pick it up when we integrate changes from upstream & have to fix it to complete that integration) or no signal, and it'll break when the function is finally removed.</div><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><font face="monospace">std::string GetFullyQualifiedCanonicalType(QualType qual_type, const<span style="font-size:medium;color:rgb(0,0,0);white-space:pre-wrap"> </span>ASTContext<span style="font-size:medium;color:rgb(0,0,0);white-space:pre-wrap"> &</span>ast<span style="font-size:medium;color:rgb(0,0,0);white-space:pre-wrap">,</span>) </font></div><div><font face="monospace"> clang::PrintingPolicy print_policy(ast.GetASTContext().getLangOpts());<br> print_policy.FullyQualifiedName = 1;<br> print_policy.SuppressScope = 0;<br> print_policy.PrintCanonicalTypes = 1;<br> print_policy.GlobalScopeQualifiedName = 1;<br> QualType canonical_type = qual_type.getCanonicalType();<br> return canonical_type.getAsString(print_policy);<br>}</font><br></div><div>(c) Then, people can upgrade asynchronously, maybe someone will be unhappy with this behavior and will suggest something else, etc.</div><div><br></div><div>If we just blindly delete it, it means for example that we have to fix all usages in Google to be able to upgrade Clang. It may be the approach that is decided we should follow, but I just wanted to make it clear that I will not be able to do that job^^ While, having an incremental fix in Clang, and then fix Clif is doable as it does not imply to fix all calls in one go.</div><div><br></div><div>I just wanted to develop these points.</div></div></blockquote><div><br></div><div>Sure enough - appreciate the awareness of the cost to external clients, to be sure.<br><br>- Dave</div><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><br></div><div>Thanks!</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 7:59 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</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 dir="ltr">+Mr. Smith for visibility.<br><br>I'm /guessing/ the right path might be to change the implementation of getFullyQualifiedName to use the type printing/pretty printer approach with the extra feature you're suggesting. That way all users get the desired behavior<br><br><a class="gmail_plusreply" id="gmail-m_1625477013998801475gmail-m_241918858012614672m_-4294094340746894579gmail-m_141052555089163653gmail-m_3371060255040687771plusReplyChip-1" href="mailto:sammccall@google.com" target="_blank">+Sam McCall</a> who (if I understand correctly) has a lot to do with the Clang Tooling work - looks like Google's got a bunch of uses of this function (getFullyQualifiedName) internally in clang tools (I wonder why that's the case when there are still zero external callers - is that OK? Or are external users doing something different (better? worse?) to answer this question - or the tooling uses in LLVM proper just don't have the same needs?). So probably best not to leave a buggy implementation lying around - either deleting it, or fixing it.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 11, 2020 at 11:28 PM Jean-Baptiste Lespiau via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</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 dir="ltr">Hi,<div><br></div><div><b>Context and history:</b></div><div><br></div><div>I have found a bug in <a href="https://github.com/google/clif" target="_blank">CLIF</a>, which does not correctly fully qualify templated names when they are nested, e.g.</div><div><br></div><div>::tensorfn::Nested< ::std::variant<Tensor, DeviceTensor> ><br></div><div><br></div><div>should have been:</div><div><br></div><div>::tensorfn::Nested< ::std::variant<::tensorflow::Tensor,::tensorfn::DeviceTensor> ><br></div><div><br></div><div>I tracked it down to </div><div><a href="https://github.com/google/clif/blob/master/clif/backend/matcher.cc#L172" target="_blank">https://github.com/google/clif/blob/master/clif/backend/matcher.cc#L172</a><br></div><div>which calls</div><div><a href="https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp" target="_blank">https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp</a><br></div><div>and the error is exactly at the line, but I could not really understand why.</div><div><a href="https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp#L457" target="_blank">https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp#L457</a><br></div><div><br></div><div>Historically, it has been added by the developers of CLIF (including Sterling Augustine)</div><div><a href="https://github.com/llvm/llvm-project/commit/0dd191a5c4bf27cc8a2b6033436b00f0cbdc4ce7" target="_blank">https://github.com/llvm/llvm-project/commit/0dd191a5c4bf27cc8a2b6033436b00f0cbdc4ce7</a>.<br></div><div>They explained to me, that they pushed this to Clang hoping it would be used by other tools and maintained by the community, but that it kind of failed at that, and it (i.e. QualTypeName.pp) is not much used, and not much maintained.</div><div><br></div><div>I was not able to understand this file to provide a fix. On the other side, it was easy to understand TypePrinter.cpp and PrettyPrinter.cpp, so I tried extending it to fit my need.</div><div><br></div><div><b>Suggestion</b></div><div><b><br></b></div><div> As I wanted fully qualified types (it's usually more convenient for tools generating code), to prevent some complex errors), I added ~10 lines that add an option to prepend "::" to qualified types (see the patch).</div><div><br></div><div>In practice, it is still a different display at what QualTypeNames.cpp was doing, as, for example, it displays</div><div><br></div><div>::tensorfn::Nested<::std<b>::__u</b>::variant<tensorflow::Tensor, ::tensorfn::DeviceTensor>><br></div><div><br></div><div>but I was able to solve my issues. More generally, it is more verbose, as it displays the exact underlying type, including default parameter types in template arguments. So it's verbose, but it's correct (what is best?^^).</div><div><br></div><div>I am contacting you, so we can discuss:</div><div><br></div><div>- Whether <a href="https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp" target="_blank">QualTypeNames.cpp</a> is something useful for the Clang project, whether you think we should fix the bug I have found (but I cannot, as I do not understand it), or whether we should deprecate it, or modify the current printing mechanism (TypePrinter.cpp and PrettyPrinter.cpp) to add more options to tune the display in ways people may want to.</div><div>- Whether adding the CL I have attached is positive, and if yes, what should be done in addition to that (does it need tests? Are there more types that we may want to prepend "::" to its fully qualified name?).</div><div><br></div><div>Thanks!</div><div><br></div><div></div></div>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div>