frontend 0.4.1

rustc's frontend with no LLVM and no std: parsing through MIR, as a library
//! Dataflow analysis results.

use crate::rustc_index::IndexVec;
use crate::rustc_middle::mir::{BasicBlock, Body};

use super::{Analysis, ResultsCursor};

pub type EntryStates<D> = IndexVec<BasicBlock, D>;

/// The results of a dataflow analysis that has converged to fixpoint. It holds the domain values
/// (states) at the entry of each basic block. Domain values in other parts of the block are
/// recomputed on the fly by visitors (i.e. `ResultsCursor`, or `ResultsVisitor` impls). The
/// analysis is also present because it's often needed alongside the entry states.
pub struct Results<'tcx, A>
where
    A: Analysis<'tcx>,
{
    pub analysis: A,
    pub entry_states: EntryStates<A::Domain>,
}

impl<'tcx, A> Results<'tcx, A>
where
    A: Analysis<'tcx>,
{
    /// Creates a `ResultsCursor` that takes ownership of `self`.
    pub fn into_results_cursor<'mir>(self, body: &'mir Body<'tcx>) -> ResultsCursor<'mir, 'tcx, A> {
        ResultsCursor::new_owning(body, self)
    }
}