[PATCH] preview patch for fixit for finding modules needing import/inclusion

Richard Smith richard at metafoo.co.uk
Wed Mar 26 15:25:18 PDT 2014


  This looks like basically the right approach to me.


================
Comment at: lib/Sema/SemaLookup.cpp:4060-4061
@@ -4056,1 +4059,4 @@
 
+  // Look for the symbol in non-imported modules.
+  if (getLangOpts().Modules && getLangOpts().ModulesSearchAll) {
+    // Try to find the type in modules via the global module index.
----------------
We should probably only do this if we got to the end of typo-correction and found no corrections.

================
Comment at: lib/Sema/SemaLookup.cpp:4096-4098
@@ +4095,5 @@
+            TC.setCorrectionDecl(ModRes.getAsSingle<NamedDecl>());
+          // Hide the module again. diagnoseTypo will unhide the decl module.
+          Loader.makeModuleVisible(TheModule, Module::Hidden,
+            TypoName.getLoc(), false);
+        }
----------------
This won't work. We don't support visibility decreasing. Instead, you should be able to just load the module rather than making it visible, and tell your `LookupResult` to find hidden results during the lookup.

================
Comment at: lib/Frontend/CompilerInstance.cpp:1440
@@ +1439,3 @@
+		    // Load a module as hidden.  This also adds it to the global index.
+        ModuleLoadResult Result = loadModule(TheModule->DefinitionLoc, Path,
+          Module::Hidden, false);
----------------
It looks like this will build every module described in any module map we've loaded. That could be extremely time-consuming, and could produce errors. Is that what you want here?

================
Comment at: lib/Serialization/GlobalModuleIndex.cpp:345-358
@@ -344,1 +344,16 @@
 
+void GlobalModuleIndex::dump() {
+  std::fprintf(stderr, "*** Global Module Index Dump:\n");
+  std::fprintf(stderr, "Module files:\n");
+  for (llvm::SmallVector<ModuleInfo, 16>::iterator I = Modules.begin(),
+      E = Modules.end(); I != E; ++I) {
+    ModuleInfo *MI = (ModuleInfo*)I;
+    std::fprintf(stderr, "** %s\n", MI->FileName.c_str());
+    if (MI->File)
+      MI->File->dump();
+    else
+      std::fprintf(stderr, "\n");
+  }
+  std::fprintf(stderr, "\n");
+}
+
----------------
Feel free to just check this part in.


http://llvm-reviews.chandlerc.com/D2671



More information about the cfe-commits mailing list