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.
This commit is contained in:
Alex Crichton 2017-08-31 12:30:25 -07:00
parent 490f34ac0c
commit bf5550b9b2
4 changed files with 18 additions and 5 deletions

View file

@ -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 {

View file

@ -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();
}

View file

@ -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> {

View file

@ -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),
}
}
}