Skip to content

Commit f15e5c1

Browse files
committed
Skip MIR optimisation for cargo check
1 parent ab8b961 commit f15e5c1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/librustc_metadata/encoder.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc::traits::specialization_graph;
2828
use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName};
2929
use rustc::ty::codec::{self as ty_codec, TyEncoder};
3030

31-
use rustc::session::config::{self, CrateTypeProcMacro};
31+
use rustc::session::config::{self, CrateTypeProcMacro, OutputType};
3232
use rustc::util::nodemap::FxHashMap;
3333

3434
use rustc_data_structures::stable_hasher::StableHasher;
@@ -833,6 +833,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
833833
}
834834
}
835835

836+
fn metadata_output_only(&self) -> bool {
837+
// MIR optimisation can be skipped when we're just interested in the metadata.
838+
self.tcx.sess.opts.output_types.keys().count() == 1 &&
839+
self.tcx.sess.opts.output_types.contains_key(&OutputType::Metadata)
840+
}
841+
836842
fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
837843
debug!("IsolatedEncoder::encode_info_for_impl_item({:?})", def_id);
838844
let tcx = self.tcx;
@@ -877,7 +883,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
877883
} else if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
878884
let generics = self.tcx.generics_of(def_id);
879885
let types = generics.parent_types as usize + generics.types.len();
880-
let needs_inline = types > 0 || tcx.trans_fn_attrs(def_id).requests_inline();
886+
let needs_inline = (types > 0 || tcx.trans_fn_attrs(def_id).requests_inline()) &&
887+
!self.metadata_output_only();
881888
let is_const_fn = sig.constness == hir::Constness::Const;
882889
let ast = if is_const_fn { Some(body) } else { None };
883890
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
@@ -1168,7 +1175,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
11681175
hir::ItemConst(..) => self.encode_optimized_mir(def_id),
11691176
hir::ItemFn(_, _, constness, _, ref generics, _) => {
11701177
let has_tps = generics.ty_params().next().is_some();
1171-
let needs_inline = has_tps || tcx.trans_fn_attrs(def_id).requests_inline();
1178+
let needs_inline = (has_tps || tcx.trans_fn_attrs(def_id).requests_inline()) &&
1179+
!self.metadata_output_only();
11721180
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
11731181
if needs_inline || constness == hir::Constness::Const || always_encode_mir {
11741182
self.encode_optimized_mir(def_id)

0 commit comments

Comments
 (0)