{"action":"created","comment":{"url":"https://api.github.com/repos/apple/swift/pulls/comments/106572271","pull_request_review_id":27501225,"id":106572271,"diff_hunk":"@@ -11,43 +11,99 @@\n //===----------------------------------------------------------------------===//\n \n #include \"ImportedModules.h\"\n+#include \"swift/AST/ASTContext.h\"\n #include \"swift/AST/Decl.h\"\n #include \"swift/AST/DiagnosticEngine.h\"\n #include \"swift/AST/DiagnosticsFrontend.h\"\n #include \"swift/AST/Module.h\"\n+#include \"swift/Basic/STLExtras.h\"\n+#include \"swift/ClangImporter/ClangImporter.h\"\n #include \"swift/Frontend/FrontendOptions.h\"\n+#include \"clang/Basic/Module.h\"\n #include \"llvm/ADT/SetVector.h\"\n+#include \"llvm/ADT/StringRef.h\"\n #include \"llvm/Support/FileSystem.h\"\n \n-bool swift::emitImportedModules(DiagnosticEngine &diags, ModuleDecl *module,\n+using llvm::StringRef;\n+\n+static StringRef getTopLevelName(const clang::Module *module) {\n+  return module->getTopLevelModule()->Name;\n+}\n+\n+static void findAllClangImports(const clang::Module *module,\n+                                llvm::SetVector<StringRef> &modules) {\n+  for (auto imported : module->Imports) {\n+    modules.insert(getTopLevelName(imported));\n+  }\n+\n+  for (auto sub : swift::makeIteratorRange(module->submodule_begin(),\n+                                           module->submodule_end())) {\n+    findAllClangImports(sub, modules);\n+  }\n+}\n+\n+bool swift::emitImportedModules(ASTContext &Context, ModuleDecl *mainModule,\n                                 const FrontendOptions &opts) {\n \n   auto path = opts.getSingleOutputFilename();\n   std::error_code EC;\n   llvm::raw_fd_ostream out(path, EC, llvm::sys::fs::F_None);\n \n   if (out.has_error() || EC) {\n-    diags.diagnose(SourceLoc(), diag::error_opening_output, path, EC.message());\n+    Context.Diags.diagnose(SourceLoc(), diag::error_opening_output, path,\n+                           EC.message());\n     out.clear_error();\n     return true;\n   }\n \n-  llvm::SmallVector<Decl *, 32> Decls;\n-  module->getDisplayDecls(Decls);\n+  llvm::SetVector<StringRef> Modules;\n \n-  llvm::SetVector<Identifier> Modules;\n-  for (auto *D : Decls) {\n+  // Find the imports in the main Swift code.\n+  llvm::SmallVector<Decl *, 32> Decls;\n+  mainModule->getDisplayDecls(Decls);","path":"lib/FrontendTool/ImportedModules.cpp","position":null,"original_position":59,"commit_id":"e423ca90c0747dd32768f0ac810a269fb5dc1a80","original_commit_id":"e423ca90c0747dd32768f0ac810a269fb5dc1a80","user":{"login":"jrose-apple","id":15097531,"avatar_url":"https://avatars1.githubusercontent.com/u/15097531?v=3","gravatar_id":"","url":"https://api.github.com/users/jrose-apple","html_url":"https://github.com/jrose-apple","followers_url":"https://api.github.com/users/jrose-apple/followers","following_url":"https://api.github.com/users/jrose-apple/following{/other_user}","gists_url":"https://api.github.com/users/jrose-apple/gists{/gist_id}","starred_url":"https://api.github.com/users/jrose-apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrose-apple/subscriptions","organizations_url":"https://api.github.com/users/jrose-apple/orgs","repos_url":"https://api.github.com/users/jrose-apple/repos","events_url":"https://api.github.com/users/jrose-apple/events{/privacy}","received_events_url":"https://api.github.com/users/jrose-apple/received_events","type":"User","site_admin":false},"body":"Whoops, you're right, of course.","created_at":"2017-03-17T02:17:29Z","updated_at":"2017-03-17T02:17:29Z","html_url":"https://github.com/apple/swift/pull/8119#discussion_r106572271","pull_request_url":"https://api.github.com/repos/apple/swift/pulls/8119","_links":{"self":{"href":"https://api.github.com/repos/apple/swift/pulls/comments/106572271"},"html":{"href":"https://github.com/apple/swift/pull/8119#discussion_r106572271"},"pull_request":{"href":"https://api.github.com/repos/apple/swift/pulls/8119"}}},"pull_request":{"url":"https://api.github.com/repos/apple/swift/pulls/8119","id":110945928,"html_url":"https://github.com/apple/swift/pull/8119","diff_url":"https://github.com/apple/swift/pull/8119.diff","patch_url":"https://github.com/apple/swift/pull/8119.patch","issue_url":"https://api.github.com/repos/apple/swift/issues/8119","number":8119,"state":"open","locked":false,"title":"[Frontend] Add -emit-imported-modules: listing modules imported by the current one.","user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars2.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"body":"This is purely designed to cheaply compute dependency graphs between\r\nmodules, and thus only lists the top-level names (i.e. not submodules)\r\nand doesn't do any form of semantic analysis.\r\n\r\n\r\n---\r\n\r\nThe format is also just a plain text one-per-line listing of the modules; this can be optimised/changed easily.","created_at":"2017-03-15T21:26:13Z","updated_at":"2017-03-17T02:17:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dfaf5bb1fa3165172f5d5060297acbd7a4f8c892","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apple/swift/pulls/8119/commits","review_comments_url":"https://api.github.com/repos/apple/swift/pulls/8119/comments","review_comment_url":"https://api.github.com/repos/apple/swift/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apple/swift/issues/8119/comments","statuses_url":"https://api.github.com/repos/apple/swift/statuses/e423ca90c0747dd32768f0ac810a269fb5dc1a80","head":{"label":"huonw:imported-modules","ref":"imported-modules","sha":"e423ca90c0747dd32768f0ac810a269fb5dc1a80","user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars2.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"repo":{"id":67061123,"name":"swift","full_name":"huonw/swift","owner":{"login":"huonw","id":1203825,"avatar_url":"https://avatars2.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/huonw/swift","description":"The Swift Programming Language","fork":true,"url":"https://api.github.com/repos/huonw/swift","forks_url":"https://api.github.com/repos/huonw/swift/forks","keys_url":"https://api.github.com/repos/huonw/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/huonw/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/huonw/swift/teams","hooks_url":"https://api.github.com/repos/huonw/swift/hooks","issue_events_url":"https://api.github.com/repos/huonw/swift/issues/events{/number}","events_url":"https://api.github.com/repos/huonw/swift/events","assignees_url":"https://api.github.com/repos/huonw/swift/assignees{/user}","branches_url":"https://api.github.com/repos/huonw/swift/branches{/branch}","tags_url":"https://api.github.com/repos/huonw/swift/tags","blobs_url":"https://api.github.com/repos/huonw/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/huonw/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/huonw/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/huonw/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/huonw/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/huonw/swift/languages","stargazers_url":"https://api.github.com/repos/huonw/swift/stargazers","contributors_url":"https://api.github.com/repos/huonw/swift/contributors","subscribers_url":"https://api.github.com/repos/huonw/swift/subscribers","subscription_url":"https://api.github.com/repos/huonw/swift/subscription","commits_url":"https://api.github.com/repos/huonw/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/huonw/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/huonw/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/huonw/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/huonw/swift/contents/{+path}","compare_url":"https://api.github.com/repos/huonw/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/huonw/swift/merges","archive_url":"https://api.github.com/repos/huonw/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/huonw/swift/downloads","issues_url":"https://api.github.com/repos/huonw/swift/issues{/number}","pulls_url":"https://api.github.com/repos/huonw/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/huonw/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/huonw/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/huonw/swift/labels{/name}","releases_url":"https://api.github.com/repos/huonw/swift/releases{/id}","deployments_url":"https://api.github.com/repos/huonw/swift/deployments","created_at":"2016-08-31T18:00:30Z","updated_at":"2016-08-31T18:00:55Z","pushed_at":"2017-03-17T00:28:28Z","git_url":"git://github.com/huonw/swift.git","ssh_url":"git@github.com:huonw/swift.git","clone_url":"https://github.com/huonw/swift.git","svn_url":"https://github.com/huonw/swift","homepage":"https://swift.org/","size":170891,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apple:master","ref":"master","sha":"46af3eb1024c699e9c48b7053096a66eb3a37b59","user":{"login":"apple","id":10639145,"avatar_url":"https://avatars3.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"repo":{"id":44838949,"name":"swift","full_name":"apple/swift","owner":{"login":"apple","id":10639145,"avatar_url":"https://avatars3.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apple/swift","description":"The Swift Programming Language","fork":false,"url":"https://api.github.com/repos/apple/swift","forks_url":"https://api.github.com/repos/apple/swift/forks","keys_url":"https://api.github.com/repos/apple/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apple/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apple/swift/teams","hooks_url":"https://api.github.com/repos/apple/swift/hooks","issue_events_url":"https://api.github.com/repos/apple/swift/issues/events{/number}","events_url":"https://api.github.com/repos/apple/swift/events","assignees_url":"https://api.github.com/repos/apple/swift/assignees{/user}","branches_url":"https://api.github.com/repos/apple/swift/branches{/branch}","tags_url":"https://api.github.com/repos/apple/swift/tags","blobs_url":"https://api.github.com/repos/apple/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apple/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apple/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/apple/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apple/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/apple/swift/languages","stargazers_url":"https://api.github.com/repos/apple/swift/stargazers","contributors_url":"https://api.github.com/repos/apple/swift/contributors","subscribers_url":"https://api.github.com/repos/apple/swift/subscribers","subscription_url":"https://api.github.com/repos/apple/swift/subscription","commits_url":"https://api.github.com/repos/apple/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/apple/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/apple/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/apple/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/apple/swift/contents/{+path}","compare_url":"https://api.github.com/repos/apple/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apple/swift/merges","archive_url":"https://api.github.com/repos/apple/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apple/swift/downloads","issues_url":"https://api.github.com/repos/apple/swift/issues{/number}","pulls_url":"https://api.github.com/repos/apple/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/apple/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/apple/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apple/swift/labels{/name}","releases_url":"https://api.github.com/repos/apple/swift/releases{/id}","deployments_url":"https://api.github.com/repos/apple/swift/deployments","created_at":"2015-10-23T21:15:07Z","updated_at":"2017-03-17T01:43:54Z","pushed_at":"2017-03-17T02:15:58Z","git_url":"git://github.com/apple/swift.git","ssh_url":"git@github.com:apple/swift.git","clone_url":"https://github.com/apple/swift.git","svn_url":"https://github.com/apple/swift","homepage":"https://swift.org/","size":177817,"stargazers_count":37291,"watchers_count":37291,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5512,"mirror_url":null,"open_issues_count":141,"forks":5512,"open_issues":141,"watchers":37291,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apple/swift/pulls/8119"},"html":{"href":"https://github.com/apple/swift/pull/8119"},"issue":{"href":"https://api.github.com/repos/apple/swift/issues/8119"},"comments":{"href":"https://api.github.com/repos/apple/swift/issues/8119/comments"},"review_comments":{"href":"https://api.github.com/repos/apple/swift/pulls/8119/comments"},"review_comment":{"href":"https://api.github.com/repos/apple/swift/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apple/swift/pulls/8119/commits"},"statuses":{"href":"https://api.github.com/repos/apple/swift/statuses/e423ca90c0747dd32768f0ac810a269fb5dc1a80"}}}}
{"actor":{"display_login":"jrose-apple"}}