Auto merge of #81003 - tmiasko:generator-layout, r=oli-obk

Encode optimized MIR of generators when emitting metadata
This commit is contained in:
bors 2021-01-14 11:58:17 +00:00
commit 7bb163095d
3 changed files with 38 additions and 1 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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() {}