Move BodyWithBorrowckFacts to consumers

This commit is contained in:
Dominik Stolz 2023-05-23 11:16:59 +02:00
parent 75e172e710
commit c6e3f27864
3 changed files with 36 additions and 33 deletions

View File

@ -3,10 +3,13 @@
//! This file provides API for compiler consumers.
use rustc_hir::def_id::LocalDefId;
use rustc_index::IndexSlice;
use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_middle::mir::Body;
use rustc_middle::mir::{Body, Promoted};
use rustc_middle::ty::TyCtxt;
use std::rc::Rc;
use crate::borrow_set::BorrowSet;
pub use super::{
dataflow::{calculate_borrows_out_of_scope_at_location, BorrowIndex, Borrows},
@ -16,7 +19,6 @@ pub use super::{
place_ext::PlaceExt,
places_conflict::{places_conflict, PlaceConflictBias},
region_infer::RegionInferenceContext,
BodyWithBorrowckFacts,
};
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
@ -56,6 +58,34 @@ impl ConsumerOptions {
}
}
/// A `Body` with information computed by the borrow checker. This struct is
/// intended to be consumed by compiler consumers.
///
/// We need to include the MIR body here because the region identifiers must
/// match the ones in the Polonius facts.
pub struct BodyWithBorrowckFacts<'tcx> {
/// A mir body that contains region identifiers.
pub body: Body<'tcx>,
/// The mir bodies of promoteds.
pub promoted: IndexVec<Promoted, Body<'tcx>>,
/// The set of borrows occurring in `body` with data about them.
pub borrow_set: Rc<BorrowSet<'tcx>>,
/// Context generated during borrowck, intended to be passed to
/// [`calculate_borrows_out_of_scope_at_location`].
pub region_inference_context: Rc<RegionInferenceContext<'tcx>>,
/// The table that maps Polonius points to locations in the table.
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
/// or [`ConsumerOptions::PoloniusOutputFacts`].
pub location_table: Option<LocationTable>,
/// Polonius input facts.
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
/// or [`ConsumerOptions::PoloniusOutputFacts`].
pub input_facts: Option<Box<PoloniusInput>>,
/// Polonius output facts. Populated when using
/// [`ConsumerOptions::PoloniusOutputFacts`].
pub output_facts: Option<Rc<PoloniusOutput>>,
}
/// This function computes borrowck facts for the given body. The [`ConsumerOptions`]
/// determine which facts are returned. This function makes a copy of the body because
/// it needs to regenerate the region identifiers. It should never be invoked during a

View File

@ -62,8 +62,7 @@ use crate::session_diagnostics::VarNeedNotMut;
use self::diagnostics::{AccessKind, RegionName};
use self::location::LocationTable;
use self::prefixes::PrefixSet;
use consumers::ConsumerOptions;
use facts::AllFacts;
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
use self::path_utils::*;
@ -463,32 +462,6 @@ fn do_mir_borrowck<'tcx>(
(result, body_with_facts)
}
/// A `Body` with information computed by the borrow checker. This struct is
/// intended to be consumed by compiler consumers.
///
/// We need to include the MIR body here because the region identifiers must
/// match the ones in the Polonius facts.
pub struct BodyWithBorrowckFacts<'tcx> {
/// A mir body that contains region identifiers.
pub body: Body<'tcx>,
/// The mir bodies of promoteds.
pub promoted: IndexVec<Promoted, Body<'tcx>>,
/// The set of borrows occurring in `body` with data about them.
pub borrow_set: Rc<BorrowSet<'tcx>>,
/// Context generated during borrowck, intended to be passed to
/// [`OutOfScopePrecomputer`](dataflow::OutOfScopePrecomputer).
pub region_inference_context: Rc<RegionInferenceContext<'tcx>>,
/// The table that maps Polonius points to locations in the table. Populated
/// when using [`ConsumerOptions::PoloniusInputFacts`] or above.
pub location_table: Option<LocationTable>,
/// Polonius input facts. Populated when using
/// [`ConsumerOptions::PoloniusInputFacts`] or above.
pub input_facts: Option<Box<AllFacts>>,
/// Polonius output facts. Populated when using
/// [`ConsumerOptions::PoloniusOutputFacts`] or above.
pub output_facts: Option<Rc<self::nll::PoloniusOutput>>,
}
pub struct BorrowckInferCtxt<'cx, 'tcx> {
pub(crate) infcx: &'cx InferCtxt<'tcx>,
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,

View File

@ -18,7 +18,7 @@ extern crate rustc_interface;
extern crate rustc_middle;
extern crate rustc_session;
use rustc_borrowck::consumers::BodyWithBorrowckFacts;
use rustc_borrowck::consumers::{self, BodyWithBorrowckFacts, ConsumerOptions};
use rustc_driver::Compilation;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
@ -128,7 +128,7 @@ thread_local! {
fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ProvidedValue<'tcx> {
let opts = ConsumerOptions::PoloniusInputFacts;
let body_with_facts = rustc_borrowck::consumers::get_body_with_borrowck_facts(tcx, def_id, opts);
let body_with_facts = consumers::get_body_with_borrowck_facts(tcx, def_id, opts);
// SAFETY: The reader casts the 'static lifetime to 'tcx before using it.
let body_with_facts: BodyWithBorrowckFacts<'static> =
unsafe { std::mem::transmute(body_with_facts) };