check.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/check/check.h"
  5. #include <string>
  6. #include <utility>
  7. #include "common/check.h"
  8. #include "common/map.h"
  9. #include "common/pretty_stack_trace_function.h"
  10. #include "toolchain/check/check_unit.h"
  11. #include "toolchain/check/context.h"
  12. #include "toolchain/check/cpp/import.h"
  13. #include "toolchain/check/diagnostic_emitter.h"
  14. #include "toolchain/check/diagnostic_helpers.h"
  15. #include "toolchain/diagnostics/consumer.h"
  16. #include "toolchain/diagnostics/diagnostic.h"
  17. #include "toolchain/diagnostics/format_providers.h"
  18. #include "toolchain/lex/token_kind.h"
  19. #include "toolchain/parse/node_ids.h"
  20. #include "toolchain/parse/tree.h"
  21. #include "toolchain/sem_ir/file.h"
  22. #include "toolchain/sem_ir/formatter.h"
  23. #include "toolchain/sem_ir/typed_insts.h"
  24. namespace Carbon::Check {
  25. // The package and library names, used as map keys.
  26. using ImportKey = std::pair<llvm::StringRef, llvm::StringRef>;
  27. // Returns a key form of the package object. file_package_id is only used for
  28. // imports, not the main package declaration; as a consequence, it will be
  29. // `None` for the main package declaration.
  30. static auto GetImportKey(UnitAndImports& unit_info,
  31. PackageNameId file_package_id,
  32. Parse::Tree::PackagingNames names) -> ImportKey {
  33. auto* stores = unit_info.unit->value_stores;
  34. PackageNameId package_id =
  35. names.package_id.has_value() ? names.package_id : file_package_id;
  36. llvm::StringRef package_name;
  37. if (package_id.has_value()) {
  38. auto package_ident_id = package_id.AsIdentifierId();
  39. package_name = package_ident_id.has_value()
  40. ? stores->identifiers().Get(package_ident_id)
  41. : package_id.AsSpecialName();
  42. }
  43. llvm::StringRef library_name =
  44. names.library_id.has_value()
  45. ? stores->string_literal_values().Get(names.library_id)
  46. : "";
  47. return {package_name, library_name};
  48. }
  49. static constexpr llvm::StringLiteral MainPackageName = "Main";
  50. static auto RenderImportKey(ImportKey import_key) -> std::string {
  51. if (import_key.first.empty()) {
  52. import_key.first = MainPackageName;
  53. }
  54. if (import_key.second.empty()) {
  55. return import_key.first.str();
  56. }
  57. return llvm::formatv("{0}//{1}", import_key.first, import_key.second).str();
  58. }
  59. // Marks an import as required on both the source and target file.
  60. //
  61. // The ID comparisons between the import and unit are okay because they both
  62. // come from the same file.
  63. static auto TrackImport(Map<ImportKey, UnitAndImports*>& api_map,
  64. Map<ImportKey, Parse::NodeId>* explicit_import_map,
  65. UnitAndImports& unit_info,
  66. Parse::Tree::PackagingNames import, bool fuzzing)
  67. -> void {
  68. if (import.package_id == PackageNameId::Cpp) {
  69. if (!explicit_import_map) {
  70. // Don't diagnose the implicit import in `impl package Cpp`, because we'll
  71. // have diagnosed the use of `Cpp` in the declaration.
  72. return;
  73. }
  74. if (fuzzing) {
  75. // Clang is not crash-resilient.
  76. CARBON_DIAGNOSTIC(CppInteropFuzzing, Error,
  77. "`Cpp` import found during fuzzing");
  78. unit_info.emitter.Emit(import.node_id, CppInteropFuzzing);
  79. return;
  80. }
  81. unit_info.cpp_imports.push_back(import);
  82. return;
  83. }
  84. if (import.inline_body_id.has_value()) {
  85. CARBON_DIAGNOSTIC(InlineImportNotCpp, Error,
  86. "`inline` import not in package `Cpp`");
  87. unit_info.emitter.Emit(import.node_id, InlineImportNotCpp);
  88. return;
  89. }
  90. const auto& packaging = unit_info.parse_tree().packaging_decl();
  91. PackageNameId file_package_id =
  92. packaging ? packaging->names.package_id : PackageNameId::None;
  93. const auto import_key = GetImportKey(unit_info, file_package_id, import);
  94. // True if the import has `Main` as the package name, even if it comes from
  95. // the file's packaging (diagnostics may differentiate).
  96. bool is_explicit_main = import_key.first == MainPackageName;
  97. // Explicit imports need more validation than implicit ones. We try to do
  98. // these in an order of imports that should be removed, followed by imports
  99. // that might be valid with syntax fixes.
  100. if (explicit_import_map) {
  101. // Diagnose redundant imports.
  102. if (auto insert_result =
  103. explicit_import_map->Insert(import_key, import.node_id);
  104. !insert_result.is_inserted()) {
  105. CARBON_DIAGNOSTIC(RepeatedImport, Error,
  106. "library imported more than once");
  107. CARBON_DIAGNOSTIC(FirstImported, Note, "first import here");
  108. unit_info.emitter.Build(import.node_id, RepeatedImport)
  109. .Note(insert_result.value(), FirstImported)
  110. .Emit();
  111. return;
  112. }
  113. // True if the file's package is implicitly `Main` (by omitting an explicit
  114. // package name).
  115. bool is_file_implicit_main =
  116. !packaging || !packaging->names.package_id.has_value();
  117. // True if the import is using implicit "current package" syntax (by
  118. // omitting an explicit package name).
  119. bool is_import_implicit_current_package = !import.package_id.has_value();
  120. // True if the import is using `default` library syntax.
  121. bool is_import_default_library = !import.library_id.has_value();
  122. // True if the import and file point at the same package, even by
  123. // incorrectly specifying the current package name to `import`.
  124. bool is_same_package = is_import_implicit_current_package ||
  125. import.package_id == file_package_id;
  126. // True if the import points at the same library as the file's library.
  127. bool is_same_library =
  128. is_same_package &&
  129. (packaging ? import.library_id == packaging->names.library_id
  130. : is_import_default_library);
  131. // Diagnose explicit imports of the same library, whether from `api` or
  132. // `impl`.
  133. if (is_same_library) {
  134. CARBON_DIAGNOSTIC(ExplicitImportApi, Error,
  135. "explicit import of `api` from `impl` file is "
  136. "redundant with implicit import");
  137. CARBON_DIAGNOSTIC(ImportSelf, Error, "file cannot import itself");
  138. bool is_impl = !packaging || packaging->is_impl;
  139. unit_info.emitter.Emit(import.node_id,
  140. is_impl ? ExplicitImportApi : ImportSelf);
  141. return;
  142. }
  143. // Diagnose explicit imports of `Main//default`. There is no `api` for it.
  144. // This lets other diagnostics handle explicit `Main` package naming.
  145. if (is_file_implicit_main && is_import_implicit_current_package &&
  146. is_import_default_library) {
  147. CARBON_DIAGNOSTIC(ImportMainDefaultLibrary, Error,
  148. "cannot import `Main//default`");
  149. unit_info.emitter.Emit(import.node_id, ImportMainDefaultLibrary);
  150. return;
  151. }
  152. if (!is_import_implicit_current_package) {
  153. // Diagnose explicit imports of the same package that use the package
  154. // name.
  155. if (is_same_package || (is_file_implicit_main && is_explicit_main)) {
  156. CARBON_DIAGNOSTIC(
  157. ImportCurrentPackageByName, Error,
  158. "imports from the current package must omit the package name");
  159. unit_info.emitter.Emit(import.node_id, ImportCurrentPackageByName);
  160. return;
  161. }
  162. // Diagnose explicit imports from `Main`.
  163. if (is_explicit_main) {
  164. CARBON_DIAGNOSTIC(ImportMainPackage, Error,
  165. "cannot import `Main` from other packages");
  166. unit_info.emitter.Emit(import.node_id, ImportMainPackage);
  167. return;
  168. }
  169. }
  170. } else if (is_explicit_main) {
  171. // An implicit import with an explicit `Main` occurs when a `package` rule
  172. // has bad syntax, which will have been diagnosed when building the API map.
  173. // As a consequence, we return silently.
  174. return;
  175. }
  176. // Get the package imports, or create them if this is the first.
  177. auto create_imports = [&]() -> int32_t {
  178. int32_t index = unit_info.package_imports.size();
  179. unit_info.package_imports.push_back(
  180. PackageImports(import.package_id, import.node_id));
  181. return index;
  182. };
  183. auto insert_result =
  184. unit_info.package_imports_map.Insert(import.package_id, create_imports);
  185. PackageImports& package_imports =
  186. unit_info.package_imports[insert_result.value()];
  187. if (auto api_lookup = api_map.Lookup(import_key)) {
  188. // Add references between the file and imported api.
  189. UnitAndImports* api = api_lookup.value();
  190. package_imports.imports.push_back({import, api});
  191. ++unit_info.imports_remaining;
  192. api->incoming_imports.push_back(&unit_info);
  193. // If this is the implicit import, note we have it.
  194. if (!explicit_import_map) {
  195. CARBON_CHECK(!unit_info.api_for_impl);
  196. unit_info.api_for_impl = api;
  197. }
  198. } else {
  199. // The imported api is missing.
  200. package_imports.has_load_error = true;
  201. CARBON_DIAGNOSTIC(LibraryApiNotFound, Error,
  202. "corresponding API for '{0}' not found", std::string);
  203. CARBON_DIAGNOSTIC(ImportNotFound, Error, "imported API '{0}' not found",
  204. std::string);
  205. unit_info.emitter.Emit(
  206. import.node_id,
  207. explicit_import_map ? ImportNotFound : LibraryApiNotFound,
  208. RenderImportKey(import_key));
  209. }
  210. }
  211. // Builds a map of `api` files which might be imported. Also diagnoses issues
  212. // related to the packaging because the strings are loaded as part of getting
  213. // the ImportKey (which we then do for `impl` files too).
  214. static auto BuildApiMapAndDiagnosePackaging(
  215. llvm::MutableArrayRef<UnitAndImports> unit_infos)
  216. -> Map<ImportKey, UnitAndImports*> {
  217. Map<ImportKey, UnitAndImports*> api_map;
  218. for (auto& unit_info : unit_infos) {
  219. const auto& packaging = unit_info.parse_tree().packaging_decl();
  220. // An import key formed from the `package` or `library` declaration. Or, for
  221. // Main//default, a placeholder key.
  222. auto import_key = packaging ? GetImportKey(unit_info, PackageNameId::None,
  223. packaging->names)
  224. // Construct a boring key for Main//default.
  225. : ImportKey{"", ""};
  226. // Diagnose restricted package names before they become marked as possible
  227. // APIs.
  228. if (import_key.first == MainPackageName) {
  229. CARBON_DIAGNOSTIC(ExplicitMainPackage, Error,
  230. "`Main//default` must omit `package` declaration");
  231. CARBON_DIAGNOSTIC(
  232. ExplicitMainLibrary, Error,
  233. "use `library` declaration in `Main` package libraries");
  234. unit_info.emitter.Emit(packaging->names.node_id,
  235. import_key.second.empty() ? ExplicitMainPackage
  236. : ExplicitMainLibrary);
  237. continue;
  238. }
  239. if (packaging && packaging->names.package_id == PackageNameId::Cpp) {
  240. CARBON_DIAGNOSTIC(CppPackageDeclaration, Error,
  241. "`Cpp` cannot be used by a `package` declaration");
  242. unit_info.emitter.Emit(packaging->names.node_id, CppPackageDeclaration);
  243. continue;
  244. }
  245. bool is_impl = packaging && packaging->is_impl;
  246. // Add to the `api` map and diagnose duplicates. This occurs before the
  247. // file extension check because we might emit both diagnostics in situations
  248. // where the user forgets (or has syntax errors with) a package line
  249. // multiple times.
  250. if (!is_impl) {
  251. auto insert_result = api_map.Insert(import_key, &unit_info);
  252. if (!insert_result.is_inserted()) {
  253. llvm::StringRef prev_filename =
  254. insert_result.value()->source().filename();
  255. if (packaging) {
  256. CARBON_DIAGNOSTIC(DuplicateLibraryApi, Error,
  257. "library's API previously provided by `{0}`",
  258. std::string);
  259. unit_info.emitter.Emit(packaging->names.node_id, DuplicateLibraryApi,
  260. prev_filename.str());
  261. } else {
  262. CARBON_DIAGNOSTIC(DuplicateMainApi, Error,
  263. "`Main//default` previously provided by `{0}`",
  264. std::string);
  265. // Use `NodeId::None` because there's no node to associate with.
  266. unit_info.emitter.Emit(Parse::NodeId::None, DuplicateMainApi,
  267. prev_filename.str());
  268. }
  269. }
  270. }
  271. // Validate file extensions. Note imports rely the packaging declaration,
  272. // not the extension. If the input is not a regular file, for example
  273. // because it is stdin, no filename checking is performed.
  274. if (unit_info.source().is_regular_file()) {
  275. auto filename = unit_info.source().filename();
  276. static constexpr llvm::StringLiteral ApiExt = ".carbon";
  277. static constexpr llvm::StringLiteral ImplExt = ".impl.carbon";
  278. bool is_api_with_impl_ext = !is_impl && filename.ends_with(ImplExt);
  279. auto want_ext = is_impl ? ImplExt : ApiExt;
  280. if (is_api_with_impl_ext || !filename.ends_with(want_ext)) {
  281. CARBON_DIAGNOSTIC(
  282. IncorrectExtension, Error,
  283. "file extension of `{0:.impl|}.carbon` required for {0:`impl`|api}",
  284. Diagnostics::BoolAsSelect);
  285. auto diag = unit_info.emitter.Build(
  286. packaging ? packaging->names.node_id : Parse::NodeId::None,
  287. IncorrectExtension, is_impl);
  288. if (is_api_with_impl_ext) {
  289. CARBON_DIAGNOSTIC(
  290. IncorrectExtensionImplNote, Note,
  291. "file extension of `.impl.carbon` only allowed for `impl`");
  292. diag.Note(Parse::NodeId::None, IncorrectExtensionImplNote);
  293. }
  294. diag.Emit();
  295. }
  296. }
  297. }
  298. return api_map;
  299. }
  300. // Handles printing of formatted SemIR.
  301. static auto MaybeDumpFormattedSemIR(
  302. const SemIR::File& sem_ir, int total_ir_count,
  303. Parse::GetTreeAndSubtreesFn tree_and_subtrees_getter, bool include_in_dumps,
  304. const CheckParseTreesOptions& options) -> void {
  305. bool dump = options.dump_stream && include_in_dumps;
  306. if (!options.vlog_stream && !dump) {
  307. return;
  308. }
  309. const auto& tokens = sem_ir.parse_tree().tokens();
  310. if (options.dump_sem_ir_ranges ==
  311. CheckParseTreesOptions::DumpSemIRRanges::Only &&
  312. !tokens.has_dump_sem_ir_ranges() && !tokens.has_include_in_dumps()) {
  313. return;
  314. }
  315. bool use_dump_sem_ir_ranges =
  316. options.dump_sem_ir_ranges !=
  317. CheckParseTreesOptions::DumpSemIRRanges::Ignore &&
  318. tokens.has_dump_sem_ir_ranges();
  319. SemIR::Formatter formatter(&sem_ir, total_ir_count, tree_and_subtrees_getter,
  320. options.include_in_dumps, use_dump_sem_ir_ranges);
  321. formatter.Format();
  322. if (options.vlog_stream) {
  323. CARBON_VLOG_TO(options.vlog_stream, "*** SemIR::File ***\n");
  324. formatter.Write(*options.vlog_stream);
  325. }
  326. if (dump) {
  327. formatter.Write(*options.dump_stream);
  328. }
  329. }
  330. // Handles options for dumping SemIR, including verbose output.
  331. static auto MaybeDumpSemIR(
  332. llvm::ArrayRef<Unit> units,
  333. const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
  334. const CheckParseTreesOptions& options) -> void {
  335. if (!options.vlog_stream && !options.dump_stream &&
  336. !options.raw_dump_stream) {
  337. return;
  338. }
  339. // Flush diagnostics before printing.
  340. for (const auto& unit : units) {
  341. unit.consumer->Flush();
  342. }
  343. for (const auto& unit : units) {
  344. bool include_in_dumps =
  345. options.include_in_dumps->Get(unit.sem_ir->check_ir_id());
  346. if (include_in_dumps && options.raw_dump_stream) {
  347. unit.sem_ir->Print(*options.raw_dump_stream,
  348. options.dump_raw_sem_ir_builtins);
  349. }
  350. MaybeDumpFormattedSemIR(
  351. *unit.sem_ir, units.size(),
  352. tree_and_subtrees_getters.Get(unit.sem_ir->check_ir_id()),
  353. include_in_dumps, options);
  354. }
  355. }
  356. // Handles options for dumping C++ AST.
  357. static auto MaybeDumpCppAST(llvm::ArrayRef<Unit> units,
  358. const CheckParseTreesOptions& options) -> void {
  359. if (!options.dump_cpp_ast_stream) {
  360. return;
  361. }
  362. for (const Unit& unit : units) {
  363. if (options.include_in_dumps->Get(unit.sem_ir->check_ir_id())) {
  364. if (auto* cpp_file = unit.sem_ir->cpp_file()) {
  365. cpp_file->ast_context().getTranslationUnitDecl()->dump(
  366. *options.dump_cpp_ast_stream);
  367. }
  368. }
  369. }
  370. }
  371. auto CheckParseTrees(
  372. llvm::MutableArrayRef<Unit> units,
  373. const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
  374. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  375. const CheckParseTreesOptions& options,
  376. std::shared_ptr<clang::CompilerInvocation> clang_invocation) -> void {
  377. // UnitAndImports is big due to its SmallVectors, so we default to 0 on the
  378. // stack.
  379. llvm::SmallVector<UnitAndImports, 0> unit_infos(
  380. llvm::map_range(units, [&](Unit& unit) {
  381. return UnitAndImports(
  382. &unit, tree_and_subtrees_getters.Get(unit.sem_ir->check_ir_id()));
  383. }));
  384. // Dump the raw SemIR in the event of a crash. We dump it to a separate file
  385. // to keep the stack trace manageable.
  386. PrettyStackTraceFunction sem_ir_dumper([&](llvm::raw_ostream& output) {
  387. if (!options.sem_ir_crash_dump.empty()) {
  388. output << "Dumping raw SemIR to " << options.sem_ir_crash_dump << "\n";
  389. std::error_code error_code;
  390. llvm::raw_fd_ostream sem_ir_dump(options.sem_ir_crash_dump, error_code);
  391. if (error_code) {
  392. output << "Raw SemIR dump failed: " << error_code.category().name()
  393. << ":" << error_code.value() << ": " << error_code.message()
  394. << "\n";
  395. } else {
  396. for (const auto& unit_info : unit_infos) {
  397. if (unit_info.is_checked && unit_info.unit->sem_ir != nullptr) {
  398. unit_info.unit->sem_ir->Print(sem_ir_dump);
  399. }
  400. }
  401. }
  402. }
  403. });
  404. Map<ImportKey, UnitAndImports*> api_map =
  405. BuildApiMapAndDiagnosePackaging(unit_infos);
  406. // Mark down imports for all files.
  407. llvm::SmallVector<UnitAndImports*> ready_to_check;
  408. ready_to_check.reserve(units.size());
  409. for (auto& unit_info : unit_infos) {
  410. const auto& packaging = unit_info.parse_tree().packaging_decl();
  411. if (packaging && packaging->is_impl) {
  412. // An `impl` has an implicit import of its `api`.
  413. auto implicit_names = packaging->names;
  414. implicit_names.package_id = PackageNameId::None;
  415. TrackImport(api_map, nullptr, unit_info, implicit_names, options.fuzzing);
  416. }
  417. Map<ImportKey, Parse::NodeId> explicit_import_map;
  418. // Add the prelude import. It's added to explicit_import_map so that it can
  419. // conflict with an explicit import of the prelude.
  420. if (options.prelude_import &&
  421. !(packaging && packaging->names.package_id == PackageNameId::Core)) {
  422. auto prelude_id =
  423. unit_info.unit->value_stores->string_literal_values().Add("prelude");
  424. TrackImport(api_map, &explicit_import_map, unit_info,
  425. {.node_id = Parse::NoneNodeId(),
  426. .package_id = PackageNameId::Core,
  427. .library_id = prelude_id},
  428. options.fuzzing);
  429. }
  430. for (const auto& import : unit_info.parse_tree().imports()) {
  431. TrackImport(api_map, &explicit_import_map, unit_info, import,
  432. options.fuzzing);
  433. }
  434. // If there were no imports, mark the file as ready to check for below.
  435. if (unit_info.imports_remaining == 0) {
  436. ready_to_check.push_back(&unit_info);
  437. }
  438. }
  439. // Check everything with no dependencies. Earlier entries with dependencies
  440. // will be checked as soon as all their dependencies have been checked.
  441. for (int check_index = 0;
  442. check_index < static_cast<int>(ready_to_check.size()); ++check_index) {
  443. auto* unit_info = ready_to_check[check_index];
  444. CheckUnit(unit_info, &tree_and_subtrees_getters, fs,
  445. unit_info->unit->llvm_context, clang_invocation,
  446. options.vlog_stream)
  447. .Run();
  448. for (auto* incoming_import : unit_info->incoming_imports) {
  449. --incoming_import->imports_remaining;
  450. if (incoming_import->imports_remaining == 0) {
  451. ready_to_check.push_back(incoming_import);
  452. }
  453. }
  454. }
  455. // If there are still units with remaining imports, it means there's a
  456. // dependency loop.
  457. if (ready_to_check.size() < unit_infos.size()) {
  458. // Go through units and mask out unevaluated imports. This breaks everything
  459. // associated with a loop equivalently, whether it's part of it or depending
  460. // on a part of it.
  461. // TODO: Better identify cycles, maybe try to untangle them.
  462. for (auto& unit_info : unit_infos) {
  463. if (unit_info.imports_remaining > 0) {
  464. for (auto& package_imports : unit_info.package_imports) {
  465. for (auto* import_it = package_imports.imports.begin();
  466. import_it != package_imports.imports.end();) {
  467. if (import_it->unit_info->is_checked) {
  468. // The import is checked, so continue.
  469. ++import_it;
  470. } else {
  471. // The import hasn't been checked, indicating a cycle.
  472. CARBON_DIAGNOSTIC(ImportCycleDetected, Error,
  473. "import cannot be used due to a cycle; cycle "
  474. "must be fixed to import");
  475. unit_info.emitter.Emit(import_it->names.node_id,
  476. ImportCycleDetected);
  477. // Make this look the same as an import which wasn't found.
  478. package_imports.has_load_error = true;
  479. if (unit_info.api_for_impl == import_it->unit_info) {
  480. unit_info.api_for_impl = nullptr;
  481. }
  482. import_it = package_imports.imports.erase(import_it);
  483. }
  484. }
  485. }
  486. }
  487. }
  488. // Check the remaining file contents, which are probably broken due to
  489. // incomplete imports.
  490. for (auto& unit_info : unit_infos) {
  491. if (unit_info.imports_remaining > 0) {
  492. CheckUnit(&unit_info, &tree_and_subtrees_getters, fs,
  493. unit_info.unit->llvm_context, clang_invocation,
  494. options.vlog_stream)
  495. .Run();
  496. }
  497. }
  498. }
  499. MaybeDumpSemIR(units, tree_and_subtrees_getters, options);
  500. MaybeDumpCppAST(units, options);
  501. }
  502. } // namespace Carbon::Check