check.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 "common/check.h"
  6. #include "toolchain/base/pretty_stack_trace_function.h"
  7. #include "toolchain/base/value_store.h"
  8. #include "toolchain/check/context.h"
  9. #include "toolchain/diagnostics/diagnostic_emitter.h"
  10. #include "toolchain/lex/token_kind.h"
  11. #include "toolchain/parse/tree.h"
  12. #include "toolchain/parse/tree_node_location_translator.h"
  13. #include "toolchain/sem_ir/file.h"
  14. #include "toolchain/sem_ir/typed_insts.h"
  15. namespace Carbon::Check {
  16. struct UnitInfo {
  17. // A given import within the file, with its destination.
  18. struct Import {
  19. Parse::Tree::PackagingNames names;
  20. UnitInfo* unit_info;
  21. };
  22. // A file's imports corresponding to a single package, for the map.
  23. struct PackageImports {
  24. // Use the constructor so that the SmallVector is only constructed
  25. // as-needed.
  26. explicit PackageImports(Parse::NodeId node) : node(node) {}
  27. // The first `import` directive in the file, which declared the package's
  28. // identifier (even if the import failed). Used for associating diagnostics
  29. // not specific to a single import.
  30. Parse::NodeId node;
  31. // Whether there's an import that failed to load.
  32. bool has_load_error = false;
  33. // The list of valid imports.
  34. llvm::SmallVector<Import> imports;
  35. };
  36. explicit UnitInfo(Unit& unit)
  37. : unit(&unit),
  38. translator(unit.tokens, unit.tokens->source().filename(),
  39. unit.parse_tree),
  40. err_tracker(*unit.consumer),
  41. emitter(translator, err_tracker) {}
  42. Unit* unit;
  43. // Emitter information.
  44. Parse::NodeLocationTranslator translator;
  45. ErrorTrackingDiagnosticConsumer err_tracker;
  46. DiagnosticEmitter<Parse::NodeLocation> emitter;
  47. // A map of package names to outgoing imports. If the
  48. // import's target isn't available, the unit will be nullptr to assist with
  49. // name lookup. Invalid imports (for example, `import Main;`) aren't added
  50. // because they won't add identifiers to name lookup.
  51. llvm::DenseMap<IdentifierId, PackageImports> package_imports_map;
  52. // The remaining number of imports which must be checked before this unit can
  53. // be processed.
  54. int32_t imports_remaining = 0;
  55. // A list of incoming imports. This will be empty for `impl` files, because
  56. // imports only touch `api` files.
  57. llvm::SmallVector<UnitInfo*> incoming_imports;
  58. };
  59. // Add imports to the root block.
  60. static auto InitPackageScopeAndImports(Context& context, UnitInfo& unit_info)
  61. -> void {
  62. // Define the package scope, with an instruction for `package` expressions to
  63. // reference.
  64. auto package_scope_id =
  65. context.name_scopes().Add(SemIR::InstId::PackageNamespace);
  66. CARBON_CHECK(package_scope_id == SemIR::NameScopeId::Package);
  67. auto package_inst = context.AddInst(SemIR::Namespace{
  68. Parse::NodeId::Invalid,
  69. context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType),
  70. SemIR::NameScopeId::Package});
  71. CARBON_CHECK(package_inst == SemIR::InstId::PackageNamespace);
  72. // Add imports from the current package.
  73. auto self_import = unit_info.package_imports_map.find(IdentifierId::Invalid);
  74. if (self_import != unit_info.package_imports_map.end()) {
  75. auto& package_scope =
  76. context.name_scopes().Get(SemIR::NameScopeId::Package);
  77. package_scope.has_error = self_import->second.has_load_error;
  78. for (const auto& import : self_import->second.imports) {
  79. const auto& import_sem_ir = **import.unit_info->unit->sem_ir;
  80. const auto& import_scope =
  81. import_sem_ir.name_scopes().Get(SemIR::NameScopeId::Package);
  82. // If an import of the current package caused an error for the imported
  83. // file, it transitively affects the current file too.
  84. package_scope.has_error |= import_scope.has_error;
  85. auto ir_id = context.sem_ir().cross_ref_irs().Add(&import_sem_ir);
  86. for (const auto& [import_name_id, import_inst_id] : import_scope.names) {
  87. // Translate the name to the current IR.
  88. auto name_id = SemIR::NameId::Invalid;
  89. if (auto import_identifier_id = import_name_id.AsIdentifierId();
  90. import_identifier_id.is_valid()) {
  91. auto name = import_sem_ir.identifiers().Get(import_identifier_id);
  92. name_id =
  93. SemIR::NameId::ForIdentifier(context.identifiers().Add(name));
  94. } else {
  95. // A builtin name ID which is equivalent cross-IR.
  96. name_id = import_name_id;
  97. }
  98. // Leave a placeholder that the inst comes from the other IR.
  99. auto target_id = context.AddInst(
  100. SemIR::LazyImportRef{.ir_id = ir_id, .inst_id = import_inst_id});
  101. // TODO: The scope's names should be changed to allow for ambiguous
  102. // names.
  103. package_scope.names.insert({name_id, target_id});
  104. }
  105. }
  106. // Push the scope.
  107. context.PushScope(package_inst, SemIR::NameScopeId::Package,
  108. package_scope.has_error);
  109. } else {
  110. // Push the scope; there are no names to add.
  111. context.PushScope(package_inst, SemIR::NameScopeId::Package);
  112. }
  113. for (auto& [package_id, package_imports] : unit_info.package_imports_map) {
  114. if (!package_id.is_valid()) {
  115. // Current package is handled above.
  116. continue;
  117. }
  118. llvm::SmallVector<const SemIR::File*> sem_irs;
  119. for (auto import : package_imports.imports) {
  120. sem_irs.push_back(&**import.unit_info->unit->sem_ir);
  121. }
  122. context.AddPackageImports(package_imports.node, package_id, sem_irs,
  123. package_imports.has_load_error);
  124. }
  125. }
  126. // Loops over all nodes in the tree. On some errors, this may return early,
  127. // for example if an unrecoverable state is encountered.
  128. static auto ProcessParseNodes(Context& context,
  129. ErrorTrackingDiagnosticConsumer& err_tracker)
  130. -> bool {
  131. for (auto parse_node : context.parse_tree().postorder()) {
  132. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  133. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  134. switch (auto parse_kind = context.parse_tree().node_kind(parse_node)) {
  135. #define CARBON_PARSE_NODE_KIND(Name) \
  136. case Parse::NodeKind::Name: { \
  137. if (!Check::Handle##Name(context, parse_node)) { \
  138. CARBON_CHECK(err_tracker.seen_error()) \
  139. << "Handle" #Name " returned false without printing a diagnostic"; \
  140. return false; \
  141. } \
  142. break; \
  143. }
  144. #include "toolchain/parse/node_kind.def"
  145. }
  146. }
  147. return true;
  148. }
  149. // Produces and checks the IR for the provided Parse::Tree.
  150. static auto CheckParseTree(const SemIR::File& builtin_ir, UnitInfo& unit_info,
  151. llvm::raw_ostream* vlog_stream) -> void {
  152. unit_info.unit->sem_ir->emplace(
  153. *unit_info.unit->value_stores,
  154. unit_info.unit->tokens->source().filename().str(), &builtin_ir);
  155. // For ease-of-access.
  156. SemIR::File& sem_ir = **unit_info.unit->sem_ir;
  157. Context context(*unit_info.unit->tokens, unit_info.emitter,
  158. *unit_info.unit->parse_tree, sem_ir, vlog_stream);
  159. PrettyStackTraceFunction context_dumper(
  160. [&](llvm::raw_ostream& output) { context.PrintForStackDump(output); });
  161. // Add a block for the file.
  162. context.inst_block_stack().Push();
  163. InitPackageScopeAndImports(context, unit_info);
  164. if (!ProcessParseNodes(context, unit_info.err_tracker)) {
  165. context.sem_ir().set_has_errors(true);
  166. return;
  167. }
  168. // Pop information for the file-level scope.
  169. sem_ir.set_top_inst_block_id(context.inst_block_stack().Pop());
  170. context.PopScope();
  171. context.VerifyOnFinish();
  172. sem_ir.set_has_errors(unit_info.err_tracker.seen_error());
  173. #ifndef NDEBUG
  174. if (auto verify = sem_ir.Verify(); !verify.ok()) {
  175. CARBON_FATAL() << sem_ir << "Built invalid semantics IR: " << verify.error()
  176. << "\n";
  177. }
  178. #endif
  179. }
  180. // The package and library names, used as map keys.
  181. using ImportKey = std::pair<llvm::StringRef, llvm::StringRef>;
  182. // Returns a key form of the package object. file_package_id is only used for
  183. // imports, not the main package directive; as a consequence, it will be invalid
  184. // for the main package directive.
  185. static auto GetImportKey(UnitInfo& unit_info, IdentifierId file_package_id,
  186. Parse::Tree::PackagingNames names) -> ImportKey {
  187. auto* stores = unit_info.unit->value_stores;
  188. llvm::StringRef package_name =
  189. names.package_id.is_valid() ? stores->identifiers().Get(names.package_id)
  190. : file_package_id.is_valid() ? stores->identifiers().Get(file_package_id)
  191. : "";
  192. llvm::StringRef library_name =
  193. names.library_id.is_valid()
  194. ? stores->string_literal_values().Get(names.library_id)
  195. : "";
  196. return {package_name, library_name};
  197. }
  198. static constexpr llvm::StringLiteral ExplicitMainName = "Main";
  199. // Marks an import as required on both the source and target file.
  200. //
  201. // The ID comparisons between the import and unit are okay because they both
  202. // come from the same file.
  203. static auto TrackImport(
  204. llvm::DenseMap<ImportKey, UnitInfo*>& api_map,
  205. llvm::DenseMap<ImportKey, Parse::NodeId>* explicit_import_map,
  206. UnitInfo& unit_info, Parse::Tree::PackagingNames import) -> void {
  207. const auto& packaging = unit_info.unit->parse_tree->packaging_directive();
  208. IdentifierId file_package_id =
  209. packaging ? packaging->names.package_id : IdentifierId::Invalid;
  210. auto import_key = GetImportKey(unit_info, file_package_id, import);
  211. // True if the import has `Main` as the package name, even if it comes from
  212. // the file's packaging (diagnostics may differentiate).
  213. bool is_explicit_main = import_key.first == ExplicitMainName;
  214. // Explicit imports need more validation than implicit ones. We try to do
  215. // these in an order of imports that should be removed, followed by imports
  216. // that might be valid with syntax fixes.
  217. if (explicit_import_map) {
  218. // Diagnose redundant imports.
  219. if (auto [insert_it, success] =
  220. explicit_import_map->insert({import_key, import.node});
  221. !success) {
  222. CARBON_DIAGNOSTIC(RepeatedImport, Error,
  223. "Library imported more than once.");
  224. CARBON_DIAGNOSTIC(FirstImported, Note, "First import here.");
  225. unit_info.emitter.Build(import.node, RepeatedImport)
  226. .Note(insert_it->second, FirstImported)
  227. .Emit();
  228. return;
  229. }
  230. // True if the file's package is implicitly `Main` (by omitting an explicit
  231. // package name).
  232. bool is_file_implicit_main =
  233. !packaging || !packaging->names.package_id.is_valid();
  234. // True if the import is using implicit "current package" syntax (by
  235. // omitting an explicit package name).
  236. bool is_import_implicit_current_package = !import.package_id.is_valid();
  237. // True if the import is using `default` library syntax.
  238. bool is_import_default_library = !import.library_id.is_valid();
  239. // True if the import and file point at the same package, even by
  240. // incorrectly specifying the current package name to `import`.
  241. bool is_same_package = is_import_implicit_current_package ||
  242. import.package_id == file_package_id;
  243. // True if the import points at the same library as the file's library.
  244. bool is_same_library =
  245. is_same_package &&
  246. (packaging ? import.library_id == packaging->names.library_id
  247. : is_import_default_library);
  248. // Diagnose explicit imports of the same library, whether from `api` or
  249. // `impl`.
  250. if (is_same_library) {
  251. CARBON_DIAGNOSTIC(ExplicitImportApi, Error,
  252. "Explicit import of `api` from `impl` file is "
  253. "redundant with implicit import.");
  254. CARBON_DIAGNOSTIC(ImportSelf, Error, "File cannot import itself.");
  255. bool is_impl =
  256. !packaging || packaging->api_or_impl == Parse::Tree::ApiOrImpl::Impl;
  257. unit_info.emitter.Emit(import.node,
  258. is_impl ? ExplicitImportApi : ImportSelf);
  259. return;
  260. }
  261. // Diagnose explicit imports of `Main//default`. There is no `api` for it.
  262. // This lets other diagnostics handle explicit `Main` package naming.
  263. if (is_file_implicit_main && is_import_implicit_current_package &&
  264. is_import_default_library) {
  265. CARBON_DIAGNOSTIC(ImportMainDefaultLibrary, Error,
  266. "Cannot import `Main//default`.");
  267. unit_info.emitter.Emit(import.node, ImportMainDefaultLibrary);
  268. return;
  269. }
  270. if (!is_import_implicit_current_package) {
  271. // Diagnose explicit imports of the same package that use the package
  272. // name.
  273. if (is_same_package || (is_file_implicit_main && is_explicit_main)) {
  274. CARBON_DIAGNOSTIC(
  275. ImportCurrentPackageByName, Error,
  276. "Imports from the current package must omit the package name.");
  277. unit_info.emitter.Emit(import.node, ImportCurrentPackageByName);
  278. return;
  279. }
  280. // Diagnose explicit imports from `Main`.
  281. if (is_explicit_main) {
  282. CARBON_DIAGNOSTIC(ImportMainPackage, Error,
  283. "Cannot import `Main` from other packages.");
  284. unit_info.emitter.Emit(import.node, ImportMainPackage);
  285. return;
  286. }
  287. }
  288. } else if (is_explicit_main) {
  289. // An implicit import with an explicit `Main` occurs when a `package` rule
  290. // has bad syntax, which will have been diagnosed when building the API map.
  291. // As a consequence, we return silently.
  292. return;
  293. }
  294. // Get the package imports.
  295. auto package_imports_it =
  296. unit_info.package_imports_map.try_emplace(import.package_id, import.node)
  297. .first;
  298. if (auto api = api_map.find(import_key); api != api_map.end()) {
  299. // Add references between the file and imported api.
  300. package_imports_it->second.imports.push_back({import, api->second});
  301. ++unit_info.imports_remaining;
  302. api->second->incoming_imports.push_back(&unit_info);
  303. } else {
  304. // The imported api is missing.
  305. package_imports_it->second.has_load_error = true;
  306. CARBON_DIAGNOSTIC(LibraryApiNotFound, Error,
  307. "Corresponding API not found.");
  308. CARBON_DIAGNOSTIC(ImportNotFound, Error, "Imported API not found.");
  309. unit_info.emitter.Emit(
  310. import.node, explicit_import_map ? ImportNotFound : LibraryApiNotFound);
  311. }
  312. }
  313. // Builds a map of `api` files which might be imported. Also diagnoses issues
  314. // related to the packaging because the strings are loaded as part of getting
  315. // the ImportKey (which we then do for `impl` files too).
  316. static auto BuildApiMapAndDiagnosePackaging(
  317. llvm::SmallVector<UnitInfo, 0>& unit_infos)
  318. -> llvm::DenseMap<ImportKey, UnitInfo*> {
  319. llvm::DenseMap<ImportKey, UnitInfo*> api_map;
  320. for (auto& unit_info : unit_infos) {
  321. const auto& packaging = unit_info.unit->parse_tree->packaging_directive();
  322. // An import key formed from the `package` or `library` directive. Or, for
  323. // Main//default, a placeholder key.
  324. auto import_key = packaging ? GetImportKey(unit_info, IdentifierId::Invalid,
  325. packaging->names)
  326. // Construct a boring key for Main//default.
  327. : ImportKey{"", ""};
  328. // Diagnose explicit `Main` uses before they become marked as possible
  329. // APIs.
  330. if (import_key.first == ExplicitMainName) {
  331. CARBON_DIAGNOSTIC(ExplicitMainPackage, Error,
  332. "`Main//default` must omit `package` directive.");
  333. CARBON_DIAGNOSTIC(ExplicitMainLibrary, Error,
  334. "Use `library` directive in `Main` package libraries.");
  335. unit_info.emitter.Emit(packaging->names.node, import_key.second.empty()
  336. ? ExplicitMainPackage
  337. : ExplicitMainLibrary);
  338. continue;
  339. }
  340. bool is_impl =
  341. packaging && packaging->api_or_impl == Parse::Tree::ApiOrImpl::Impl;
  342. // Add to the `api` map and diagnose duplicates. This occurs before the
  343. // file extension check because we might emit both diagnostics in situations
  344. // where the user forgets (or has syntax errors with) a package line
  345. // multiple times.
  346. if (!is_impl) {
  347. auto [entry, success] = api_map.insert({import_key, &unit_info});
  348. if (!success) {
  349. llvm::StringRef prev_filename =
  350. entry->second->unit->tokens->source().filename();
  351. if (packaging) {
  352. CARBON_DIAGNOSTIC(DuplicateLibraryApi, Error,
  353. "Library's API previously provided by `{0}`.",
  354. std::string);
  355. unit_info.emitter.Emit(packaging->names.node, DuplicateLibraryApi,
  356. prev_filename.str());
  357. } else {
  358. CARBON_DIAGNOSTIC(DuplicateMainApi, Error,
  359. "Main//default previously provided by `{0}`.",
  360. std::string);
  361. // Use the invalid node because there's no node to associate with.
  362. unit_info.emitter.Emit(Parse::NodeId::Invalid, DuplicateMainApi,
  363. prev_filename.str());
  364. }
  365. }
  366. }
  367. // Validate file extensions. Note imports rely the packaging directive, not
  368. // the extension. If the input is not a regular file, for example because it
  369. // is stdin, no filename checking is performed.
  370. if (unit_info.unit->tokens->source().is_regular_file()) {
  371. auto filename = unit_info.unit->tokens->source().filename();
  372. static constexpr llvm::StringLiteral ApiExt = ".carbon";
  373. static constexpr llvm::StringLiteral ImplExt = ".impl.carbon";
  374. bool is_api_with_impl_ext = !is_impl && filename.ends_with(ImplExt);
  375. auto want_ext = is_impl ? ImplExt : ApiExt;
  376. if (is_api_with_impl_ext || !filename.ends_with(want_ext)) {
  377. CARBON_DIAGNOSTIC(IncorrectExtension, Error,
  378. "File extension of `{0}` required for `{1}`.",
  379. llvm::StringLiteral, Lex::TokenKind);
  380. auto diag = unit_info.emitter.Build(
  381. packaging ? packaging->names.node : Parse::NodeId::Invalid,
  382. IncorrectExtension, want_ext,
  383. is_impl ? Lex::TokenKind::Impl : Lex::TokenKind::Api);
  384. if (is_api_with_impl_ext) {
  385. CARBON_DIAGNOSTIC(IncorrectExtensionImplNote, Note,
  386. "File extension of `{0}` only allowed for `{1}`.",
  387. llvm::StringLiteral, Lex::TokenKind);
  388. diag.Note(Parse::NodeId::Invalid, IncorrectExtensionImplNote, ImplExt,
  389. Lex::TokenKind::Impl);
  390. }
  391. diag.Emit();
  392. }
  393. }
  394. }
  395. return api_map;
  396. }
  397. auto CheckParseTrees(const SemIR::File& builtin_ir,
  398. llvm::MutableArrayRef<Unit> units,
  399. llvm::raw_ostream* vlog_stream) -> void {
  400. // Prepare diagnostic emitters in case we run into issues during package
  401. // checking.
  402. //
  403. // UnitInfo is big due to its SmallVectors, so we default to 0 on the stack.
  404. llvm::SmallVector<UnitInfo, 0> unit_infos;
  405. unit_infos.reserve(units.size());
  406. for (auto& unit : units) {
  407. unit_infos.emplace_back(unit);
  408. }
  409. llvm::DenseMap<ImportKey, UnitInfo*> api_map =
  410. BuildApiMapAndDiagnosePackaging(unit_infos);
  411. // Mark down imports for all files.
  412. llvm::SmallVector<UnitInfo*> ready_to_check;
  413. ready_to_check.reserve(units.size());
  414. for (auto& unit_info : unit_infos) {
  415. if (const auto& packaging =
  416. unit_info.unit->parse_tree->packaging_directive()) {
  417. if (packaging->api_or_impl == Parse::Tree::ApiOrImpl::Impl) {
  418. // An `impl` has an implicit import of its `api`.
  419. auto implicit_names = packaging->names;
  420. implicit_names.package_id = IdentifierId::Invalid;
  421. TrackImport(api_map, nullptr, unit_info, implicit_names);
  422. }
  423. }
  424. llvm::DenseMap<ImportKey, Parse::NodeId> explicit_import_map;
  425. for (const auto& import : unit_info.unit->parse_tree->imports()) {
  426. TrackImport(api_map, &explicit_import_map, unit_info, import);
  427. }
  428. // If there were no imports, mark the file as ready to check for below.
  429. if (unit_info.imports_remaining == 0) {
  430. ready_to_check.push_back(&unit_info);
  431. }
  432. }
  433. // Check everything with no dependencies. Earlier entries with dependencies
  434. // will be checked as soon as all their dependencies have been checked.
  435. for (int check_index = 0;
  436. check_index < static_cast<int>(ready_to_check.size()); ++check_index) {
  437. auto* unit_info = ready_to_check[check_index];
  438. CheckParseTree(builtin_ir, *unit_info, vlog_stream);
  439. for (auto* incoming_import : unit_info->incoming_imports) {
  440. --incoming_import->imports_remaining;
  441. if (incoming_import->imports_remaining == 0) {
  442. ready_to_check.push_back(incoming_import);
  443. }
  444. }
  445. }
  446. // If there are still units with remaining imports, it means there's a
  447. // dependency loop.
  448. if (ready_to_check.size() < unit_infos.size()) {
  449. // Go through units and mask out unevaluated imports. This breaks everything
  450. // associated with a loop equivalently, whether it's part of it or depending
  451. // on a part of it.
  452. // TODO: Better identify cycles, maybe try to untangle them.
  453. for (auto& unit_info : unit_infos) {
  454. if (unit_info.imports_remaining > 0) {
  455. for (auto& [package_id, package_imports] :
  456. unit_info.package_imports_map) {
  457. for (auto* import_it = package_imports.imports.begin();
  458. import_it != package_imports.imports.end();) {
  459. if (*import_it->unit_info->unit->sem_ir) {
  460. // The import is checked, so continue.
  461. ++import_it;
  462. } else {
  463. // The import hasn't been checked, indicating a cycle.
  464. CARBON_DIAGNOSTIC(ImportCycleDetected, Error,
  465. "Import cannot be used due to a cycle. Cycle "
  466. "must be fixed to import.");
  467. unit_info.emitter.Emit(import_it->names.node,
  468. ImportCycleDetected);
  469. // Make this look the same as an import which wasn't found.
  470. package_imports.has_load_error = true;
  471. import_it = package_imports.imports.erase(import_it);
  472. }
  473. }
  474. }
  475. }
  476. }
  477. // Check the remaining file contents, which are probably broken due to
  478. // incomplete imports.
  479. for (auto& unit_info : unit_infos) {
  480. if (unit_info.imports_remaining > 0) {
  481. CheckParseTree(builtin_ir, unit_info, vlog_stream);
  482. }
  483. }
  484. }
  485. }
  486. } // namespace Carbon::Check