|
20 | 20 | #include "toolchain/check/inst.h" |
21 | 21 | #include "toolchain/check/node_id_traversal.h" |
22 | 22 | #include "toolchain/check/type.h" |
| 23 | +#include "toolchain/sem_ir/function.h" |
| 24 | +#include "toolchain/sem_ir/ids.h" |
23 | 25 | #include "toolchain/sem_ir/import_ir.h" |
24 | 26 |
|
25 | 27 | namespace Carbon::Check { |
@@ -440,9 +442,11 @@ auto CheckUnit::CheckRequiredDeclarations() -> void { |
440 | 442 | auto CheckUnit::CheckRequiredDefinitions() -> void { |
441 | 443 | CARBON_DIAGNOSTIC(MissingDefinitionInImpl, Error, |
442 | 444 | "no definition found for declaration in impl file"); |
| 445 | + |
443 | 446 | // Note that more required definitions can be added during this loop. |
444 | | - for (size_t i = 0; i != context_.definitions_required().size(); ++i) { |
445 | | - SemIR::InstId decl_inst_id = context_.definitions_required()[i]; |
| 447 | + // NOLINTNEXTLINE(modernize-loop-convert) |
| 448 | + for (size_t i = 0; i != context_.definitions_required_by_decl().size(); ++i) { |
| 449 | + SemIR::InstId decl_inst_id = context_.definitions_required_by_decl()[i]; |
446 | 450 | SemIR::Inst decl_inst = context_.insts().Get(decl_inst_id); |
447 | 451 | CARBON_KIND_SWITCH(context_.insts().Get(decl_inst_id)) { |
448 | 452 | case CARBON_KIND(SemIR::ClassDecl class_decl): { |
@@ -474,33 +478,32 @@ auto CheckUnit::CheckRequiredDefinitions() -> void { |
474 | 478 | // https://github.com/carbon-language/carbon-lang/issues/4071. |
475 | 479 | CARBON_FATAL("TODO: Support interfaces in DiagnoseMissingDefinitions"); |
476 | 480 | } |
477 | | - case CARBON_KIND(SemIR::SpecificFunction specific_function): { |
478 | | - // TODO: Track a location for the use. In general we may want to track a |
479 | | - // list of enclosing locations if this was used from a generic. |
480 | | - SemIRLoc use_loc = decl_inst_id; |
481 | | - if (!ResolveSpecificDefinition(context_, use_loc, |
482 | | - specific_function.specific_id)) { |
483 | | - CARBON_DIAGNOSTIC(MissingGenericFunctionDefinition, Error, |
484 | | - "use of undefined generic function"); |
485 | | - CARBON_DIAGNOSTIC(MissingGenericFunctionDefinitionHere, Note, |
486 | | - "generic function declared here"); |
487 | | - auto generic_decl_id = |
488 | | - context_.generics() |
489 | | - .Get(context_.specifics() |
490 | | - .Get(specific_function.specific_id) |
491 | | - .generic_id) |
492 | | - .decl_id; |
493 | | - emitter_.Build(decl_inst_id, MissingGenericFunctionDefinition) |
494 | | - .Note(generic_decl_id, MissingGenericFunctionDefinitionHere) |
495 | | - .Emit(); |
496 | | - } |
497 | | - break; |
498 | | - } |
499 | 481 | default: { |
500 | 482 | CARBON_FATAL("Unexpected inst in definitions_required: {0}", decl_inst); |
501 | 483 | } |
502 | 484 | } |
503 | 485 | } |
| 486 | + |
| 487 | + // Note that more required definitions can be added during this loop. |
| 488 | + // NOLINTNEXTLINE(modernize-loop-convert) |
| 489 | + for (size_t i = 0; i != context_.definitions_required_by_use().size(); ++i) { |
| 490 | + // This is using the location for the use. We could track the |
| 491 | + // list of enclosing locations if this was used from a generic. |
| 492 | + auto [loc, specific_id] = context_.definitions_required_by_use()[i]; |
| 493 | + if (!ResolveSpecificDefinition(context_, loc, specific_id)) { |
| 494 | + CARBON_DIAGNOSTIC(MissingGenericFunctionDefinition, Error, |
| 495 | + "use of undefined generic function"); |
| 496 | + CARBON_DIAGNOSTIC(MissingGenericFunctionDefinitionHere, Note, |
| 497 | + "generic function declared here"); |
| 498 | + auto generic_decl_id = |
| 499 | + context_.generics() |
| 500 | + .Get(context_.specifics().Get(specific_id).generic_id) |
| 501 | + .decl_id; |
| 502 | + emitter_.Build(loc, MissingGenericFunctionDefinition) |
| 503 | + .Note(generic_decl_id, MissingGenericFunctionDefinitionHere) |
| 504 | + .Emit(); |
| 505 | + } |
| 506 | + } |
504 | 507 | } |
505 | 508 |
|
506 | 509 | auto CheckUnit::FinishRun() -> void { |
|
0 commit comments