Skip to content

Commit c6e3f27

Browse files
committed
Move BodyWithBorrowckFacts to consumers
1 parent 75e172e commit c6e3f27

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

compiler/rustc_borrowck/src/consumers.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
//! This file provides API for compiler consumers.
44
55
use rustc_hir::def_id::LocalDefId;
6-
use rustc_index::IndexSlice;
6+
use rustc_index::{IndexSlice, IndexVec};
77
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
8-
use rustc_middle::mir::Body;
8+
use rustc_middle::mir::{Body, Promoted};
99
use rustc_middle::ty::TyCtxt;
10+
use std::rc::Rc;
11+
12+
use crate::borrow_set::BorrowSet;
1013

1114
pub use super::{
1215
dataflow::{calculate_borrows_out_of_scope_at_location, BorrowIndex, Borrows},
@@ -16,7 +19,6 @@ pub use super::{
1619
place_ext::PlaceExt,
1720
places_conflict::{places_conflict, PlaceConflictBias},
1821
region_infer::RegionInferenceContext,
19-
BodyWithBorrowckFacts,
2022
};
2123

2224
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
@@ -56,6 +58,34 @@ impl ConsumerOptions {
5658
}
5759
}
5860

61+
/// A `Body` with information computed by the borrow checker. This struct is
62+
/// intended to be consumed by compiler consumers.
63+
///
64+
/// We need to include the MIR body here because the region identifiers must
65+
/// match the ones in the Polonius facts.
66+
pub struct BodyWithBorrowckFacts<'tcx> {
67+
/// A mir body that contains region identifiers.
68+
pub body: Body<'tcx>,
69+
/// The mir bodies of promoteds.
70+
pub promoted: IndexVec<Promoted, Body<'tcx>>,
71+
/// The set of borrows occurring in `body` with data about them.
72+
pub borrow_set: Rc<BorrowSet<'tcx>>,
73+
/// Context generated during borrowck, intended to be passed to
74+
/// [`calculate_borrows_out_of_scope_at_location`].
75+
pub region_inference_context: Rc<RegionInferenceContext<'tcx>>,
76+
/// The table that maps Polonius points to locations in the table.
77+
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
78+
/// or [`ConsumerOptions::PoloniusOutputFacts`].
79+
pub location_table: Option<LocationTable>,
80+
/// Polonius input facts.
81+
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
82+
/// or [`ConsumerOptions::PoloniusOutputFacts`].
83+
pub input_facts: Option<Box<PoloniusInput>>,
84+
/// Polonius output facts. Populated when using
85+
/// [`ConsumerOptions::PoloniusOutputFacts`].
86+
pub output_facts: Option<Rc<PoloniusOutput>>,
87+
}
88+
5989
/// This function computes borrowck facts for the given body. The [`ConsumerOptions`]
6090
/// determine which facts are returned. This function makes a copy of the body because
6191
/// it needs to regenerate the region identifiers. It should never be invoked during a

compiler/rustc_borrowck/src/lib.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ use crate::session_diagnostics::VarNeedNotMut;
6262
use self::diagnostics::{AccessKind, RegionName};
6363
use self::location::LocationTable;
6464
use self::prefixes::PrefixSet;
65-
use consumers::ConsumerOptions;
66-
use facts::AllFacts;
65+
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
6766

6867
use self::path_utils::*;
6968

@@ -463,32 +462,6 @@ fn do_mir_borrowck<'tcx>(
463462
(result, body_with_facts)
464463
}
465464

466-
/// A `Body` with information computed by the borrow checker. This struct is
467-
/// intended to be consumed by compiler consumers.
468-
///
469-
/// We need to include the MIR body here because the region identifiers must
470-
/// match the ones in the Polonius facts.
471-
pub struct BodyWithBorrowckFacts<'tcx> {
472-
/// A mir body that contains region identifiers.
473-
pub body: Body<'tcx>,
474-
/// The mir bodies of promoteds.
475-
pub promoted: IndexVec<Promoted, Body<'tcx>>,
476-
/// The set of borrows occurring in `body` with data about them.
477-
pub borrow_set: Rc<BorrowSet<'tcx>>,
478-
/// Context generated during borrowck, intended to be passed to
479-
/// [`OutOfScopePrecomputer`](dataflow::OutOfScopePrecomputer).
480-
pub region_inference_context: Rc<RegionInferenceContext<'tcx>>,
481-
/// The table that maps Polonius points to locations in the table. Populated
482-
/// when using [`ConsumerOptions::PoloniusInputFacts`] or above.
483-
pub location_table: Option<LocationTable>,
484-
/// Polonius input facts. Populated when using
485-
/// [`ConsumerOptions::PoloniusInputFacts`] or above.
486-
pub input_facts: Option<Box<AllFacts>>,
487-
/// Polonius output facts. Populated when using
488-
/// [`ConsumerOptions::PoloniusOutputFacts`] or above.
489-
pub output_facts: Option<Rc<self::nll::PoloniusOutput>>,
490-
}
491-
492465
pub struct BorrowckInferCtxt<'cx, 'tcx> {
493466
pub(crate) infcx: &'cx InferCtxt<'tcx>,
494467
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,

tests/run-make-fulldeps/obtain-borrowck/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate rustc_interface;
1818
extern crate rustc_middle;
1919
extern crate rustc_session;
2020

21-
use rustc_borrowck::consumers::BodyWithBorrowckFacts;
21+
use rustc_borrowck::consumers::{self, BodyWithBorrowckFacts, ConsumerOptions};
2222
use rustc_driver::Compilation;
2323
use rustc_hir::def::DefKind;
2424
use rustc_hir::def_id::LocalDefId;
@@ -128,7 +128,7 @@ thread_local! {
128128

129129
fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ProvidedValue<'tcx> {
130130
let opts = ConsumerOptions::PoloniusInputFacts;
131-
let body_with_facts = rustc_borrowck::consumers::get_body_with_borrowck_facts(tcx, def_id, opts);
131+
let body_with_facts = consumers::get_body_with_borrowck_facts(tcx, def_id, opts);
132132
// SAFETY: The reader casts the 'static lifetime to 'tcx before using it.
133133
let body_with_facts: BodyWithBorrowckFacts<'static> =
134134
unsafe { std::mem::transmute(body_with_facts) };

0 commit comments

Comments
 (0)