diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-08-31 12:30:25 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-09-05 07:37:58 -0700 |
| commit | bf5550b9b2dfee20f0689a8f2bfcbb9e2cb4168f (patch) | |
| tree | fbc0dc01a6a9508b67eec187e52389f2e0bfa986 /src | |
| parent | 490f34ac0cf6b8c62d835e2f7c55a3f911854a9c (diff) | |
| download | rust-bf5550b9b2dfee20f0689a8f2bfcbb9e2cb4168f.tar.gz rust-bf5550b9b2dfee20f0689a8f2bfcbb9e2cb4168f.zip | |
rustc: Convert `freevars` to a query
This removes a public mutable (but not actually used mutably) field from the `TyCtxt`, moving it over to a query to ensure that it's tracked over time.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/dep_graph/dep_node.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/context.rs | 8 | ||||
| -rw-r--r-- | src/librustc/ty/maps.rs | 8 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 5 |
4 files changed, 18 insertions, 5 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index c684440296f..52028ffe0c7 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -569,6 +569,8 @@ define_dep_nodes!( <'tcx> [] MissingExternCrateItem(CrateNum), [] UsedCrateSource(CrateNum), [] PostorderCnums, + + [] Freevars(HirId), ); trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 0e02d5b992a..8ba42eacf30 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -33,7 +33,6 @@ use traits; use ty::{self, Ty, TypeAndMut}; use ty::{TyS, TypeVariants, Slice}; use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region}; -use hir::FreevarMap; use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate}; use ty::RegionKind; use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid}; @@ -837,7 +836,7 @@ pub struct GlobalCtxt<'tcx> { // Records the free variables refrenced by every closure // expression. Do not track deps for this, just recompute it from // scratch every time. - pub freevars: RefCell<FreevarMap>, + freevars: FxHashMap<HirId, Rc<Vec<hir::Freevar>>>, pub maybe_unused_trait_imports: NodeSet, @@ -1066,11 +1065,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { export_map: resolutions.export_map.into_iter().map(|(k, v)| { (hir.node_to_hir_id(k), Rc::new(v)) }).collect(), + freevars: resolutions.freevars.into_iter().map(|(k, v)| { + (hir.node_to_hir_id(k), Rc::new(v)) + }).collect(), hir, def_path_hash_to_def_id, maps: maps::Maps::new(providers), mir_passes, - freevars: RefCell::new(resolutions.freevars), maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports, maybe_unused_extern_crates: resolutions.maybe_unused_extern_crates, rcache: RefCell::new(FxHashMap()), @@ -2018,4 +2019,5 @@ pub fn provide(providers: &mut ty::maps::Providers) { assert_eq!(id, LOCAL_CRATE); Rc::new(middle::lang_items::collect(tcx)) }; + providers.freevars = |tcx, id| tcx.gcx.freevars.get(&id).cloned(); } diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 78f85fd58ac..b1ff59e7e49 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -730,6 +730,12 @@ impl<'tcx> QueryDescription for queries::postorder_cnums<'tcx> { } } +impl<'tcx> QueryDescription for queries::freevars<'tcx> { + fn describe(_tcx: TyCtxt, _: HirId) -> String { + format!("looking up free variables for a node") + } +} + // If enabled, send a message to the profile-queries thread macro_rules! profq_msg { ($tcx:expr, $msg:expr) => { @@ -1345,6 +1351,8 @@ define_maps! { <'tcx> [] missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool, [] used_crate_source: UsedCrateSource(CrateNum) -> Rc<CrateSource>, [] postorder_cnums: postorder_cnums_node(CrateNum) -> Rc<Vec<CrateNum>>, + + [] freevars: Freevars(HirId) -> Option<Rc<Vec<hir::Freevar>>>, } fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index ad14a311c54..d4c352f00a7 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2340,9 +2340,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn with_freevars<T, F>(self, fid: NodeId, f: F) -> T where F: FnOnce(&[hir::Freevar]) -> T, { - match self.freevars.borrow().get(&fid) { + let hir_id = self.hir.node_to_hir_id(fid); + match self.freevars(hir_id) { None => f(&[]), - Some(d) => f(&d[..]) + Some(d) => f(&d), } } } |
