Skip to content

Commit

Permalink
Address comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
alinas committed Mar 5, 2025
1 parent a3f5ddf commit 666bc62
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions toolchain/lower/file_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,7 @@ auto FileContext::BuildDICompileUnit(llvm::StringRef module_name,

auto FileContext::GetGlobal(SemIR::InstId inst_id,
SemIR::SpecificId specific_id) -> llvm::Value* {
auto inst = sem_ir().insts().Get(inst_id);

if (specific_id.has_value()) {
inst_id = sem_ir().constant_values().GetInstIdIfValid(
GetConstantValueInSpecific(sem_ir(), specific_id, inst_id));
CARBON_CHECK(inst_id.has_value(),
"Expected to find an instruction id for a specific in the "
"file context");
}

auto const_id = sem_ir().constant_values().Get(inst_id);
auto const_id = GetConstantValueInSpecific(sem_ir(), specific_id, inst_id);
if (const_id.is_concrete()) {
auto const_inst_id = sem_ir().constant_values().GetInstId(const_id);

Expand All @@ -151,7 +141,8 @@ auto FileContext::GetGlobal(SemIR::InstId inst_id,
// If we want a pointer to the constant, materialize a global to hold it.
// TODO: We could reuse the same global if the constant is used more than
// once.
auto value_rep = SemIR::ValueRepr::ForType(sem_ir(), inst.type_id());
auto value_rep = SemIR::ValueRepr::ForType(
sem_ir(), sem_ir().insts().Get(const_inst_id).type_id());
if (value_rep.kind == SemIR::ValueRepr::Pointer) {
// Include both the name of the constant, if any, and the point of use in
// the name of the variable.
Expand Down Expand Up @@ -182,9 +173,7 @@ auto FileContext::GetGlobal(SemIR::InstId inst_id,
return const_value;
}

// TODO: For generics, handle references to symbolic constants.

CARBON_FATAL("Missing value: {0} {1}", inst_id,
CARBON_FATAL("Missing value: {0} {1} {2}", inst_id, specific_id,
sem_ir().insts().Get(inst_id));
}

Expand Down

0 comments on commit 666bc62

Please sign in to comment.