[clang] debd9bf - [NFC] follow up code cleanup after D123837

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon May 9 19:03:11 PDT 2022


Author: Chuanqi Xu
Date: 2022-05-10T10:01:06+08:00
New Revision: debd9bf3f0198984cb4ae66c16758e0c8eeb2e9e

URL: https://github.com/llvm/llvm-project/commit/debd9bf3f0198984cb4ae66c16758e0c8eeb2e9e
DIFF: https://github.com/llvm/llvm-project/commit/debd9bf3f0198984cb4ae66c16758e0c8eeb2e9e.diff

LOG: [NFC] follow up code cleanup after D123837

Reviewed By: iains

Differential Revision: https://reviews.llvm.org/D124149

Added: 
    

Modified: 
    clang/lib/Sema/SemaLookup.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 2a378741e7aa6..9f2e1eac41be6 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1565,27 +1565,27 @@ bool Sema::isUsableModule(const Module *M) {
   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 LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) {
 
 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.


        


More information about the cfe-commits mailing list