Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errors

Rename `rustc_abi::Abi` to `BackendRepr`

Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights.

Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
This commit is contained in:
Jubilee 2024-10-30 14:01:37 -07:00 committed by GitHub
commit 906cd32637
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,7 +6,7 @@ use base_db::ra_salsa::Cycle;
use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy}; use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy};
use hir_def::{ use hir_def::{
layout::{ layout::{
Abi, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutData, BackendRepr, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutData,
Primitive, ReprOptions, Scalar, Size, StructKind, TargetDataLayout, WrappingRange, Primitive, ReprOptions, Scalar, Size, StructKind, TargetDataLayout, WrappingRange,
}, },
LocalFieldId, StructId, LocalFieldId, StructId,
@ -168,7 +168,7 @@ fn layout_of_simd_ty(
// Compute the ABI of the element type: // Compute the ABI of the element type:
let e_ly = db.layout_of_ty(e_ty, env)?; let e_ly = db.layout_of_ty(e_ty, env)?;
let Abi::Scalar(e_abi) = e_ly.abi else { let BackendRepr::Scalar(e_abi) = e_ly.backend_repr else {
return Err(LayoutError::Unknown); return Err(LayoutError::Unknown);
}; };
@ -190,7 +190,7 @@ fn layout_of_simd_ty(
Ok(Arc::new(Layout { Ok(Arc::new(Layout {
variants: Variants::Single { index: struct_variant_idx() }, variants: Variants::Single { index: struct_variant_idx() },
fields, fields,
abi: Abi::Vector { element: e_abi, count: e_len }, backend_repr: BackendRepr::Vector { element: e_abi, count: e_len },
largest_niche: e_ly.largest_niche, largest_niche: e_ly.largest_niche,
size, size,
align, align,
@ -294,10 +294,10 @@ pub fn layout_of_ty_query(
.checked_mul(count, dl) .checked_mul(count, dl)
.ok_or(LayoutError::BadCalc(LayoutCalculatorError::SizeOverflow))?; .ok_or(LayoutError::BadCalc(LayoutCalculatorError::SizeOverflow))?;
let abi = if count != 0 && matches!(element.abi, Abi::Uninhabited) { let backend_repr = if count != 0 && matches!(element.backend_repr, BackendRepr::Uninhabited) {
Abi::Uninhabited BackendRepr::Uninhabited
} else { } else {
Abi::Aggregate { sized: true } BackendRepr::Memory { sized: true }
}; };
let largest_niche = if count != 0 { element.largest_niche } else { None }; let largest_niche = if count != 0 { element.largest_niche } else { None };
@ -305,7 +305,7 @@ pub fn layout_of_ty_query(
Layout { Layout {
variants: Variants::Single { index: struct_variant_idx() }, variants: Variants::Single { index: struct_variant_idx() },
fields: FieldsShape::Array { stride: element.size, count }, fields: FieldsShape::Array { stride: element.size, count },
abi, backend_repr,
largest_niche, largest_niche,
align: element.align, align: element.align,
size, size,
@ -318,7 +318,7 @@ pub fn layout_of_ty_query(
Layout { Layout {
variants: Variants::Single { index: struct_variant_idx() }, variants: Variants::Single { index: struct_variant_idx() },
fields: FieldsShape::Array { stride: element.size, count: 0 }, fields: FieldsShape::Array { stride: element.size, count: 0 },
abi: Abi::Aggregate { sized: false }, backend_repr: BackendRepr::Memory { sized: false },
largest_niche: None, largest_niche: None,
align: element.align, align: element.align,
size: Size::ZERO, size: Size::ZERO,
@ -329,7 +329,7 @@ pub fn layout_of_ty_query(
TyKind::Str => Layout { TyKind::Str => Layout {
variants: Variants::Single { index: struct_variant_idx() }, variants: Variants::Single { index: struct_variant_idx() },
fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 }, fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 },
abi: Abi::Aggregate { sized: false }, backend_repr: BackendRepr::Memory { sized: false },
largest_niche: None, largest_niche: None,
align: dl.i8_align, align: dl.i8_align,
size: Size::ZERO, size: Size::ZERO,
@ -379,8 +379,8 @@ pub fn layout_of_ty_query(
TyKind::Never => cx.calc.layout_of_never_type(), TyKind::Never => cx.calc.layout_of_never_type(),
TyKind::Dyn(_) | TyKind::Foreign(_) => { TyKind::Dyn(_) | TyKind::Foreign(_) => {
let mut unit = layout_of_unit(&cx)?; let mut unit = layout_of_unit(&cx)?;
match &mut unit.abi { match &mut unit.backend_repr {
Abi::Aggregate { sized } => *sized = false, BackendRepr::Memory { sized } => *sized = false,
_ => return Err(LayoutError::Unknown), _ => return Err(LayoutError::Unknown),
} }
unit unit