Move instance related methods from TyCtxt to Instance

This commit is contained in:
Maik Klein 2017-10-27 11:27:05 +02:00 committed by Ariel Ben-Yehuda
parent d3c4142880
commit dfbb6e8640
2 changed files with 37 additions and 1 deletions

View File

@ -77,6 +77,42 @@ impl<'tcx> InstanceDef<'tcx> {
pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> { pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
tcx.get_attrs(self.def_id()) tcx.get_attrs(self.def_id())
} }
pub fn is_inline<'a>(
&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>
) -> bool {
use hir::map::DefPathData;
let def_id = match *self {
ty::InstanceDef::Item(def_id) => def_id,
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
_ => return true
};
match tcx.def_key(def_id).disambiguated_data.data {
DefPathData::StructCtor |
DefPathData::EnumVariant(..) |
DefPathData::ClosureExpr => true,
_ => false
}
}
pub fn requires_local<'a>(
&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>
) -> bool {
use syntax::attr::requests_inline;
if self.is_inline(tcx) {
return true
}
if let ty::InstanceDef::DropGlue(..) = *self {
// Drop glue wants to be instantiated at every translation
// unit, but without an #[inline] hint. We should make this
// available to normal end-users.
return true
}
requests_inline(&self.attrs(tcx)[..]) ||
tcx.is_const_fn(self.def_id())
}
} }
impl<'tcx> fmt::Display for Instance<'tcx> { impl<'tcx> fmt::Display for Instance<'tcx> {

View File

@ -96,7 +96,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
// If this function isn't inlined or otherwise has explicit // If this function isn't inlined or otherwise has explicit
// linkage, then we'll be creating a globally shared version. // linkage, then we'll be creating a globally shared version.
if self.explicit_linkage(tcx).is_some() || if self.explicit_linkage(tcx).is_some() ||
!tcx.requires_local_instance(instance) !instance.def.requires_local(tcx)
{ {
return InstantiationMode::GloballyShared { may_conflict: false } return InstantiationMode::GloballyShared { may_conflict: false }
} }