<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 14, 2015 at 2:29 PM Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Sep 14, 2015 at 4:38 PM, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:<br>
><br>
><br>
> On Mon, Sep 14, 2015 at 12:26 PM Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>><br>
> wrote:<br>
>><br>
>> On Mon, Sep 14, 2015 at 2:45 PM, Daniel Jasper <<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>> wrote:<br>
>> > By this point, I see that change might be profitable overall. However,<br>
>> > lets<br>
>> > completely map this out. Changing just cxxRecordDecl() can actually<br>
>> > increase<br>
>> > confusion in other areas. Right now, not a single AST matcher has the<br>
>> > cxx<br>
>> > prefix (although a total of 28 stand for the corresponding CXX.. AST<br>
>> > node).<br>
>> > This is consistent and people knowing this will never try to write<br>
>> > cxxConstructExpr(). As soon as people have used cxxRecordDecl(), the<br>
>> > chance<br>
>> > of them trying cxxConstructExpr() increases. You have spent a long time<br>
>> > figuring out that recordDecl means cxxRecordDecl(), which is one<br>
>> > datapoint,<br>
>> > but I am not aware of anyone else having this specific issue. And we<br>
>> > could<br>
>> > make this less bad with better documentation, I think.<br>
>> ><br>
>> > So, for me, the questions are:<br>
>> > 1) Do we want/need this change?<br>
>><br>
>> We definitely need *a* change because there currently is no way to<br>
>> match a C struct or union when compiling in C mode. I discovered this<br>
>> because I was trying to write a new checker for clang-tidy that<br>
>> focuses on C code and it would fail to match when compiling in C mode.<br>
>> Whether we decide to go with cxxRecordDecl vs recordDecl vs structDecl<br>
>> (etc) is less important to me than the ability to write clang-tidy<br>
>> checks for C code.<br>
>><br>
>> > 2) Do we want to be consistent and change the other 27 matchers as well?<br>
>><br>
>> I'm on the fence about this for all the reasons you point out.<br>
>><br>
>> > A fundamental question is whether we want AST matchers to match AST<br>
>> > nodes<br>
>> > 1:1 or whether they should be an abstraction from some implementation<br>
>> > details of the AST.<br>
>><br>
>> I absolutely agree that this is a fundamental question. I think a<br>
>> higher priority fundamental question that goes along with it is: are<br>
>> we okay with breaking a lot of user code (are these meant to be stable<br>
>> APIs like the LLVM C APIs)? If we want these APIs to be stable, that<br>
>> changes the answer of what kind of mapping we can have.<br>
><br>
><br>
> I think the AST matchers are so closely coupled to the AST that it trying to<br>
> be more stable than the AST doesn't help. Basically all uses of AST matchers<br>
> do something with the AST nodes afterwards, which will break anyway.<br>
<br>
I can get behind that logic. So we're okay with breaking their code<br>
because there's no way around it -- it's tied to the AST, so users<br>
cannot rely on the AST APIs remaining the same from release to release<br>
anyway.<br></blockquote><div><br></div><div>We might even *want* the code to break, as the use of the AST node might now be incorrect on a semantic level.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
><br>
>><br>
>> > And this is not an easy question to answer. There are<br>
>> > many places where we don't follow a strict 1:1 mapping. Mostly node<br>
>> > matchers, but also in traversal matchers, e.g. isDerivedFrom().<br>
>> ><br>
>> > Personally, I'd really hate to have the cxx Prefix everywhere, but<br>
>> > that's<br>
>> > just my personal opinion. I would even prefer matchers like record() and<br>
>> > method(), but I think somebody convinced me that that would be a very<br>
>> > bad<br>
>> > idea ;-).<br>
>><br>
>> My personal opinion is that (1) breaking code is fine, but we should<br>
>> avoid doing it without very clear benefit, and (2) the mapping between<br>
>> AST node identifiers and AST matcher identifiers needs to be<br>
>> incredibly obvious, but perhaps not slavishly 1:1. If we instead<br>
>> decide we want a 1:1 mapping, then I think we need to start seriously<br>
>> considering auto-generating the AST node (and type) matchers from<br>
>> tablegen so that the AST nodes *cannot* get out of sync with the AST<br>
>> matchers, otherwise we'll be right back here again in a few years when<br>
>> we modify the name of an AST node.<br>
><br>
><br>
> I do think we want to auto-generate the matchers, but I don't think tablegen<br>
> is the right approach (I think an ast-matcher based tool is ;)<br>
> That said, auto-generating all the matchers is a) a lot of effort and b) the<br>
> code-size and compile time of matchers already matters, so it's unclear<br>
> which ones we would want to generate, especially for traversal matchers :(<br>
<br>
Oh, that's an excellent point (I'm talking about (b), I already knew<br>
(a) was a lot of work). Thank you for pointing that out!<br>
<br>
><br>
>><br>
>> My definition of "incredibly obvious" is: if the AST has a prefixed<br>
>> and unprefixed version, or two different prefixes, we should mimic<br>
>> that directly with the matchers. Otherwise, existing AST matchers<br>
>> without prefix shenanigans can remain as they are, and new AST<br>
>> matchers should prefix as-required. If we decide we're okay breaking<br>
>> code, then I don't see a problem with changing ctorInitializer() into<br>
>> cxxCtorInitializer() when C adds constructors. ;-)<br>
><br>
><br>
> I think the main things is cost for developers who try to write matchers and<br>
> work from the -ast-dump. Figuring out that there *is* a matcher with an<br>
> unprefixed node can take a while.<br>
<br>
Hmm, yes, but "take a while" should be relatively short, I would<br>
think. In that use-case, the user does an -ast-dump, sees<br>
"CXXFrobbleGnasher", they go to the AST matcher reference and they<br>
search for "CXXFrobberGnasher." The first hit won't be<br>
cxxFrobbleGnasher, but the entry for frobbleGnasher (which is still<br>
the first hit when searching from the top of the document due to the<br>
way we position node matchers) will have a parameter of<br>
CXXFrobbleGnasher, so they will find still get to the right matcher on<br>
the first hit. If someone doesn't read the documentation at all,<br>
they're going to try cxxFrobbleGnasher() and get a compile error/no<br>
known matcher. Then they'll go look at ASTMatchers.h and figure out<br>
it's called frobbleGnasher by searching there instead of the<br>
documentation.<br></blockquote><div><br></div><div>The problem is that I've learned that sometimes people try to make things work in ways that I couldn't even imagine, and they lose more time than I could ever imagine them using :) Also, I agree the time is probably on average not that large, but we pay it over a long time in the future, and it tends to add up.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That's compared to having the matcher name always be the same as the<br>
AST node, where the user writes cxxFrobbleGnasher and it just works,<br>
which is definitely a mark in favor of making everything consistent. I<br>
just don't think the current approach is too onerous in the case where<br>
the matcher is at least *provided* for the user with a relatively sane<br>
name.<br>
<br>
>> I should be clear, I'm not opposed to just having a 1:1 mapping. I'm<br>
>> just not certain the benefits of being strict about that outweigh the<br>
>> costs to broken code. cxxCtorInitializer will break someone's code,<br>
>> but I don't think it adds any clarity to their code, so I don't see<br>
>> the benefit of forcing the change.<br>
><br>
> Well, I think there's the cost of broken code *once* now, vs. the (smaller)<br>
> cost for users in all future.<br>
> I'm still strongly in favor of breaking now, and having a simpler model<br>
> going forward.<br>
<br>
I'm definitely in favor of breaking now in the case of RecordDecl vs<br>
CXXRecordDecl. I think having recordDecl match CXXRecordDecl is a bug<br>
given that there's no way to match a RecordDecl.<br>
<br>
I would also be totally in favor of being consistent if we were<br>
starting from scratch. I'm very, very weakly opposed to breaking more<br>
user's code than we have to in order to get usable matchers because it<br>
seems gratuitous. Breaking code to get something that works seems<br>
reasonable. Breaking code that already works just to change the name<br>
for consistency elsewhere, I'm a bit less keen on. But the fact that<br>
we already can break user's code at-will because of the reliance on<br>
the AST nodes makes me think it may be the right approach for the best<br>
API, since that's what I would want if we were starting from scratch.<br>
<br>
Okay, I'm convinced. I think we should rename the type and node<br>
matchers (not traversal and narrowing matchers) to match the AST node<br>
names in all cases. We can document the breakage in the release notes,<br>
but (hopefully) only have to do this dance one time instead of<br>
spreading the pain out as it happens to eventually get to the same<br>
place anyway.<br></blockquote><div><br></div><div>Yea, people who want more stability do use releases anyway.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Daniel, is this something you would be okay with? (I'm assuming<br>
Richard finds it acceptable based on previous comments from Manuel,<br>
but Richard, feel free to chime in.)<br></blockquote><div><br></div><div>Offline conversation with Richard says that he is convinced.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
~Aaron<br>
</blockquote></div></div>