[PATCH] D84919: [clangd] Be more explicit on testing the optional DefLoc in LocatedSymbol.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 30 03:23:27 PDT 2020


kadircet added inline comments.


================
Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:285
 ::testing::Matcher<LocatedSymbol> Sym(std::string Name, Range Decl) {
-  return Sym(Name, Decl, llvm::None);
+  return Sym(Name, Decl, Decl);
 }
----------------
hokein wrote:
> kadircet wrote:
> > i am not sure if this change is aligned with the whole idea. we are trying to make the matcher more explicit, so if user wants to assert on the definition being equal to some range I think they should be explicitly specifying it. so I believe this should keep passing `llvm::None` to underlying matcher.
> > 
> > I know it is likely more work than this version, but otherwise we are not really making it explicit.
> yeah, it seems odd. I think this function is used as a syntax sugar to check `LocatedSymbol` has the *same* decl/def range, most callers have this assumptions.
> 
> options:
> 
> 1. keeps it as is, and rename it to something like `SymWithSameDeclDefRange` (a better name is welcome);
> 2. remove it, and use the 3-arg matcher above, callers have to be more verbose (passing decl/def ranges explicitly, even they are the same), and we have 15 references;
> 
> 1 is my preference, what do you think?
> yeah, it seems odd. I think this function is used as a syntax sugar to check LocatedSymbol has the *same* decl/def range, most callers have this assumptions.

my reading of the previous state was:

the real matcher treated `llvm::None` on the last parameter as a `Dont care`, it was basically ignoring the definition. hence the two parameter version was used in places where people didn't care about definition range (or even its existence). so this patch is changing the behaviour of this two parameter version from `don't care` to `make sure they are equal`, i am not saying that's a bad thing but it just feels like more implicit (which is against the idea of the patch).

> keeps it as is, and rename it to something like SymWithSameDeclDefRange (a better name is welcome);

renaming would be one way of dealing with implicitness here. i am just not sure if it is really worth it though. I don't really think the existing call sites had the idea of `make sure def and decl range are identical` in mind. so I would opt for 2nd option you proposed if that's ok with you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84919/new/

https://reviews.llvm.org/D84919



More information about the cfe-commits mailing list