Skip to content

Commit

Permalink
Encode optimized MIR of generators when emitting metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Jan 14, 2021
1 parent c7b0ddb commit ea4cbff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,10 @@ impl EncodeContext<'a, 'tcx> {
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
}
self.encode_generics(def_id.to_def_id());
let opt_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir || self.emit_codegen_mir;
let opt_mir = // FIXME: Optimized MIR is necessary to determine the layout of generators.
matches!(ty.kind(), ty::Generator(..))
|| self.tcx.sess.opts.debugging_opts.always_encode_mir
|| self.emit_codegen_mir;
if opt_mir {
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/generator/auxiliary/metadata-sufficient-for-layout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// compile-flags: --emit metadata
#![feature(generators, generator_trait)]

use std::marker::Unpin;
use std::ops::Generator;

pub fn g() -> impl Generator<(), Yield = (), Return = ()> {
|| {
yield;
}
}
23 changes: 23 additions & 0 deletions src/test/ui/generator/metadata-sufficient-for-layout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Check that the layout of a generator is available when auxiliary crate
// is compiled with --emit metadata.
//
// Regression test for #80998.
//
// aux-build:metadata-sufficient-for-layout.rs
// check-pass

#![feature(type_alias_impl_trait)]
#![feature(generator_trait)]

extern crate metadata_sufficient_for_layout;

use std::ops::Generator;

type F = impl Generator<(), Yield = (), Return = ()>;

// Static queries the layout of the generator.
static A: Option<F> = None;

fn f() -> F { metadata_sufficient_for_layout::g() }

fn main() {}

0 comments on commit ea4cbff

Please sign in to comment.