Skip to content

Commit bf5550b

Browse files
committed
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.
1 parent 490f34a commit bf5550b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ define_dep_nodes!( <'tcx>
569569
[] MissingExternCrateItem(CrateNum),
570570
[] UsedCrateSource(CrateNum),
571571
[] PostorderCnums,
572+
573+
[] Freevars(HirId),
572574
);
573575

574576
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/ty/context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use traits;
3333
use ty::{self, Ty, TypeAndMut};
3434
use ty::{TyS, TypeVariants, Slice};
3535
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region};
36-
use hir::FreevarMap;
3736
use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
3837
use ty::RegionKind;
3938
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
@@ -837,7 +836,7 @@ pub struct GlobalCtxt<'tcx> {
837836
// Records the free variables refrenced by every closure
838837
// expression. Do not track deps for this, just recompute it from
839838
// scratch every time.
840-
pub freevars: RefCell<FreevarMap>,
839+
freevars: FxHashMap<HirId, Rc<Vec<hir::Freevar>>>,
841840

842841
pub maybe_unused_trait_imports: NodeSet,
843842

@@ -1066,11 +1065,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10661065
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
10671066
(hir.node_to_hir_id(k), Rc::new(v))
10681067
}).collect(),
1068+
freevars: resolutions.freevars.into_iter().map(|(k, v)| {
1069+
(hir.node_to_hir_id(k), Rc::new(v))
1070+
}).collect(),
10691071
hir,
10701072
def_path_hash_to_def_id,
10711073
maps: maps::Maps::new(providers),
10721074
mir_passes,
1073-
freevars: RefCell::new(resolutions.freevars),
10741075
maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
10751076
maybe_unused_extern_crates: resolutions.maybe_unused_extern_crates,
10761077
rcache: RefCell::new(FxHashMap()),
@@ -2018,4 +2019,5 @@ pub fn provide(providers: &mut ty::maps::Providers) {
20182019
assert_eq!(id, LOCAL_CRATE);
20192020
Rc::new(middle::lang_items::collect(tcx))
20202021
};
2022+
providers.freevars = |tcx, id| tcx.gcx.freevars.get(&id).cloned();
20212023
}

src/librustc/ty/maps.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ impl<'tcx> QueryDescription for queries::postorder_cnums<'tcx> {
730730
}
731731
}
732732

733+
impl<'tcx> QueryDescription for queries::freevars<'tcx> {
734+
fn describe(_tcx: TyCtxt, _: HirId) -> String {
735+
format!("looking up free variables for a node")
736+
}
737+
}
738+
733739
// If enabled, send a message to the profile-queries thread
734740
macro_rules! profq_msg {
735741
($tcx:expr, $msg:expr) => {
@@ -1345,6 +1351,8 @@ define_maps! { <'tcx>
13451351
[] missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
13461352
[] used_crate_source: UsedCrateSource(CrateNum) -> Rc<CrateSource>,
13471353
[] postorder_cnums: postorder_cnums_node(CrateNum) -> Rc<Vec<CrateNum>>,
1354+
1355+
[] freevars: Freevars(HirId) -> Option<Rc<Vec<hir::Freevar>>>,
13481356
}
13491357

13501358
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

src/librustc/ty/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,9 +2340,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23402340
pub fn with_freevars<T, F>(self, fid: NodeId, f: F) -> T where
23412341
F: FnOnce(&[hir::Freevar]) -> T,
23422342
{
2343-
match self.freevars.borrow().get(&fid) {
2343+
let hir_id = self.hir.node_to_hir_id(fid);
2344+
match self.freevars(hir_id) {
23442345
None => f(&[]),
2345-
Some(d) => f(&d[..])
2346+
Some(d) => f(&d),
23462347
}
23472348
}
23482349
}

0 commit comments

Comments
 (0)