Skip to content

Commit 4b23bd4

Browse files
committed
Update Place and Operand to take slices
The latest locals() method in stable MIR returns slices instead of vecs. This commit also includes fixes to the existing tests that previously referenced the private locals field.
1 parent fe4dfb8 commit 4b23bd4

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

compiler/stable_mir/src/mir/body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ pub enum NullOp {
517517
}
518518

519519
impl Operand {
520-
pub fn ty(&self, locals: &LocalDecls) -> Ty {
520+
pub fn ty(&self, locals: &[LocalDecl]) -> Ty {
521521
match self {
522522
Operand::Copy(place) | Operand::Move(place) => place.ty(locals),
523523
Operand::Constant(c) => c.ty(),
@@ -532,7 +532,7 @@ impl Constant {
532532
}
533533

534534
impl Place {
535-
pub fn ty(&self, locals: &LocalDecls) -> Ty {
535+
pub fn ty(&self, locals: &[LocalDecl]) -> Ty {
536536
let _start_ty = locals[self.local].ty;
537537
todo!("Implement projection")
538538
}

tests/ui-fulldeps/stable-mir/check_instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn test_body(body: mir::Body) {
5959
for term in body.blocks.iter().map(|bb| &bb.terminator) {
6060
match &term.kind {
6161
Call { func, .. } => {
62-
let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() };
62+
let TyKind::RigidTy(ty) = func.ty(body.locals()).kind() else { unreachable!() };
6363
let RigidTy::FnDef(def, args) = ty else { unreachable!() };
6464
let result = Instance::resolve(def, &args);
6565
assert!(result.is_ok());

tests/ui-fulldeps/stable-mir/crate-info.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
4747

4848
let bar = get_item(&items, (DefKind::Fn, "bar")).unwrap();
4949
let body = bar.body();
50-
assert_eq!(body.locals.len(), 2);
50+
assert_eq!(body.locals().len(), 2);
5151
assert_eq!(body.blocks.len(), 1);
5252
let block = &body.blocks[0];
5353
assert_eq!(block.statements.len(), 1);
@@ -62,7 +62,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
6262

6363
let foo_bar = get_item(&items, (DefKind::Fn, "foo_bar")).unwrap();
6464
let body = foo_bar.body();
65-
assert_eq!(body.locals.len(), 5);
65+
assert_eq!(body.locals().len(), 5);
6666
assert_eq!(body.blocks.len(), 4);
6767
let block = &body.blocks[0];
6868
match &block.terminator.kind {
@@ -72,29 +72,29 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
7272

7373
let types = get_item(&items, (DefKind::Fn, "types")).unwrap();
7474
let body = types.body();
75-
assert_eq!(body.locals.len(), 6);
75+
assert_eq!(body.locals().len(), 6);
7676
assert_matches!(
77-
body.locals[0].ty.kind(),
77+
body.locals()[0].ty.kind(),
7878
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
7979
);
8080
assert_matches!(
81-
body.locals[1].ty.kind(),
81+
body.locals()[1].ty.kind(),
8282
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
8383
);
8484
assert_matches!(
85-
body.locals[2].ty.kind(),
85+
body.locals()[2].ty.kind(),
8686
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
8787
);
8888
assert_matches!(
89-
body.locals[3].ty.kind(),
89+
body.locals()[3].ty.kind(),
9090
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
9191
);
9292
assert_matches!(
93-
body.locals[4].ty.kind(),
93+
body.locals()[4].ty.kind(),
9494
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
9595
);
9696
assert_matches!(
97-
body.locals[5].ty.kind(),
97+
body.locals()[5].ty.kind(),
9898
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float(
9999
stable_mir::ty::FloatTy::F64
100100
))
@@ -123,10 +123,10 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
123123
for block in instance.body().blocks {
124124
match &block.terminator.kind {
125125
stable_mir::mir::TerminatorKind::Call { func, .. } => {
126-
let TyKind::RigidTy(ty) = func.ty(&body.locals).kind() else { unreachable!() };
126+
let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() };
127127
let RigidTy::FnDef(def, args) = ty else { unreachable!() };
128128
let next_func = Instance::resolve(def, &args).unwrap();
129-
match next_func.body().locals[1].ty.kind() {
129+
match next_func.body().locals()[1].ty.kind() {
130130
TyKind::RigidTy(RigidTy::Uint(_)) | TyKind::RigidTy(RigidTy::Tuple(_)) => {}
131131
other => panic!("{other:?}"),
132132
}

tests/ui-fulldeps/stable-mir/smir_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const CRATE_NAME: &str = "input";
2929
fn test_translation(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
3030
let main_fn = stable_mir::entry_fn().unwrap();
3131
let body = main_fn.body();
32-
let orig_ty = body.locals[0].ty;
32+
let orig_ty = body.locals()[0].ty;
3333
let rustc_ty = rustc_internal::internal(&orig_ty);
3434
assert!(rustc_ty.is_unit());
3535
ControlFlow::Continue(())

0 commit comments

Comments
 (0)