Skip to content

Commit

Permalink
Remove ty from CloneCopyShim so that it creates a single shim for all…
Browse files Browse the repository at this point in the history
… monomorphizations
  • Loading branch information
Manishearth committed Feb 8, 2018
1 parent d45a70c commit 9898cff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,9 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::InstanceDef<'gcx> {
def_id.hash_stable(hcx, hasher);
t.hash_stable(hcx, hasher);
}
ty::InstanceDef::CloneCopyShim(def_id, t) |
ty::InstanceDef::CloneCopyShim(def_id) => {
def_id.hash_stable(hcx, hasher);
}
ty::InstanceDef::CloneStructuralShim(def_id, t) |
ty::InstanceDef::CloneNominalShim(def_id, t) => {
def_id.hash_stable(hcx, hasher);
Expand Down
10 changes: 6 additions & 4 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum InstanceDef<'tcx> {
///`<T as Clone>::clone` shim for Copy types
///
/// The DefId is the DefId of the Clone::clone function
CloneCopyShim(DefId, Ty<'tcx>),
CloneCopyShim(DefId),
///`<T as Clone>::clone` shim for arrays and tuples
///
/// The DefId is the DefId of the Clone::clone function
Expand Down Expand Up @@ -78,7 +78,7 @@ impl<'tcx> InstanceDef<'tcx> {
InstanceDef::Intrinsic(def_id, ) |
InstanceDef::ClosureOnceShim { call_once: def_id } |
InstanceDef::DropGlue(def_id, _) |
InstanceDef::CloneCopyShim(def_id, _) |
InstanceDef::CloneCopyShim(def_id) |
InstanceDef::CloneStructuralShim(def_id, _) |
InstanceDef::CloneNominalShim(def_id, _) => def_id
}
Expand Down Expand Up @@ -146,7 +146,9 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
InstanceDef::DropGlue(_, ty) => {
write!(f, " - shim({:?})", ty)
}
InstanceDef::CloneCopyShim(_, ty) |
InstanceDef::CloneCopyShim(def) => {
write!(f, " - shim({:?})", def)
}
InstanceDef::CloneStructuralShim(_, ty) |
InstanceDef::CloneNominalShim(_, ty) => {
write!(f, " - shim({:?})", ty)
Expand Down Expand Up @@ -311,7 +313,7 @@ fn resolve_associated_item<'a, 'tcx>(
let self_ty = trait_ref.self_ty();
match self_ty.sty {
_ if !self_ty.moves_by_default(tcx, param_env, DUMMY_SP) => {
ty::InstanceDef::CloneCopyShim(def_id, self_ty)
ty::InstanceDef::CloneCopyShim(def_id)
}
ty::TyArray(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
ty::TyTuple(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty::InstanceDef::DropGlue(def_id, ty) => {
build_drop_shim(tcx, def_id, ty)
}
ty::InstanceDef::CloneCopyShim(def_id, ty) |
ty::InstanceDef::CloneCopyShim(def_id) => {
let substs = Substs::identity_for_item(tcx, def_id);
let self_ty = substs.type_at(0);
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
builder.copy_shim();
builder.into_mir()
}
ty::InstanceDef::CloneNominalShim(def_id, ty) |
ty::InstanceDef::CloneStructuralShim(def_id, ty) => {
build_clone_shim(tcx, def_id, ty)
Expand Down Expand Up @@ -289,13 +295,11 @@ fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
debug!("build_clone_shim(def_id={:?})", def_id);

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

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

match self_ty.sty {
_ if is_copy => builder.copy_shim(),
ty::TyArray(ty, len) => {
let len = len.val.to_const_int().unwrap().to_u64().unwrap();
builder.array_shim(dest, src, ty, len)
Expand Down

0 comments on commit 9898cff

Please sign in to comment.