Skip to content

Commit e20026c

Browse files
Rollup merge of #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.
2 parents c9347f1 + 5f91811 commit e20026c

File tree

5 files changed

+31
-43
lines changed

5 files changed

+31
-43
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'tcx> Tables<'tcx> {
170170
stable_mir::mir::mono::StaticDef(self.create_def_id(did))
171171
}
172172

173-
pub(crate) fn layout_id(&mut self, layout: rustc_target::abi::Layout<'tcx>) -> Layout {
173+
pub(crate) fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> Layout {
174174
self.layouts.create_or_fetch(layout)
175175
}
176176
}

compiler/rustc_smir/src/rustc_smir/alloc.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_abi::{Align, Size};
12
use rustc_middle::mir::ConstValue;
23
use rustc_middle::mir::interpret::{AllocRange, Pointer, alloc_range};
34
use stable_mir::Error;
@@ -7,7 +8,7 @@ use stable_mir::ty::{Allocation, ProvenanceMap};
78
use crate::rustc_smir::{Stable, Tables};
89

910
/// Creates new empty `Allocation` from given `Align`.
10-
fn new_empty_allocation(align: rustc_target::abi::Align) -> Allocation {
11+
fn new_empty_allocation(align: Align) -> Allocation {
1112
Allocation {
1213
bytes: Vec::new(),
1314
provenance: ProvenanceMap { ptrs: Vec::new() },
@@ -45,7 +46,7 @@ pub(crate) fn try_new_allocation<'tcx>(
4546
.align;
4647
let mut allocation = rustc_middle::mir::interpret::Allocation::uninit(size, align.abi);
4748
allocation
48-
.write_scalar(&tables.tcx, alloc_range(rustc_target::abi::Size::ZERO, size), scalar)
49+
.write_scalar(&tables.tcx, alloc_range(Size::ZERO, size), scalar)
4950
.map_err(|e| e.stable(tables))?;
5051
allocation.stable(tables)
5152
}
@@ -59,7 +60,7 @@ pub(crate) fn try_new_allocation<'tcx>(
5960
}
6061
ConstValue::Slice { data, meta } => {
6162
let alloc_id = tables.tcx.reserve_and_set_memory_alloc(data);
62-
let ptr = Pointer::new(alloc_id.into(), rustc_target::abi::Size::ZERO);
63+
let ptr = Pointer::new(alloc_id.into(), Size::ZERO);
6364
let scalar_ptr = rustc_middle::mir::interpret::Scalar::from_pointer(ptr, &tables.tcx);
6465
let scalar_meta =
6566
rustc_middle::mir::interpret::Scalar::from_target_usize(meta, &tables.tcx);
@@ -72,7 +73,7 @@ pub(crate) fn try_new_allocation<'tcx>(
7273
allocation
7374
.write_scalar(
7475
&tables.tcx,
75-
alloc_range(rustc_target::abi::Size::ZERO, tables.tcx.data_layout.pointer_size),
76+
alloc_range(Size::ZERO, tables.tcx.data_layout.pointer_size),
7677
scalar_ptr,
7778
)
7879
.map_err(|e| e.stable(tables))?;
@@ -112,10 +113,7 @@ pub(super) fn allocation_filter<'tcx>(
112113
.map(Some)
113114
.collect();
114115
for (i, b) in bytes.iter_mut().enumerate() {
115-
if !alloc
116-
.init_mask()
117-
.get(rustc_target::abi::Size::from_bytes(i + alloc_range.start.bytes_usize()))
118-
{
116+
if !alloc.init_mask().get(Size::from_bytes(i + alloc_range.start.bytes_usize())) {
119117
*b = None;
120118
}
121119
}

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

+22-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//! Conversion of internal Rust compiler `rustc_target::abi` and `rustc_abi` items to stable ones.
1+
//! Conversion of internal Rust compiler `rustc_target` and `rustc_abi` items to stable ones.
22
33
#![allow(rustc::usage_of_qualified_ty)]
44

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

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

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

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

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

44-
impl<'tcx> Stable<'tcx> for rustc_target::abi::Layout<'tcx> {
44+
impl<'tcx> Stable<'tcx> for rustc_abi::Layout<'tcx> {
4545
type T = Layout;
4646

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

52-
impl<'tcx> Stable<'tcx>
53-
for rustc_abi::LayoutData<rustc_target::abi::FieldIdx, rustc_target::abi::VariantIdx>
54-
{
52+
impl<'tcx> Stable<'tcx> for rustc_abi::LayoutData<rustc_abi::FieldIdx, rustc_abi::VariantIdx> {
5553
type T = LayoutShape;
5654

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

68-
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
66+
impl<'tcx> Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> {
6967
type T = FnAbi;
7068

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

84-
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>> {
82+
impl<'tcx> Stable<'tcx> for callconv::ArgAbi<'tcx, ty::Ty<'tcx>> {
8583
type T = ArgAbi;
8684

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

96-
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
94+
impl<'tcx> Stable<'tcx> for callconv::Conv {
9795
type T = CallConvention;
9896

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

125-
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::PassMode {
123+
impl<'tcx> Stable<'tcx> for callconv::PassMode {
126124
type T = PassMode;
127125

128126
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
129127
match self {
130-
rustc_target::abi::call::PassMode::Ignore => PassMode::Ignore,
131-
rustc_target::abi::call::PassMode::Direct(attr) => PassMode::Direct(opaque(attr)),
132-
rustc_target::abi::call::PassMode::Pair(first, second) => {
128+
callconv::PassMode::Ignore => PassMode::Ignore,
129+
callconv::PassMode::Direct(attr) => PassMode::Direct(opaque(attr)),
130+
callconv::PassMode::Pair(first, second) => {
133131
PassMode::Pair(opaque(first), opaque(second))
134132
}
135-
rustc_target::abi::call::PassMode::Cast { pad_i32, cast } => {
133+
callconv::PassMode::Cast { pad_i32, cast } => {
136134
PassMode::Cast { pad_i32: *pad_i32, cast: opaque(cast) }
137135
}
138-
rustc_target::abi::call::PassMode::Indirect { attrs, meta_attrs, on_stack } => {
139-
PassMode::Indirect {
140-
attrs: opaque(attrs),
141-
meta_attrs: opaque(meta_attrs),
142-
on_stack: *on_stack,
143-
}
144-
}
136+
callconv::PassMode::Indirect { attrs, meta_attrs, on_stack } => PassMode::Indirect {
137+
attrs: opaque(attrs),
138+
meta_attrs: opaque(meta_attrs),
139+
on_stack: *on_stack,
140+
},
145141
}
146142
}
147143
}
148144

149-
impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_target::abi::FieldIdx> {
145+
impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_abi::FieldIdx> {
150146
type T = FieldsShape;
151147

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

166-
impl<'tcx> Stable<'tcx>
167-
for rustc_abi::Variants<rustc_target::abi::FieldIdx, rustc_target::abi::VariantIdx>
168-
{
162+
impl<'tcx> Stable<'tcx> for rustc_abi::Variants<rustc_abi::FieldIdx, rustc_abi::VariantIdx> {
169163
type T = VariantsShape;
170164

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

188-
impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_target::abi::VariantIdx> {
182+
impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_abi::VariantIdx> {
189183
type T = TagEncoding;
190184

191185
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
691691
type T = stable_mir::ty::Allocation;
692692

693693
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
694-
alloc::allocation_filter(
695-
self,
696-
alloc_range(rustc_target::abi::Size::ZERO, self.size()),
697-
tables,
698-
)
694+
alloc::allocation_filter(self, alloc_range(rustc_abi::Size::ZERO, self.size()), tables)
699695
}
700696
}
701697

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Tables<'tcx> {
3636
pub(crate) instances: IndexMap<ty::Instance<'tcx>, InstanceDef>,
3737
pub(crate) ty_consts: IndexMap<ty::Const<'tcx>, TyConstId>,
3838
pub(crate) mir_consts: IndexMap<mir::Const<'tcx>, MirConstId>,
39-
pub(crate) layouts: IndexMap<rustc_target::abi::Layout<'tcx>, Layout>,
39+
pub(crate) layouts: IndexMap<rustc_abi::Layout<'tcx>, Layout>,
4040
}
4141

4242
impl<'tcx> Tables<'tcx> {

0 commit comments

Comments
 (0)