Skip to content

Commit d45a70c

Browse files
committed
Split CloneShim into CloneCopyShim, CloneStructuralShim, CloneNominalShim
1 parent 8bdb10d commit d45a70c

File tree

7 files changed

+58
-14
lines changed

7 files changed

+58
-14
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::CloneShim(def_id, t) => {
761+
ty::InstanceDef::CloneCopyShim(def_id, t) |
762+
ty::InstanceDef::CloneStructuralShim(def_id, t) |
763+
ty::InstanceDef::CloneNominalShim(def_id, t) => {
762764
def_id.hash_stable(hcx, hasher);
763765
t.hash_stable(hcx, hasher);
764766
}

src/librustc/ty/instance.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use ty::{self, Ty, TypeFoldable, Substs, TyCtxt};
1313
use ty::subst::Kind;
1414
use traits;
1515
use syntax::abi::Abi;
16+
use syntax::codemap::DUMMY_SP;
1617
use util::ppaux;
1718

1819
use std::fmt;
@@ -39,10 +40,22 @@ pub enum InstanceDef<'tcx> {
3940
ClosureOnceShim { call_once: DefId },
4041

4142
/// drop_in_place::<T>; None for empty drop glue.
43+
///
44+
/// The DefId is the DefId of drop_in_place
4245
DropGlue(DefId, Option<Ty<'tcx>>),
4346

44-
///`<T as Clone>::clone` shim.
45-
CloneShim(DefId, Ty<'tcx>),
47+
///`<T as Clone>::clone` shim for Copy types
48+
///
49+
/// The DefId is the DefId of the Clone::clone function
50+
CloneCopyShim(DefId, Ty<'tcx>),
51+
///`<T as Clone>::clone` shim for arrays and tuples
52+
///
53+
/// The DefId is the DefId of the Clone::clone function
54+
CloneStructuralShim(DefId, Ty<'tcx>),
55+
///`<T as Clone>::clone` shim for closures
56+
///
57+
/// The DefId is the DefId of the Clone::clone function
58+
CloneNominalShim(DefId, Ty<'tcx>),
4659
}
4760

4861
impl<'a, 'tcx> Instance<'tcx> {
@@ -65,7 +78,9 @@ impl<'tcx> InstanceDef<'tcx> {
6578
InstanceDef::Intrinsic(def_id, ) |
6679
InstanceDef::ClosureOnceShim { call_once: def_id } |
6780
InstanceDef::DropGlue(def_id, _) |
68-
InstanceDef::CloneShim(def_id, _) => def_id
81+
InstanceDef::CloneCopyShim(def_id, _) |
82+
InstanceDef::CloneStructuralShim(def_id, _) |
83+
InstanceDef::CloneNominalShim(def_id, _) => def_id
6984
}
7085
}
7186

@@ -131,7 +146,9 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
131146
InstanceDef::DropGlue(_, ty) => {
132147
write!(f, " - shim({:?})", ty)
133148
}
134-
InstanceDef::CloneShim(_, ty) => {
149+
InstanceDef::CloneCopyShim(_, ty) |
150+
InstanceDef::CloneStructuralShim(_, ty) |
151+
InstanceDef::CloneNominalShim(_, ty) => {
135152
write!(f, " - shim({:?})", ty)
136153
}
137154
}
@@ -291,7 +308,16 @@ fn resolve_associated_item<'a, 'tcx>(
291308
if let Some(_) = tcx.lang_items().clone_trait() {
292309
let name = tcx.item_name(def_id);
293310
let def = if name == "clone" {
294-
ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty())
311+
let self_ty = trait_ref.self_ty();
312+
match self_ty.sty {
313+
_ if !self_ty.moves_by_default(tcx, param_env, DUMMY_SP) => {
314+
ty::InstanceDef::CloneCopyShim(def_id, self_ty)
315+
}
316+
ty::TyArray(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
317+
ty::TyTuple(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
318+
ty::TyClosure(..) => ty::InstanceDef::CloneNominalShim(def_id, self_ty),
319+
_ => unreachable!("Type {:?} does not have clone shims", self_ty)
320+
}
295321
} else {
296322
ty::InstanceDef::Item(def_id)
297323
};

src/librustc/ty/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23512351
ty::InstanceDef::Virtual(..) |
23522352
ty::InstanceDef::ClosureOnceShim { .. } |
23532353
ty::InstanceDef::DropGlue(..) |
2354-
ty::InstanceDef::CloneShim(..) => {
2354+
ty::InstanceDef::CloneCopyShim(..) |
2355+
ty::InstanceDef::CloneStructuralShim(..) |
2356+
ty::InstanceDef::CloneNominalShim(..) => {
23552357
self.mir_shims(instance)
23562358
}
23572359
}

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
295295
}
296296
ty::InstanceDef::FnPtrShim(..) |
297297
ty::InstanceDef::DropGlue(..) |
298-
ty::InstanceDef::CloneShim(..) |
298+
ty::InstanceDef::CloneCopyShim(..) |
299+
ty::InstanceDef::CloneStructuralShim(..) |
300+
ty::InstanceDef::CloneNominalShim(..) |
299301
ty::InstanceDef::Item(_) => {
300302
// Push the stack frame, and potentially be entirely done if the call got hooked
301303
if M::eval_fn_call(self, instance, destination, args, span, sig)? {

src/librustc_mir/monomorphize/collector.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,9 @@ fn visit_instance_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
711711
ty::InstanceDef::ClosureOnceShim { .. } |
712712
ty::InstanceDef::Item(..) |
713713
ty::InstanceDef::FnPtrShim(..) |
714-
ty::InstanceDef::CloneShim(..) => {
714+
ty::InstanceDef::CloneCopyShim(..) |
715+
ty::InstanceDef::CloneStructuralShim(..) |
716+
ty::InstanceDef::CloneNominalShim(..) => {
715717
output.push(create_fn_mono_item(instance));
716718
}
717719
}
@@ -729,7 +731,9 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
729731
ty::InstanceDef::FnPtrShim(..) |
730732
ty::InstanceDef::DropGlue(..) |
731733
ty::InstanceDef::Intrinsic(_) |
732-
ty::InstanceDef::CloneShim(..) => return true
734+
ty::InstanceDef::CloneCopyShim(..) |
735+
ty::InstanceDef::CloneStructuralShim(..) |
736+
ty::InstanceDef::CloneNominalShim(..) => return true
733737
};
734738
match tcx.hir.get_if_local(def_id) {
735739
Some(hir_map::NodeForeignItem(..)) => {

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ pub trait CodegenUnitExt<'tcx> {
175175
InstanceDef::Virtual(..) |
176176
InstanceDef::ClosureOnceShim { .. } |
177177
InstanceDef::DropGlue(..) |
178-
InstanceDef::CloneShim(..) => {
178+
InstanceDef::CloneCopyShim(..) |
179+
InstanceDef::CloneStructuralShim(..) |
180+
InstanceDef::CloneNominalShim(..) => {
179181
None
180182
}
181183
}
@@ -376,7 +378,9 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
376378
InstanceDef::Intrinsic(..) |
377379
InstanceDef::ClosureOnceShim { .. } |
378380
InstanceDef::DropGlue(..) |
379-
InstanceDef::CloneShim(..) => {
381+
InstanceDef::CloneCopyShim(..) |
382+
InstanceDef::CloneStructuralShim(..) |
383+
InstanceDef::CloneNominalShim(..) => {
380384
Visibility::Hidden
381385
}
382386
};
@@ -619,7 +623,9 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
619623
ty::InstanceDef::Intrinsic(..) |
620624
ty::InstanceDef::DropGlue(..) |
621625
ty::InstanceDef::Virtual(..) |
622-
ty::InstanceDef::CloneShim(..) => return None
626+
ty::InstanceDef::CloneCopyShim(..) |
627+
ty::InstanceDef::CloneStructuralShim(..) |
628+
ty::InstanceDef::CloneNominalShim(..) => return None
623629
};
624630

625631
// If this is a method, we want to put it into the same module as

src/librustc_mir/shim.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ 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::CloneShim(def_id, ty) => {
102+
ty::InstanceDef::CloneCopyShim(def_id, ty) |
103+
ty::InstanceDef::CloneNominalShim(def_id, ty) |
104+
ty::InstanceDef::CloneStructuralShim(def_id, ty) => {
103105
build_clone_shim(tcx, def_id, ty)
104106
}
105107
ty::InstanceDef::Intrinsic(_) => {

0 commit comments

Comments
 (0)