Skip to content

Commit d6a2dd9

Browse files
committed
Auto merge of #49433 - varkor:metadata-skip-mir-opt, r=michaelwoerister
Skip MIR encoding for cargo check Resolves #48662. r? @michaelwoerister
2 parents 532764c + 5576ce8 commit d6a2dd9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/librustc/session/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ impl OutputTypes {
246246
self.0.values()
247247
}
248248

249+
pub fn len(&self) -> usize {
250+
self.0.len()
251+
}
252+
249253
// True if any of the output types require codegen or linking.
250254
pub fn should_trans(&self) -> bool {
251255
self.0.keys().any(|k| match *k {

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub fn compile_input(trans: Box<TransCrate>,
168168

169169
write_out_deps(sess, &outputs, &output_paths);
170170
if sess.opts.output_types.contains_key(&OutputType::DepInfo) &&
171-
sess.opts.output_types.keys().count() == 1 {
171+
sess.opts.output_types.len() == 1 {
172172
return Ok(())
173173
}
174174

src/librustc_metadata/encoder.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,11 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
864864
}
865865
}
866866

867+
fn metadata_output_only(&self) -> bool {
868+
// MIR optimisation can be skipped when we're just interested in the metadata.
869+
!self.tcx.sess.opts.output_types.should_trans()
870+
}
871+
867872
fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
868873
debug!("IsolatedEncoder::encode_info_for_impl_item({:?})", def_id);
869874
let tcx = self.tcx;
@@ -908,7 +913,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
908913
} else if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
909914
let generics = self.tcx.generics_of(def_id);
910915
let types = generics.parent_types as usize + generics.types.len();
911-
let needs_inline = types > 0 || tcx.trans_fn_attrs(def_id).requests_inline();
916+
let needs_inline = (types > 0 || tcx.trans_fn_attrs(def_id).requests_inline()) &&
917+
!self.metadata_output_only();
912918
let is_const_fn = sig.constness == hir::Constness::Const;
913919
let ast = if is_const_fn { Some(body) } else { None };
914920
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
@@ -1199,7 +1205,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
11991205
hir::ItemConst(..) => self.encode_optimized_mir(def_id),
12001206
hir::ItemFn(_, _, constness, _, ref generics, _) => {
12011207
let has_tps = generics.ty_params().next().is_some();
1202-
let needs_inline = has_tps || tcx.trans_fn_attrs(def_id).requests_inline();
1208+
let needs_inline = (has_tps || tcx.trans_fn_attrs(def_id).requests_inline()) &&
1209+
!self.metadata_output_only();
12031210
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
12041211
if needs_inline || constness == hir::Constness::Const || always_encode_mir {
12051212
self.encode_optimized_mir(def_id)

0 commit comments

Comments
 (0)