diff options
| author | Maik Klein <maikklein@googlemail.com> | 2017-10-27 11:27:05 +0200 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-12-18 17:08:49 +0200 |
| commit | dfbb6e864091740608fb551fef7eabbd7567351c (patch) | |
| tree | 263b7f102f557979603ce9690303382f0805e823 | |
| parent | d3c4142880e525e7e222edf4f2707e1a72087f9b (diff) | |
| download | rust-dfbb6e864091740608fb551fef7eabbd7567351c.tar.gz rust-dfbb6e864091740608fb551fef7eabbd7567351c.zip | |
Move instance related methods from TyCtxt to Instance
| -rw-r--r-- | src/librustc/ty/instance.rs | 36 | ||||
| -rw-r--r-- | src/librustc_mir/monomorphize/item.rs | 2 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 1f505a07dab..5259e790e92 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -77,6 +77,42 @@ impl<'tcx> InstanceDef<'tcx> { pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> { 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> { diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index a81808d8afc..72efe23f77b 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -96,7 +96,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug { // If this function isn't inlined or otherwise has explicit // linkage, then we'll be creating a globally shared version. if self.explicit_linkage(tcx).is_some() || - !tcx.requires_local_instance(instance) + !instance.def.requires_local(tcx) { return InstantiationMode::GloballyShared { may_conflict: false } } |
