From f15e5c133efe472afb8ce2e2b7cc3762ecc8d97d Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 27 Mar 2018 22:53:30 +0100 Subject: [PATCH 1/3] Skip MIR optimisation for cargo check --- src/librustc_metadata/encoder.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 39de1ec852e..77e916305c5 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -28,7 +28,7 @@ use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName}; use rustc::ty::codec::{self as ty_codec, TyEncoder}; -use rustc::session::config::{self, CrateTypeProcMacro}; +use rustc::session::config::{self, CrateTypeProcMacro, OutputType}; use rustc::util::nodemap::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; @@ -833,6 +833,12 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> { } } + fn metadata_output_only(&self) -> bool { + // MIR optimisation can be skipped when we're just interested in the metadata. + self.tcx.sess.opts.output_types.keys().count() == 1 && + self.tcx.sess.opts.output_types.contains_key(&OutputType::Metadata) + } + fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> { debug!("IsolatedEncoder::encode_info_for_impl_item({:?})", def_id); let tcx = self.tcx; @@ -877,7 +883,8 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> { } else if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node { let generics = self.tcx.generics_of(def_id); let types = generics.parent_types as usize + generics.types.len(); - let needs_inline = types > 0 || tcx.trans_fn_attrs(def_id).requests_inline(); + let needs_inline = (types > 0 || tcx.trans_fn_attrs(def_id).requests_inline()) && + !self.metadata_output_only(); let is_const_fn = sig.constness == hir::Constness::Const; let ast = if is_const_fn { Some(body) } else { None }; let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir; @@ -1168,7 +1175,8 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) -> hir::ItemConst(..) => self.encode_optimized_mir(def_id), hir::ItemFn(_, _, constness, _, ref generics, _) => { let has_tps = generics.ty_params().next().is_some(); - let needs_inline = has_tps || tcx.trans_fn_attrs(def_id).requests_inline(); + let needs_inline = (has_tps || tcx.trans_fn_attrs(def_id).requests_inline()) && + !self.metadata_output_only(); let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir; if needs_inline || constness == hir::Constness::Const || always_encode_mir { self.encode_optimized_mir(def_id) From 8414520436699c5063e286f8a68c95f2e8383d35 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 28 Mar 2018 00:13:34 +0100 Subject: [PATCH 2/3] Add len() method to OutputTypes --- src/librustc/session/config.rs | 4 ++++ src/librustc_driver/driver.rs | 2 +- src/librustc_metadata/encoder.rs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 9a5e929d85f..365ad880c4b 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -246,6 +246,10 @@ pub fn values<'a>(&'a self) -> BTreeMapValuesIter<'a, OutputType, Option usize { + self.0.len() + } + // True if any of the output types require codegen or linking. pub fn should_trans(&self) -> bool { self.0.keys().any(|k| match *k { diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index a3115544f30..44fc819ebb7 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -168,7 +168,7 @@ macro_rules! controller_entry_point { write_out_deps(sess, &outputs, &output_paths); if sess.opts.output_types.contains_key(&OutputType::DepInfo) && - sess.opts.output_types.keys().count() == 1 { + sess.opts.output_types.len() == 1 { return Ok(()) } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 77e916305c5..3eefe68fb1f 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -835,7 +835,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> { fn metadata_output_only(&self) -> bool { // MIR optimisation can be skipped when we're just interested in the metadata. - self.tcx.sess.opts.output_types.keys().count() == 1 && + self.tcx.sess.opts.output_types.len() == 1 && self.tcx.sess.opts.output_types.contains_key(&OutputType::Metadata) } From 5576ce84cf13a32ebcf9a08366e3117da9832c84 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 9 Apr 2018 16:37:32 +0100 Subject: [PATCH 3/3] Take OutputType::DepInfo into account for metadata_output_only --- src/librustc_metadata/encoder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 3eefe68fb1f..767ab82aa34 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -28,7 +28,7 @@ use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName}; use rustc::ty::codec::{self as ty_codec, TyEncoder}; -use rustc::session::config::{self, CrateTypeProcMacro, OutputType}; +use rustc::session::config::{self, CrateTypeProcMacro}; use rustc::util::nodemap::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; @@ -835,8 +835,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> { fn metadata_output_only(&self) -> bool { // MIR optimisation can be skipped when we're just interested in the metadata. - self.tcx.sess.opts.output_types.len() == 1 && - self.tcx.sess.opts.output_types.contains_key(&OutputType::Metadata) + !self.tcx.sess.opts.output_types.should_trans() } fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {