add span to statements
This commit is contained in:
parent
999a354a81
commit
a79567b01c
3 changed files with 98 additions and 73 deletions
|
@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{alloc_range, AllocId};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
|
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
|
||||||
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||||
use rustc_target::abi::FieldIdx;
|
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::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy};
|
||||||
use stable_mir::{self, opaque, Context};
|
use stable_mir::{self, opaque, Context};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
@ -231,40 +231,71 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
|
||||||
type T = stable_mir::mir::Statement;
|
type T = stable_mir::mir::Statement;
|
||||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
use rustc_middle::mir::StatementKind::*;
|
use rustc_middle::mir::StatementKind::*;
|
||||||
|
let span = self.source_info.span.stable(tables);
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
Assign(assign) => {
|
Assign(assign) => Statement {
|
||||||
stable_mir::mir::Statement::Assign(assign.0.stable(tables), assign.1.stable(tables))
|
kind: stable_mir::mir::StatementKind::Assign(
|
||||||
}
|
assign.0.stable(tables),
|
||||||
FakeRead(fake_read_place) => stable_mir::mir::Statement::FakeRead(
|
assign.1.stable(tables),
|
||||||
fake_read_place.0.stable(tables),
|
),
|
||||||
fake_read_place.1.stable(tables),
|
span,
|
||||||
),
|
},
|
||||||
SetDiscriminant { place: plc, variant_index: idx } => {
|
FakeRead(fake_read_place) => Statement {
|
||||||
stable_mir::mir::Statement::SetDiscriminant {
|
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),
|
place: plc.as_ref().stable(tables),
|
||||||
variant_index: idx.stable(tables),
|
variant_index: idx.stable(tables),
|
||||||
}
|
},
|
||||||
}
|
span,
|
||||||
Deinit(place) => stable_mir::mir::Statement::Deinit(place.stable(tables)),
|
},
|
||||||
StorageLive(place) => stable_mir::mir::Statement::StorageLive(place.stable(tables)),
|
Deinit(place) => Statement {
|
||||||
StorageDead(place) => stable_mir::mir::Statement::StorageDead(place.stable(tables)),
|
kind: stable_mir::mir::StatementKind::Deinit(place.stable(tables)),
|
||||||
Retag(retag, place) => {
|
span,
|
||||||
stable_mir::mir::Statement::Retag(retag.stable(tables), place.stable(tables))
|
},
|
||||||
}
|
StorageLive(place) => Statement {
|
||||||
PlaceMention(place) => stable_mir::mir::Statement::PlaceMention(place.stable(tables)),
|
kind: stable_mir::mir::StatementKind::StorageLive(place.stable(tables)),
|
||||||
AscribeUserType(place_projection, variance) => {
|
span,
|
||||||
stable_mir::mir::Statement::AscribeUserType {
|
},
|
||||||
|
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),
|
place: place_projection.as_ref().0.stable(tables),
|
||||||
projections: place_projection.as_ref().1.stable(tables),
|
projections: place_projection.as_ref().1.stable(tables),
|
||||||
variance: variance.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) => Statement {
|
||||||
Intrinsic(intrinstic) => {
|
kind: stable_mir::mir::StatementKind::Intrinsic(intrinstic.stable(tables)),
|
||||||
stable_mir::mir::Statement::Intrinsic(intrinstic.stable(tables))
|
span,
|
||||||
|
},
|
||||||
|
ConstEvalCounter => {
|
||||||
|
Statement { kind: stable_mir::mir::StatementKind::ConstEvalCounter, span }
|
||||||
}
|
}
|
||||||
ConstEvalCounter => stable_mir::mir::Statement::ConstEvalCounter,
|
Nop => Statement { kind: stable_mir::mir::StatementKind::Nop, span },
|
||||||
Nop => stable_mir::mir::Statement::Nop,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -816,11 +847,11 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
|
||||||
use rustc_middle::mir::TerminatorKind::*;
|
use rustc_middle::mir::TerminatorKind::*;
|
||||||
use stable_mir::mir::Terminator;
|
use stable_mir::mir::Terminator;
|
||||||
use stable_mir::mir::TerminatorKind;
|
use stable_mir::mir::TerminatorKind;
|
||||||
|
let span = self.source_info.span.stable(tables);
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
Goto { target } => Terminator {
|
Goto { target } => {
|
||||||
kind: TerminatorKind::Goto { target: target.as_usize() },
|
Terminator { kind: TerminatorKind::Goto { target: target.as_usize() }, span }
|
||||||
span: self.source_info.span.stable(tables),
|
}
|
||||||
},
|
|
||||||
SwitchInt { discr, targets } => Terminator {
|
SwitchInt { discr, targets } => Terminator {
|
||||||
kind: TerminatorKind::SwitchInt {
|
kind: TerminatorKind::SwitchInt {
|
||||||
discr: discr.stable(tables),
|
discr: discr.stable(tables),
|
||||||
|
@ -833,31 +864,19 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
|
||||||
.collect(),
|
.collect(),
|
||||||
otherwise: targets.otherwise().as_usize(),
|
otherwise: targets.otherwise().as_usize(),
|
||||||
},
|
},
|
||||||
span: self.source_info.span.stable(tables),
|
span,
|
||||||
},
|
|
||||||
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),
|
|
||||||
},
|
},
|
||||||
|
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 {
|
Drop { place, target, unwind, replace: _ } => Terminator {
|
||||||
kind: TerminatorKind::Drop {
|
kind: TerminatorKind::Drop {
|
||||||
place: place.stable(tables),
|
place: place.stable(tables),
|
||||||
target: target.as_usize(),
|
target: target.as_usize(),
|
||||||
unwind: unwind.stable(tables),
|
unwind: unwind.stable(tables),
|
||||||
},
|
},
|
||||||
span: self.source_info.span.stable(tables),
|
span,
|
||||||
},
|
},
|
||||||
Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => {
|
Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => {
|
||||||
Terminator {
|
Terminator {
|
||||||
|
@ -868,7 +887,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
|
||||||
target: target.map(|t| t.as_usize()),
|
target: target.map(|t| t.as_usize()),
|
||||||
unwind: unwind.stable(tables),
|
unwind: unwind.stable(tables),
|
||||||
},
|
},
|
||||||
span: self.source_info.span.stable(tables),
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert { cond, expected, msg, target, unwind } => Terminator {
|
Assert { cond, expected, msg, target, unwind } => Terminator {
|
||||||
|
@ -879,7 +898,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
|
||||||
target: target.as_usize(),
|
target: target.as_usize(),
|
||||||
unwind: unwind.stable(tables),
|
unwind: unwind.stable(tables),
|
||||||
},
|
},
|
||||||
span: self.source_info.span.stable(tables),
|
span,
|
||||||
},
|
},
|
||||||
InlineAsm { template, operands, options, line_spans, destination, unwind } => {
|
InlineAsm { template, operands, options, line_spans, destination, unwind } => {
|
||||||
Terminator {
|
Terminator {
|
||||||
|
@ -891,7 +910,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
|
||||||
destination: destination.map(|d| d.as_usize()),
|
destination: destination.map(|d| d.as_usize()),
|
||||||
unwind: unwind.stable(tables),
|
unwind: unwind.stable(tables),
|
||||||
},
|
},
|
||||||
span: self.source_info.span.stable(tables),
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
|
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
|
||||||
|
|
|
@ -191,7 +191,13 @@ pub enum NonDivergingIntrinsic {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Statement {
|
pub struct Statement {
|
||||||
|
pub kind: StatementKind,
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum StatementKind {
|
||||||
Assign(Place, Rvalue),
|
Assign(Place, Rvalue),
|
||||||
FakeRead(FakeReadCause, Place),
|
FakeRead(FakeReadCause, Place),
|
||||||
SetDiscriminant { place: Place, variant_index: VariantIdx },
|
SetDiscriminant { place: Place, variant_index: VariantIdx },
|
||||||
|
|
|
@ -47,12 +47,12 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
assert_eq!(body.blocks.len(), 1);
|
assert_eq!(body.blocks.len(), 1);
|
||||||
let block = &body.blocks[0];
|
let block = &body.blocks[0];
|
||||||
assert_eq!(block.statements.len(), 1);
|
assert_eq!(block.statements.len(), 1);
|
||||||
match &block.statements[0] {
|
match &block.statements[0].kind {
|
||||||
stable_mir::mir::Statement::Assign(..) => {}
|
stable_mir::mir::StatementKind::Assign(..) => {}
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
match &block.terminator {
|
match &block.terminator.kind {
|
||||||
stable_mir::mir::Terminator::Return => {}
|
stable_mir::mir::TerminatorKind::Return => {}
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
assert_eq!(body.locals.len(), 7);
|
assert_eq!(body.locals.len(), 7);
|
||||||
assert_eq!(body.blocks.len(), 4);
|
assert_eq!(body.blocks.len(), 4);
|
||||||
let block = &body.blocks[0];
|
let block = &body.blocks[0];
|
||||||
match &block.terminator {
|
match &block.terminator.kind {
|
||||||
stable_mir::mir::Terminator::Call { .. } => {}
|
stable_mir::mir::TerminatorKind::Call { .. } => {}
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,27 +70,27 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
let body = types.body();
|
let body = types.body();
|
||||||
assert_eq!(body.locals.len(), 6);
|
assert_eq!(body.locals.len(), 6);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
body.locals[0].kind(),
|
body.locals[0].ty.kind(),
|
||||||
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
||||||
);
|
);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
body.locals[1].kind(),
|
body.locals[1].ty.kind(),
|
||||||
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
||||||
);
|
);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
body.locals[2].kind(),
|
body.locals[2].ty.kind(),
|
||||||
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
|
||||||
);
|
);
|
||||||
assert_matches!(
|
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))
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
|
||||||
);
|
);
|
||||||
assert_matches!(
|
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))
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
|
||||||
);
|
);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
body.locals[5].kind(),
|
body.locals[5].ty.kind(),
|
||||||
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float(
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float(
|
||||||
stable_mir::ty::FloatTy::F64
|
stable_mir::ty::FloatTy::F64
|
||||||
))
|
))
|
||||||
|
@ -100,8 +100,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
let body = drop.body();
|
let body = drop.body();
|
||||||
assert_eq!(body.blocks.len(), 2);
|
assert_eq!(body.blocks.len(), 2);
|
||||||
let block = &body.blocks[0];
|
let block = &body.blocks[0];
|
||||||
match &block.terminator {
|
match &block.terminator.kind {
|
||||||
stable_mir::mir::Terminator::Drop { .. } => {}
|
stable_mir::mir::TerminatorKind::Drop { .. } => {}
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,15 +109,15 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
let body = assert.body();
|
let body = assert.body();
|
||||||
assert_eq!(body.blocks.len(), 2);
|
assert_eq!(body.blocks.len(), 2);
|
||||||
let block = &body.blocks[0];
|
let block = &body.blocks[0];
|
||||||
match &block.terminator {
|
match &block.terminator.kind {
|
||||||
stable_mir::mir::Terminator::Assert { .. } => {}
|
stable_mir::mir::TerminatorKind::Assert { .. } => {}
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let monomorphic = get_item(&items, (DefKind::Fn, "monomorphic")).unwrap();
|
let monomorphic = get_item(&items, (DefKind::Fn, "monomorphic")).unwrap();
|
||||||
for block in monomorphic.body().blocks {
|
for block in monomorphic.body().blocks {
|
||||||
match &block.terminator {
|
match &block.terminator.kind {
|
||||||
stable_mir::mir::Terminator::Call { func, .. } => match func {
|
stable_mir::mir::TerminatorKind::Call { func, .. } => match func {
|
||||||
stable_mir::mir::Operand::Constant(c) => match &c.literal.literal {
|
stable_mir::mir::Operand::Constant(c) => match &c.literal.literal {
|
||||||
stable_mir::ty::ConstantKind::Allocated(alloc) => {
|
stable_mir::ty::ConstantKind::Allocated(alloc) => {
|
||||||
assert!(alloc.bytes.is_empty());
|
assert!(alloc.bytes.is_empty());
|
||||||
|
@ -127,7 +127,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
mut args,
|
mut args,
|
||||||
)) => {
|
)) => {
|
||||||
let func = def.body();
|
let func = def.body();
|
||||||
match func.locals[1]
|
match func.locals[1].ty
|
||||||
.fold(&mut args)
|
.fold(&mut args)
|
||||||
.continue_value()
|
.continue_value()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -149,7 +149,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
},
|
},
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
},
|
},
|
||||||
stable_mir::mir::Terminator::Return => {}
|
stable_mir::mir::TerminatorKind::Return => {}
|
||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue