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

Richard Smith richard at metafoo.co.uk
Tue Mar 4 18:15:51 PST 2014



================
Comment at: include/clang/Sema/Sema.h:1326-1328
@@ +1325,5 @@
+
+  // Calls getTypeName, and if not found, will search for a module with the
+  // type, implicitly importing it and displaying a fixit message.
+  ParsedType getTypeNameWithModuleCheck(const IdentifierInfo &II,
+                         SourceLocation NameLoc,
----------------
I'm not fond of this approach -- we'll end up with these `WithModuleCheck` functions scattered throughout various places that perform name lookup, with lots of duplication.

The existing recovery for missing imports is performed in `Sema::CorrectTypo`; I would suggest putting the new functionality there too. Perhaps if typo correction fails to find a result using its normal resolution mechanism, you could pull in all the modules that the global index is aware of, and try again?

================
Comment at: lib/Lex/HeaderSearch.cpp:697-706
@@ -692,1 +696,12 @@
 
+  // If no includers (as in case of module build), and not an angled
+  // include, do a final check in the current directory
+  if (Includers.empty() && !isAngled && !NoCurDirSearch) {
+    const FileEntry *Result = FileMgr.getFile(Filename, /*openFile=*/true);
+    if (Result) {
+      CacheLookup.second
+        = LookupFileCache.GetOrCreateValue(Filename).getValue().second;
+      return Result;
+    }
+  }
+
----------------
I'd like for this to be split out into a separate change. I also find this a little surprising, so I'd like an explanation of why this is the appropriate thing to do. If we're using -I-, we should probably still look for the contents of a module relative to the module. If this is fixing the bug I think it's fixing, I think the problem is that we put the wrong paths into the synthetic file containing `#include`s, and fixing it there would be better.


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



More information about the cfe-commits mailing list