Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir.rs')
-rw-r--r--crates/hir-ty/src/mir.rs34
1 files changed, 31 insertions, 3 deletions
diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs
index 140caad545..5d8a81a3ee 100644
--- a/crates/hir-ty/src/mir.rs
+++ b/crates/hir-ty/src/mir.rs
@@ -7,17 +7,19 @@ use crate::{
};
use chalk_ir::Mutability;
use hir_def::{
- expr::{Expr, Ordering},
+ expr::{BindingId, Expr, ExprId, Ordering, PatId},
DefWithBodyId, FieldId, UnionId, VariantId,
};
-use la_arena::{Arena, Idx, RawIdx};
+use la_arena::{Arena, ArenaMap, Idx, RawIdx};
mod eval;
mod lower;
+pub mod borrowck;
pub use eval::{interpret_mir, pad16, Evaluator, MirEvalError};
pub use lower::{lower_to_mir, mir_body_query, mir_body_recover, MirLowerError};
use smallvec::{smallvec, SmallVec};
+use stdx::impl_from;
use super::consteval::{intern_const_scalar, try_const_usize};
@@ -181,6 +183,11 @@ impl SwitchTargets {
iter::zip(&self.values, &self.targets).map(|(x, y)| (*x, *y))
}
+ /// Returns a slice with all possible jump targets (including the fallback target).
+ pub fn all_targets(&self) -> &[BasicBlockId] {
+ &self.targets
+ }
+
/// Finds the `BasicBlock` to which this `SwitchInt` will branch given the
/// specific value. This cannot fail, as it'll return the `otherwise`
/// branch if there's not a specific match for the value.
@@ -758,7 +765,7 @@ pub enum Rvalue {
}
#[derive(Debug, PartialEq, Eq, Clone)]
-pub enum Statement {
+pub enum StatementKind {
Assign(Place, Rvalue),
//FakeRead(Box<(FakeReadCause, Place)>),
//SetDiscriminant {
@@ -773,6 +780,17 @@ pub enum Statement {
//Intrinsic(Box<NonDivergingIntrinsic>),
Nop,
}
+impl StatementKind {
+ fn with_span(self, span: MirSpan) -> Statement {
+ Statement { kind: self, span }
+ }
+}
+
+#[derive(Debug, PartialEq, Eq, Clone)]
+pub struct Statement {
+ pub kind: StatementKind,
+ pub span: MirSpan,
+}
#[derive(Debug, Default, PartialEq, Eq)]
pub struct BasicBlock {
@@ -803,6 +821,7 @@ pub struct MirBody {
pub start_block: BasicBlockId,
pub owner: DefWithBodyId,
pub arg_count: usize,
+ pub binding_locals: ArenaMap<BindingId, LocalId>,
}
impl MirBody {}
@@ -810,3 +829,12 @@ impl MirBody {}
fn const_as_usize(c: &Const) -> usize {
try_const_usize(c).unwrap() as usize
}
+
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+pub enum MirSpan {
+ ExprId(ExprId),
+ PatId(PatId),
+ Unknown,
+}
+
+impl_from!(ExprId, PatId for MirSpan);