check.cpp 23 KB

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