Skip to content

Commit 9898cff

Browse files
committed
Remove ty from CloneCopyShim so that it creates a single shim for all monomorphizations
1 parent d45a70c commit 9898cff

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::InstanceDef<'gcx> {
758758
def_id.hash_stable(hcx, hasher);
759759
t.hash_stable(hcx, hasher);
760760
}
761-
ty::InstanceDef::CloneCopyShim(def_id, t) |
761+
ty::InstanceDef::CloneCopyShim(def_id) => {
762+
def_id.hash_stable(hcx, hasher);
763+
}
762764
ty::InstanceDef::CloneStructuralShim(def_id, t) |
763765
ty::InstanceDef::CloneNominalShim(def_id, t) => {
764766
def_id.hash_stable(hcx, hasher);

src/librustc/ty/instance.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum InstanceDef<'tcx> {
4747
///`<T as Clone>::clone` shim for Copy types
4848
///
4949
/// The DefId is the DefId of the Clone::clone function
50-
CloneCopyShim(DefId, Ty<'tcx>),
50+
CloneCopyShim(DefId),
5151
///`<T as Clone>::clone` shim for arrays and tuples
5252
///
5353
/// The DefId is the DefId of the Clone::clone function
@@ -78,7 +78,7 @@ impl<'tcx> InstanceDef<'tcx> {
7878
InstanceDef::Intrinsic(def_id, ) |
7979
InstanceDef::ClosureOnceShim { call_once: def_id } |
8080
InstanceDef::DropGlue(def_id, _) |
81-
InstanceDef::CloneCopyShim(def_id, _) |
81+
InstanceDef::CloneCopyShim(def_id) |
8282
InstanceDef::CloneStructuralShim(def_id, _) |
8383
InstanceDef::CloneNominalShim(def_id, _) => def_id
8484
}
@@ -146,7 +146,9 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
146146
InstanceDef::DropGlue(_, ty) => {
147147
write!(f, " - shim({:?})", ty)
148148
}
149-
InstanceDef::CloneCopyShim(_, ty) |
149+
InstanceDef::CloneCopyShim(def) => {
150+
write!(f, " - shim({:?})", def)
151+
}
150152
InstanceDef::CloneStructuralShim(_, ty) |
151153
InstanceDef::CloneNominalShim(_, ty) => {
152154
write!(f, " - shim({:?})", ty)
@@ -311,7 +313,7 @@ fn resolve_associated_item<'a, 'tcx>(
311313
let self_ty = trait_ref.self_ty();
312314
match self_ty.sty {
313315
_ if !self_ty.moves_by_default(tcx, param_env, DUMMY_SP) => {
314-
ty::InstanceDef::CloneCopyShim(def_id, self_ty)
316+
ty::InstanceDef::CloneCopyShim(def_id)
315317
}
316318
ty::TyArray(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
317319
ty::TyTuple(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),

src/librustc_mir/shim.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9999
ty::InstanceDef::DropGlue(def_id, ty) => {
100100
build_drop_shim(tcx, def_id, ty)
101101
}
102-
ty::InstanceDef::CloneCopyShim(def_id, ty) |
102+
ty::InstanceDef::CloneCopyShim(def_id) => {
103+
let substs = Substs::identity_for_item(tcx, def_id);
104+
let self_ty = substs.type_at(0);
105+
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
106+
builder.copy_shim();
107+
builder.into_mir()
108+
}
103109
ty::InstanceDef::CloneNominalShim(def_id, ty) |
104110
ty::InstanceDef::CloneStructuralShim(def_id, ty) => {
105111
build_clone_shim(tcx, def_id, ty)
@@ -289,13 +295,11 @@ fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
289295
debug!("build_clone_shim(def_id={:?})", def_id);
290296

291297
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
292-
let is_copy = !self_ty.moves_by_default(tcx, tcx.param_env(def_id), builder.span);
293298

294299
let dest = Place::Local(RETURN_PLACE);
295300
let src = Place::Local(Local::new(1+0)).deref();
296301

297302
match self_ty.sty {
298-
_ if is_copy => builder.copy_shim(),
299303
ty::TyArray(ty, len) => {
300304
let len = len.val.to_const_int().unwrap().to_u64().unwrap();
301305
builder.array_shim(dest, src, ty, len)

0 commit comments

Comments
 (0)