Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode optimized MIR of generators when emitting metadata #81003

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}