This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Refactor LookupVisibleDecls. NFC
ClosedPublic

Authored by ilya-biryukov on Aug 5 2019, 8:20 AM.

Details

Summary

We accumulated some configuration parameters for LookupVisibleDecls that
are being passed unchanged to recursive calls, e.g. LoadExternal and
IncludeDependentBases.

At the same time, there is a bunch of parameters that can change in the
recursive invocations.

It is hard to tell the difference between those groups, making the code
hard to follow.

This change introduces a helper struct and factors out the non-changing
bits into fields, making recursive calls in the implementation code easier
to read.

Diff Detail

Repository
rL LLVM

Event Timeline

ilya-biryukov created this revision.Aug 5 2019, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2019, 8:20 AM
  • Remove accidental change from revision

This is just a proposal, there are probably other ways to reach better readability, e.g. group some of those parameters into a struct.
But let me know what you think, happy to refactor in a slightly different manner or simply drop this revision.

This looks reasonable to me, there are a couple of variations you might think about:

  • also treat QualifiedNameLookup as an option, and override in places with an RAII pattern like ScopedOverride Unqual(QualifiedNameLookup, false) (why don't we have a class like that?). This would further reduce args.
  • put the options in a LookupOpts struct and pass it by const reference - this is a less invasive change

This looks reasonable to me, there are a couple of variations you might think about:

  • also treat QualifiedNameLookup as an option, and override in places with an RAII pattern like ScopedOverride Unqual(QualifiedNameLookup, false) (why don't we have a class like that?). This would further reduce args.

I actually think it's good to have it as an explicit option. Qualified and unqualified lookup are so vastly different use-cases, that having the flag that discriminates them as a function parameter looks like a better trade-off.
Besides, RAII objects are more code and more complicated.

  • put the options in a LookupOpts struct and pass it by const reference - this is a less invasive change

Also an option. I personally like the current version more even though it's more invasive; it adds more structure IMO.

Those decisions are personal preferences, I don't have strong opinions there.
@doug.gregor as an original author of the code, do you have any opinions on where this code should go?

sammccall accepted this revision.Aug 12 2019, 4:47 AM

Agreed, this seems fine as is.

This revision is now accepted and ready to land.Aug 12 2019, 4:47 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2019, 1:58 AM