From 9130484db91e609686e287f7547fc7c085068d9b Mon Sep 17 00:00:00 2001 From: ouz-a Date: Sat, 30 Sep 2023 16:40:15 +0300 Subject: [PATCH 1/4] create localdecl and add span to it --- compiler/rustc_smir/src/rustc_smir/mod.rs | 9 ++++++++- compiler/stable_mir/src/mir/body.rs | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index c6c97ce35e8b9..d83b92b578b03 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -106,7 +106,14 @@ impl<'tcx> Context for Tables<'tcx> { .collect(), }) .collect(), - locals: mir.local_decls.iter().map(|decl| self.intern_ty(decl.ty)).collect(), + locals: mir + .local_decls + .iter() + .map(|decl| stable_mir::mir::LocalDecl { + ty: self.intern_ty(decl.ty), + span: decl.source_info.span.stable(self), + }) + .collect(), } } diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 6f8f7b06fa393..f2cdee0aafcd0 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -5,7 +5,13 @@ use crate::{ty::Ty, Span}; #[derive(Clone, Debug)] pub struct Body { pub blocks: Vec, - pub locals: Vec, + pub locals: Vec, +} + +#[derive(Clone, Debug)] +pub struct LocalDecl { + pub ty: Ty, + pub span: Span, } #[derive(Clone, Debug)] From 999a354a81e472e43670b21f4101179243ba79cd Mon Sep 17 00:00:00 2001 From: ouz-a Date: Sat, 30 Sep 2023 16:52:10 +0300 Subject: [PATCH 2/4] add span to terminator --- compiler/rustc_smir/src/rustc_smir/mod.rs | 107 ++++++++++++++-------- compiler/stable_mir/src/mir/body.rs | 8 +- 2 files changed, 76 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index d83b92b578b03..134c707ce8538 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -815,52 +815,83 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { use rustc_middle::mir::TerminatorKind::*; use stable_mir::mir::Terminator; + use stable_mir::mir::TerminatorKind; match &self.kind { - Goto { target } => Terminator::Goto { target: target.as_usize() }, - SwitchInt { discr, targets } => Terminator::SwitchInt { - discr: discr.stable(tables), - targets: targets - .iter() - .map(|(value, target)| stable_mir::mir::SwitchTarget { - value, - target: target.as_usize(), - }) - .collect(), - otherwise: targets.otherwise().as_usize(), + Goto { target } => Terminator { + kind: TerminatorKind::Goto { target: target.as_usize() }, + span: self.source_info.span.stable(tables), }, - UnwindResume => Terminator::Resume, - UnwindTerminate(_) => Terminator::Abort, - Return => Terminator::Return, - Unreachable => Terminator::Unreachable, - Drop { place, target, unwind, replace: _ } => Terminator::Drop { - place: place.stable(tables), - target: target.as_usize(), - unwind: unwind.stable(tables), + SwitchInt { discr, targets } => Terminator { + kind: TerminatorKind::SwitchInt { + discr: discr.stable(tables), + targets: targets + .iter() + .map(|(value, target)| stable_mir::mir::SwitchTarget { + value, + target: target.as_usize(), + }) + .collect(), + otherwise: targets.otherwise().as_usize(), + }, + span: self.source_info.span.stable(tables), }, - Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => { - Terminator::Call { - func: func.stable(tables), - args: args.iter().map(|arg| arg.stable(tables)).collect(), - destination: destination.stable(tables), - target: target.map(|t| t.as_usize()), + UnwindResume => Terminator { + kind: TerminatorKind::Resume, + span: self.source_info.span.stable(tables), + }, + UnwindTerminate(_) => Terminator { + kind: TerminatorKind::Abort, + span: self.source_info.span.stable(tables), + }, + Return => Terminator { + kind: TerminatorKind::Return, + span: self.source_info.span.stable(tables), + }, + Unreachable => Terminator { + kind: TerminatorKind::Unreachable, + span: self.source_info.span.stable(tables), + }, + Drop { place, target, unwind, replace: _ } => Terminator { + kind: TerminatorKind::Drop { + place: place.stable(tables), + target: target.as_usize(), unwind: unwind.stable(tables), + }, + span: self.source_info.span.stable(tables), + }, + Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => { + Terminator { + kind: TerminatorKind::Call { + func: func.stable(tables), + args: args.iter().map(|arg| arg.stable(tables)).collect(), + destination: destination.stable(tables), + target: target.map(|t| t.as_usize()), + unwind: unwind.stable(tables), + }, + span: self.source_info.span.stable(tables), } } - Assert { cond, expected, msg, target, unwind } => Terminator::Assert { - cond: cond.stable(tables), - expected: *expected, - msg: msg.stable(tables), - target: target.as_usize(), - unwind: unwind.stable(tables), + Assert { cond, expected, msg, target, unwind } => Terminator { + kind: TerminatorKind::Assert { + cond: cond.stable(tables), + expected: *expected, + msg: msg.stable(tables), + target: target.as_usize(), + unwind: unwind.stable(tables), + }, + span: self.source_info.span.stable(tables), }, InlineAsm { template, operands, options, line_spans, destination, unwind } => { - Terminator::InlineAsm { - template: format!("{template:?}"), - operands: operands.iter().map(|operand| operand.stable(tables)).collect(), - options: format!("{options:?}"), - line_spans: format!("{line_spans:?}"), - destination: destination.map(|d| d.as_usize()), - unwind: unwind.stable(tables), + Terminator { + kind: TerminatorKind::InlineAsm { + template: format!("{template:?}"), + operands: operands.iter().map(|operand| operand.stable(tables)).collect(), + options: format!("{options:?}"), + line_spans: format!("{line_spans:?}"), + destination: destination.map(|d| d.as_usize()), + unwind: unwind.stable(tables), + }, + span: self.source_info.span.stable(tables), } } Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(), diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index f2cdee0aafcd0..6c8b2a6684003 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -21,7 +21,13 @@ pub struct BasicBlock { } #[derive(Clone, Debug)] -pub enum Terminator { +pub struct Terminator { + pub kind: TerminatorKind, + pub span: Span, +} + +#[derive(Clone, Debug)] +pub enum TerminatorKind { Goto { target: usize, }, From a79567b01c0b5000025896a191b709e422f4923f Mon Sep 17 00:00:00 2001 From: ouz-a Date: Sat, 30 Sep 2023 17:18:31 +0300 Subject: [PATCH 3/4] add span to statements --- compiler/rustc_smir/src/rustc_smir/mod.rs | 123 ++++++++++++--------- compiler/stable_mir/src/mir/body.rs | 8 +- tests/ui-fulldeps/stable-mir/crate-info.rs | 40 +++---- 3 files changed, 98 insertions(+), 73 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 134c707ce8538..8467eaba44de6 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{alloc_range, AllocId}; use rustc_middle::ty::{self, Ty, TyCtxt, Variance}; use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_target::abi::FieldIdx; -use stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx}; +use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx}; use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy}; use stable_mir::{self, opaque, Context}; use tracing::debug; @@ -231,40 +231,71 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> { type T = stable_mir::mir::Statement; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { use rustc_middle::mir::StatementKind::*; + let span = self.source_info.span.stable(tables); match &self.kind { - Assign(assign) => { - stable_mir::mir::Statement::Assign(assign.0.stable(tables), assign.1.stable(tables)) - } - FakeRead(fake_read_place) => stable_mir::mir::Statement::FakeRead( - fake_read_place.0.stable(tables), - fake_read_place.1.stable(tables), - ), - SetDiscriminant { place: plc, variant_index: idx } => { - stable_mir::mir::Statement::SetDiscriminant { + Assign(assign) => Statement { + kind: stable_mir::mir::StatementKind::Assign( + assign.0.stable(tables), + assign.1.stable(tables), + ), + span, + }, + FakeRead(fake_read_place) => Statement { + kind: stable_mir::mir::StatementKind::FakeRead( + fake_read_place.0.stable(tables), + fake_read_place.1.stable(tables), + ), + span, + }, + SetDiscriminant { place: plc, variant_index: idx } => Statement { + kind: stable_mir::mir::StatementKind::SetDiscriminant { place: plc.as_ref().stable(tables), variant_index: idx.stable(tables), - } - } - Deinit(place) => stable_mir::mir::Statement::Deinit(place.stable(tables)), - StorageLive(place) => stable_mir::mir::Statement::StorageLive(place.stable(tables)), - StorageDead(place) => stable_mir::mir::Statement::StorageDead(place.stable(tables)), - Retag(retag, place) => { - stable_mir::mir::Statement::Retag(retag.stable(tables), place.stable(tables)) - } - PlaceMention(place) => stable_mir::mir::Statement::PlaceMention(place.stable(tables)), - AscribeUserType(place_projection, variance) => { - stable_mir::mir::Statement::AscribeUserType { + }, + span, + }, + Deinit(place) => Statement { + kind: stable_mir::mir::StatementKind::Deinit(place.stable(tables)), + span, + }, + StorageLive(place) => Statement { + kind: stable_mir::mir::StatementKind::StorageLive(place.stable(tables)), + span, + }, + StorageDead(place) => Statement { + kind: stable_mir::mir::StatementKind::StorageDead(place.stable(tables)), + span, + }, + Retag(retag, place) => Statement { + kind: stable_mir::mir::StatementKind::Retag( + retag.stable(tables), + place.stable(tables), + ), + span, + }, + PlaceMention(place) => Statement { + kind: stable_mir::mir::StatementKind::PlaceMention(place.stable(tables)), + span, + }, + AscribeUserType(place_projection, variance) => Statement { + kind: stable_mir::mir::StatementKind::AscribeUserType { place: place_projection.as_ref().0.stable(tables), projections: place_projection.as_ref().1.stable(tables), variance: variance.stable(tables), - } + }, + span, + }, + Coverage(coverage) => { + Statement { kind: stable_mir::mir::StatementKind::Coverage(opaque(coverage)), span } } - Coverage(coverage) => stable_mir::mir::Statement::Coverage(opaque(coverage)), - Intrinsic(intrinstic) => { - stable_mir::mir::Statement::Intrinsic(intrinstic.stable(tables)) + Intrinsic(intrinstic) => Statement { + kind: stable_mir::mir::StatementKind::Intrinsic(intrinstic.stable(tables)), + span, + }, + ConstEvalCounter => { + Statement { kind: stable_mir::mir::StatementKind::ConstEvalCounter, span } } - ConstEvalCounter => stable_mir::mir::Statement::ConstEvalCounter, - Nop => stable_mir::mir::Statement::Nop, + Nop => Statement { kind: stable_mir::mir::StatementKind::Nop, span }, } } } @@ -816,11 +847,11 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { use rustc_middle::mir::TerminatorKind::*; use stable_mir::mir::Terminator; use stable_mir::mir::TerminatorKind; + let span = self.source_info.span.stable(tables); match &self.kind { - Goto { target } => Terminator { - kind: TerminatorKind::Goto { target: target.as_usize() }, - span: self.source_info.span.stable(tables), - }, + Goto { target } => { + Terminator { kind: TerminatorKind::Goto { target: target.as_usize() }, span } + } SwitchInt { discr, targets } => Terminator { kind: TerminatorKind::SwitchInt { discr: discr.stable(tables), @@ -833,31 +864,19 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { .collect(), otherwise: targets.otherwise().as_usize(), }, - span: self.source_info.span.stable(tables), - }, - UnwindResume => Terminator { - kind: TerminatorKind::Resume, - span: self.source_info.span.stable(tables), - }, - UnwindTerminate(_) => Terminator { - kind: TerminatorKind::Abort, - span: self.source_info.span.stable(tables), - }, - Return => Terminator { - kind: TerminatorKind::Return, - span: self.source_info.span.stable(tables), - }, - Unreachable => Terminator { - kind: TerminatorKind::Unreachable, - span: self.source_info.span.stable(tables), + span, }, + UnwindResume => Terminator { kind: TerminatorKind::Resume, span }, + UnwindTerminate(_) => Terminator { kind: TerminatorKind::Abort, span }, + Return => Terminator { kind: TerminatorKind::Return, span }, + Unreachable => Terminator { kind: TerminatorKind::Unreachable, span }, Drop { place, target, unwind, replace: _ } => Terminator { kind: TerminatorKind::Drop { place: place.stable(tables), target: target.as_usize(), unwind: unwind.stable(tables), }, - span: self.source_info.span.stable(tables), + span, }, Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => { Terminator { @@ -868,7 +887,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { target: target.map(|t| t.as_usize()), unwind: unwind.stable(tables), }, - span: self.source_info.span.stable(tables), + span, } } Assert { cond, expected, msg, target, unwind } => Terminator { @@ -879,7 +898,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { target: target.as_usize(), unwind: unwind.stable(tables), }, - span: self.source_info.span.stable(tables), + span, }, InlineAsm { template, operands, options, line_spans, destination, unwind } => { Terminator { @@ -891,7 +910,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { destination: destination.map(|d| d.as_usize()), unwind: unwind.stable(tables), }, - span: self.source_info.span.stable(tables), + span, } } Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(), diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 6c8b2a6684003..72f026ee8de09 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -191,7 +191,13 @@ pub enum NonDivergingIntrinsic { } #[derive(Clone, Debug)] -pub enum Statement { +pub struct Statement { + pub kind: StatementKind, + pub span: Span, +} + +#[derive(Clone, Debug)] +pub enum StatementKind { Assign(Place, Rvalue), FakeRead(FakeReadCause, Place), SetDiscriminant { place: Place, variant_index: VariantIdx }, diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs index ce4ee3c2463eb..d482f62ff0643 100644 --- a/tests/ui-fulldeps/stable-mir/crate-info.rs +++ b/tests/ui-fulldeps/stable-mir/crate-info.rs @@ -47,12 +47,12 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { assert_eq!(body.blocks.len(), 1); let block = &body.blocks[0]; assert_eq!(block.statements.len(), 1); - match &block.statements[0] { - stable_mir::mir::Statement::Assign(..) => {} + match &block.statements[0].kind { + stable_mir::mir::StatementKind::Assign(..) => {} other => panic!("{other:?}"), } - match &block.terminator { - stable_mir::mir::Terminator::Return => {} + match &block.terminator.kind { + stable_mir::mir::TerminatorKind::Return => {} other => panic!("{other:?}"), } @@ -61,8 +61,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { assert_eq!(body.locals.len(), 7); assert_eq!(body.blocks.len(), 4); let block = &body.blocks[0]; - match &block.terminator { - stable_mir::mir::Terminator::Call { .. } => {} + match &block.terminator.kind { + stable_mir::mir::TerminatorKind::Call { .. } => {} other => panic!("{other:?}"), } @@ -70,27 +70,27 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { let body = types.body(); assert_eq!(body.locals.len(), 6); assert_matches!( - body.locals[0].kind(), + body.locals[0].ty.kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool) ); assert_matches!( - body.locals[1].kind(), + body.locals[1].ty.kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool) ); assert_matches!( - body.locals[2].kind(), + body.locals[2].ty.kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char) ); assert_matches!( - body.locals[3].kind(), + body.locals[3].ty.kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32)) ); assert_matches!( - body.locals[4].kind(), + body.locals[4].ty.kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64)) ); assert_matches!( - body.locals[5].kind(), + body.locals[5].ty.kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float( stable_mir::ty::FloatTy::F64 )) @@ -100,8 +100,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { let body = drop.body(); assert_eq!(body.blocks.len(), 2); let block = &body.blocks[0]; - match &block.terminator { - stable_mir::mir::Terminator::Drop { .. } => {} + match &block.terminator.kind { + stable_mir::mir::TerminatorKind::Drop { .. } => {} other => panic!("{other:?}"), } @@ -109,15 +109,15 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { let body = assert.body(); assert_eq!(body.blocks.len(), 2); let block = &body.blocks[0]; - match &block.terminator { - stable_mir::mir::Terminator::Assert { .. } => {} + match &block.terminator.kind { + stable_mir::mir::TerminatorKind::Assert { .. } => {} other => panic!("{other:?}"), } let monomorphic = get_item(&items, (DefKind::Fn, "monomorphic")).unwrap(); for block in monomorphic.body().blocks { - match &block.terminator { - stable_mir::mir::Terminator::Call { func, .. } => match func { + match &block.terminator.kind { + stable_mir::mir::TerminatorKind::Call { func, .. } => match func { stable_mir::mir::Operand::Constant(c) => match &c.literal.literal { stable_mir::ty::ConstantKind::Allocated(alloc) => { assert!(alloc.bytes.is_empty()); @@ -127,7 +127,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { mut args, )) => { let func = def.body(); - match func.locals[1] + match func.locals[1].ty .fold(&mut args) .continue_value() .unwrap() @@ -149,7 +149,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { }, other => panic!("{other:?}"), }, - stable_mir::mir::Terminator::Return => {} + stable_mir::mir::TerminatorKind::Return => {} other => panic!("{other:?}"), } } From a49138e46e09a019ecf26077a488cf579bd1a135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20A=C4=9Fcayaz=C4=B1?= Date: Thu, 5 Oct 2023 11:13:05 +0300 Subject: [PATCH 4/4] impl stable for kinds --- compiler/rustc_smir/src/rustc_smir/mod.rs | 228 +++++++++++----------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 8467eaba44de6..7d1122c2fd21d 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -230,72 +230,64 @@ pub(crate) trait Stable<'tcx> { impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> { type T = stable_mir::mir::Statement; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { - use rustc_middle::mir::StatementKind::*; - let span = self.source_info.span.stable(tables); - match &self.kind { - Assign(assign) => Statement { - kind: stable_mir::mir::StatementKind::Assign( - assign.0.stable(tables), - assign.1.stable(tables), - ), - span, - }, - FakeRead(fake_read_place) => Statement { - kind: stable_mir::mir::StatementKind::FakeRead( + Statement { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) } + } +} + +impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> { + type T = stable_mir::mir::StatementKind; + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + match self { + mir::StatementKind::Assign(assign) => stable_mir::mir::StatementKind::Assign( + assign.0.stable(tables), + assign.1.stable(tables), + ), + mir::StatementKind::FakeRead(fake_read_place) => { + stable_mir::mir::StatementKind::FakeRead( fake_read_place.0.stable(tables), fake_read_place.1.stable(tables), - ), - span, - }, - SetDiscriminant { place: plc, variant_index: idx } => Statement { - kind: stable_mir::mir::StatementKind::SetDiscriminant { - place: plc.as_ref().stable(tables), - variant_index: idx.stable(tables), - }, - span, - }, - Deinit(place) => Statement { - kind: stable_mir::mir::StatementKind::Deinit(place.stable(tables)), - span, - }, - StorageLive(place) => Statement { - kind: stable_mir::mir::StatementKind::StorageLive(place.stable(tables)), - span, - }, - StorageDead(place) => Statement { - kind: stable_mir::mir::StatementKind::StorageDead(place.stable(tables)), - span, - }, - Retag(retag, place) => Statement { - kind: stable_mir::mir::StatementKind::Retag( - retag.stable(tables), - place.stable(tables), - ), - span, - }, - PlaceMention(place) => Statement { - kind: stable_mir::mir::StatementKind::PlaceMention(place.stable(tables)), - span, - }, - AscribeUserType(place_projection, variance) => Statement { - kind: stable_mir::mir::StatementKind::AscribeUserType { + ) + } + mir::StatementKind::SetDiscriminant { place, variant_index } => { + stable_mir::mir::StatementKind::SetDiscriminant { + place: place.as_ref().stable(tables), + variant_index: variant_index.stable(tables), + } + } + mir::StatementKind::Deinit(place) => { + stable_mir::mir::StatementKind::Deinit(place.stable(tables)) + } + + mir::StatementKind::StorageLive(place) => { + stable_mir::mir::StatementKind::StorageLive(place.stable(tables)) + } + + mir::StatementKind::StorageDead(place) => { + stable_mir::mir::StatementKind::StorageDead(place.stable(tables)) + } + mir::StatementKind::Retag(retag, place) => { + stable_mir::mir::StatementKind::Retag(retag.stable(tables), place.stable(tables)) + } + mir::StatementKind::PlaceMention(place) => { + stable_mir::mir::StatementKind::PlaceMention(place.stable(tables)) + } + mir::StatementKind::AscribeUserType(place_projection, variance) => { + stable_mir::mir::StatementKind::AscribeUserType { place: place_projection.as_ref().0.stable(tables), projections: place_projection.as_ref().1.stable(tables), variance: variance.stable(tables), - }, - span, - }, - Coverage(coverage) => { - Statement { kind: stable_mir::mir::StatementKind::Coverage(opaque(coverage)), span } + } } - Intrinsic(intrinstic) => Statement { - kind: stable_mir::mir::StatementKind::Intrinsic(intrinstic.stable(tables)), - span, - }, - ConstEvalCounter => { - Statement { kind: stable_mir::mir::StatementKind::ConstEvalCounter, span } + mir::StatementKind::Coverage(coverage) => { + stable_mir::mir::StatementKind::Coverage(opaque(coverage)) + } + mir::StatementKind::Intrinsic(intrinstic) => { + stable_mir::mir::StatementKind::Intrinsic(intrinstic.stable(tables)) + } + mir::StatementKind::ConstEvalCounter => { + stable_mir::mir::StatementKind::ConstEvalCounter } - Nop => Statement { kind: stable_mir::mir::StatementKind::Nop, span }, + mir::StatementKind::Nop => stable_mir::mir::StatementKind::Nop, } } } @@ -844,76 +836,84 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> { impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { type T = stable_mir::mir::Terminator; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { - use rustc_middle::mir::TerminatorKind::*; use stable_mir::mir::Terminator; + Terminator { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) } + } +} + +impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> { + type T = stable_mir::mir::TerminatorKind; + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { use stable_mir::mir::TerminatorKind; - let span = self.source_info.span.stable(tables); - match &self.kind { - Goto { target } => { - Terminator { kind: TerminatorKind::Goto { target: target.as_usize() }, span } - } - SwitchInt { discr, targets } => Terminator { - kind: TerminatorKind::SwitchInt { - discr: discr.stable(tables), - targets: targets - .iter() - .map(|(value, target)| stable_mir::mir::SwitchTarget { - value, - target: target.as_usize(), - }) - .collect(), - otherwise: targets.otherwise().as_usize(), - }, - span, + match self { + mir::TerminatorKind::Goto { target } => { + TerminatorKind::Goto { target: target.as_usize() } + } + mir::TerminatorKind::SwitchInt { discr, targets } => TerminatorKind::SwitchInt { + discr: discr.stable(tables), + targets: targets + .iter() + .map(|(value, target)| stable_mir::mir::SwitchTarget { + value, + target: target.as_usize(), + }) + .collect(), + otherwise: targets.otherwise().as_usize(), }, - UnwindResume => Terminator { kind: TerminatorKind::Resume, span }, - UnwindTerminate(_) => Terminator { kind: TerminatorKind::Abort, span }, - Return => Terminator { kind: TerminatorKind::Return, span }, - Unreachable => Terminator { kind: TerminatorKind::Unreachable, span }, - Drop { place, target, unwind, replace: _ } => Terminator { - kind: TerminatorKind::Drop { + mir::TerminatorKind::UnwindResume => TerminatorKind::Resume, + mir::TerminatorKind::UnwindTerminate(_) => TerminatorKind::Abort, + mir::TerminatorKind::Return => TerminatorKind::Return, + mir::TerminatorKind::Unreachable => TerminatorKind::Unreachable, + mir::TerminatorKind::Drop { place, target, unwind, replace: _ } => { + TerminatorKind::Drop { place: place.stable(tables), target: target.as_usize(), unwind: unwind.stable(tables), - }, - span, - }, - Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => { - Terminator { - kind: TerminatorKind::Call { - func: func.stable(tables), - args: args.iter().map(|arg| arg.stable(tables)).collect(), - destination: destination.stable(tables), - target: target.map(|t| t.as_usize()), - unwind: unwind.stable(tables), - }, - span, } } - Assert { cond, expected, msg, target, unwind } => Terminator { - kind: TerminatorKind::Assert { + mir::TerminatorKind::Call { + func, + args, + destination, + target, + unwind, + call_source: _, + fn_span: _, + } => TerminatorKind::Call { + func: func.stable(tables), + args: args.iter().map(|arg| arg.stable(tables)).collect(), + destination: destination.stable(tables), + target: target.map(|t| t.as_usize()), + unwind: unwind.stable(tables), + }, + mir::TerminatorKind::Assert { cond, expected, msg, target, unwind } => { + TerminatorKind::Assert { cond: cond.stable(tables), expected: *expected, msg: msg.stable(tables), target: target.as_usize(), unwind: unwind.stable(tables), - }, - span, - }, - InlineAsm { template, operands, options, line_spans, destination, unwind } => { - Terminator { - kind: TerminatorKind::InlineAsm { - template: format!("{template:?}"), - operands: operands.iter().map(|operand| operand.stable(tables)).collect(), - options: format!("{options:?}"), - line_spans: format!("{line_spans:?}"), - destination: destination.map(|d| d.as_usize()), - unwind: unwind.stable(tables), - }, - span, } } - Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(), + mir::TerminatorKind::InlineAsm { + template, + operands, + options, + line_spans, + destination, + unwind, + } => TerminatorKind::InlineAsm { + template: format!("{template:?}"), + operands: operands.iter().map(|operand| operand.stable(tables)).collect(), + options: format!("{options:?}"), + line_spans: format!("{line_spans:?}"), + destination: destination.map(|d| d.as_usize()), + unwind: unwind.stable(tables), + }, + mir::TerminatorKind::Yield { .. } + | mir::TerminatorKind::GeneratorDrop + | mir::TerminatorKind::FalseEdge { .. } + | mir::TerminatorKind::FalseUnwind { .. } => unreachable!(), } } }