Skip to content

Commit

Permalink
impl stable for kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Oct 5, 2023
1 parent a79567b commit a49138e
Showing 1 changed file with 114 additions and 114 deletions.
228 changes: 114 additions & 114 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -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!(),
}
}
}
Expand Down

0 comments on commit a49138e

Please sign in to comment.