Skip to content

Commit

Permalink
Pass down the self def id instead of the type
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 8, 2018
1 parent 9898cff commit 2c33d2f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,11 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::InstanceDef<'gcx> {
ty::InstanceDef::CloneCopyShim(def_id) => {
def_id.hash_stable(hcx, hasher);
}
ty::InstanceDef::CloneStructuralShim(def_id, t) |
ty::InstanceDef::CloneNominalShim(def_id, t) => {
ty::InstanceDef::CloneNominalShim { clone, ty } => {
clone.hash_stable(hcx, hasher);
ty.hash_stable(hcx, hasher);
}
ty::InstanceDef::CloneStructuralShim(def_id, t) => {
def_id.hash_stable(hcx, hasher);
t.hash_stable(hcx, hasher);
}
Expand Down
28 changes: 19 additions & 9 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ pub enum InstanceDef<'tcx> {
/// The DefId is the DefId of the Clone::clone function
CloneStructuralShim(DefId, Ty<'tcx>),
///`<T as Clone>::clone` shim for closures
///
/// The DefId is the DefId of the Clone::clone function
CloneNominalShim(DefId, Ty<'tcx>),
CloneNominalShim {
/// The DefId of the Clone::clone trait method def
clone: DefId,
/// The DefId of the self type
ty: DefId
},
}

impl<'a, 'tcx> Instance<'tcx> {
Expand All @@ -80,7 +83,7 @@ impl<'tcx> InstanceDef<'tcx> {
InstanceDef::DropGlue(def_id, _) |
InstanceDef::CloneCopyShim(def_id) |
InstanceDef::CloneStructuralShim(def_id, _) |
InstanceDef::CloneNominalShim(def_id, _) => def_id
InstanceDef::CloneNominalShim{ clone: def_id, ..} => def_id
}
}

Expand Down Expand Up @@ -146,11 +149,11 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
InstanceDef::DropGlue(_, ty) => {
write!(f, " - shim({:?})", ty)
}
InstanceDef::CloneCopyShim(def) => {
InstanceDef::CloneCopyShim(def) |
InstanceDef::CloneNominalShim { ty: def, ..} => {
write!(f, " - shim({:?})", def)
}
InstanceDef::CloneStructuralShim(_, ty) |
InstanceDef::CloneNominalShim(_, ty) => {
InstanceDef::CloneStructuralShim(_, ty) => {
write!(f, " - shim({:?})", ty)
}
}
Expand Down Expand Up @@ -308,6 +311,7 @@ fn resolve_associated_item<'a, 'tcx>(
}
traits::VtableBuiltin(..) => {
if let Some(_) = tcx.lang_items().clone_trait() {
let mut substs = rcvr_substs;
let name = tcx.item_name(def_id);
let def = if name == "clone" {
let self_ty = trait_ref.self_ty();
Expand All @@ -317,15 +321,21 @@ fn resolve_associated_item<'a, 'tcx>(
}
ty::TyArray(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
ty::TyTuple(..) => ty::InstanceDef::CloneStructuralShim(def_id, self_ty),
ty::TyClosure(..) => ty::InstanceDef::CloneNominalShim(def_id, self_ty),
ty::TyClosure(ty_did, closure_substs) => {
substs = closure_substs.substs;
ty::InstanceDef::CloneNominalShim {
clone: def_id,
ty: ty_did
}
}
_ => unreachable!("Type {:?} does not have clone shims", self_ty)
}
} else {
ty::InstanceDef::Item(def_id)
};
Some(Instance {
def,
substs: rcvr_substs
substs
})
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
ty::InstanceDef::DropGlue(..) |
ty::InstanceDef::CloneCopyShim(..) |
ty::InstanceDef::CloneStructuralShim(..) |
ty::InstanceDef::CloneNominalShim(..) => {
ty::InstanceDef::CloneNominalShim { .. } => {
self.mir_shims(instance)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
ty::InstanceDef::DropGlue(..) |
ty::InstanceDef::CloneCopyShim(..) |
ty::InstanceDef::CloneStructuralShim(..) |
ty::InstanceDef::CloneNominalShim(..) |
ty::InstanceDef::CloneNominalShim { .. } |
ty::InstanceDef::Item(_) => {
// Push the stack frame, and potentially be entirely done if the call got hooked
if M::eval_fn_call(self, instance, destination, args, span, sig)? {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ fn visit_instance_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty::InstanceDef::FnPtrShim(..) |
ty::InstanceDef::CloneCopyShim(..) |
ty::InstanceDef::CloneStructuralShim(..) |
ty::InstanceDef::CloneNominalShim(..) => {
ty::InstanceDef::CloneNominalShim { .. } => {
output.push(create_fn_mono_item(instance));
}
}
Expand All @@ -733,7 +733,7 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
ty::InstanceDef::Intrinsic(_) |
ty::InstanceDef::CloneCopyShim(..) |
ty::InstanceDef::CloneStructuralShim(..) |
ty::InstanceDef::CloneNominalShim(..) => return true
ty::InstanceDef::CloneNominalShim { .. } => return true
};
match tcx.hir.get_if_local(def_id) {
Some(hir_map::NodeForeignItem(..)) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/monomorphize/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub trait CodegenUnitExt<'tcx> {
InstanceDef::DropGlue(..) |
InstanceDef::CloneCopyShim(..) |
InstanceDef::CloneStructuralShim(..) |
InstanceDef::CloneNominalShim(..) => {
InstanceDef::CloneNominalShim { .. } => {
None
}
}
Expand Down Expand Up @@ -380,7 +380,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
InstanceDef::DropGlue(..) |
InstanceDef::CloneCopyShim(..) |
InstanceDef::CloneStructuralShim(..) |
InstanceDef::CloneNominalShim(..) => {
InstanceDef::CloneNominalShim { .. } => {
Visibility::Hidden
}
};
Expand Down Expand Up @@ -625,7 +625,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty::InstanceDef::Virtual(..) |
ty::InstanceDef::CloneCopyShim(..) |
ty::InstanceDef::CloneStructuralShim(..) |
ty::InstanceDef::CloneNominalShim(..) => return None
ty::InstanceDef::CloneNominalShim { .. } => return None
};

// If this is a method, we want to put it into the same module as
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
builder.copy_shim();
builder.into_mir()
}
ty::InstanceDef::CloneNominalShim(def_id, ty) |
ty::InstanceDef::CloneNominalShim { clone, ty } => {
let ty = tcx.type_of(ty);
build_clone_shim(tcx, clone, ty)
}
ty::InstanceDef::CloneStructuralShim(def_id, ty) => {
build_clone_shim(tcx, def_id, ty)
}
Expand Down

0 comments on commit 2c33d2f

Please sign in to comment.