Skip to content

Commit e6fca1d

Browse files
committed
remove the closure_tys map from TypeckTables
The information we need is now part of the closure type.
1 parent d0bda66 commit e6fca1d

File tree

6 files changed

+34
-45
lines changed

6 files changed

+34
-45
lines changed

src/librustc/infer/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,9 +1484,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14841484
if let Some(tables) = self.in_progress_tables {
14851485
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
14861486
let hir_id = self.tcx.hir.node_to_hir_id(id);
1487-
if let Some(&ty) = tables.borrow().closure_tys().get(hir_id) {
1488-
return ty;
1489-
}
1487+
let closure_ty = tables.borrow().node_id_to_type(hir_id);
1488+
let (closure_def_id, closure_substs) = match closure_ty.sty {
1489+
ty::TyClosure(closure_def_id, closure_substs) =>
1490+
(closure_def_id, closure_substs),
1491+
_ =>
1492+
bug!("closure with non-closure type: {:?}", closure_ty),
1493+
};
1494+
assert_eq!(def_id, closure_def_id);
1495+
let closure_sig_ty = closure_substs.closure_sig_ty(def_id, self.tcx);
1496+
let closure_sig_ty = self.shallow_resolve(&closure_sig_ty);
1497+
return closure_sig_ty.fn_sig(self.tcx);
14901498
}
14911499
}
14921500

src/librustc/ty/context.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ pub struct TypeckTables<'tcx> {
356356
/// Borrows
357357
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
358358

359-
/// Records the type of each closure.
360-
closure_tys: ItemLocalMap<ty::PolyFnSig<'tcx>>,
361-
362359
/// Records the reasons that we picked the kind of each closure;
363360
/// not all closures are present in the map.
364361
closure_kind_origins: ItemLocalMap<(Span, ast::Name)>,
@@ -413,7 +410,6 @@ impl<'tcx> TypeckTables<'tcx> {
413410
upvar_capture_map: FxHashMap(),
414411
generator_sigs: ItemLocalMap(),
415412
generator_interiors: ItemLocalMap(),
416-
closure_tys: ItemLocalMap(),
417413
closure_kind_origins: ItemLocalMap(),
418414
liberated_fn_sigs: ItemLocalMap(),
419415
fru_field_types: ItemLocalMap(),
@@ -609,21 +605,6 @@ impl<'tcx> TypeckTables<'tcx> {
609605
self.upvar_capture_map[&upvar_id]
610606
}
611607

612-
pub fn closure_tys(&self) -> LocalTableInContext<ty::PolyFnSig<'tcx>> {
613-
LocalTableInContext {
614-
local_id_root: self.local_id_root,
615-
data: &self.closure_tys
616-
}
617-
}
618-
619-
pub fn closure_tys_mut(&mut self)
620-
-> LocalTableInContextMut<ty::PolyFnSig<'tcx>> {
621-
LocalTableInContextMut {
622-
local_id_root: self.local_id_root,
623-
data: &mut self.closure_tys
624-
}
625-
}
626-
627608
pub fn closure_kind_origins(&self) -> LocalTableInContext<(Span, ast::Name)> {
628609
LocalTableInContext {
629610
local_id_root: self.local_id_root,
@@ -730,7 +711,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
730711
ref pat_binding_modes,
731712
ref pat_adjustments,
732713
ref upvar_capture_map,
733-
ref closure_tys,
734714
ref closure_kind_origins,
735715
ref liberated_fn_sigs,
736716
ref fru_field_types,
@@ -773,7 +753,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
773753
hcx.def_path_hash(closure_def_id))
774754
});
775755

776-
closure_tys.hash_stable(hcx, hasher);
777756
closure_kind_origins.hash_stable(hcx, hasher);
778757
liberated_fn_sigs.hash_stable(hcx, hasher);
779758
fru_field_types.hash_stable(hcx, hasher);

src/librustc/ty/sty.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,19 @@ impl<'tcx> ClosureSubsts<'tcx> {
297297
}
298298

299299
/// Returns the closure kind for this closure; may return a type
300-
/// variable during inference.
300+
/// variable during inference. To get the closure kind during
301+
/// inference, use `infcx.closure_kind(def_id, substs)`.
301302
pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> {
302303
self.split(def_id, tcx).closure_kind_ty
303304
}
304305

305306
/// Returns the type representing the closure signature for this
306-
/// closure; may contain type variables during inference.
307+
/// closure; may contain type variables during inference. To get
308+
/// the closure signature during inference, use
309+
/// `infcx.fn_sig(def_id)`.
307310
pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> {
308311
self.split(def_id, tcx).closure_sig_ty
309312
}
310-
311-
/// Extracts the signature from the closure.
312-
pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> ty::PolyFnSig<'tcx> {
313-
match &self.split(def_id, tcx).closure_sig_ty.sty {
314-
ty::TyFnPtr(sig) => *sig,
315-
t => bug!("closure_sig_ty is not a fn-ptr: {:?}", t),
316-
}
317-
}
318313
}
319314

320315
impl<'tcx> ClosureSubsts<'tcx> {
@@ -324,6 +319,16 @@ impl<'tcx> ClosureSubsts<'tcx> {
324319
pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::ClosureKind {
325320
self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap()
326321
}
322+
323+
/// Extracts the signature from the closure; only usable outside
324+
/// of an inference context, because in that context we know that
325+
/// there are no type variables.
326+
pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::PolyFnSig<'tcx> {
327+
match self.closure_sig_ty(def_id, tcx).sty {
328+
ty::TyFnPtr(sig) => sig,
329+
ref t => bug!("closure_sig_ty is not a fn-ptr: {:?}", t),
330+
}
331+
}
327332
}
328333

329334
impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> {

src/librustc_typeck/check/closure.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
146146
sig_fn_ptr_ty,
147147
substs.closure_sig_ty(expr_def_id, self.tcx));
148148

149-
self.tables.borrow_mut().closure_tys_mut().insert(expr.hir_id, sig);
150149
if let Some(kind) = opt_kind {
151150
self.demand_eqtype(expr.span,
152151
kind.to_ty(self.tcx),

src/librustc_typeck/check/writeback.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,6 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
243243
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
244244
let common_local_id_root = fcx_tables.local_id_root.unwrap();
245245

246-
for (&id, closure_ty) in fcx_tables.closure_tys().iter() {
247-
let hir_id = hir::HirId {
248-
owner: common_local_id_root.index,
249-
local_id: id,
250-
};
251-
let closure_ty = self.resolve(closure_ty, &hir_id);
252-
self.tables.closure_tys_mut().insert(hir_id, closure_ty);
253-
}
254-
255246
for (&id, &origin) in fcx_tables.closure_kind_origins().iter() {
256247
let hir_id = hir::HirId {
257248
owner: common_local_id_root.index,

src/librustc_typeck/collect.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,14 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12651265
}
12661266

12671267
NodeExpr(&hir::Expr { node: hir::ExprClosure(..), hir_id, .. }) => {
1268-
tcx.typeck_tables_of(def_id).closure_tys()[hir_id]
1268+
let tables = tcx.typeck_tables_of(def_id);
1269+
match tables.node_id_to_type(hir_id).sty {
1270+
ty::TyClosure(closure_def_id, closure_substs) => {
1271+
assert_eq!(def_id, closure_def_id);
1272+
return closure_substs.closure_sig(closure_def_id, tcx);
1273+
}
1274+
ref t => bug!("closure with non-closure type: {:?}", t),
1275+
}
12691276
}
12701277

12711278
x => {

0 commit comments

Comments
 (0)