impl stable for kinds

This commit is contained in:
Oğuz Ağcayazı 2023-10-05 11:13:05 +03:00
parent a79567b01c
commit a49138e46e

View File

@ -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(
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),
),
span,
},
FakeRead(fake_read_place) => Statement {
kind: stable_mir::mir::StatementKind::FakeRead(
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 }
}
Nop => Statement { kind: stable_mir::mir::StatementKind::Nop, 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
}
mir::StatementKind::Nop => stable_mir::mir::StatementKind::Nop,
}
}
}
@ -844,16 +836,20 @@ 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;
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 }
Terminator { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) }
}
SwitchInt { discr, targets } => Terminator {
kind: TerminatorKind::SwitchInt {
}
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;
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()
@ -864,45 +860,49 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
.collect(),
otherwise: targets.otherwise().as_usize(),
},
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 {
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 {
}
}
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),
},
span,
}
}
Assert { cond, expected, msg, target, unwind } => Terminator {
kind: TerminatorKind::Assert {
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 {
}
}
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:?}"),
@ -910,10 +910,10 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
destination: destination.map(|d| d.as_usize()),
unwind: unwind.stable(tables),
},
span,
}
}
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
mir::TerminatorKind::Yield { .. }
| mir::TerminatorKind::GeneratorDrop
| mir::TerminatorKind::FalseEdge { .. }
| mir::TerminatorKind::FalseUnwind { .. } => unreachable!(),
}
}
}