This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules][7/8] Find the primary interface name for a module.
ClosedPublic

Authored by iains on Jan 31 2022, 4:47 AM.

Details

Summary

When we are building modules, there are cases where the only way to determine
validity of access is by comparing primary interface names. This is because we need
to be able to associate a primary interface name with an imported partition, but
before the primary interface module is complete - so that textual comparison is
necessary.

If this turns out to be needed many times, we could cache the result, but it seems
unlikely to be significant (at this time); cases with very many imported partitions
would seem unusual.

Diff Detail

Event Timeline

iains created this revision.Jan 31 2022, 4:47 AM
iains updated this revision to Diff 405600.Feb 3 2022, 5:42 AM

rebased onto import state machine

iains updated this revision to Diff 408765.Feb 15 2022, 1:30 AM

Rebased onto other modules work.

iains published this revision for review.Feb 15 2022, 8:33 AM

patch 7 of 8 to implement basic C++20 module partition support.

Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2022, 8:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
iains updated this revision to Diff 409209.Feb 16 2022, 4:35 AM

rebased onto changes in parent patches.

iains retitled this revision from [C++20][Modules] Find the primary interface name for a module. to [C++20][Modules][7/8] Find the primary interface name for a module..Feb 16 2022, 4:35 AM
urnathan added inline comments.Feb 16 2022, 8:32 AM
clang/include/clang/Basic/Module.h
520–522

stray blank line?

523–524

haven't you added an IsPartition flag to Module? can't you test that before searching? Also, Almost Always Auto?

urnathan added inline comments.Feb 16 2022, 8:39 AM
clang/include/clang/Basic/Module.h
522

Is it possible to return a StringRef rather than a copy?

iains added inline comments.Feb 16 2022, 8:52 AM
clang/include/clang/Basic/Module.h
523–524
  1. The case we are dealing with is

we're building A{,:B}
we encounter :Part

So we do not have a module for the importer ('cos we didn't build it yet) but we need to know the primary module name for the imported partition (even to be able to find it).

So it's a wee bit icky, but we are reduced to manipulating text (none of the content of Module.h is available - we are looking at parser tokens).

  1. auto and StringRefs - yes probably I could do better.

The consolation is that this is not an action we'd reasonably expect to be carried out many times c.f. other parser jobs - of course, I'll be proven wrong and someone will import 10^6 partitions ....

iains added inline comments.Feb 16 2022, 9:12 AM
clang/include/clang/Basic/Module.h
523–524

(none of the content of Module.h is available - we are looking at parser tokens).

maybe I retract that, at least partially, we do not have a module (built) - but some of the base information is saved in sema when the module decl is built, so we probably do know if we are building A:B or just A.

If we think that this could be a pain point - sema can cache the primary module name and we can then return a StringRef to that.

My implementation is

StringRef getPrimaryModuleName() const {
    if (Check Kind)
      return Name;
    return StringRef(Name).split('-').first;
  }
iains updated this revision to Diff 409665.Feb 17 2022, 8:18 AM

address review comments, rebase

iains updated this revision to Diff 409666.Feb 17 2022, 8:20 AM
iains marked an inline comment as done.

remove stray blank line

iains marked 2 inline comments as done.Feb 17 2022, 8:23 AM
iains added inline comments.
clang/include/clang/Basic/Module.h
523–524

I've reworked this to use a StringRef - so that the source string components are owned by the importing module (which we're building) and then we construct a new module name (for the imported module) which we will use to find it. We have enough of the module at this point to do this.

urnathan accepted this revision.Feb 17 2022, 8:33 AM
This revision is now accepted and ready to land.Feb 17 2022, 8:33 AM
ChuanqiXu added inline comments.Feb 17 2022, 11:04 PM
clang/include/clang/Basic/Module.h
527

Here we could return Name simply.

iains updated this revision to Diff 410539.Feb 22 2022, 7:59 AM

rebased, addressed review comment.

iains marked an inline comment as done.Feb 22 2022, 8:00 AM
iains updated this revision to Diff 411546.Feb 25 2022, 4:01 PM

rebased

This revision was landed with ongoing or failed builds.Feb 28 2022, 12:50 AM
This revision was automatically updated to reflect the committed changes.