Skip to content

Commit 6e4b8ef

Browse files
committed
Don't keep {Closure,Generator}Substs synthetics in an Instance.
1 parent 5533705 commit 6e4b8ef

File tree

7 files changed

+15
-44
lines changed

7 files changed

+15
-44
lines changed

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
211211
let instance = Instance::resolve_closure(
212212
bx.cx().tcx(),
213213
def_id,
214-
substs,
214+
substs.as_closure(),
215215
ty::ClosureKind::FnOnce,
216216
);
217217
OperandValue::Immediate(bx.cx().get_fn_addr(instance))

src/librustc_middle/ty/instance.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,14 @@ impl<'tcx> Instance<'tcx> {
382382
pub fn resolve_closure(
383383
tcx: TyCtxt<'tcx>,
384384
def_id: DefId,
385-
substs: ty::SubstsRef<'tcx>,
385+
closure_substs: ty::ClosureSubsts<'tcx>,
386386
requested_kind: ty::ClosureKind,
387387
) -> Instance<'tcx> {
388-
let actual_kind = substs.as_closure().kind();
388+
let actual_kind = closure_substs.kind();
389389

390390
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
391-
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
392-
_ => Instance::new(def_id, substs),
391+
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, closure_substs),
392+
_ => Instance::new(def_id, tcx.intern_substs(closure_substs.base_substs())),
393393
}
394394
}
395395

@@ -399,12 +399,12 @@ impl<'tcx> Instance<'tcx> {
399399
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
400400
}
401401

402-
pub fn fn_once_adapter_instance(
402+
fn fn_once_adapter_instance(
403403
tcx: TyCtxt<'tcx>,
404404
closure_did: DefId,
405-
substs: ty::SubstsRef<'tcx>,
405+
closure_substs: ty::ClosureSubsts<'tcx>,
406406
) -> Instance<'tcx> {
407-
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
407+
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, closure_substs);
408408
let fn_once = tcx.require_lang_item(FnOnceTraitLangItem, None);
409409
let call_once = tcx
410410
.associated_items(fn_once)
@@ -414,9 +414,9 @@ impl<'tcx> Instance<'tcx> {
414414
.def_id;
415415
let def = ty::InstanceDef::ClosureOnceShim { call_once };
416416

417-
let self_ty = tcx.mk_closure(closure_did, substs);
417+
let self_ty = tcx.mk_closure(closure_did, closure_substs.substs);
418418

419-
let sig = substs.as_closure().sig();
419+
let sig = closure_substs.sig();
420420
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
421421
assert_eq!(sig.inputs().len(), 1);
422422
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);

src/librustc_mir/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9696
let instance = ty::Instance::resolve_closure(
9797
*self.tcx,
9898
def_id,
99-
substs,
99+
substs.as_closure(),
100100
ty::ClosureKind::FnOnce,
101101
);
102102
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
581581
let instance = Instance::resolve_closure(
582582
self.tcx,
583583
def_id,
584-
substs,
584+
substs.as_closure(),
585585
ty::ClosureKind::FnOnce,
586586
);
587587
if should_monomorphize_locally(self.tcx, &instance) {

src/librustc_ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn resolve_associated_item<'tcx>(
190190
Some(Instance::resolve_closure(
191191
tcx,
192192
closure_data.closure_def_id,
193-
closure_data.substs,
193+
closure_data.substs.as_closure(),
194194
trait_closure_kind,
195195
))
196196
}

src/librustc_typeck/collect.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
224224
if let hir::ExprKind::Closure(..) = expr.kind {
225225
let def_id = self.tcx.hir().local_def_id(expr.hir_id);
226226
self.tcx.ensure().generics_of(def_id);
227-
self.tcx.ensure().type_of(def_id);
228227
}
229228
intravisit::walk_expr(self, expr);
230229
}
@@ -1362,29 +1361,6 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13621361
}
13631362
}));
13641363

1365-
// provide junk type parameter defs - the only place that
1366-
// cares about anything but the length is instantiation,
1367-
// and we don't do that for closures.
1368-
if let Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(.., gen), .. }) = node {
1369-
let dummy_args = if gen.is_some() {
1370-
&["<resume_ty>", "<yield_ty>", "<return_ty>", "<witness>", "<upvars>"][..]
1371-
} else {
1372-
&["<closure_kind>", "<closure_signature>", "<upvars>"][..]
1373-
};
1374-
1375-
params.extend(dummy_args.iter().enumerate().map(|(i, &arg)| ty::GenericParamDef {
1376-
index: type_start + i as u32,
1377-
name: Symbol::intern(arg),
1378-
def_id,
1379-
pure_wrt_drop: false,
1380-
kind: ty::GenericParamDefKind::Type {
1381-
has_default: false,
1382-
object_lifetime_default: rl::Set1::Empty,
1383-
synthetic: None,
1384-
},
1385-
}));
1386-
}
1387-
13881364
let param_def_id_to_index = params.iter().map(|param| (param.def_id, param.index)).collect();
13891365

13901366
ty::Generics {

src/librustc_typeck/collect/type_of.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
177177

178178
Node::Field(field) => icx.to_ty(&field.ty),
179179

180-
Node::Expr(&Expr { kind: ExprKind::Closure(.., gen), .. }) => {
181-
let substs = InternalSubsts::identity_for_item(tcx, def_id);
182-
if let Some(movability) = gen {
183-
tcx.mk_generator(def_id, substs, movability)
184-
} else {
185-
tcx.mk_closure(def_id, substs)
186-
}
180+
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => {
181+
tcx.typeck_tables_of(def_id.expect_local()).node_type(hir_id)
187182
}
188183

189184
Node::AnonConst(_) => {

0 commit comments

Comments
 (0)