mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Refactor ReturnTypeInfo and InitRepr. (#4169)
Rename `ReturnInfo` to `ReturnTypeInfo`. Move it and `InitRepr` into `type_info.h` alongside `ValueRepr`. Replace `ReturnSlot` with `InitRepr`, and extend `InitRepr` to be able to represent the incomplete-type case instead of CHECK-failing. Remove `has_return_slot` from `InitRepr` and instead only provide that as part of `ReturnTypeInfo`.
This commit is contained in:
@@ -38,7 +38,7 @@ static auto GetAggregateElement(FunctionContext& context,
|
||||
|
||||
case SemIR::ExprCategory::Value: {
|
||||
auto value_rep =
|
||||
SemIR::GetValueRepr(context.sem_ir(), aggr_inst.type_id());
|
||||
SemIR::ValueRepr::ForType(context.sem_ir(), aggr_inst.type_id());
|
||||
CARBON_CHECK(value_rep.aggregate_kind != SemIR::ValueRepr::NotAggregate)
|
||||
<< "aggregate type should have aggregate value representation";
|
||||
switch (value_rep.kind) {
|
||||
@@ -67,7 +67,8 @@ static auto GetAggregateElement(FunctionContext& context,
|
||||
|
||||
// `elem_ptr` points to a value representation. Load it.
|
||||
auto result_value_type_id =
|
||||
SemIR::GetValueRepr(context.sem_ir(), result_type_id).type_id;
|
||||
SemIR::ValueRepr::ForType(context.sem_ir(), result_type_id)
|
||||
.type_id;
|
||||
return context.builder().CreateLoad(
|
||||
context.GetType(result_value_type_id), elem_ptr, name + ".load");
|
||||
}
|
||||
@@ -123,7 +124,7 @@ static auto EmitAggregateInitializer(FunctionContext& context,
|
||||
llvm::Twine name) -> llvm::Value* {
|
||||
auto* llvm_type = context.GetType(type_id);
|
||||
|
||||
switch (SemIR::GetInitRepr(context.sem_ir(), type_id).kind) {
|
||||
switch (SemIR::InitRepr::ForType(context.sem_ir(), type_id).kind) {
|
||||
case SemIR::InitRepr::None:
|
||||
case SemIR::InitRepr::InPlace:
|
||||
// TODO: Add a helper to poison a value slot.
|
||||
@@ -139,6 +140,10 @@ static auto EmitAggregateInitializer(FunctionContext& context,
|
||||
llvm::PoisonValue::get(llvm_type), context.GetValue(refs[0]), {0},
|
||||
name);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::Incomplete:
|
||||
CARBON_FATAL() << "Lowering aggregate initialization of incomplete type "
|
||||
<< context.sem_ir().types().GetAsInst(type_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +174,7 @@ auto HandleInst(FunctionContext& /*context*/, SemIR::InstId /*inst_id*/,
|
||||
static auto EmitAggregateValueRepr(FunctionContext& context,
|
||||
SemIR::TypeId type_id,
|
||||
SemIR::InstBlockId refs_id) -> llvm::Value* {
|
||||
auto value_rep = SemIR::GetValueRepr(context.sem_ir(), type_id);
|
||||
auto value_rep = SemIR::ValueRepr::ForType(context.sem_ir(), type_id);
|
||||
switch (value_rep.kind) {
|
||||
case SemIR::ValueRepr::Unknown:
|
||||
CARBON_FATAL() << "Incomplete aggregate type in lowering";
|
||||
|
||||
Reference in New Issue
Block a user