From 6e930f72d0a735a6c1dfdde438a458a8624d37be Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 18 Apr 2020 13:13:06 +0100 Subject: [PATCH] Accept `LocalDefId` as key for `mir_borrowck` query --- src/librustc_interface/passes.rs | 2 +- src/librustc_middle/query/mod.rs | 9 ++++----- src/librustc_mir/borrow_check/mod.rs | 10 +++++----- src/librustc_mir/borrow_check/type_check/mod.rs | 12 ++++++++---- src/librustc_mir/transform/mod.rs | 4 ++-- src/librustc_typeck/collect/type_of.rs | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 4b09148eab6..9a8a05713c8 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -835,7 +835,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { }); 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", || { diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 62837685e8b..23a83a7a7e6 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -494,12 +494,11 @@ rustc_queries! { BorrowChecking { /// Borrow-checks the function body. If this is a closure, returns /// additional requirements that the closure's creator must verify. - query mir_borrowck(key: DefId) -> &'tcx mir::BorrowCheckResult<'tcx> { - desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) } + query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> { + desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if(tcx, opt_result) { - key.is_local() - && (tcx.is_closure(key) - || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())) + tcx.is_closure(key.to_def_id()) + || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()) } } } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 7c7251c9134..21f988c9f3b 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -92,14 +92,14 @@ pub fn provide(providers: &mut Providers<'_>) { *providers = Providers { mir_borrowck, ..*providers }; } -fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> &BorrowCheckResult<'_> { - let (input_body, promoted) = tcx.mir_validated(def_id); - debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id)); +fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &BorrowCheckResult<'_> { + let (input_body, promoted) = tcx.mir_validated(def_id.to_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 input_body: &Body<'_> = &input_body.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"); @@ -1268,7 +1268,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { match **aggregate_kind { AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => { 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); for field in used_mut_upvars { self.propagate_closure_used_mut_upvar(&operands[field.index()]); diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 428b6c8f854..d60ab2b81fd 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -9,7 +9,7 @@ use rustc_data_structures::frozen::Frozen; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::struct_span_err; 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_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::outlives::env::RegionBoundPairs; @@ -2569,7 +2569,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // clauses on the struct. AggregateKind::Closure(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(), @@ -2584,14 +2584,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn prove_closure_bounds( &mut self, tcx: TyCtxt<'tcx>, - def_id: DefId, + def_id: LocalDefId, substs: SubstsRef<'tcx>, location: Location, ) -> ty::InstantiatedPredicates<'tcx> { if let Some(ref closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements { 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 // constraints to their parents -- they are enforced diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index df6e415300d..17fbbbfdab7 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -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 // 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 mut body = body.steal(); @@ -387,7 +387,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec> 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 mut promoted = promoted.steal(); diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs index 5302b0cdb78..cf0e3f9cdf5 100644 --- a/src/librustc_typeck/collect/type_of.rs +++ b/src/librustc_typeck/collect/type_of.rs @@ -114,7 +114,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), origin, .. }) => { let concrete_types = match origin { OpaqueTyOrigin::FnReturn | OpaqueTyOrigin::AsyncFn => { - &tcx.mir_borrowck(owner).concrete_opaque_types + &tcx.mir_borrowck(owner.expect_local()).concrete_opaque_types } OpaqueTyOrigin::Misc => { // We shouldn't leak borrowck results through impl trait in bindings.