Skip to content

Commit 61361c1

Browse files
committed
Fix Stable trait and its impls to work with the new with_tables
1 parent 06a9dbe commit 61361c1

File tree

9 files changed

+173
-132
lines changed

9 files changed

+173
-132
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,19 @@ impl DroplessArena {
484484
}
485485
}
486486

487+
/// Used by `Lift` to check whether this slice is allocated
488+
/// in this arena.
489+
#[inline]
490+
pub fn contains_slice<T>(&self, slice: &[T]) -> bool {
491+
for chunk in self.chunks.borrow_mut().iter_mut() {
492+
let ptr = slice.as_ptr().cast::<u8>().cast_mut();
493+
if chunk.start() <= ptr && chunk.end() >= ptr {
494+
return true;
495+
}
496+
}
497+
false
498+
}
499+
487500
/// Allocates a string slice that is copied into the `DroplessArena`, returning a
488501
/// reference to it. Will panic if passed an empty string.
489502
///

compiler/rustc_middle/src/mir/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx> ConstValue<'tcx> {
195195
/// Constants
196196
197197
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
198-
#[derive(TypeFoldable, TypeVisitable)]
198+
#[derive(TypeFoldable, TypeVisitable, Lift)]
199199
pub enum Const<'tcx> {
200200
/// This constant came from the type system.
201201
///
@@ -456,7 +456,7 @@ impl<'tcx> Const<'tcx> {
456456

457457
/// An unevaluated (potentially generic) constant used in MIR.
458458
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
459-
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
459+
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable, Lift)]
460460
pub struct UnevaluatedConst<'tcx> {
461461
pub def: DefId,
462462
pub args: GenericArgsRef<'tcx>,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,7 @@ nop_lift! {const_; Const<'a> => Const<'tcx>}
14161416
nop_lift! {const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx>}
14171417
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
14181418
nop_lift! {predicate; Clause<'a> => Clause<'tcx>}
1419+
nop_lift! {layout; Layout<'a> => Layout<'tcx>}
14191420

14201421
nop_list_lift! {type_lists; Ty<'a> => Ty<'tcx>}
14211422
nop_list_lift! {poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>}
@@ -1424,8 +1425,28 @@ nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariable
14241425
// This is the impl for `&'a GenericArgs<'a>`.
14251426
nop_list_lift! {args; GenericArg<'a> => GenericArg<'tcx>}
14261427

1428+
macro_rules! nop_slice_lift {
1429+
($ty:ty => $lifted:ty) => {
1430+
impl<'a, 'tcx> Lift<'tcx> for &'a [$ty] {
1431+
type Lifted = &'tcx [$lifted];
1432+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1433+
if self.is_empty() {
1434+
return Some(&[]);
1435+
}
1436+
tcx.interners
1437+
.arena
1438+
.dropless
1439+
.contains_slice(self)
1440+
.then(|| unsafe { mem::transmute(self) })
1441+
}
1442+
}
1443+
};
1444+
}
1445+
1446+
nop_slice_lift! {ty::ValTree<'a> => ty::ValTree<'tcx>}
1447+
14271448
TrivialLiftImpls! {
1428-
ImplPolarity,
1449+
ImplPolarity, Promoted
14291450
}
14301451

14311452
macro_rules! sty_debug_print {

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use stable_mir::{opaque, Opaque};
1414

1515
impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
1616
type T = VariantIdx;
17-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
17+
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
1818
VariantIdx::to_val(self.as_usize())
1919
}
2020
}
2121

2222
impl<'tcx> Stable<'tcx> for rustc_abi::Endian {
2323
type T = stable_mir::target::Endian;
2424

25-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
25+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
2626
match self {
2727
rustc_abi::Endian::Little => stable_mir::target::Endian::Little,
2828
rustc_abi::Endian::Big => stable_mir::target::Endian::Big,
@@ -33,16 +33,16 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Endian {
3333
impl<'tcx> Stable<'tcx> for rustc_target::abi::TyAndLayout<'tcx, ty::Ty<'tcx>> {
3434
type T = TyAndLayout;
3535

36-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
36+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
3737
TyAndLayout { ty: self.ty.stable(tables), layout: self.layout.stable(tables) }
3838
}
3939
}
4040

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

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

@@ -51,7 +51,7 @@ impl<'tcx> Stable<'tcx>
5151
{
5252
type T = LayoutShape;
5353

54-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
54+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
5555
LayoutShape {
5656
fields: self.fields.stable(tables),
5757
variants: self.variants.stable(tables),
@@ -65,7 +65,7 @@ impl<'tcx> Stable<'tcx>
6565
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
6666
type T = FnAbi;
6767

68-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
68+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
6969
assert!(self.args.len() >= self.fixed_count as usize);
7070
assert!(!self.c_variadic || matches!(self.conv, Conv::C));
7171
FnAbi {
@@ -81,7 +81,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
8181
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>> {
8282
type T = ArgAbi;
8383

84-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
84+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
8585
ArgAbi {
8686
ty: self.layout.ty.stable(tables),
8787
layout: self.layout.layout.stable(tables),
@@ -93,7 +93,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>>
9393
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
9494
type T = CallConvention;
9595

96-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
96+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
9797
match self {
9898
Conv::C => CallConvention::C,
9999
Conv::Rust => CallConvention::Rust,
@@ -122,7 +122,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
122122
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::PassMode {
123123
type T = PassMode;
124124

125-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
125+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
126126
match self {
127127
rustc_target::abi::call::PassMode::Ignore => PassMode::Ignore,
128128
rustc_target::abi::call::PassMode::Direct(attr) => PassMode::Direct(opaque(attr)),
@@ -146,7 +146,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::PassMode {
146146
impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_target::abi::FieldIdx> {
147147
type T = FieldsShape;
148148

149-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
149+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
150150
match self {
151151
rustc_abi::FieldsShape::Primitive => FieldsShape::Primitive,
152152
rustc_abi::FieldsShape::Union(count) => FieldsShape::Union(*count),
@@ -165,7 +165,7 @@ impl<'tcx> Stable<'tcx>
165165
{
166166
type T = VariantsShape;
167167

168-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
168+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
169169
match self {
170170
rustc_abi::Variants::Single { index } => {
171171
VariantsShape::Single { index: index.stable(tables) }
@@ -185,7 +185,7 @@ impl<'tcx> Stable<'tcx>
185185
impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_target::abi::VariantIdx> {
186186
type T = TagEncoding;
187187

188-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
188+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
189189
match self {
190190
rustc_abi::TagEncoding::Direct => TagEncoding::Direct,
191191
rustc_abi::TagEncoding::Niche { untagged_variant, niche_variants, niche_start } => {
@@ -202,7 +202,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_target::abi::VariantIdx
202202
impl<'tcx> Stable<'tcx> for rustc_abi::Abi {
203203
type T = ValueAbi;
204204

205-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
205+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
206206
match *self {
207207
rustc_abi::Abi::Uninhabited => ValueAbi::Uninhabited,
208208
rustc_abi::Abi::Scalar(scalar) => ValueAbi::Scalar(scalar.stable(tables)),
@@ -220,23 +220,23 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Abi {
220220
impl<'tcx> Stable<'tcx> for rustc_abi::Size {
221221
type T = Size;
222222

223-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
223+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
224224
self.bytes_usize()
225225
}
226226
}
227227

228228
impl<'tcx> Stable<'tcx> for rustc_abi::Align {
229229
type T = Align;
230230

231-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
231+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
232232
self.bytes()
233233
}
234234
}
235235

236236
impl<'tcx> Stable<'tcx> for rustc_abi::Scalar {
237237
type T = Opaque;
238238

239-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
239+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
240240
opaque(self)
241241
}
242242
}

compiler/rustc_smir/src/rustc_smir/convert/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use rustc_middle::ty::layout::LayoutError;
88
impl<'tcx> Stable<'tcx> for LayoutError<'tcx> {
99
type T = stable_mir::Error;
1010

11-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
11+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
1212
stable_mir::Error::new(format!("{self:?}"))
1313
}
1414
}
1515

1616
impl<'tcx> Stable<'tcx> for AllocError {
1717
type T = stable_mir::Error;
1818

19-
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
19+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
2020
stable_mir::Error::new(format!("{self:?}"))
2121
}
2222
}

0 commit comments

Comments
 (0)