From c6e3f27864080730298dd7260f94af8784fbdc42 Mon Sep 17 00:00:00 2001 From: Dominik Stolz Date: Tue, 23 May 2023 11:16:59 +0200 Subject: [PATCH] Move BodyWithBorrowckFacts to consumers --- compiler/rustc_borrowck/src/consumers.rs | 36 +++++++++++++++++-- compiler/rustc_borrowck/src/lib.rs | 29 +-------------- .../obtain-borrowck/driver.rs | 4 +-- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index 810f1991579..3b749a3a38e 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -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>, + /// The set of borrows occurring in `body` with data about them. + pub borrow_set: Rc>, + /// Context generated during borrowck, intended to be passed to + /// [`calculate_borrows_out_of_scope_at_location`]. + pub region_inference_context: Rc>, + /// The table that maps Polonius points to locations in the table. + /// Populated when using [`ConsumerOptions::PoloniusInputFacts`] + /// or [`ConsumerOptions::PoloniusOutputFacts`]. + pub location_table: Option, + /// Polonius input facts. + /// Populated when using [`ConsumerOptions::PoloniusInputFacts`] + /// or [`ConsumerOptions::PoloniusOutputFacts`]. + pub input_facts: Option>, + /// Polonius output facts. Populated when using + /// [`ConsumerOptions::PoloniusOutputFacts`]. + pub output_facts: Option>, +} + /// 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 diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 4f1e12c364e..28e5f3e2a16 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -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>, - /// The set of borrows occurring in `body` with data about them. - pub borrow_set: Rc>, - /// Context generated during borrowck, intended to be passed to - /// [`OutOfScopePrecomputer`](dataflow::OutOfScopePrecomputer). - pub region_inference_context: Rc>, - /// The table that maps Polonius points to locations in the table. Populated - /// when using [`ConsumerOptions::PoloniusInputFacts`] or above. - pub location_table: Option, - /// Polonius input facts. Populated when using - /// [`ConsumerOptions::PoloniusInputFacts`] or above. - pub input_facts: Option>, - /// Polonius output facts. Populated when using - /// [`ConsumerOptions::PoloniusOutputFacts`] or above. - pub output_facts: Option>, -} - pub struct BorrowckInferCtxt<'cx, 'tcx> { pub(crate) infcx: &'cx InferCtxt<'tcx>, pub(crate) reg_var_to_origin: RefCell>, diff --git a/tests/run-make-fulldeps/obtain-borrowck/driver.rs b/tests/run-make-fulldeps/obtain-borrowck/driver.rs index c8990e535b0..b59a65a713f 100644 --- a/tests/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/tests/run-make-fulldeps/obtain-borrowck/driver.rs @@ -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) };