[PATCH] D61656: -frewrite-imports: Add support for wildcard rules in umbrella modules with

2019-05-07 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360195: -frewrite-imports: Add support for wildcard rules in 
umbrella modules with (authored by dblaikie, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61656?vs=198528=198533#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61656/new/

https://reviews.llvm.org/D61656

Files:
  include/clang/Basic/Module.h
  lib/Basic/Module.cpp
  lib/Lex/Pragma.cpp
  test/Modules/preprocess-umbrella.cpp

Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1584,16 +1584,15 @@
 
 // Find the module we're entering. We require that a module map for it
 // be loaded or implicitly loadable.
-// FIXME: We could create the submodule here. We'd need to know whether
-// it's supposed to be explicit, but not much else.
-Module *M = PP.getHeaderSearchInfo().lookupModule(Current);
+auto  = PP.getHeaderSearchInfo();
+Module *M = HSI.lookupModule(Current);
 if (!M) {
   PP.Diag(ModuleName.front().second,
   diag::err_pp_module_begin_no_module_map) << Current;
   return;
 }
 for (unsigned I = 1; I != ModuleName.size(); ++I) {
-  auto *NewM = M->findSubmodule(ModuleName[I].first->getName());
+  auto *NewM = M->findOrInferSubmodule(ModuleName[I].first->getName());
   if (!NewM) {
 PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule)
   << M->getFullModuleName() << ModuleName[I].first;
Index: lib/Basic/Module.cpp
===
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -321,6 +321,21 @@
   return SubModules[Pos->getValue()];
 }
 
+Module *Module::findOrInferSubmodule(StringRef Name) {
+  llvm::StringMap::const_iterator Pos = SubModuleIndex.find(Name);
+  if (Pos != SubModuleIndex.end())
+return SubModules[Pos->getValue()];
+  if (!InferSubmodules)
+return nullptr;
+  Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0);
+  Result->InferExplicitSubmodules = InferExplicitSubmodules;
+  Result->InferSubmodules = InferSubmodules;
+  Result->InferExportWildcard = InferExportWildcard;
+  if (Result->InferExportWildcard)
+Result->Exports.push_back(Module::ExportDecl(nullptr, true));
+  return Result;
+}
+
 void Module::getExportedModules(SmallVectorImpl ) const {
   // All non-explicit submodules are exported.
   for (std::vector::const_iterator I = SubModules.begin(),
Index: include/clang/Basic/Module.h
===
--- include/clang/Basic/Module.h
+++ include/clang/Basic/Module.h
@@ -541,6 +541,7 @@
   ///
   /// \returns The submodule if found, or NULL otherwise.
   Module *findSubmodule(StringRef Name) const;
+  Module *findOrInferSubmodule(StringRef Name);
 
   /// Determine whether the specified module would be visible to
   /// a lookup at the end of this module.
Index: test/Modules/preprocess-umbrella.cpp
===
--- test/Modules/preprocess-umbrella.cpp
+++ test/Modules/preprocess-umbrella.cpp
@@ -0,0 +1,36 @@
+// FIXME: The standalone module still seems to cause clang to want to test for
+// the existence of a 'foo' directory:
+// RUN: mkdir %t
+// RUN: cp %s %t
+// RUN: mkdir %t/foo
+// RUN: cd %t
+// RUN: not %clang_cc1 -fmodules -fsyntax-only %s 2>&1 | FileCheck %s
+
+// CHECK: error: no matching function for call to 'foo'
+// CHECK: note: candidate function not viable: requires 0 arguments, but 1 was provided
+
+// FIXME: This should use -verify, but it seems it doesn't hook up the
+// SourceManager correctly or something, and the foo.h note gets attributed to
+// the synthetic module translation unit "foo.map Line 2:...".
+// %clang_cc1 -fmodules -verify %s
+
+#pragma clang module build foo
+module foo {
+  umbrella "foo"
+  module * {
+export *
+  }
+}
+#pragma clang module contents
+#pragma clang module begin foo.foo
+# 1 "foo.h" 1
+#ifndef FOO_FOO_H
+void foo();
+#endif
+#pragma clang module end
+#pragma clang module endbuild
+#pragma clang module import foo.foo
+// expected-note@foo.h:2 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
+int main() {
+  foo(1); // expected-error {{no matching function for call to 'foo'}}
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61656: -frewrite-imports: Add support for wildcard rules in umbrella modules with

2019-05-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie marked an inline comment as done.
dblaikie added inline comments.



Comment at: test/Modules/preprocess-umbrella.cpp:1-2
+// FIXME: The standalone module still seems to cause clang to want to test for
+// the existence of a 'foo' directory:
+// RUN: mkdir %t

rsmith wrote:
> FWIW, I think that probably happens when parsing the `umbrella "foo"` 
> directive.
Thanks for the pointer - yeah, I'd come across that too. Both the ModuleMap and 
the Module ( 
https://clang.llvm.org/doxygen/classclang_1_1Module.html#acb7c8570da610974e567675303baa77b
 ) depend on a non-null DirectoryEntry to record the modules umbrella-ness.

Any ideas on how I might go about removing that limitation?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61656/new/

https://reviews.llvm.org/D61656



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61656: -frewrite-imports: Add support for wildcard rules in umbrella modules with

2019-05-07 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Basic/Module.cpp:324
 
+Module *Module::findOrCreateSubmodule(StringRef Name) {
+  llvm::StringMap::const_iterator Pos = SubModuleIndex.find(Name);

Maybe `findOrInferSubmodule`; the current name suggests that this would always 
create a submodule if one doesn't exist (like `ModuleMap::findOrCreateModule` 
does).



Comment at: lib/Lex/Pragma.cpp:1587-1588
 // be loaded or implicitly loadable.
 // FIXME: We could create the submodule here. We'd need to know whether
 // it's supposed to be explicit, but not much else.
+auto  = PP.getHeaderSearchInfo();

Remove fixed FIXME please :)



Comment at: test/Modules/preprocess-umbrella.cpp:1-2
+// FIXME: The standalone module still seems to cause clang to want to test for
+// the existence of a 'foo' directory:
+// RUN: mkdir %t

FWIW, I think that probably happens when parsing the `umbrella "foo"` directive.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61656/new/

https://reviews.llvm.org/D61656



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61656: -frewrite-imports: Add support for wildcard rules in umbrella modules with

2019-05-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
dblaikie updated this revision to Diff 198528.
dblaikie added a comment.

Add another FIXME


This trips over a few other limitations, but in the interests of incremental 
development I'm starting here & I'll look at the issues with -verify and 
filesystem checks (the fact that the behavior depends on the existence of a 
'foo' directory even though it shouldn't need it), etc.


Repository:
  rC Clang

https://reviews.llvm.org/D61656

Files:
  include/clang/Basic/Module.h
  lib/Basic/Module.cpp
  lib/Lex/Pragma.cpp
  test/Modules/preprocess-umbrella.cpp

Index: test/Modules/preprocess-umbrella.cpp
===
--- /dev/null
+++ test/Modules/preprocess-umbrella.cpp
@@ -0,0 +1,36 @@
+// FIXME: The standalone module still seems to cause clang to want to test for
+// the existence of a 'foo' directory:
+// RUN: mkdir %t
+// RUN: cp %s %t
+// RUN: mkdir %t/foo
+// RUN: cd %t
+// RUN: not %clang_cc1 -fmodules -fsyntax-only %s 2>&1 | FileCheck %s
+
+// CHECK: error: no matching function for call to 'foo'
+// CHECK: note: candidate function not viable: requires 0 arguments, but 1 was provided
+
+// FIXME: This should use -verify, but it seems it doesn't hook up the
+// SourceManager correctly or something, and the foo.h note gets attributed to
+// the synthetic module translation unit "foo.map Line 2:...".
+// %clang_cc1 -fmodules -verify %s
+
+#pragma clang module build foo
+module foo {
+  umbrella "foo"
+  module * {
+export *
+  }
+}
+#pragma clang module contents
+#pragma clang module begin foo.foo
+# 1 "foo.h" 1
+#ifndef FOO_FOO_H
+void foo();
+#endif
+#pragma clang module end
+#pragma clang module endbuild
+#pragma clang module import foo.foo
+// expected-note@foo.h:2 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
+int main() {
+  foo(1); // expected-error {{no matching function for call to 'foo'}}
+}
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1586,14 +1586,15 @@
 // be loaded or implicitly loadable.
 // FIXME: We could create the submodule here. We'd need to know whether
 // it's supposed to be explicit, but not much else.
-Module *M = PP.getHeaderSearchInfo().lookupModule(Current);
+auto  = PP.getHeaderSearchInfo();
+Module *M = HSI.lookupModule(Current);
 if (!M) {
   PP.Diag(ModuleName.front().second,
   diag::err_pp_module_begin_no_module_map) << Current;
   return;
 }
 for (unsigned I = 1; I != ModuleName.size(); ++I) {
-  auto *NewM = M->findSubmodule(ModuleName[I].first->getName());
+  auto *NewM = M->findOrCreateSubmodule(ModuleName[I].first->getName());
   if (!NewM) {
 PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule)
   << M->getFullModuleName() << ModuleName[I].first;
Index: lib/Basic/Module.cpp
===
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -321,6 +321,21 @@
   return SubModules[Pos->getValue()];
 }
 
+Module *Module::findOrCreateSubmodule(StringRef Name) {
+  llvm::StringMap::const_iterator Pos = SubModuleIndex.find(Name);
+  if (Pos != SubModuleIndex.end())
+return SubModules[Pos->getValue()];
+  if (!InferSubmodules)
+return nullptr;
+  Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0);
+  Result->InferExplicitSubmodules = InferExplicitSubmodules;
+  Result->InferSubmodules = InferSubmodules;
+  Result->InferExportWildcard = InferExportWildcard;
+  if (Result->InferExportWildcard)
+Result->Exports.push_back(Module::ExportDecl(nullptr, true));
+  return Result;
+}
+
 void Module::getExportedModules(SmallVectorImpl ) const {
   // All non-explicit submodules are exported.
   for (std::vector::const_iterator I = SubModules.begin(),
Index: include/clang/Basic/Module.h
===
--- include/clang/Basic/Module.h
+++ include/clang/Basic/Module.h
@@ -541,6 +541,7 @@
   ///
   /// \returns The submodule if found, or NULL otherwise.
   Module *findSubmodule(StringRef Name) const;
+  Module *findOrCreateSubmodule(StringRef Name);
 
   /// Determine whether the specified module would be visible to
   /// a lookup at the end of this module.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61656: -frewrite-imports: Add support for wildcard rules in umbrella modules with

2019-05-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 198528.
dblaikie added a comment.

Add another FIXME


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61656/new/

https://reviews.llvm.org/D61656

Files:
  include/clang/Basic/Module.h
  lib/Basic/Module.cpp
  lib/Lex/Pragma.cpp
  test/Modules/preprocess-umbrella.cpp

Index: test/Modules/preprocess-umbrella.cpp
===
--- /dev/null
+++ test/Modules/preprocess-umbrella.cpp
@@ -0,0 +1,36 @@
+// FIXME: The standalone module still seems to cause clang to want to test for
+// the existence of a 'foo' directory:
+// RUN: mkdir %t
+// RUN: cp %s %t
+// RUN: mkdir %t/foo
+// RUN: cd %t
+// RUN: not %clang_cc1 -fmodules -fsyntax-only %s 2>&1 | FileCheck %s
+
+// CHECK: error: no matching function for call to 'foo'
+// CHECK: note: candidate function not viable: requires 0 arguments, but 1 was provided
+
+// FIXME: This should use -verify, but it seems it doesn't hook up the
+// SourceManager correctly or something, and the foo.h note gets attributed to
+// the synthetic module translation unit "foo.map Line 2:...".
+// %clang_cc1 -fmodules -verify %s
+
+#pragma clang module build foo
+module foo {
+  umbrella "foo"
+  module * {
+export *
+  }
+}
+#pragma clang module contents
+#pragma clang module begin foo.foo
+# 1 "foo.h" 1
+#ifndef FOO_FOO_H
+void foo();
+#endif
+#pragma clang module end
+#pragma clang module endbuild
+#pragma clang module import foo.foo
+// expected-note@foo.h:2 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
+int main() {
+  foo(1); // expected-error {{no matching function for call to 'foo'}}
+}
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1586,14 +1586,15 @@
 // be loaded or implicitly loadable.
 // FIXME: We could create the submodule here. We'd need to know whether
 // it's supposed to be explicit, but not much else.
-Module *M = PP.getHeaderSearchInfo().lookupModule(Current);
+auto  = PP.getHeaderSearchInfo();
+Module *M = HSI.lookupModule(Current);
 if (!M) {
   PP.Diag(ModuleName.front().second,
   diag::err_pp_module_begin_no_module_map) << Current;
   return;
 }
 for (unsigned I = 1; I != ModuleName.size(); ++I) {
-  auto *NewM = M->findSubmodule(ModuleName[I].first->getName());
+  auto *NewM = M->findOrCreateSubmodule(ModuleName[I].first->getName());
   if (!NewM) {
 PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule)
   << M->getFullModuleName() << ModuleName[I].first;
Index: lib/Basic/Module.cpp
===
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -321,6 +321,21 @@
   return SubModules[Pos->getValue()];
 }
 
+Module *Module::findOrCreateSubmodule(StringRef Name) {
+  llvm::StringMap::const_iterator Pos = SubModuleIndex.find(Name);
+  if (Pos != SubModuleIndex.end())
+return SubModules[Pos->getValue()];
+  if (!InferSubmodules)
+return nullptr;
+  Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0);
+  Result->InferExplicitSubmodules = InferExplicitSubmodules;
+  Result->InferSubmodules = InferSubmodules;
+  Result->InferExportWildcard = InferExportWildcard;
+  if (Result->InferExportWildcard)
+Result->Exports.push_back(Module::ExportDecl(nullptr, true));
+  return Result;
+}
+
 void Module::getExportedModules(SmallVectorImpl ) const {
   // All non-explicit submodules are exported.
   for (std::vector::const_iterator I = SubModules.begin(),
Index: include/clang/Basic/Module.h
===
--- include/clang/Basic/Module.h
+++ include/clang/Basic/Module.h
@@ -541,6 +541,7 @@
   ///
   /// \returns The submodule if found, or NULL otherwise.
   Module *findSubmodule(StringRef Name) const;
+  Module *findOrCreateSubmodule(StringRef Name);
 
   /// Determine whether the specified module would be visible to
   /// a lookup at the end of this module.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits