mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 17:11:04 +01:00
Add import context for locations. (#3807)
As discussed around #3792, identify the import a diagnostic message came from prior to the diagnostic message itself. This occurs during location translation so that the logic can be central. I'd considered associating the parse node with ImportRef instructions, but I realized about halfway through that because I need to store the ImportDirectiveId on the ImportIR for cross-package imports, it's there for use in location translation without extra work. That saves a fair amount of stringing it through declarations, as well as an oddity where ImportRef instructions would have a node that didn't really represent them.
This commit is contained in:
@@ -137,7 +137,7 @@ auto Context::ReplaceInstBeforeConstantUse(
|
||||
auto Context::AddImportRef(SemIR::ImportIRId ir_id, SemIR::InstId inst_id)
|
||||
-> SemIR::InstId {
|
||||
auto import_ref_id =
|
||||
AddPlaceholderInstInNoBlock(SemIR::ImportRefUnused{ir_id, inst_id});
|
||||
AddPlaceholderInstInNoBlock({SemIR::ImportRefUnused{ir_id, inst_id}});
|
||||
|
||||
// We can't insert this instruction into whatever block we happen to be in,
|
||||
// because this function is typically called by name lookup in the middle of
|
||||
@@ -303,7 +303,8 @@ static auto LookupInImportIRScopes(Context& context, SemIRLocation loc,
|
||||
// Determine the NameId in the import IR.
|
||||
SemIR::NameId import_name_id = name_id;
|
||||
if (identifier_id.is_valid()) {
|
||||
auto import_identifier_id = import_ir->identifiers().Lookup(identifier);
|
||||
auto import_identifier_id =
|
||||
import_ir.sem_ir->identifiers().Lookup(identifier);
|
||||
if (!import_identifier_id.is_valid()) {
|
||||
// Name doesn't exist in the import IR.
|
||||
continue;
|
||||
@@ -312,7 +313,8 @@ static auto LookupInImportIRScopes(Context& context, SemIRLocation loc,
|
||||
}
|
||||
|
||||
// Look up the name in the import scope.
|
||||
const auto& import_scope = import_ir->name_scopes().Get(import_scope_id);
|
||||
const auto& import_scope =
|
||||
import_ir.sem_ir->name_scopes().Get(import_scope_id);
|
||||
auto it = import_scope.names.find(import_name_id);
|
||||
if (it == import_scope.names.end()) {
|
||||
// Name doesn't exist in the import scope.
|
||||
@@ -742,7 +744,7 @@ class TypeCompleter {
|
||||
auto BuildImportRefUsedValueRepr(SemIR::TypeId type_id,
|
||||
SemIR::ImportRefUsed import_ref) const
|
||||
-> SemIR::ValueRepr {
|
||||
const auto& import_ir = context_.import_irs().Get(import_ref.ir_id);
|
||||
const auto& import_ir = context_.import_irs().Get(import_ref.ir_id).sem_ir;
|
||||
auto import_inst = import_ir->insts().Get(import_ref.inst_id);
|
||||
CARBON_CHECK(import_inst.kind() != SemIR::InstKind::ImportRefUsed)
|
||||
<< "If ImportRefUsed can point at another, this would be recursive.";
|
||||
|
||||
Reference in New Issue
Block a user