[PATCH] D124149: [NFC] follow up code cleanup after D123837

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 20 23:35:49 PDT 2022


ChuanqiXu created this revision.
ChuanqiXu added a reviewer: iains.
ChuanqiXu added a project: clang.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

I found there are chances to do simplify the codes further after I landed D123837 <https://reviews.llvm.org/D123837>. This one should be NFC only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124149

Files:
  clang/lib/Sema/SemaLookup.cpp


Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1565,27 +1565,27 @@
   if (UsableModuleUnitsCache.count(M))
     return true;
 
-  // If M is the global module fragment of a module that we've not yet finished
-  // parsing, then M should be the global module fragment in current TU. So it
+  // If M is the global module fragment of the current translation unit. So it
   // should be usable.
   // [module.global.frag]p1:
   //   The global module fragment can be used to provide declarations that are
   //   attached to the global module and usable within the module unit.
-  if ((M->isGlobalModule() && !M->Parent) ||
-      // If M is the private module fragment, it is usable only if it is within
-      // the current module unit. And it must be the current parsing module unit
-      // if it is within the current module unit according to the grammar of the
-      // private module fragment.
-      // NOTE: This is covered by the following condition. The intention of the
-      // check is to avoid string comparison as much as possible.
-      (M->isPrivateModule() && M == getCurrentModule()) ||
+  if (M == GlobalModuleFragment ||
+      // If M is the module we're parsing, it should be usable. This covers the
+      // private module fragment. The private module fragment is usable only if
+      // it is within the current module unit. And it must be the current
+      // parsing module unit if it is within the current module unit according
+      // to the grammar of the private module fragment. NOTE: This is covered by
+      // the following condition. The intention of the check is to avoid string
+      // comparison as much as possible.
+      M == getCurrentModule() ||
       // The module unit which is in the same module with the current module
       // unit is usable.
       //
       // FIXME: Here we judge if they are in the same module by comparing the
       // string. Is there any better solution?
-      (M->getPrimaryModuleInterfaceName() ==
-       llvm::StringRef(getLangOpts().CurrentModule).split(':').first)) {
+      M->getPrimaryModuleInterfaceName() ==
+          llvm::StringRef(getLangOpts().CurrentModule).split(':').first) {
     UsableModuleUnitsCache.insert(M);
     return true;
   }
@@ -1781,31 +1781,14 @@
 
 bool Sema::isModuleVisible(const Module *M, bool ModulePrivate) {
   // The module might be ordinarily visible. For a module-private query, that
-  // means it is part of the current module. For any other query, that means it
-  // is in our visible module set.
-  if (ModulePrivate) {
-    if (isUsableModule(M))
-      return true;
-    else if (M->Kind == Module::ModuleKind::ModulePartitionImplementation &&
-             isModuleDirectlyImported(M))
-      // Unless a partition implementation is directly imported it is not
-      // counted as visible for lookup, although the contained decls might
-      // still be reachable.  It's a partition, so it must be part of the
-      // current module to be a valid import.
-      return true;
-    else if (getLangOpts().CPlusPlusModules && !ModuleScopes.empty() &&
-             ModuleScopes[0].Module->Kind ==
-                 Module::ModuleKind::ModulePartitionImplementation &&
-             ModuleScopes[0].Module->getPrimaryModuleInterfaceName() ==
-                 M->Name &&
-             isModuleDirectlyImported(M))
-      // We are building a module implementation partition and the TU imports
-      // the primary module interface unit.
-      return true;
-  } else {
-    if (VisibleModules.isVisible(M))
-      return true;
-  }
+  // means it is part of the current module.
+  if (ModulePrivate && isUsableModule(M))
+    return true;
+
+  // For a query which is not module-private, that means it is in our visible
+  // module set.
+  if (!ModulePrivate && VisibleModules.isVisible(M))
+    return true;
 
   // Otherwise, it might be visible by virtue of the query being within a
   // template instantiation or similar that is permitted to look inside M.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124149.424103.patch
Type: text/x-patch
Size: 4135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220421/1dde4197/attachment.bin>


More information about the cfe-commits mailing list