summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_metadata
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_metadata')
-rw-r--r--compiler/rustc_metadata/Cargo.toml20
-rw-r--r--compiler/rustc_metadata/messages.ftl3
-rw-r--r--compiler/rustc_metadata/src/creader.rs5
-rw-r--r--compiler/rustc_metadata/src/dependency_format.rs7
-rw-r--r--compiler/rustc_metadata/src/errors.rs12
-rw-r--r--compiler/rustc_metadata/src/lib.rs9
-rw-r--r--compiler/rustc_metadata/src/locator.rs46
-rw-r--r--compiler/rustc_metadata/src/native_libs.rs4
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs21
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs5
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs107
-rw-r--r--compiler/rustc_metadata/src/rmeta/mod.rs5
-rw-r--r--compiler/rustc_metadata/src/rmeta/table.rs26
13 files changed, 141 insertions, 129 deletions
diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml
index 840111c31..a4012592c 100644
--- a/compiler/rustc_metadata/Cargo.toml
+++ b/compiler/rustc_metadata/Cargo.toml
@@ -3,30 +3,30 @@ name = "rustc_metadata"
version = "0.0.0"
edition = "2021"
-[lib]
-
[dependencies]
+# tidy-alphabetical-start
bitflags = "1.2.1"
libloading = "0.7.1"
odht = { version = "0.3.1", features = ["nightly"] }
-snap = "1"
-tracing = "0.1"
-tempfile = "3.2"
-rustc_middle = { path = "../rustc_middle" }
+rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
+rustc_expand = { path = "../rustc_expand" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_fs_util = { path = "../rustc_fs_util" }
rustc_hir = { path = "../rustc_hir" }
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
-rustc_target = { path = "../rustc_target" }
rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" }
+rustc_middle = { path = "../rustc_middle" }
rustc_serialize = { path = "../rustc_serialize" }
-rustc_ast = { path = "../rustc_ast" }
-rustc_expand = { path = "../rustc_expand" }
-rustc_span = { path = "../rustc_span" }
rustc_session = { path = "../rustc_session" }
+rustc_span = { path = "../rustc_span" }
+rustc_target = { path = "../rustc_target" }
rustc_type_ir = { path = "../rustc_type_ir" }
+snap = "1"
+tempfile = "3.2"
+tracing = "0.1"
+# tidy-alphabetical-end
diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl
index 633004fdd..d1815717e 100644
--- a/compiler/rustc_metadata/messages.ftl
+++ b/compiler/rustc_metadata/messages.ftl
@@ -196,9 +196,6 @@ metadata_newer_crate_version =
metadata_no_crate_with_triple =
couldn't find crate `{$crate_name}` with expected target triple {$locator_triple}{$add_info}
-metadata_no_dylib_plugin =
- plugin `{$crate_name}` only found in rlib format, but must be available in dylib format
-
metadata_no_link_mod_override =
overriding linking modifiers from command line is not supported
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs
index 692214753..14bbe65d5 100644
--- a/compiler/rustc_metadata/src/creader.rs
+++ b/compiler/rustc_metadata/src/creader.rs
@@ -10,6 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard};
use rustc_expand::base::SyntaxExtension;
+use rustc_fs_util::try_canonicalize;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
use rustc_hir::definitions::Definitions;
use rustc_index::IndexVec;
@@ -31,7 +32,7 @@ use std::error::Error;
use std::ops::Fn;
use std::path::Path;
use std::time::Duration;
-use std::{cmp, env, iter};
+use std::{cmp, iter};
pub struct CStore {
metadata_loader: Box<MetadataLoaderDyn>,
@@ -677,7 +678,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
stable_crate_id: StableCrateId,
) -> Result<&'static [ProcMacro], CrateError> {
// Make sure the path contains a / or the linker will search for it.
- let path = env::current_dir().unwrap().join(path);
+ let path = try_canonicalize(path).unwrap();
let lib = load_dylib(&path, 5).map_err(|err| CrateError::DlOpen(err))?;
let sym_name = self.sess.generate_proc_macro_decls_symbol(stable_crate_id);
diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs
index 783d35ac7..cb057cd39 100644
--- a/compiler/rustc_metadata/src/dependency_format.rs
+++ b/compiler/rustc_metadata/src/dependency_format.rs
@@ -396,11 +396,14 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
continue;
}
- if let Some(found_strategy) = tcx.required_panic_strategy(cnum) && desired_strategy != found_strategy {
+ if let Some(found_strategy) = tcx.required_panic_strategy(cnum)
+ && desired_strategy != found_strategy
+ {
sess.emit_err(RequiredPanicStrategy {
crate_name: tcx.crate_name(cnum),
found_strategy,
- desired_strategy});
+ desired_strategy,
+ });
}
let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs
index 91220629f..70daee291 100644
--- a/compiler/rustc_metadata/src/errors.rs
+++ b/compiler/rustc_metadata/src/errors.rs
@@ -419,7 +419,9 @@ impl<'a> MissingNativeLibrary<'a> {
// if it looks like the user has provided a complete filename rather just the bare lib name,
// then provide a note that they might want to try trimming the name
let suggested_name = if !verbatim {
- if let Some(libname) = libname.strip_prefix("lib") && let Some(libname) = libname.strip_suffix(".a") {
+ if let Some(libname) = libname.strip_prefix("lib")
+ && let Some(libname) = libname.strip_suffix(".a")
+ {
// this is a unix style filename so trim prefix & suffix
Some(libname)
} else if let Some(libname) = libname.strip_suffix(".lib") {
@@ -681,14 +683,6 @@ impl IntoDiagnostic<'_> for CannotFindCrate {
}
#[derive(Diagnostic)]
-#[diag(metadata_no_dylib_plugin, code = "E0457")]
-pub struct NoDylibPlugin {
- #[primary_span]
- pub span: Span,
- pub crate_name: Symbol,
-}
-
-#[derive(Diagnostic)]
#[diag(metadata_crate_location_unknown_type)]
pub struct CrateLocationUnknownType<'a> {
#[primary_span]
diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs
index fa77b36c4..b06b4fb87 100644
--- a/compiler/rustc_metadata/src/lib.rs
+++ b/compiler/rustc_metadata/src/lib.rs
@@ -1,9 +1,14 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
+#![cfg_attr(not(bootstrap), doc(rust_logo))]
+#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
+#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(decl_macro)]
#![feature(extract_if)]
-#![feature(generators)]
-#![feature(iter_from_generator)]
+#![cfg_attr(bootstrap, feature(generators))]
+#![cfg_attr(not(bootstrap), feature(coroutines))]
+#![feature(iter_from_coroutine)]
#![feature(let_chains)]
+#![feature(if_let_guard)]
#![feature(proc_macro_internals)]
#![feature(macro_metavar_expr)]
#![feature(min_specialization)]
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index 3062939d8..3a99ddc1b 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -220,7 +220,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::slice_owned;
use rustc_data_structures::svh::Svh;
-use rustc_errors::{DiagnosticArgValue, FatalError, IntoDiagnosticArg};
+use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_fs_util::try_canonicalize;
use rustc_session::config;
use rustc_session::cstore::{CrateSource, MetadataLoader};
@@ -857,46 +857,6 @@ fn get_metadata_section<'p>(
}
}
-/// Look for a plugin registrar. Returns its library path and crate disambiguator.
-pub fn find_plugin_registrar(
- sess: &Session,
- metadata_loader: &dyn MetadataLoader,
- span: Span,
- name: Symbol,
-) -> PathBuf {
- find_plugin_registrar_impl(sess, metadata_loader, name).unwrap_or_else(|err| {
- // `core` is always available if we got as far as loading plugins.
- err.report(sess, span, false);
- FatalError.raise()
- })
-}
-
-fn find_plugin_registrar_impl<'a>(
- sess: &'a Session,
- metadata_loader: &dyn MetadataLoader,
- name: Symbol,
-) -> Result<PathBuf, CrateError> {
- info!("find plugin registrar `{}`", name);
- let mut locator = CrateLocator::new(
- sess,
- metadata_loader,
- name,
- false, // is_rlib
- None, // hash
- None, // extra_filename
- true, // is_host
- PathKind::Crate,
- );
-
- match locator.maybe_load_library_crate()? {
- Some(library) => match library.source.dylib {
- Some(dylib) => Ok(dylib.0),
- None => Err(CrateError::NonDylibPlugin(name)),
- },
- None => Err(locator.into_error(None)),
- }
-}
-
/// A diagnostic function for dumping crate metadata to an output stream.
pub fn list_file_metadata(
target: &Target,
@@ -964,7 +924,6 @@ pub(crate) enum CrateError {
DlOpen(String),
DlSym(String),
LocatorCombined(Box<CombinedLocatorError>),
- NonDylibPlugin(Symbol),
NotFound(Symbol),
}
@@ -1134,9 +1093,6 @@ impl CrateError {
});
}
}
- CrateError::NonDylibPlugin(crate_name) => {
- sess.emit_err(errors::NoDylibPlugin { span, crate_name });
- }
CrateError::NotFound(crate_name) => {
sess.emit_err(errors::CannotFindCrate {
span,
diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index 098c411c8..ab135851b 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -383,7 +383,9 @@ impl<'tcx> Collector<'tcx> {
// First, check for errors
let mut renames = FxHashSet::default();
for lib in &self.tcx.sess.opts.libs {
- if let NativeLibKind::Framework { .. } = lib.kind && !self.tcx.sess.target.is_like_osx {
+ if let NativeLibKind::Framework { .. } = lib.kind
+ && !self.tcx.sess.target.is_like_osx
+ {
// Cannot check this when parsing options because the target is not yet available.
self.tcx.sess.emit_err(errors::LibFrameworkApple);
}
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index b189e79df..354023cea 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -1239,7 +1239,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
id: DefIndex,
sess: &'a Session,
) -> impl Iterator<Item = ModChild> + 'a {
- iter::from_generator(move || {
+ iter::from_coroutine(move || {
if let Some(data) = &self.root.proc_macro_data {
// If we are loading as a proc macro, we want to return
// the view of this crate as a proc macro crate.
@@ -1273,6 +1273,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
self.root.tables.optimized_mir.get(self, id).is_some()
}
+ fn cross_crate_inlinable(self, id: DefIndex) -> bool {
+ self.root.tables.cross_crate_inlinable.get(self, id).unwrap_or(false)
+ }
+
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
self.root
.tables
@@ -1692,17 +1696,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
// `try_to_translate_virtual_to_real` don't have to worry about how the
// compiler is bootstrapped.
if let Some(virtual_dir) = &sess.opts.unstable_opts.simulate_remapped_rust_src_base
- && let Some(real_dir) = &sess.opts.real_rust_source_base_dir
- && let rustc_span::FileName::Real(ref mut old_name) = name {
+ && let Some(real_dir) = &sess.opts.real_rust_source_base_dir
+ && let rustc_span::FileName::Real(ref mut old_name) = name
+ {
let relative_path = match old_name {
- rustc_span::RealFileName::LocalPath(local) => local.strip_prefix(real_dir).ok(),
+ rustc_span::RealFileName::LocalPath(local) => {
+ local.strip_prefix(real_dir).ok()
+ }
rustc_span::RealFileName::Remapped { virtual_name, .. } => {
- option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").and_then(|virtual_dir| virtual_name.strip_prefix(virtual_dir).ok())
+ option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR")
+ .and_then(|virtual_dir| virtual_name.strip_prefix(virtual_dir).ok())
}
};
debug!(?relative_path, ?virtual_dir, "simulate_remapped_rust_src_base");
for subdir in ["library", "compiler"] {
- if let Some(rest) = relative_path.and_then(|p| p.strip_prefix(subdir).ok()) {
+ if let Some(rest) = relative_path.and_then(|p| p.strip_prefix(subdir).ok())
+ {
*old_name = rustc_span::RealFileName::Remapped {
local_path: None, // FIXME: maybe we should preserve this?
virtual_name: virtual_dir.join(subdir).join(rest),
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
index f27eee0d7..595d816e9 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
@@ -221,7 +221,7 @@ provide! { tcx, def_id, other, cdata,
optimized_mir => { table }
mir_for_ctfe => { table }
closure_saved_names_of_captured_variables => { table }
- mir_generator_witnesses => { table }
+ mir_coroutine_witnesses => { table }
promoted_mir => { table }
def_span => { table }
def_ident_span => { table }
@@ -241,7 +241,7 @@ provide! { tcx, def_id, other, cdata,
rendered_const => { table }
asyncness => { table_direct }
fn_arg_names => { table }
- generator_kind => { table }
+ coroutine_kind => { table }
trait_def => { table }
deduced_param_attrs => { table }
is_type_alias_impl_trait => {
@@ -287,6 +287,7 @@ provide! { tcx, def_id, other, cdata,
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
+ cross_crate_inlinable => { cdata.cross_crate_inlinable(def_id.index) }
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
is_private_dep => {
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index a4ba94327..2042863d1 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -525,9 +525,17 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// the remapped version -- as is necessary for reproducible builds.
let mut source_file = match source_file.name {
FileName::Real(ref original_file_name) => {
- let adapted_file_name = source_map
- .path_mapping()
- .to_embeddable_absolute_path(original_file_name.clone(), working_directory);
+ let adapted_file_name = if self.tcx.sess.should_prefer_remapped_for_codegen() {
+ source_map.path_mapping().to_embeddable_absolute_path(
+ original_file_name.clone(),
+ working_directory,
+ )
+ } else {
+ source_map.path_mapping().to_local_embeddable_absolute_path(
+ original_file_name.clone(),
+ working_directory,
+ )
+ };
if adapted_file_name != *original_file_name {
let mut adapted: SourceFile = (**source_file).clone();
@@ -848,7 +856,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
| DefKind::Field
| DefKind::Impl { .. }
| DefKind::Closure
- | DefKind::Generator => true,
+ | DefKind::Coroutine => true,
DefKind::ForeignMod | DefKind::GlobalAsm => false,
}
}
@@ -889,7 +897,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
| DefKind::OpaqueTy
| DefKind::LifetimeParam
| DefKind::GlobalAsm
- | DefKind::Generator => false,
+ | DefKind::Coroutine => false,
}
}
@@ -925,7 +933,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Closure
- | DefKind::Generator => false,
+ | DefKind::Coroutine => false,
}
}
@@ -960,7 +968,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
| DefKind::GlobalAsm
| DefKind::Impl { .. }
| DefKind::Closure
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ExternCrate => false,
}
}
@@ -996,7 +1004,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
| DefKind::InlineConst
| DefKind::GlobalAsm
| DefKind::Closure
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ExternCrate => false,
}
}
@@ -1046,14 +1054,14 @@ fn should_encode_mir(
|| (tcx.sess.opts.output_types.should_codegen()
&& reachable_set.contains(&def_id)
&& (generics.requires_monomorphization(tcx)
- || tcx.codegen_fn_attrs(def_id).requests_inline()));
+ || tcx.cross_crate_inlinable(def_id)));
// The function has a `const` modifier or is in a `#[const_trait]`.
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
|| tcx.is_const_default_method(def_id.to_def_id());
(is_const_fn, opt)
}
- // Generators require optimized MIR to compute layout.
- DefKind::Generator => (false, true),
+ // Coroutines require optimized MIR to compute layout.
+ DefKind::Coroutine => (false, true),
// The others don't have MIR.
_ => (false, false),
}
@@ -1089,7 +1097,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
| DefKind::InlineConst
| DefKind::GlobalAsm
| DefKind::Closure
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ExternCrate => false,
DefKind::TyAlias => tcx.type_alias_is_lazy(def_id),
}
@@ -1119,7 +1127,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
| DefKind::Field
| DefKind::TyParam
| DefKind::Closure
- | DefKind::Generator => true,
+ | DefKind::Coroutine => true,
DefKind::Mod
| DefKind::ForeignMod
| DefKind::ConstParam
@@ -1148,14 +1156,15 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
| DefKind::AssocFn
| DefKind::AssocConst
| DefKind::Closure
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::AnonConst
| DefKind::InlineConst => true,
DefKind::OpaqueTy => {
let origin = tcx.opaque_type_origin(def_id);
- if let hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id) = origin
+ if let hir::OpaqueTyOrigin::FnReturn(fn_def_id)
+ | hir::OpaqueTyOrigin::AsyncFn(fn_def_id) = origin
&& let hir::Node::TraitItem(trait_item) = tcx.hir().get_by_def_id(fn_def_id)
&& let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
{
@@ -1208,7 +1217,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
| DefKind::Impl { .. }
| DefKind::AssocConst
| DefKind::Closure
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::AnonConst
| DefKind::InlineConst
@@ -1247,7 +1256,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
| DefKind::OpaqueTy
| DefKind::Impl { of_trait: false }
| DefKind::ForeignTy
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::InlineConst
| DefKind::AssocTy
@@ -1282,7 +1291,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
| DefKind::Impl { .. }
| DefKind::AssocFn
| DefKind::Closure
- | DefKind::Generator
+ | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::AssocTy
| DefKind::TyParam
@@ -1357,7 +1366,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if should_encode_expn_that_defined(def_kind) {
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
}
- if should_encode_span(def_kind) && let Some(ident_span) = tcx.def_ident_span(def_id) {
+ if should_encode_span(def_kind)
+ && let Some(ident_span) = tcx.def_ident_span(def_id)
+ {
record!(self.tables.def_ident_span[def_id] <- ident_span);
}
if def_kind.has_codegen_attrs() {
@@ -1435,9 +1446,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.encode_info_for_assoc_item(def_id);
}
}
- if let DefKind::Generator = def_kind {
- let data = self.tcx.generator_kind(def_id).unwrap();
- record!(self.tables.generator_kind[def_id] <- data);
+ if let DefKind::Coroutine = def_kind {
+ let data = self.tcx.coroutine_kind(def_id).unwrap();
+ record!(self.tables.coroutine_kind[def_id] <- data);
}
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
self.encode_info_for_adt(local_id);
@@ -1612,13 +1623,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EntryBuilder::encode_mir({:?})", def_id);
if encode_opt {
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
+ self.tables
+ .cross_crate_inlinable
+ .set(def_id.to_def_id().index, Some(self.tcx.cross_crate_inlinable(def_id)));
record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
<- tcx.closure_saved_names_of_captured_variables(def_id));
- if let DefKind::Generator = self.tcx.def_kind(def_id)
- && let Some(witnesses) = tcx.mir_generator_witnesses(def_id)
+ if let DefKind::Coroutine = self.tcx.def_kind(def_id)
+ && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
{
- record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses);
+ record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
}
}
if encode_const {
@@ -1642,10 +1656,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
- if let DefKind::Generator = self.tcx.def_kind(def_id)
- && let Some(witnesses) = tcx.mir_generator_witnesses(def_id)
+ if let DefKind::Coroutine = self.tcx.def_kind(def_id)
+ && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
{
- record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses);
+ record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
}
let instance = ty::InstanceDef::Item(def_id.to_def_id());
@@ -1958,8 +1972,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.impl_trait_ref[def_id] <- trait_ref);
let trait_ref = trait_ref.instantiate_identity();
- let simplified_self_ty =
- fast_reject::simplify_type(self.tcx, trait_ref.self_ty(), TreatParams::AsCandidateKey);
+ let simplified_self_ty = fast_reject::simplify_type(
+ self.tcx,
+ trait_ref.self_ty(),
+ TreatParams::AsCandidateKey,
+ );
fx_hash_map
.entry(trait_ref.def_id)
.or_default()
@@ -2369,30 +2386,32 @@ pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: hir::BodyId) -> String {
}
}
- let classification = classify(value);
-
- if classification == Literal
- && !value.span.from_expansion()
- && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) {
- // For literals, we avoid invoking the pretty-printer and use the source snippet instead to
- // preserve certain stylistic choices the user likely made for the sake legibility like
+ match classify(value) {
+ // For non-macro literals, we avoid invoking the pretty-printer and use the source snippet
+ // instead to preserve certain stylistic choices the user likely made for the sake of
+ // legibility, like:
//
// * hexadecimal notation
// * underscores
// * character escapes
//
// FIXME: This passes through `-/*spacer*/0` verbatim.
- snippet
- } else if classification == Simple {
+ Literal if !value.span.from_expansion()
+ && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) => {
+ snippet
+ }
+
// Otherwise we prefer pretty-printing to get rid of extraneous whitespace, comments and
// other formatting artifacts.
- id_to_string(&hir, body.hir_id)
- } else if tcx.def_kind(hir.body_owner_def_id(body).to_def_id()) == DefKind::AnonConst {
+ Literal | Simple => id_to_string(&hir, body.hir_id),
+
// FIXME: Omit the curly braces if the enclosing expression is an array literal
// with a repeated element (an `ExprKind::Repeat`) as in such case it
// would not actually need any disambiguation.
- "{ _ }".to_owned()
- } else {
- "_".to_owned()
+ Complex => if tcx.def_kind(hir.body_owner_def_id(body).to_def_id()) == DefKind::AnonConst {
+ "{ _ }".to_owned()
+ } else {
+ "_".to_owned()
+ }
}
}
diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs
index 42764af52..9ae5c0af0 100644
--- a/compiler/rustc_metadata/src/rmeta/mod.rs
+++ b/compiler/rustc_metadata/src/rmeta/mod.rs
@@ -427,8 +427,9 @@ define_tables! {
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
+ cross_crate_inlinable: Table<DefIndex, bool>,
closure_saved_names_of_captured_variables: Table<DefIndex, LazyValue<IndexVec<FieldIdx, Symbol>>>,
- mir_generator_witnesses: Table<DefIndex, LazyValue<mir::GeneratorLayout<'static>>>,
+ mir_coroutine_witnesses: Table<DefIndex, LazyValue<mir::CoroutineLayout<'static>>>,
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,
thir_abstract_const: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::Const<'static>>>>,
impl_parent: Table<DefIndex, RawDefId>,
@@ -441,7 +442,7 @@ define_tables! {
rendered_const: Table<DefIndex, LazyValue<String>>,
asyncness: Table<DefIndex, ty::Asyncness>,
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
- generator_kind: Table<DefIndex, LazyValue<hir::GeneratorKind>>,
+ coroutine_kind: Table<DefIndex, LazyValue<hir::CoroutineKind>>,
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
trait_item_def_id: Table<DefIndex, RawDefId>,
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs
index bb1320942..027994c40 100644
--- a/compiler/rustc_metadata/src/rmeta/table.rs
+++ b/compiler/rustc_metadata/src/rmeta/table.rs
@@ -167,7 +167,7 @@ fixed_size_enum! {
( Impl { of_trait: false } )
( Impl { of_trait: true } )
( Closure )
- ( Generator )
+ ( Coroutine )
( Static(ast::Mutability::Not) )
( Static(ast::Mutability::Mut) )
( Ctor(CtorOf::Struct, CtorKind::Fn) )
@@ -299,6 +299,30 @@ impl FixedSizeEncoding for bool {
}
}
+impl FixedSizeEncoding for Option<bool> {
+ type ByteArray = [u8; 1];
+
+ #[inline]
+ fn from_bytes(b: &[u8; 1]) -> Self {
+ match b[0] {
+ 0 => Some(false),
+ 1 => Some(true),
+ 2 => None,
+ _ => unreachable!(),
+ }
+ }
+
+ #[inline]
+ fn write_to_bytes(self, b: &mut [u8; 1]) {
+ debug_assert!(!self.is_default());
+ b[0] = match self {
+ Some(false) => 0,
+ Some(true) => 1,
+ None => 2,
+ };
+ }
+}
+
impl FixedSizeEncoding for UnusedGenericParams {
type ByteArray = [u8; 4];