summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_metadata
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_metadata
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_metadata')
-rw-r--r--compiler/rustc_metadata/messages.ftl7
-rw-r--r--compiler/rustc_metadata/src/creader.rs28
-rw-r--r--compiler/rustc_metadata/src/errors.rs21
-rw-r--r--compiler/rustc_metadata/src/fs.rs5
-rw-r--r--compiler/rustc_metadata/src/lib.rs13
-rw-r--r--compiler/rustc_metadata/src/locator.rs14
-rw-r--r--compiler/rustc_metadata/src/native_libs.rs14
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs84
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs6
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs191
-rw-r--r--compiler/rustc_metadata/src/rmeta/mod.rs9
-rw-r--r--compiler/rustc_metadata/src/rmeta/table.rs14
12 files changed, 191 insertions, 215 deletions
diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl
index d1815717e..8da6f0007 100644
--- a/compiler/rustc_metadata/messages.ftl
+++ b/compiler/rustc_metadata/messages.ftl
@@ -63,11 +63,8 @@ metadata_extern_location_not_file =
metadata_fail_create_file_encoder =
failed to create file encoder: {$err}
-metadata_fail_seek_file =
- failed to seek the file: {$err}
-
metadata_fail_write_file =
- failed to write to the file: {$err}
+ failed to write to `{$path}`: {$err}
metadata_failed_copy_to_stdout =
failed to copy {$filename} to stdout: {$err}
@@ -272,7 +269,7 @@ metadata_unknown_import_name_type =
unknown import name type `{$import_name_type}`, expected one of: decorated, noprefix, undecorated
metadata_unknown_link_kind =
- unknown link kind `{$kind}`, expected one of: static, dylib, framework, raw-dylib
+ unknown link kind `{$kind}`, expected one of: static, dylib, framework, raw-dylib, link-arg
.label = unknown link kind
metadata_unknown_link_modifier =
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs
index 14bbe65d5..972c84b10 100644
--- a/compiler/rustc_metadata/src/creader.rs
+++ b/compiler/rustc_metadata/src/creader.rs
@@ -7,8 +7,9 @@ use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob
use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind};
use rustc_ast::{self as ast, *};
use rustc_data_structures::fx::FxHashSet;
+use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::svh::Svh;
-use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard};
+use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard};
use rustc_expand::base::SyntaxExtension;
use rustc_fs_util::try_canonicalize;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
@@ -16,16 +17,14 @@ use rustc_hir::definitions::Definitions;
use rustc_index::IndexVec;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{self, CrateType, ExternLocation};
-use rustc_session::cstore::{
- CrateDepKind, CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
-};
+use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
use rustc_session::lint;
use rustc_session::output::validate_crate_name;
use rustc_session::search_paths::PathKind;
use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP};
-use rustc_target::spec::{PanicStrategy, TargetTriple};
+use rustc_target::spec::{PanicStrategy, Target, TargetTriple};
use proc_macro::bridge::client::ProcMacro;
use std::error::Error;
@@ -34,6 +33,17 @@ use std::path::Path;
use std::time::Duration;
use std::{cmp, iter};
+/// The backend's way to give the crate store access to the metadata in a library.
+/// Note that it returns the raw metadata bytes stored in the library file, whether
+/// it is compressed, uncompressed, some weird mix, etc.
+/// rmeta files are backend independent and not handled here.
+pub trait MetadataLoader {
+ fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
+ fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
+}
+
+pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
+
pub struct CStore {
metadata_loader: Box<MetadataLoaderDyn>,
@@ -257,7 +267,7 @@ impl CStore {
let unused_externs =
self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>();
- tcx.sess.parse_sess.span_diagnostic.emit_unused_externs(
+ tcx.sess.dcx().emit_unused_externs(
level,
json_unused_externs.is_loud(),
&unused_externs,
@@ -427,7 +437,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
let crate_metadata = CrateMetadata::new(
self.sess,
- &self.cstore,
+ self.cstore,
metadata,
crate_root,
raw_proc_macros,
@@ -515,7 +525,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
Err(err) => {
let missing_core =
self.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None).is_err();
- err.report(&self.sess, span, missing_core);
+ err.report(self.sess, span, missing_core);
None
}
}
@@ -987,7 +997,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
self.report_unused_deps(krate);
- info!("{:?}", CrateDump(&self.cstore));
+ info!("{:?}", CrateDump(self.cstore));
}
pub fn process_extern_crate(
diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs
index 70daee291..206c15edd 100644
--- a/compiler/rustc_metadata/src/errors.rs
+++ b/compiler/rustc_metadata/src/errors.rs
@@ -308,14 +308,9 @@ pub struct FailCreateFileEncoder {
}
#[derive(Diagnostic)]
-#[diag(metadata_fail_seek_file)]
-pub struct FailSeekFile {
- pub err: Error,
-}
-
-#[derive(Diagnostic)]
#[diag(metadata_fail_write_file)]
-pub struct FailWriteFile {
+pub struct FailWriteFile<'a> {
+ pub path: &'a Path,
pub err: Error,
}
@@ -503,9 +498,9 @@ pub(crate) struct MultipleCandidates {
impl IntoDiagnostic<'_> for MultipleCandidates {
fn into_diagnostic(
self,
- handler: &'_ rustc_errors::Handler,
+ dcx: &'_ rustc_errors::DiagCtxt,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
- let mut diag = handler.struct_err(fluent::metadata_multiple_candidates);
+ let mut diag = dcx.struct_err(fluent::metadata_multiple_candidates);
diag.set_arg("crate_name", self.crate_name);
diag.set_arg("flavor", self.flavor);
diag.code(error_code!(E0464));
@@ -602,9 +597,9 @@ impl IntoDiagnostic<'_> for InvalidMetadataFiles {
#[track_caller]
fn into_diagnostic(
self,
- handler: &'_ rustc_errors::Handler,
+ dcx: &'_ rustc_errors::DiagCtxt,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
- let mut diag = handler.struct_err(fluent::metadata_invalid_meta_files);
+ let mut diag = dcx.struct_err(fluent::metadata_invalid_meta_files);
diag.set_arg("crate_name", self.crate_name);
diag.set_arg("add_info", self.add_info);
diag.code(error_code!(E0786));
@@ -632,9 +627,9 @@ impl IntoDiagnostic<'_> for CannotFindCrate {
#[track_caller]
fn into_diagnostic(
self,
- handler: &'_ rustc_errors::Handler,
+ dcx: &'_ rustc_errors::DiagCtxt,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
- let mut diag = handler.struct_err(fluent::metadata_cannot_find_crate);
+ let mut diag = dcx.struct_err(fluent::metadata_cannot_find_crate);
diag.set_arg("crate_name", self.crate_name);
diag.set_arg("current_crate", self.current_crate);
diag.set_arg("add_info", self.add_info);
diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs
index 7eb2a347d..e80afcc48 100644
--- a/compiler/rustc_metadata/src/fs.rs
+++ b/compiler/rustc_metadata/src/fs.rs
@@ -91,10 +91,7 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> (EncodedMetadata, bool) {
}
};
if tcx.sess.opts.json_artifact_notifications {
- tcx.sess
- .parse_sess
- .span_diagnostic
- .emit_artifact_notification(&out_filename.as_path(), "metadata");
+ tcx.sess.dcx().emit_artifact_notification(out_filename.as_path(), "metadata");
}
(filename, None)
} else {
diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs
index b06b4fb87..6c6c60af0 100644
--- a/compiler/rustc_metadata/src/lib.rs
+++ b/compiler/rustc_metadata/src/lib.rs
@@ -1,11 +1,10 @@
#![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))]
+#![doc(rust_logo)]
+#![feature(rustdoc_internals)]
+#![allow(internal_features)]
#![feature(decl_macro)]
#![feature(extract_if)]
-#![cfg_attr(bootstrap, feature(generators))]
-#![cfg_attr(not(bootstrap), feature(coroutines))]
+#![feature(coroutines)]
#![feature(iter_from_coroutine)]
#![feature(let_chains)]
#![feature(if_let_guard)]
@@ -32,8 +31,6 @@ extern crate rustc_middle;
extern crate tracing;
pub use rmeta::provide;
-use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
-use rustc_fluent_macro::fluent_messages;
mod dependency_format;
mod foreign_modules;
@@ -49,4 +46,4 @@ pub use fs::{emit_wrapper_file, METADATA_FILENAME};
pub use native_libs::find_native_static_library;
pub use rmeta::{encode_metadata, rendered_const, EncodedMetadata, METADATA_HEADER};
-fluent_messages! { "../messages.ftl" }
+rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index 3a99ddc1b..f9219d12a 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -212,7 +212,7 @@
//! no means all of the necessary details. Take a look at the rest of
//! metadata::locator or metadata::creader for all the juicy details!
-use crate::creader::Library;
+use crate::creader::{Library, MetadataLoader};
use crate::errors;
use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER};
@@ -223,7 +223,7 @@ use rustc_data_structures::svh::Svh;
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_fs_util::try_canonicalize;
use rustc_session::config;
-use rustc_session::cstore::{CrateSource, MetadataLoader};
+use rustc_session::cstore::CrateSource;
use rustc_session::filesearch::FileSearch;
use rustc_session::search_paths::PathKind;
use rustc_session::utils::CanonicalizedPath;
@@ -783,8 +783,8 @@ fn get_metadata_section<'p>(
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
// The header is uncompressed
let header_len = METADATA_HEADER.len();
- // header + u32 length of data
- let data_start = header_len + 4;
+ // header + u64 length of data
+ let data_start = header_len + 8;
debug!("checking {} bytes of metadata-version stamp", header_len);
let header = &buf[..cmp::min(header_len, buf.len())];
@@ -797,13 +797,13 @@ fn get_metadata_section<'p>(
// Length of the compressed stream - this allows linkers to pad the section if they want
let Ok(len_bytes) =
- <[u8; 4]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
+ <[u8; 8]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
else {
return Err(MetadataError::LoadFailure(
"invalid metadata length found".to_string(),
));
};
- let compressed_len = u32::from_be_bytes(len_bytes) as usize;
+ let compressed_len = u64::from_le_bytes(len_bytes) as usize;
// Header is okay -> inflate the actual metadata
let compressed_bytes = buf.slice(|buf| &buf[data_start..(data_start + compressed_len)]);
@@ -980,7 +980,7 @@ impl CrateError {
for CrateMismatch { path, .. } in mismatches {
sess.emit_err(errors::CrateLocationUnknownType {
span,
- path: &path,
+ path: path,
crate_name,
});
sess.emit_err(errors::LibFilenameForm {
diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index ab135851b..b3760b109 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -160,6 +160,18 @@ impl<'tcx> Collector<'tcx> {
}
NativeLibKind::RawDylib
}
+ "link-arg" => {
+ if !features.link_arg_attribute {
+ feature_err(
+ &sess.parse_sess,
+ sym::link_arg_attribute,
+ span,
+ "link kind `link-arg` is unstable",
+ )
+ .emit();
+ }
+ NativeLibKind::LinkArg
+ }
kind => {
sess.emit_err(errors::UnknownLinkKind { span, kind });
continue;
@@ -470,7 +482,7 @@ impl<'tcx> Collector<'tcx> {
}
fn i686_arg_list_size(&self, item: DefId) -> usize {
- let argument_types: &List<Ty<'_>> = self.tcx.erase_late_bound_regions(
+ let argument_types: &List<Ty<'_>> = self.tcx.instantiate_bound_regions_with_erased(
self.tcx
.type_of(item)
.instantiate_identity()
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index 354023cea..281a0eafe 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -1,43 +1,34 @@
// Decoding metadata from a single crate's metadata
-use crate::creader::{CStore, CrateMetadataRef};
+use crate::creader::CStore;
use crate::rmeta::table::IsDefault;
use crate::rmeta::*;
use rustc_ast as ast;
use rustc_data_structures::captures::Captures;
-use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::owned_slice::OwnedSlice;
-use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{AppendOnlyVec, AtomicBool, Lock, Lrc, OnceLock};
use rustc_data_structures::unhash::UnhashMap;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};
-use rustc_hir::def::{CtorKind, DefKind, DocLinkResMap, Res};
-use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
-use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
+use rustc_hir::def::Res;
+use rustc_hir::def_id::{DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
+use rustc_hir::definitions::{DefPath, DefPathData};
use rustc_hir::diagnostic_items::DiagnosticItems;
-use rustc_index::{Idx, IndexVec};
-use rustc_middle::metadata::ModChild;
-use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
-use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
+use rustc_index::Idx;
+use rustc_middle::middle::lib_features::LibFeatures;
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::ty::codec::TyDecoder;
-use rustc_middle::ty::fast_reject::SimplifiedType;
-use rustc_middle::ty::{self, ParameterizedOverTcx, Ty, TyCtxt, Visibility};
+use rustc_middle::ty::Visibility;
use rustc_serialize::opaque::MemDecoder;
use rustc_serialize::{Decodable, Decoder};
-use rustc_session::cstore::{
- CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib,
-};
+use rustc_session::cstore::{CrateSource, ExternCrate};
use rustc_session::Session;
-use rustc_span::hygiene::ExpnIndex;
-use rustc_span::symbol::{kw, Ident, Symbol};
-use rustc_span::{self, BytePos, ExpnId, Pos, Span, SpanData, SyntaxContext, DUMMY_SP};
+use rustc_span::symbol::kw;
+use rustc_span::{BytePos, Pos, SpanData, SyntaxContext, DUMMY_SP};
use proc_macro::bridge::client::ProcMacro;
use std::iter::TrustedLen;
-use std::num::NonZeroUsize;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::{io, iter, mem};
@@ -699,28 +690,25 @@ impl MetadataBlob {
}
pub(crate) fn get_rustc_version(&self) -> String {
- LazyValue::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len() + 4).unwrap())
+ LazyValue::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len() + 8).unwrap())
.decode(self)
}
- pub(crate) fn get_header(&self) -> CrateHeader {
- let slice = &self.blob()[..];
+ fn root_pos(&self) -> NonZeroUsize {
let offset = METADATA_HEADER.len();
+ let pos_bytes = self.blob()[offset..][..8].try_into().unwrap();
+ let pos = u64::from_le_bytes(pos_bytes);
+ NonZeroUsize::new(pos as usize).unwrap()
+ }
- let pos_bytes = slice[offset..][..4].try_into().unwrap();
- let pos = u32::from_be_bytes(pos_bytes) as usize;
-
- LazyValue::<CrateHeader>::from_position(NonZeroUsize::new(pos).unwrap()).decode(self)
+ pub(crate) fn get_header(&self) -> CrateHeader {
+ let pos = self.root_pos();
+ LazyValue::<CrateHeader>::from_position(pos).decode(self)
}
pub(crate) fn get_root(&self) -> CrateRoot {
- let slice = &self.blob()[..];
- let offset = METADATA_HEADER.len();
-
- let pos_bytes = slice[offset..][..4].try_into().unwrap();
- let pos = u32::from_be_bytes(pos_bytes) as usize;
-
- LazyValue::<CrateRoot>::from_position(NonZeroUsize::new(pos).unwrap()).decode(self)
+ let pos = self.root_pos();
+ LazyValue::<CrateRoot>::from_position(pos).decode(self)
}
pub(crate) fn list_crate_metadata(
@@ -828,7 +816,7 @@ impl MetadataBlob {
out,
"{}{}",
feature,
- if let Some(since) = since {
+ if let FeatureStability::AcceptedSince(since) = since {
format!(" since {since}")
} else {
String::new()
@@ -849,7 +837,7 @@ impl MetadataBlob {
) -> io::Result<()> {
let root = blob.get_root();
- let def_kind = root.tables.opt_def_kind.get(blob, item).unwrap();
+ let def_kind = root.tables.def_kind.get(blob, item).unwrap();
let def_key = root.tables.def_keys.get(blob, item).unwrap().decode(blob);
let def_name = if item == CRATE_DEF_INDEX {
rustc_span::symbol::kw::Crate
@@ -1000,14 +988,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
fn def_kind(self, item_id: DefIndex) -> DefKind {
- self.root.tables.opt_def_kind.get(self, item_id).unwrap_or_else(|| {
- bug!(
- "CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}",
- item_id,
- self.root.name(),
- self.cnum,
- )
- })
+ self.root
+ .tables
+ .def_kind
+ .get(self, item_id)
+ .unwrap_or_else(|| self.missing("def_kind", item_id))
}
fn get_span(self, index: DefIndex, sess: &Session) -> Span {
@@ -1176,8 +1161,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
/// Iterates over all the stability attributes in the given crate.
- fn get_lib_features(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Option<Symbol>)] {
- tcx.arena.alloc_from_iter(self.root.lib_features.decode(self))
+ fn get_lib_features(self) -> LibFeatures {
+ LibFeatures {
+ stability: self
+ .root
+ .lib_features
+ .decode(self)
+ .map(|(sym, stab)| (sym, (stab, DUMMY_SP)))
+ .collect(),
+ }
}
/// Iterates over the stability implications in the given crate (when a `#[unstable]` attribute
@@ -1208,7 +1200,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
/// Iterates over the diagnostic items in the given crate.
fn get_diagnostic_items(self) -> DiagnosticItems {
- let mut id_to_name = FxHashMap::default();
+ let mut id_to_name = DefIdMap::default();
let name_to_id = self
.root
.diagnostic_items
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
index 595d816e9..f6cd013d2 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
@@ -231,7 +231,7 @@ provide! { tcx, def_id, other, cdata,
lookup_deprecation_entry => { table }
params_in_repr => { table }
unused_generic_params => { cdata.root.tables.unused_generic_params.get(cdata, def_id.index) }
- opt_def_kind => { table_direct }
+ def_kind => { cdata.def_kind(def_id.index) }
impl_parent => { table }
impl_polarity => { table_direct }
defaultness => { table_direct }
@@ -346,7 +346,7 @@ provide! { tcx, def_id, other, cdata,
module_children => {
tcx.arena.alloc_from_iter(cdata.get_module_children(def_id.index, tcx.sess))
}
- defined_lib_features => { cdata.get_lib_features(tcx) }
+ lib_features => { cdata.get_lib_features() }
stability_implications => {
cdata.get_stability_implications(tcx).iter().copied().collect()
}
@@ -394,7 +394,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
native_library: |tcx, id| {
tcx.native_libraries(id.krate)
.iter()
- .filter(|lib| native_libs::relevant_lib(&tcx.sess, lib))
+ .filter(|lib| native_libs::relevant_lib(tcx.sess, lib))
.find(|lib| {
let Some(fm_id) = lib.foreign_module else {
return false;
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 2042863d1..ad3fea65e 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -1,49 +1,37 @@
-use crate::errors::{FailCreateFileEncoder, FailSeekFile, FailWriteFile};
-use crate::rmeta::def_path_hash_map::DefPathHashMapRef;
-use crate::rmeta::table::TableBuilder;
+use crate::errors::{FailCreateFileEncoder, FailWriteFile};
use crate::rmeta::*;
-use rustc_ast::expand::StrippedCfgItem;
use rustc_ast::Attribute;
use rustc_data_structures::fingerprint::Fingerprint;
-use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
+use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::memmap::{Mmap, MmapMut};
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
use rustc_data_structures::sync::{join, par_for_each_in, Lrc};
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_hir as hir;
-use rustc_hir::def::DefKind;
-use rustc_hir::def_id::{
- CrateNum, DefId, DefIndex, LocalDefId, LocalDefIdSet, CRATE_DEF_ID, CRATE_DEF_INDEX,
- LOCAL_CRATE,
-};
+use rustc_hir::def_id::{LocalDefId, LocalDefIdSet, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::DefPathData;
-use rustc_hir::lang_items::LangItem;
use rustc_hir_pretty::id_to_string;
-use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Linkage;
-use rustc_middle::middle::exported_symbols::{
- metadata_symbol_name, ExportedSymbol, SymbolExportInfo,
-};
+use rustc_middle::middle::exported_symbols::metadata_symbol_name;
use rustc_middle::mir::interpret;
use rustc_middle::query::LocalCrate;
use rustc_middle::query::Providers;
use rustc_middle::traits::specialization_graph;
use rustc_middle::ty::codec::TyEncoder;
-use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams};
-use rustc_middle::ty::{self, AssocItemContainer, SymbolName, Ty, TyCtxt};
+use rustc_middle::ty::fast_reject::{self, TreatParams};
+use rustc_middle::ty::{AssocItemContainer, SymbolName};
use rustc_middle::util::common::to_readable_str;
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
use rustc_session::config::{CrateType, OptLevel};
-use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
-use rustc_span::hygiene::{ExpnIndex, HygieneEncodeContext, MacroKind};
-use rustc_span::symbol::{sym, Symbol};
-use rustc_span::{self, ExternalSource, FileName, SourceFile, Span, SpanData, SyntaxContext};
+use rustc_span::hygiene::HygieneEncodeContext;
+use rustc_span::symbol::sym;
+use rustc_span::{ExternalSource, FileName, SourceFile, SpanData, SyntaxContext};
use std::borrow::Borrow;
use std::collections::hash_map::Entry;
+use std::fs::File;
use std::hash::Hash;
use std::io::{Read, Seek, Write};
-use std::num::NonZeroUsize;
use std::path::{Path, PathBuf};
pub(super) struct EncodeContext<'a, 'tcx> {
@@ -159,7 +147,7 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for ExpnIndex {
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for SyntaxContext {
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
- rustc_span::hygiene::raw_encode_syntax_context(*self, &s.hygiene_ctxt, s);
+ rustc_span::hygiene::raw_encode_syntax_context(*self, s.hygiene_ctxt, s);
}
}
@@ -656,10 +644,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let debugger_visualizers =
stat!("debugger-visualizers", || self.encode_debugger_visualizers());
- // Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
- // this as late as possible to give the prefetching as much time as possible to complete.
+ // Encode exported symbols info. This is prefetched in `encode_metadata`.
let exported_symbols = stat!("exported-symbols", || {
- self.encode_exported_symbols(&tcx.exported_symbols(LOCAL_CRATE))
+ self.encode_exported_symbols(tcx.exported_symbols(LOCAL_CRATE))
});
// Encode the hygiene data.
@@ -693,15 +680,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
- has_default_lib_allocator: attr::contains_name(&attrs, sym::default_lib_allocator),
+ has_default_lib_allocator: attr::contains_name(attrs, sym::default_lib_allocator),
proc_macro_data,
debugger_visualizers,
- compiler_builtins: attr::contains_name(&attrs, sym::compiler_builtins),
- needs_allocator: attr::contains_name(&attrs, sym::needs_allocator),
- needs_panic_runtime: attr::contains_name(&attrs, sym::needs_panic_runtime),
- no_builtins: attr::contains_name(&attrs, sym::no_builtins),
- panic_runtime: attr::contains_name(&attrs, sym::panic_runtime),
- profiler_runtime: attr::contains_name(&attrs, sym::profiler_runtime),
+ compiler_builtins: attr::contains_name(attrs, sym::compiler_builtins),
+ needs_allocator: attr::contains_name(attrs, sym::needs_allocator),
+ needs_panic_runtime: attr::contains_name(attrs, sym::needs_panic_runtime),
+ no_builtins: attr::contains_name(attrs, sym::no_builtins),
+ panic_runtime: attr::contains_name(attrs, sym::panic_runtime),
+ profiler_runtime: attr::contains_name(attrs, sym::profiler_runtime),
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
crate_deps,
@@ -855,8 +842,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
| DefKind::OpaqueTy
| DefKind::Field
| DefKind::Impl { .. }
- | DefKind::Closure
- | DefKind::Coroutine => true,
+ | DefKind::Closure => true,
DefKind::ForeignMod | DefKind::GlobalAsm => false,
}
}
@@ -896,8 +882,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
| DefKind::InlineConst
| DefKind::OpaqueTy
| DefKind::LifetimeParam
- | DefKind::GlobalAsm
- | DefKind::Coroutine => false,
+ | DefKind::GlobalAsm => false,
}
}
@@ -932,8 +917,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
| DefKind::Field
| DefKind::LifetimeParam
| DefKind::GlobalAsm
- | DefKind::Closure
- | DefKind::Coroutine => false,
+ | DefKind::Closure => false,
}
}
@@ -968,7 +952,6 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
| DefKind::GlobalAsm
| DefKind::Impl { .. }
| DefKind::Closure
- | DefKind::Coroutine
| DefKind::ExternCrate => false,
}
}
@@ -1004,7 +987,6 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
| DefKind::InlineConst
| DefKind::GlobalAsm
| DefKind::Closure
- | DefKind::Coroutine
| DefKind::ExternCrate => false,
}
}
@@ -1047,6 +1029,8 @@ fn should_encode_mir(
| DefKind::AssocConst
| DefKind::Static(..)
| DefKind::Const => (true, false),
+ // Coroutines require optimized MIR to compute layout.
+ DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
// Full-fledged functions + closures
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
let generics = tcx.generics_of(def_id);
@@ -1060,8 +1044,6 @@ fn should_encode_mir(
|| tcx.is_const_default_method(def_id.to_def_id());
(is_const_fn, opt)
}
- // Coroutines require optimized MIR to compute layout.
- DefKind::Coroutine => (false, true),
// The others don't have MIR.
_ => (false, false),
}
@@ -1097,7 +1079,6 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
| DefKind::InlineConst
| DefKind::GlobalAsm
| DefKind::Closure
- | DefKind::Coroutine
| DefKind::ExternCrate => false,
DefKind::TyAlias => tcx.type_alias_is_lazy(def_id),
}
@@ -1126,8 +1107,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
| DefKind::Impl { .. }
| DefKind::Field
| DefKind::TyParam
- | DefKind::Closure
- | DefKind::Coroutine => true,
+ | DefKind::Closure => true,
DefKind::Mod
| DefKind::ForeignMod
| DefKind::ConstParam
@@ -1156,7 +1136,6 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
| DefKind::AssocFn
| DefKind::AssocConst
| DefKind::Closure
- | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::AnonConst
| DefKind::InlineConst => true,
@@ -1165,7 +1144,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
let origin = tcx.opaque_type_origin(def_id);
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::Node::TraitItem(trait_item) = tcx.hir_node_by_def_id(fn_def_id)
&& let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
{
false
@@ -1182,7 +1161,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
}
}
DefKind::TyParam => {
- let hir::Node::GenericParam(param) = tcx.hir().get_by_def_id(def_id) else { bug!() };
+ let hir::Node::GenericParam(param) = tcx.hir_node_by_def_id(def_id) else { bug!() };
let hir::GenericParamKind::Type { default, .. } = param.kind else { bug!() };
default.is_some()
}
@@ -1217,7 +1196,6 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
| DefKind::Impl { .. }
| DefKind::AssocConst
| DefKind::Closure
- | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::AnonConst
| DefKind::InlineConst
@@ -1256,7 +1234,6 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
| DefKind::OpaqueTy
| DefKind::Impl { of_trait: false }
| DefKind::ForeignTy
- | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::InlineConst
| DefKind::AssocTy
@@ -1291,7 +1268,6 @@ fn should_encode_const(def_kind: DefKind) -> bool {
| DefKind::Impl { .. }
| DefKind::AssocFn
| DefKind::Closure
- | DefKind::Coroutine
| DefKind::ConstParam
| DefKind::AssocTy
| DefKind::TyParam
@@ -1353,9 +1329,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
for local_id in tcx.iter_local_def_id() {
let def_id = local_id.to_def_id();
- let def_kind = tcx.opt_def_kind(local_id);
- let Some(def_kind) = def_kind else { continue };
- self.tables.opt_def_kind.set_some(def_id.index, def_kind);
+ let def_kind = tcx.def_kind(local_id);
+ self.tables.def_kind.set_some(def_id.index, def_kind);
if should_encode_span(def_kind) {
let def_span = tcx.def_span(local_id);
record!(self.tables.def_span[def_id] <- def_span);
@@ -1392,7 +1367,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if should_encode_fn_sig(def_kind) {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
}
- if should_encode_generics(def_kind) {
+ // FIXME: Some anonymous constants produced by `#[rustc_legacy_const_generics]`
+ // do not have corresponding HIR nodes, so some queries usually making sense for
+ // anonymous constants will not work on them and panic. It's not clear whether it
+ // can cause any observable issues or not.
+ let anon_const_without_hir = def_kind == DefKind::AnonConst
+ && tcx.opt_hir_node(tcx.local_def_id_to_hir_id(local_id)).is_none();
+ if should_encode_generics(def_kind) && !anon_const_without_hir {
let g = tcx.generics_of(def_id);
record!(self.tables.generics_of[def_id] <- g);
record!(self.tables.explicit_predicates_of[def_id] <- self.tcx.explicit_predicates_of(def_id));
@@ -1406,7 +1387,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}
}
- if should_encode_type(tcx, local_id, def_kind) {
+ if should_encode_type(tcx, local_id, def_kind) && !anon_const_without_hir {
record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
}
if should_encode_constness(def_kind) {
@@ -1446,8 +1427,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.encode_info_for_assoc_item(def_id);
}
}
- if let DefKind::Coroutine = def_kind {
- let data = self.tcx.coroutine_kind(def_id).unwrap();
+ if def_kind == DefKind::Closure
+ && let Some(data) = self.tcx.coroutine_kind(def_id)
+ {
record!(self.tables.coroutine_kind[def_id] <- data);
}
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
@@ -1629,7 +1611,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
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::Coroutine = self.tcx.def_kind(def_id)
+ if self.tcx.is_coroutine(def_id.to_def_id())
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
{
record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
@@ -1656,7 +1638,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
- if let DefKind::Coroutine = self.tcx.def_kind(def_id)
+ if self.tcx.is_coroutine(def_id.to_def_id())
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
{
record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
@@ -1727,9 +1709,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
let tcx = self.tcx;
- let hir::ItemKind::Macro(ref macro_def, _) = tcx.hir().expect_item(def_id).kind else {
- bug!()
- };
+ let hir::ItemKind::Macro(macro_def, _) = tcx.hir().expect_item(def_id).kind else { bug!() };
self.tables.is_macro_rules.set(def_id.local_def_index, macro_def.macro_rules);
record!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
}
@@ -1786,7 +1766,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.tables.proc_macro_quoted_spans.set_some(i, span);
}
- self.tables.opt_def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod);
+ self.tables.def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod);
record!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id()));
self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local());
let vis = tcx.local_visibility(CRATE_DEF_ID).map_id(|def_id| def_id.local_def_index);
@@ -1807,7 +1787,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// so we manually encode just the information that we need
for &proc_macro in &tcx.resolutions(()).proc_macros {
let id = proc_macro;
- let proc_macro = hir.local_def_id_to_hir_id(proc_macro);
+ let proc_macro = tcx.local_def_id_to_hir_id(proc_macro);
let mut name = hir.name(proc_macro);
let span = hir.span(proc_macro);
// Proc-macros may have attributes like `#[allow_internal_unstable]`,
@@ -1834,7 +1814,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
def_key.disambiguated_data.data = DefPathData::MacroNs(name);
let def_id = id.to_def_id();
- self.tables.opt_def_kind.set_some(def_id.index, DefKind::Macro(macro_kind));
+ self.tables.def_kind.set_some(def_id.index, DefKind::Macro(macro_kind));
self.tables.proc_macro.set_some(def_id.index, macro_kind);
self.encode_attrs(id);
record!(self.tables.def_keys[def_id] <- def_key);
@@ -1902,10 +1882,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy_array(deps.iter().map(|(_, dep)| dep))
}
- fn encode_lib_features(&mut self) -> LazyArray<(Symbol, Option<Symbol>)> {
+ fn encode_lib_features(&mut self) -> LazyArray<(Symbol, FeatureStability)> {
empty_proc_macro!(self);
let tcx = self.tcx;
- let lib_features = tcx.lib_features(());
+ let lib_features = tcx.lib_features(LOCAL_CRATE);
self.lazy_array(lib_features.to_vec())
}
@@ -2198,27 +2178,19 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
// there's no need to do dep-graph tracking for any of it.
tcx.dep_graph.assert_ignored();
- join(
- || encode_metadata_impl(tcx, path),
- || {
- if tcx.sess.threads() == 1 {
- return;
- }
- // Prefetch some queries used by metadata encoding.
- // This is not necessary for correctness, but is only done for performance reasons.
- // It can be removed if it turns out to cause trouble or be detrimental to performance.
- join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE));
- },
- );
-}
+ if tcx.sess.threads() != 1 {
+ // Prefetch some queries used by metadata encoding.
+ // This is not necessary for correctness, but is only done for performance reasons.
+ // It can be removed if it turns out to cause trouble or be detrimental to performance.
+ join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE));
+ }
-fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
let mut encoder = opaque::FileEncoder::new(path)
.unwrap_or_else(|err| tcx.sess.emit_fatal(FailCreateFileEncoder { err }));
encoder.emit_raw_bytes(METADATA_HEADER);
// Will be filled with the root position after encoding everything.
- encoder.emit_raw_bytes(&[0, 0, 0, 0]);
+ encoder.emit_raw_bytes(&0u64.to_le_bytes());
let source_map_files = tcx.sess.source_map().files();
let source_file_cache = (source_map_files[0].clone(), 0);
@@ -2251,29 +2223,34 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
// culminating in the `CrateRoot` which points to all of it.
let root = ecx.encode_crate_root();
- ecx.opaque.flush();
+ // Make sure we report any errors from writing to the file.
+ // If we forget this, compilation can succeed with an incomplete rmeta file,
+ // causing an ICE when the rmeta file is read by another compilation.
+ if let Err((path, err)) = ecx.opaque.finish() {
+ tcx.sess.emit_err(FailWriteFile { path: &path, err });
+ }
+
+ let file = ecx.opaque.file();
+ if let Err(err) = encode_root_position(file, root.position.get()) {
+ tcx.sess.emit_err(FailWriteFile { path: ecx.opaque.path(), err });
+ }
+
+ // Record metadata size for self-profiling
+ tcx.prof.artifact_size("crate_metadata", "crate_metadata", file.metadata().unwrap().len());
+}
- let mut file = ecx.opaque.file();
+fn encode_root_position(mut file: &File, pos: usize) -> Result<(), std::io::Error> {
// We will return to this position after writing the root position.
let pos_before_seek = file.stream_position().unwrap();
// Encode the root position.
let header = METADATA_HEADER.len();
- file.seek(std::io::SeekFrom::Start(header as u64))
- .unwrap_or_else(|err| tcx.sess.emit_fatal(FailSeekFile { err }));
- let pos = root.position.get();
- file.write_all(&[(pos >> 24) as u8, (pos >> 16) as u8, (pos >> 8) as u8, (pos >> 0) as u8])
- .unwrap_or_else(|err| tcx.sess.emit_fatal(FailWriteFile { err }));
+ file.seek(std::io::SeekFrom::Start(header as u64))?;
+ file.write_all(&pos.to_le_bytes())?;
// Return to the position where we are before writing the root position.
- file.seek(std::io::SeekFrom::Start(pos_before_seek)).unwrap();
-
- // Record metadata size for self-profiling
- tcx.prof.artifact_size(
- "crate_metadata",
- "crate_metadata",
- file.metadata().unwrap().len() as u64,
- );
+ file.seek(std::io::SeekFrom::Start(pos_before_seek))?;
+ Ok(())
}
pub fn provide(providers: &mut Providers) {
@@ -2396,8 +2373,10 @@ pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: hir::BodyId) -> String {
// * character escapes
//
// FIXME: This passes through `-/*spacer*/0` verbatim.
- Literal if !value.span.from_expansion()
- && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) => {
+ Literal
+ if !value.span.from_expansion()
+ && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) =>
+ {
snippet
}
@@ -2408,10 +2387,12 @@ pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: hir::BodyId) -> String {
// 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.
- Complex => if tcx.def_kind(hir.body_owner_def_id(body).to_def_id()) == DefKind::AnonConst {
- "{ _ }".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 9ae5c0af0..a85822848 100644
--- a/compiler/rustc_metadata/src/rmeta/mod.rs
+++ b/compiler/rustc_metadata/src/rmeta/mod.rs
@@ -3,6 +3,7 @@ use decoder::Metadata;
use def_path_hash_map::DefPathHashMapRef;
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
+use rustc_middle::middle::lib_features::FeatureStability;
use table::TableBuilder;
use rustc_ast as ast;
@@ -56,12 +57,12 @@ pub(crate) fn rustc_version(cfg_version: &'static str) -> String {
/// Metadata encoding version.
/// N.B., increment this if you change the format of metadata such that
/// the rustc version can't be found to compare with `rustc_version()`.
-const METADATA_VERSION: u8 = 8;
+const METADATA_VERSION: u8 = 9;
/// Metadata header which includes `METADATA_VERSION`.
///
/// This header is followed by the length of the compressed data, then
-/// the position of the `CrateRoot`, which is encoded as a 32-bit big-endian
+/// the position of the `CrateRoot`, which is encoded as a 64-bit little-endian
/// unsigned integer, and further followed by the rustc version string.
pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
@@ -263,7 +264,7 @@ pub(crate) struct CrateRoot {
crate_deps: LazyArray<CrateDep>,
dylib_dependency_formats: LazyArray<Option<LinkagePreference>>,
- lib_features: LazyArray<(Symbol, Option<Symbol>)>,
+ lib_features: LazyArray<(Symbol, FeatureStability)>,
stability_implications: LazyArray<(Symbol, Symbol)>,
lang_items: LazyArray<(DefIndex, LangItem)>,
lang_items_missing: LazyArray<LangItem>,
@@ -404,7 +405,7 @@ define_tables! {
// so we can take their names, visibilities etc from other encoded tables.
module_children_non_reexports: Table<DefIndex, LazyArray<DefIndex>>,
associated_item_or_field_def_ids: Table<DefIndex, LazyArray<DefIndex>>,
- opt_def_kind: Table<DefIndex, DefKind>,
+ def_kind: Table<DefIndex, DefKind>,
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
def_span: Table<DefIndex, LazyValue<Span>>,
def_ident_span: Table<DefIndex, LazyValue<Span>>,
diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs
index 027994c40..3fc6d9db3 100644
--- a/compiler/rustc_metadata/src/rmeta/table.rs
+++ b/compiler/rustc_metadata/src/rmeta/table.rs
@@ -1,13 +1,8 @@
use crate::rmeta::*;
use rustc_data_structures::fingerprint::Fingerprint;
-use rustc_hir::def::{CtorKind, CtorOf};
+use rustc_hir::def::CtorOf;
use rustc_index::Idx;
-use rustc_middle::ty::{ParameterizedOverTcx, UnusedGenericParams};
-use rustc_serialize::opaque::FileEncoder;
-use rustc_span::hygiene::MacroKind;
-use std::marker::PhantomData;
-use std::num::NonZeroUsize;
pub(super) trait IsDefault: Default {
fn is_default(&self) -> bool;
@@ -167,7 +162,6 @@ fixed_size_enum! {
( Impl { of_trait: false } )
( Impl { of_trait: true } )
( Closure )
- ( Coroutine )
( Static(ast::Mutability::Not) )
( Static(ast::Mutability::Mut) )
( Ctor(CtorOf::Struct, CtorKind::Fn) )
@@ -382,8 +376,8 @@ impl<T> LazyArray<T> {
}
fn from_bytes_impl(position: &[u8; 8], meta: &[u8; 8]) -> Option<LazyArray<T>> {
- let position = NonZeroUsize::new(u64::from_bytes(&position) as usize)?;
- let len = u64::from_bytes(&meta) as usize;
+ let position = NonZeroUsize::new(u64::from_bytes(position) as usize)?;
+ let len = u64::from_bytes(meta) as usize;
Some(LazyArray::from_position_and_num_elems(position, len))
}
}
@@ -497,7 +491,7 @@ impl<I: Idx, const N: usize, T: FixedSizeEncoding<ByteArray = [u8; N]>> TableBui
}
LazyTable::from_position_and_encoded_size(
- NonZeroUsize::new(pos as usize).unwrap(),
+ NonZeroUsize::new(pos).unwrap(),
width,
self.blocks.len(),
)