This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Make our printing policies for Hover more consistent, especially tags
ClosedPublic

Authored by sammccall on Dec 18 2020, 9:39 AM.

Details

Summary

Different cases were using a bunch of different variants of the printing policy.
Each of these had something going for it, but the result was inconsistent.

Goals:

  • single printing policy used (almost) everywhere
  • avoid unidiomatic tags like class vector<class X>
  • be informative and easy to understand

For tags, the solution I wound up with is: we print only the outer tag and only
in the simplest cases where this elaboration won't cause confusion.

For example:

  • class X
  • enum Foo
  • vector<int>
  • X*

This seems to strike a nice balance of providing plenty of info/context in common
cases while never being confusing.

Diff Detail

Event Timeline

sammccall created this revision.Dec 18 2020, 9:39 AM
sammccall requested review of this revision.Dec 18 2020, 9:39 AM

Looks good to me, it removes a lot of duplication and corner cases.

I'd have printed the tag for reference and pointers as well (class Foo* instead of Foo*). I don't think Foo* is much more understandable than Foo, so we decide that printing class Foo is easier to understand for the user, we should print class Foo* as well.
But I agree it's even less idiomatic, so I won't argue with your choice.

sammccall added a comment.EditedDec 18 2020, 3:51 PM

Looks good to me, it removes a lot of duplication and corner cases.

I'd have printed the tag for reference and pointers as well (class Foo* instead of Foo*). I don't think Foo* is much more understandable than Foo, so we decide that printing class Foo is easier to understand for the user, we should print class Foo* as well.
But I agree it's even less idiomatic, so I won't argue with your choice.

Yeah, class Foo * doesn't seem bad, though for some reason my brain struggles with class Foo && :-)
I really think I like drawing the line *somewhere* in terms of complexity, but maybe it's not in the ideal place.

There's a pragmatic reason to draw it here: simply prepending "class " doesn't work in the presence of qualifiers. So the current patch will print class Foo but const Foo, but at least the latter is rare. The inconsistency between class Foo* and const Foo* would be a bigger deal, I think. And getting const class Foo* without also producing class Foo<class Bar> would need changes to TypePrinter, which is a bit of a yak-shave.

So I think I'll land this as an improvement over the status quo, at least.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 18 2020, 4:03 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.