Skip to content

Commit

Permalink
metadata: only encode optimized MIR for closures when required
Browse files Browse the repository at this point in the history
The metadata encoder unconditionally encoded the optimized MIR for closures, including during check builds, whereas this is usually limited to cases of actual codegen.
  • Loading branch information
lqd committed Dec 29, 2020
1 parent 6b17a76 commit d390c92
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,8 +1519,20 @@ impl EncodeContext<'a, 'tcx> {
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
}
self.encode_generics(def_id.to_def_id());
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);

let mir = {
let generics = self.tcx.generics_of(def_id);
let needs_inline = (generics.requires_monomorphization(self.tcx)
|| self.tcx.codegen_fn_attrs(def_id).requests_inline())
&& !self.metadata_output_only();
let is_generator = ty.is_generator();
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
needs_inline || is_generator || always_encode_mir
};
if mir {
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
}
}

fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) {
Expand Down

0 comments on commit d390c92

Please sign in to comment.