clean up, use opaque types
This commit is contained in:
parent
206bfc47ea
commit
2ff62fdfcc
2 changed files with 53 additions and 42 deletions
|
@ -8,7 +8,7 @@
|
||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use crate::rustc_internal::{self, opaque};
|
use crate::rustc_internal::{self, opaque};
|
||||||
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection};
|
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
|
||||||
use crate::stable_mir::ty::{FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy};
|
use crate::stable_mir::ty::{FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy};
|
||||||
use crate::stable_mir::{self, Context};
|
use crate::stable_mir::{self, Context};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -130,16 +130,11 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
|
||||||
}
|
}
|
||||||
PlaceMention(place) => stable_mir::mir::Statement::PlaceMention(place.stable(tables)),
|
PlaceMention(place) => stable_mir::mir::Statement::PlaceMention(place.stable(tables)),
|
||||||
AscribeUserType(place_projection, variance) => {
|
AscribeUserType(place_projection, variance) => {
|
||||||
stable_mir::mir::Statement::AscribeUserType(
|
stable_mir::mir::Statement::AscribeUserType {
|
||||||
(
|
place: place_projection.as_ref().0.stable(tables),
|
||||||
place_projection.as_ref().0.stable(tables),
|
projections: place_projection.as_ref().1.stable(tables),
|
||||||
UserTypeProjection {
|
variance: variance.stable(tables),
|
||||||
base: place_projection.as_ref().1.base.stable(tables),
|
}
|
||||||
projection: format!("{:?}", place_projection.as_ref().1.projs),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
variance.stable(tables),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Coverage(coverage) => stable_mir::mir::Statement::Coverage(stable_mir::mir::Coverage {
|
Coverage(coverage) => stable_mir::mir::Statement::Coverage(stable_mir::mir::Coverage {
|
||||||
kind: coverage.kind.stable(tables),
|
kind: coverage.kind.stable(tables),
|
||||||
|
@ -398,13 +393,11 @@ impl<'tcx> Stable<'tcx> for mir::FakeReadCause {
|
||||||
use mir::FakeReadCause::*;
|
use mir::FakeReadCause::*;
|
||||||
match self {
|
match self {
|
||||||
ForMatchGuard => stable_mir::mir::FakeReadCause::ForMatchGuard,
|
ForMatchGuard => stable_mir::mir::FakeReadCause::ForMatchGuard,
|
||||||
ForMatchedPlace(local_def_id) => stable_mir::mir::FakeReadCause::ForMatchedPlace(
|
ForMatchedPlace(local_def_id) => {
|
||||||
local_def_id.map(|id| id.to_def_id().index.index()),
|
stable_mir::mir::FakeReadCause::ForMatchedPlace(opaque(local_def_id))
|
||||||
),
|
}
|
||||||
ForGuardBinding => stable_mir::mir::FakeReadCause::ForGuardBinding,
|
ForGuardBinding => stable_mir::mir::FakeReadCause::ForGuardBinding,
|
||||||
ForLet(local_def_id) => stable_mir::mir::FakeReadCause::ForLet(
|
ForLet(local_def_id) => stable_mir::mir::FakeReadCause::ForLet(opaque(local_def_id)),
|
||||||
local_def_id.map(|id| id.to_def_id().index.index()),
|
|
||||||
),
|
|
||||||
ForIndex => stable_mir::mir::FakeReadCause::ForIndex,
|
ForIndex => stable_mir::mir::FakeReadCause::ForIndex,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,15 +440,15 @@ impl<'tcx> Stable<'tcx> for mir::coverage::CoverageKind {
|
||||||
CoverageKind::Counter { function_source_hash, id } => {
|
CoverageKind::Counter { function_source_hash, id } => {
|
||||||
stable_mir::mir::CoverageKind::Counter {
|
stable_mir::mir::CoverageKind::Counter {
|
||||||
function_source_hash: *function_source_hash as usize,
|
function_source_hash: *function_source_hash as usize,
|
||||||
id: id.as_usize(),
|
id: opaque(id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CoverageKind::Expression { id, lhs, op, rhs } => {
|
CoverageKind::Expression { id, lhs, op, rhs } => {
|
||||||
stable_mir::mir::CoverageKind::Expression {
|
stable_mir::mir::CoverageKind::Expression {
|
||||||
id: id.as_usize(),
|
id: opaque(id),
|
||||||
lhs: lhs.as_usize(),
|
lhs: opaque(lhs),
|
||||||
op: op.stable(tables),
|
op: op.stable(tables),
|
||||||
rhs: rhs.as_usize(),
|
rhs: opaque(rhs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CoverageKind::Unreachable => stable_mir::mir::CoverageKind::Unreachable,
|
CoverageKind::Unreachable => stable_mir::mir::CoverageKind::Unreachable,
|
||||||
|
@ -463,6 +456,14 @@ impl<'tcx> Stable<'tcx> for mir::coverage::CoverageKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
|
||||||
|
type T = stable_mir::mir::UserTypeProjection;
|
||||||
|
|
||||||
|
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
UserTypeProjection { base: self.base.as_usize(), projection: format!("{:?}", self.projs) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> Stable<'tcx> for mir::coverage::Op {
|
impl<'tcx> Stable<'tcx> for mir::coverage::Op {
|
||||||
type T = stable_mir::mir::Op;
|
type T = stable_mir::mir::Op;
|
||||||
|
|
||||||
|
@ -476,14 +477,14 @@ impl<'tcx> Stable<'tcx> for mir::coverage::Op {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Stable<'tcx> for mir::Local {
|
impl<'tcx> Stable<'tcx> for mir::Local {
|
||||||
type T = usize;
|
type T = stable_mir::mir::Local;
|
||||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||||
self.as_usize()
|
self.as_usize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
|
impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
|
||||||
type T = usize;
|
type T = VariantIdx;
|
||||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||||
self.as_usize()
|
self.as_usize()
|
||||||
}
|
}
|
||||||
|
@ -525,14 +526,12 @@ impl<'tcx> Stable<'tcx> for CodeRegion {
|
||||||
type T = stable_mir::mir::CodeRegion;
|
type T = stable_mir::mir::CodeRegion;
|
||||||
|
|
||||||
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
|
||||||
match self {
|
stable_mir::mir::CodeRegion {
|
||||||
_ => stable_mir::mir::CodeRegion {
|
file_name: self.file_name.as_str().to_string(),
|
||||||
file_name: self.file_name.as_u32() as usize,
|
start_line: self.start_line as usize,
|
||||||
start_line: self.start_line as usize,
|
start_col: self.start_col as usize,
|
||||||
start_col: self.start_col as usize,
|
end_line: self.end_line as usize,
|
||||||
end_line: self.end_line as usize,
|
end_col: self.end_col as usize,
|
||||||
end_col: self.end_col as usize,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::rustc_internal::Opaque;
|
||||||
use crate::stable_mir::ty::{
|
use crate::stable_mir::ty::{
|
||||||
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
|
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
|
||||||
};
|
};
|
||||||
|
@ -133,15 +134,18 @@ pub enum AsyncGeneratorKind {
|
||||||
Fn,
|
Fn,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: We are using `usize` for now but we should be using DefIds and find what
|
pub(crate) type LocalDefId = Opaque;
|
||||||
// what those are refering to and then use appropirate ty_defs for them (i.e AdtDef)
|
pub(crate) type CounterValueReference = Opaque;
|
||||||
|
pub(crate) type InjectedExpressionId = Opaque;
|
||||||
|
pub(crate) type ExpressionOperandId = Opaque;
|
||||||
|
|
||||||
/// The FakeReadCause describes the type of pattern why a FakeRead statement exists.
|
/// The FakeReadCause describes the type of pattern why a FakeRead statement exists.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum FakeReadCause {
|
pub enum FakeReadCause {
|
||||||
ForMatchGuard,
|
ForMatchGuard,
|
||||||
ForMatchedPlace(Option<usize>),
|
ForMatchedPlace(LocalDefId),
|
||||||
ForGuardBinding,
|
ForGuardBinding,
|
||||||
ForLet(Option<usize>),
|
ForLet(LocalDefId),
|
||||||
ForIndex,
|
ForIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,14 +174,22 @@ pub enum Op {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum CoverageKind {
|
pub enum CoverageKind {
|
||||||
Counter { function_source_hash: usize, id: usize },
|
Counter {
|
||||||
Expression { id: usize, lhs: usize, op: Op, rhs: usize },
|
function_source_hash: usize,
|
||||||
|
id: CounterValueReference,
|
||||||
|
},
|
||||||
|
Expression {
|
||||||
|
id: InjectedExpressionId,
|
||||||
|
lhs: ExpressionOperandId,
|
||||||
|
op: Op,
|
||||||
|
rhs: ExpressionOperandId,
|
||||||
|
},
|
||||||
Unreachable,
|
Unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct CodeRegion {
|
pub struct CodeRegion {
|
||||||
pub file_name: usize,
|
pub file_name: String,
|
||||||
pub start_line: usize,
|
pub start_line: usize,
|
||||||
pub start_col: usize,
|
pub start_col: usize,
|
||||||
pub end_line: usize,
|
pub end_line: usize,
|
||||||
|
@ -213,7 +225,7 @@ pub enum Statement {
|
||||||
StorageDead(Local),
|
StorageDead(Local),
|
||||||
Retag(RetagKind, Place),
|
Retag(RetagKind, Place),
|
||||||
PlaceMention(Place),
|
PlaceMention(Place),
|
||||||
AscribeUserType((Place, UserTypeProjection), Variance),
|
AscribeUserType { place: Place, projections: UserTypeProjection, variance: Variance },
|
||||||
Coverage(Coverage),
|
Coverage(Coverage),
|
||||||
Intrinsic(NonDivergingIntrinsic),
|
Intrinsic(NonDivergingIntrinsic),
|
||||||
ConstEvalCounter,
|
ConstEvalCounter,
|
||||||
|
@ -362,12 +374,12 @@ pub struct UserTypeProjection {
|
||||||
pub projection: String,
|
pub projection: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Local = usize;
|
pub type Local = usize;
|
||||||
|
|
||||||
type FieldIdx = usize;
|
type FieldIdx = usize;
|
||||||
|
|
||||||
/// The source-order index of a variant in a type.
|
/// The source-order index of a variant in a type.
|
||||||
type VariantIdx = usize;
|
pub type VariantIdx = usize;
|
||||||
|
|
||||||
type UserTypeAnnotationIndex = usize;
|
type UserTypeAnnotationIndex = usize;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue