1
Fork 0

Accept LocalDefId as key for mir_borrowck query

This commit is contained in:
marmeladema 2020-04-18 13:13:06 +01:00
parent 82823c0229
commit 6e930f72d0
6 changed files with 21 additions and 18 deletions

View file

@ -835,7 +835,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
}); });
sess.time("MIR_borrow_checking", || { sess.time("MIR_borrow_checking", || {
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id())); tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
}); });
sess.time("dumping_chalk_like_clauses", || { sess.time("dumping_chalk_like_clauses", || {

View file

@ -494,12 +494,11 @@ rustc_queries! {
BorrowChecking { BorrowChecking {
/// Borrow-checks the function body. If this is a closure, returns /// Borrow-checks the function body. If this is a closure, returns
/// additional requirements that the closure's creator must verify. /// additional requirements that the closure's creator must verify.
query mir_borrowck(key: DefId) -> &'tcx mir::BorrowCheckResult<'tcx> { query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) } desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx, opt_result) { cache_on_disk_if(tcx, opt_result) {
key.is_local() tcx.is_closure(key.to_def_id())
&& (tcx.is_closure(key) || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()))
} }
} }
} }

View file

@ -92,14 +92,14 @@ pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers { mir_borrowck, ..*providers }; *providers = Providers { mir_borrowck, ..*providers };
} }
fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> &BorrowCheckResult<'_> { fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &BorrowCheckResult<'_> {
let (input_body, promoted) = tcx.mir_validated(def_id); let (input_body, promoted) = tcx.mir_validated(def_id.to_def_id());
debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id)); debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id()));
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| { let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
let input_body: &Body<'_> = &input_body.borrow(); let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow(); let promoted: &IndexVec<_, _> = &promoted.borrow();
do_mir_borrowck(&infcx, input_body, promoted, def_id.expect_local()) do_mir_borrowck(&infcx, input_body, promoted, def_id)
}); });
debug!("mir_borrowck done"); debug!("mir_borrowck done");
@ -1268,7 +1268,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
match **aggregate_kind { match **aggregate_kind {
AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => { AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => {
let BorrowCheckResult { used_mut_upvars, .. } = let BorrowCheckResult { used_mut_upvars, .. } =
self.infcx.tcx.mir_borrowck(def_id); self.infcx.tcx.mir_borrowck(def_id.expect_local());
debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars); debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars);
for field in used_mut_upvars { for field in used_mut_upvars {
self.propagate_closure_used_mut_upvar(&operands[field.index()]); self.propagate_closure_used_mut_upvar(&operands[field.index()]);

View file

@ -9,7 +9,7 @@ use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs; use rustc_infer::infer::outlives::env::RegionBoundPairs;
@ -2569,7 +2569,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// clauses on the struct. // clauses on the struct.
AggregateKind::Closure(def_id, substs) AggregateKind::Closure(def_id, substs)
| AggregateKind::Generator(def_id, substs, _) => { | AggregateKind::Generator(def_id, substs, _) => {
self.prove_closure_bounds(tcx, *def_id, substs, location) self.prove_closure_bounds(tcx, def_id.expect_local(), substs, location)
} }
AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(), AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(),
@ -2584,14 +2584,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn prove_closure_bounds( fn prove_closure_bounds(
&mut self, &mut self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: DefId, def_id: LocalDefId,
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
location: Location, location: Location,
) -> ty::InstantiatedPredicates<'tcx> { ) -> ty::InstantiatedPredicates<'tcx> {
if let Some(ref closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements if let Some(ref closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements
{ {
let closure_constraints = QueryRegionConstraints { let closure_constraints = QueryRegionConstraints {
outlives: closure_region_requirements.apply_requirements(tcx, def_id, substs), outlives: closure_region_requirements.apply_requirements(
tcx,
def_id.to_def_id(),
substs,
),
// Presently, closures never propagate member // Presently, closures never propagate member
// constraints to their parents -- they are enforced // constraints to their parents -- they are enforced

View file

@ -371,7 +371,7 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to // (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal. // execute before we can steal.
tcx.ensure().mir_borrowck(def_id); tcx.ensure().mir_borrowck(def_id.expect_local());
let (body, _) = tcx.mir_validated(def_id); let (body, _) = tcx.mir_validated(def_id);
let mut body = body.steal(); let mut body = body.steal();
@ -387,7 +387,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec<Promoted, Body<'_>>
return tcx.intern_promoted(IndexVec::new()); return tcx.intern_promoted(IndexVec::new());
} }
tcx.ensure().mir_borrowck(def_id); tcx.ensure().mir_borrowck(def_id.expect_local());
let (_, promoted) = tcx.mir_validated(def_id); let (_, promoted) = tcx.mir_validated(def_id);
let mut promoted = promoted.steal(); let mut promoted = promoted.steal();

View file

@ -114,7 +114,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), origin, .. }) => { ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), origin, .. }) => {
let concrete_types = match origin { let concrete_types = match origin {
OpaqueTyOrigin::FnReturn | OpaqueTyOrigin::AsyncFn => { OpaqueTyOrigin::FnReturn | OpaqueTyOrigin::AsyncFn => {
&tcx.mir_borrowck(owner).concrete_opaque_types &tcx.mir_borrowck(owner.expect_local()).concrete_opaque_types
} }
OpaqueTyOrigin::Misc => { OpaqueTyOrigin::Misc => {
// We shouldn't leak borrowck results through impl trait in bindings. // We shouldn't leak borrowck results through impl trait in bindings.