Skip to content

Commit 1f13e13

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

File tree

6 files changed

+34
-45
lines changed

6 files changed

+34
-45
lines changed

src/librustc/infer/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1359,9 +1359,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13591359
if let Some(tables) = self.in_progress_tables {
13601360
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
13611361
let hir_id = self.tcx.hir.node_to_hir_id(id);
1362-
if let Some(&ty) = tables.borrow().closure_tys().get(hir_id) {
1363-
return ty;
1364-
}
1362+
let closure_ty = tables.borrow().node_id_to_type(hir_id);
1363+
let (closure_def_id, closure_substs) = match closure_ty.sty {
1364+
ty::TyClosure(closure_def_id, closure_substs) =>
1365+
(closure_def_id, closure_substs),
1366+
_ =>
1367+
bug!("closure with non-closure type: {:?}", closure_ty),
1368+
};
1369+
assert_eq!(def_id, closure_def_id);
1370+
let closure_sig_ty = closure_substs.closure_sig_ty(def_id, self.tcx);
1371+
let closure_sig_ty = self.shallow_resolve(&closure_sig_ty);
1372+
return closure_sig_ty.fn_sig(self.tcx);
13651373
}
13661374
}
13671375

src/librustc/ty/context.rs

-21
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ pub struct TypeckTables<'tcx> {
357357
/// Borrows
358358
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
359359

360-
/// Records the type of each closure.
361-
closure_tys: ItemLocalMap<ty::PolyFnSig<'tcx>>,
362-
363360
/// Records the reasons that we picked the kind of each closure;
364361
/// not all closures are present in the map.
365362
closure_kind_origins: ItemLocalMap<(Span, ast::Name)>,
@@ -414,7 +411,6 @@ impl<'tcx> TypeckTables<'tcx> {
414411
upvar_capture_map: FxHashMap(),
415412
generator_sigs: ItemLocalMap(),
416413
generator_interiors: ItemLocalMap(),
417-
closure_tys: ItemLocalMap(),
418414
closure_kind_origins: ItemLocalMap(),
419415
liberated_fn_sigs: ItemLocalMap(),
420416
fru_field_types: ItemLocalMap(),
@@ -610,21 +606,6 @@ impl<'tcx> TypeckTables<'tcx> {
610606
self.upvar_capture_map[&upvar_id]
611607
}
612608

613-
pub fn closure_tys(&self) -> LocalTableInContext<ty::PolyFnSig<'tcx>> {
614-
LocalTableInContext {
615-
local_id_root: self.local_id_root,
616-
data: &self.closure_tys
617-
}
618-
}
619-
620-
pub fn closure_tys_mut(&mut self)
621-
-> LocalTableInContextMut<ty::PolyFnSig<'tcx>> {
622-
LocalTableInContextMut {
623-
local_id_root: self.local_id_root,
624-
data: &mut self.closure_tys
625-
}
626-
}
627-
628609
pub fn closure_kind_origins(&self) -> LocalTableInContext<(Span, ast::Name)> {
629610
LocalTableInContext {
630611
local_id_root: self.local_id_root,
@@ -731,7 +712,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
731712
ref pat_binding_modes,
732713
ref pat_adjustments,
733714
ref upvar_capture_map,
734-
ref closure_tys,
735715
ref closure_kind_origins,
736716
ref liberated_fn_sigs,
737717
ref fru_field_types,
@@ -774,7 +754,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
774754
hcx.def_path_hash(closure_def_id))
775755
});
776756

777-
closure_tys.hash_stable(hcx, hasher);
778757
closure_kind_origins.hash_stable(hcx, hasher);
779758
liberated_fn_sigs.hash_stable(hcx, hasher);
780759
fru_field_types.hash_stable(hcx, hasher);

src/librustc/ty/sty.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -296,24 +296,19 @@ impl<'tcx> ClosureSubsts<'tcx> {
296296
}
297297

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

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

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

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

src/librustc_typeck/check/closure.rs

-1
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

-9
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

+8-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,14 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12371237
}
12381238

12391239
NodeExpr(&hir::Expr { node: hir::ExprClosure(..), hir_id, .. }) => {
1240-
tcx.typeck_tables_of(def_id).closure_tys()[hir_id]
1240+
let tables = tcx.typeck_tables_of(def_id);
1241+
match tables.node_id_to_type(hir_id).sty {
1242+
ty::TyClosure(closure_def_id, closure_substs) => {
1243+
assert_eq!(def_id, closure_def_id);
1244+
return closure_substs.closure_sig(closure_def_id, tcx);
1245+
}
1246+
ref t => bug!("closure with non-closure type: {:?}", t),
1247+
}
12411248
}
12421249

12431250
x => {

0 commit comments

Comments
 (0)