Skip to content

Commit

Permalink
Unrolled build for rust-lang#132247
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#132247 - workingjubilee:add-rustc-abi-to-smir, r=celinval

stable_mir: Directly use types from rustc_abi

In most cases, rustc_target is not necessary, so use rustc_abi instead of its reexports.
  • Loading branch information
rust-timer authored Oct 29, 2024
2 parents a9d1762 + 5f91811 commit e67949b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 43 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'tcx> Tables<'tcx> {
stable_mir::mir::mono::StaticDef(self.create_def_id(did))
}

pub(crate) fn layout_id(&mut self, layout: rustc_target::abi::Layout<'tcx>) -> Layout {
pub(crate) fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> Layout {
self.layouts.create_or_fetch(layout)
}
}
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_smir/src/rustc_smir/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_abi::{Align, Size};
use rustc_middle::mir::ConstValue;
use rustc_middle::mir::interpret::{AllocRange, Pointer, alloc_range};
use stable_mir::Error;
Expand All @@ -7,7 +8,7 @@ use stable_mir::ty::{Allocation, ProvenanceMap};
use crate::rustc_smir::{Stable, Tables};

/// Creates new empty `Allocation` from given `Align`.
fn new_empty_allocation(align: rustc_target::abi::Align) -> Allocation {
fn new_empty_allocation(align: Align) -> Allocation {
Allocation {
bytes: Vec::new(),
provenance: ProvenanceMap { ptrs: Vec::new() },
Expand Down Expand Up @@ -45,7 +46,7 @@ pub(crate) fn try_new_allocation<'tcx>(
.align;
let mut allocation = rustc_middle::mir::interpret::Allocation::uninit(size, align.abi);
allocation
.write_scalar(&tables.tcx, alloc_range(rustc_target::abi::Size::ZERO, size), scalar)
.write_scalar(&tables.tcx, alloc_range(Size::ZERO, size), scalar)
.map_err(|e| e.stable(tables))?;
allocation.stable(tables)
}
Expand All @@ -59,7 +60,7 @@ pub(crate) fn try_new_allocation<'tcx>(
}
ConstValue::Slice { data, meta } => {
let alloc_id = tables.tcx.reserve_and_set_memory_alloc(data);
let ptr = Pointer::new(alloc_id.into(), rustc_target::abi::Size::ZERO);
let ptr = Pointer::new(alloc_id.into(), Size::ZERO);
let scalar_ptr = rustc_middle::mir::interpret::Scalar::from_pointer(ptr, &tables.tcx);
let scalar_meta =
rustc_middle::mir::interpret::Scalar::from_target_usize(meta, &tables.tcx);
Expand All @@ -72,7 +73,7 @@ pub(crate) fn try_new_allocation<'tcx>(
allocation
.write_scalar(
&tables.tcx,
alloc_range(rustc_target::abi::Size::ZERO, tables.tcx.data_layout.pointer_size),
alloc_range(Size::ZERO, tables.tcx.data_layout.pointer_size),
scalar_ptr,
)
.map_err(|e| e.stable(tables))?;
Expand Down Expand Up @@ -112,10 +113,7 @@ pub(super) fn allocation_filter<'tcx>(
.map(Some)
.collect();
for (i, b) in bytes.iter_mut().enumerate() {
if !alloc
.init_mask()
.get(rustc_target::abi::Size::from_bytes(i + alloc_range.start.bytes_usize()))
{
if !alloc.init_mask().get(Size::from_bytes(i + alloc_range.start.bytes_usize())) {
*b = None;
}
}
Expand Down
50 changes: 22 additions & 28 deletions compiler/rustc_smir/src/rustc_smir/convert/abi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Conversion of internal Rust compiler `rustc_target::abi` and `rustc_abi` items to stable ones.
//! Conversion of internal Rust compiler `rustc_target` and `rustc_abi` items to stable ones.

#![allow(rustc::usage_of_qualified_ty)]

use rustc_middle::ty;
use rustc_target::abi::call::Conv;
use rustc_target::callconv::{self, Conv};
use stable_mir::abi::{
AddressSpace, ArgAbi, CallConvention, FieldsShape, FloatLength, FnAbi, IntegerLength, Layout,
LayoutShape, PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape,
Expand All @@ -15,7 +15,7 @@ use stable_mir::ty::{Align, IndexedVal, VariantIdx};

use crate::rustc_smir::{Stable, Tables};

impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
impl<'tcx> Stable<'tcx> for rustc_abi::VariantIdx {
type T = VariantIdx;
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
VariantIdx::to_val(self.as_usize())
Expand All @@ -33,25 +33,23 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Endian {
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::TyAndLayout<'tcx, ty::Ty<'tcx>> {
impl<'tcx> Stable<'tcx> for rustc_abi::TyAndLayout<'tcx, ty::Ty<'tcx>> {
type T = TyAndLayout;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
TyAndLayout { ty: self.ty.stable(tables), layout: self.layout.stable(tables) }
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::Layout<'tcx> {
impl<'tcx> Stable<'tcx> for rustc_abi::Layout<'tcx> {
type T = Layout;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
tables.layout_id(tables.tcx.lift(*self).unwrap())
}
}

impl<'tcx> Stable<'tcx>
for rustc_abi::LayoutData<rustc_target::abi::FieldIdx, rustc_target::abi::VariantIdx>
{
impl<'tcx> Stable<'tcx> for rustc_abi::LayoutData<rustc_abi::FieldIdx, rustc_abi::VariantIdx> {
type T = LayoutShape;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Expand All @@ -65,7 +63,7 @@ impl<'tcx> Stable<'tcx>
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
impl<'tcx> Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> {
type T = FnAbi;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Expand All @@ -81,7 +79,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>> {
impl<'tcx> Stable<'tcx> for callconv::ArgAbi<'tcx, ty::Ty<'tcx>> {
type T = ArgAbi;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Expand All @@ -93,7 +91,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>>
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
impl<'tcx> Stable<'tcx> for callconv::Conv {
type T = CallConvention;

fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
Expand Down Expand Up @@ -122,31 +120,29 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
}
}

impl<'tcx> Stable<'tcx> for rustc_target::abi::call::PassMode {
impl<'tcx> Stable<'tcx> for callconv::PassMode {
type T = PassMode;

fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
match self {
rustc_target::abi::call::PassMode::Ignore => PassMode::Ignore,
rustc_target::abi::call::PassMode::Direct(attr) => PassMode::Direct(opaque(attr)),
rustc_target::abi::call::PassMode::Pair(first, second) => {
callconv::PassMode::Ignore => PassMode::Ignore,
callconv::PassMode::Direct(attr) => PassMode::Direct(opaque(attr)),
callconv::PassMode::Pair(first, second) => {
PassMode::Pair(opaque(first), opaque(second))
}
rustc_target::abi::call::PassMode::Cast { pad_i32, cast } => {
callconv::PassMode::Cast { pad_i32, cast } => {
PassMode::Cast { pad_i32: *pad_i32, cast: opaque(cast) }
}
rustc_target::abi::call::PassMode::Indirect { attrs, meta_attrs, on_stack } => {
PassMode::Indirect {
attrs: opaque(attrs),
meta_attrs: opaque(meta_attrs),
on_stack: *on_stack,
}
}
callconv::PassMode::Indirect { attrs, meta_attrs, on_stack } => PassMode::Indirect {
attrs: opaque(attrs),
meta_attrs: opaque(meta_attrs),
on_stack: *on_stack,
},
}
}
}

impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_target::abi::FieldIdx> {
impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_abi::FieldIdx> {
type T = FieldsShape;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Expand All @@ -163,9 +159,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_target::abi::FieldIdx>
}
}

impl<'tcx> Stable<'tcx>
for rustc_abi::Variants<rustc_target::abi::FieldIdx, rustc_target::abi::VariantIdx>
{
impl<'tcx> Stable<'tcx> for rustc_abi::Variants<rustc_abi::FieldIdx, rustc_abi::VariantIdx> {
type T = VariantsShape;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Expand All @@ -185,7 +179,7 @@ impl<'tcx> Stable<'tcx>
}
}

impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_target::abi::VariantIdx> {
impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_abi::VariantIdx> {
type T = TagEncoding;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_smir/src/rustc_smir/convert/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
type T = stable_mir::ty::Allocation;

fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
alloc::allocation_filter(
self,
alloc_range(rustc_target::abi::Size::ZERO, self.size()),
tables,
)
alloc::allocation_filter(self, alloc_range(rustc_abi::Size::ZERO, self.size()), tables)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Tables<'tcx> {
pub(crate) instances: IndexMap<ty::Instance<'tcx>, InstanceDef>,
pub(crate) ty_consts: IndexMap<ty::Const<'tcx>, TyConstId>,
pub(crate) mir_consts: IndexMap<mir::Const<'tcx>, MirConstId>,
pub(crate) layouts: IndexMap<rustc_target::abi::Layout<'tcx>, Layout>,
pub(crate) layouts: IndexMap<rustc_abi::Layout<'tcx>, Layout>,
}

impl<'tcx> Tables<'tcx> {
Expand Down

0 comments on commit e67949b

Please sign in to comment.