[PATCH] D118598: [C++20][Modules] Find the primary interface name for a module.

Iain Sandoe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 15 08:33:55 PST 2022


iains created this revision.
Herald added a subscriber: dexonsmith.
iains updated this revision to Diff 405600.
iains added a comment.
iains updated this revision to Diff 408765.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rebased onto import state machine


iains added a comment.

Rebased onto other modules work.


iains added a comment.

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


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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118598

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Sema/SemaModule.cpp


Index: clang/lib/Sema/SemaModule.cpp
===================================================================
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -373,17 +373,10 @@
     // We already checked that we are in a module purview in the parser.
     assert (!ModuleScopes.empty() && "in a module purview, but no module?");
     Module *NamedMod = ModuleScopes.back().Module;
-    if (ModuleScopes.back().IsPartition) {
-      // We're importing a partition into a partition, find the name of the
-      // owning named module.
-      size_t P = NamedMod->Name.find_first_of(":");
-      ModuleName = NamedMod->Name.substr(0, P+1);
-    } else {
-      // We're importing a partition into the named module itself (either the
-      // interface or an implementation TU).
-      ModuleName =  NamedMod->Name;
-      ModuleName += ":";
-    }
+    // If we are importing into a partition, find the owning named module,
+    // otherwise, the name of the importing named module.
+    ModuleName = NamedMod->getPrimaryModuleInterfaceName();
+    ModuleName += ":";
     ModuleName += stringFromPath(Partition);
     ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Partition[0].second};
     Partition = ModuleIdPath(ModuleNameLoc);
Index: clang/include/clang/Basic/Module.h
===================================================================
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -522,6 +522,15 @@
     return Name.find(':') != std::string::npos;
   }
 
+  /// Get the primary module interface name from a partition.
+
+  std::string getPrimaryModuleInterfaceName() const {
+    std::string::size_type pos = Name.find(':');
+    if (pos == std::string::npos)
+      return Name;
+    return Name.substr(0, pos);
+  }
+
   /// Retrieve the full name of this module, including the path from
   /// its top-level module.
   /// \param AllowStringLiterals If \c true, components that might not be


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118598.408765.patch
Type: text/x-patch
Size: 1958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220215/53f045c0/attachment.bin>


More information about the cfe-commits mailing list