Move EncodedMetadata to rustc_metadata.

This commit is contained in:
Camille GILLOT 2021-09-24 18:15:36 +02:00
parent df54d3980b
commit b244b98e7c
17 changed files with 39 additions and 32 deletions

View file

@ -3706,6 +3706,7 @@ dependencies = [
"rustc_incremental", "rustc_incremental",
"rustc_index", "rustc_index",
"rustc_macros", "rustc_macros",
"rustc_metadata",
"rustc_middle", "rustc_middle",
"rustc_serialize", "rustc_serialize",
"rustc_session", "rustc_session",

View file

@ -6,8 +6,8 @@ use std::path::PathBuf;
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind}; use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::mir::mono::{CodegenUnit, MonoItem}; use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{DebugInfo, OutputType}; use rustc_session::config::{DebugInfo, OutputType};

View file

@ -30,8 +30,8 @@ use std::any::Any;
use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_codegen_ssa::CodegenResults; use rustc_codegen_ssa::CodegenResults;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_session::config::OutputFilenames; use rustc_session::config::OutputFilenames;
use rustc_session::Session; use rustc_session::Session;

View file

@ -3,7 +3,7 @@
use object::write::{Object, StandardSegment, Symbol, SymbolSection}; use object::write::{Object, StandardSegment, Symbol, SymbolSection};
use object::{SectionKind, SymbolFlags, SymbolKind, SymbolScope}; use object::{SectionKind, SymbolFlags, SymbolKind, SymbolScope};
use rustc_middle::middle::cstore::EncodedMetadata; use rustc_metadata::EncodedMetadata;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 // Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112
@ -16,7 +16,7 @@ pub(crate) fn new_metadata_object(
use std::io::Write; use std::io::Write;
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); FrameEncoder::new(&mut compressed).write_all(metadata.raw_data()).unwrap();
let triple = crate::target_triple(tcx.sess); let triple = crate::target_triple(tcx.sess);

View file

@ -25,9 +25,9 @@ use rustc_codegen_ssa::mono_item::MonoItemExt;
use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::small_c_str::SmallCStr;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph; use rustc_middle::dep_graph;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::middle::exported_symbols; use rustc_middle::middle::exported_symbols;
use rustc_middle::mir::mono::{Linkage, Visibility}; use rustc_middle::mir::mono::{Linkage, Visibility};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -64,7 +64,7 @@ pub fn write_compressed_metadata<'tcx>(
let (metadata_llcx, metadata_llmod) = (&*llvm_module.llcx, llvm_module.llmod()); let (metadata_llcx, metadata_llmod) = (&*llvm_module.llcx, llvm_module.llmod());
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); FrameEncoder::new(&mut compressed).write_all(metadata.raw_data()).unwrap();
let llmeta = common::bytes_in_context(metadata_llcx, &compressed); let llmeta = common::bytes_in_context(metadata_llcx, &compressed);
let llconst = common::struct_in_context(metadata_llcx, &[llmeta], false); let llconst = common::struct_in_context(metadata_llcx, &[llmeta], false);

View file

@ -27,8 +27,8 @@ use rustc_codegen_ssa::ModuleCodegen;
use rustc_codegen_ssa::{CodegenResults, CompiledModule}; use rustc_codegen_ssa::{CodegenResults, CompiledModule};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{ErrorReported, FatalError, Handler}; use rustc_errors::{ErrorReported, FatalError, Handler};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest}; use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest};
use rustc_session::Session; use rustc_session::Session;

View file

@ -32,6 +32,7 @@ rustc_hir = { path = "../rustc_hir" }
rustc_incremental = { path = "../rustc_incremental" } rustc_incremental = { path = "../rustc_incremental" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }

View file

@ -327,7 +327,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
// metadata in rlib files is wrapped in a "dummy" object file for // metadata in rlib files is wrapped in a "dummy" object file for
// the target platform so the rlib can be processed entirely by // the target platform so the rlib can be processed entirely by
// normal linkers for the platform. // normal linkers for the platform.
let metadata = create_metadata_file(sess, &codegen_results.metadata.raw_data); let metadata = create_metadata_file(sess, codegen_results.metadata.raw_data());
ab.add_file(&emit_metadata(sess, &metadata, tmpdir)); ab.add_file(&emit_metadata(sess, &metadata, tmpdir));
// After adding all files to the archive, we need to update the // After adding all files to the archive, we need to update the

View file

@ -21,8 +21,8 @@ use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_incremental::{ use rustc_incremental::{
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess, copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
}; };
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_middle::middle::exported_symbols::SymbolExportLevel;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::cgu_reuse_tracker::CguReuseTracker; use rustc_session::cgu_reuse_tracker::CguReuseTracker;

View file

@ -18,8 +18,8 @@ use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_metadata::EncodedMetadata;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::middle::lang_items; use rustc_middle::middle::lang_items;
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};

View file

@ -158,7 +158,7 @@ pub struct CodegenResults {
pub modules: Vec<CompiledModule>, pub modules: Vec<CompiledModule>,
pub allocator_module: Option<CompiledModule>, pub allocator_module: Option<CompiledModule>,
pub metadata_module: Option<CompiledModule>, pub metadata_module: Option<CompiledModule>,
pub metadata: rustc_middle::middle::cstore::EncodedMetadata, pub metadata: rustc_metadata::EncodedMetadata,
pub crate_info: CrateInfo, pub crate_info: CrateInfo,
} }

View file

@ -6,8 +6,9 @@ use crate::{CodegenResults, ModuleCodegen};
use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_middle::middle::cstore::MetadataLoaderDyn;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout}; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{Ty, TyCtxt}; use rustc_middle::ty::{Ty, TyCtxt};

View file

@ -16,10 +16,9 @@ use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
use rustc_hir::Crate; use rustc_hir::Crate;
use rustc_lint::LintStore; use rustc_lint::LintStore;
use rustc_metadata::creader::CStore; use rustc_metadata::creader::CStore;
use rustc_metadata::encode_metadata; use rustc_metadata::{encode_metadata, EncodedMetadata};
use rustc_middle::arena::Arena; use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::DepGraph; use rustc_middle::dep_graph::DepGraph;
use rustc_middle::middle;
use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn}; use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn};
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt}; use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
@ -978,7 +977,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
fn encode_and_write_metadata( fn encode_and_write_metadata(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
outputs: &OutputFilenames, outputs: &OutputFilenames,
) -> (middle::cstore::EncodedMetadata, bool) { ) -> (EncodedMetadata, bool) {
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(PartialEq, Eq, PartialOrd, Ord)]
enum MetadataKind { enum MetadataKind {
None, None,
@ -1001,7 +1000,7 @@ fn encode_and_write_metadata(
.unwrap_or(MetadataKind::None); .unwrap_or(MetadataKind::None);
let metadata = match metadata_kind { let metadata = match metadata_kind {
MetadataKind::None => middle::cstore::EncodedMetadata::new(), MetadataKind::None => EncodedMetadata::new(),
MetadataKind::Uncompressed | MetadataKind::Compressed => encode_metadata(tcx), MetadataKind::Uncompressed | MetadataKind::Compressed => encode_metadata(tcx),
}; };
@ -1021,7 +1020,7 @@ fn encode_and_write_metadata(
.tempdir_in(out_filename.parent().unwrap()) .tempdir_in(out_filename.parent().unwrap())
.unwrap_or_else(|err| tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err))); .unwrap_or_else(|err| tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err)));
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps); let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
let metadata_filename = emit_metadata(tcx.sess, &metadata.raw_data, &metadata_tmpdir); let metadata_filename = emit_metadata(tcx.sess, metadata.raw_data(), &metadata_tmpdir);
if let Err(e) = util::non_durable_rename(&metadata_filename, &out_filename) { if let Err(e) = util::non_durable_rename(&metadata_filename, &out_filename) {
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e)); tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
} }

View file

@ -30,5 +30,4 @@ pub mod creader;
pub mod dynamic_lib; pub mod dynamic_lib;
pub mod locator; pub mod locator;
pub use rmeta::encode_metadata; pub use rmeta::{encode_metadata, EncodedMetadata, METADATA_HEADER};
pub use rmeta::METADATA_HEADER;

View file

@ -18,7 +18,7 @@ use rustc_hir::{AnonConst, GenericParamKind};
use rustc_index::bit_set::GrowableBitSet; use rustc_index::bit_set::GrowableBitSet;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::middle::cstore::{EncodedMetadata, ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLib};
use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols::{ use rustc_middle::middle::exported_symbols::{
metadata_symbol_name, ExportedSymbol, SymbolExportLevel, metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
@ -2101,6 +2101,23 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
// will allow us to slice the metadata to the precise length that we just // will allow us to slice the metadata to the precise length that we just
// generated regardless of trailing bytes that end up in it. // generated regardless of trailing bytes that end up in it.
#[derive(Encodable, Decodable)]
pub struct EncodedMetadata {
raw_data: Vec<u8>,
}
impl EncodedMetadata {
#[inline]
pub fn new() -> EncodedMetadata {
EncodedMetadata { raw_data: Vec::new() }
}
#[inline]
pub fn raw_data(&self) -> &[u8] {
&self.raw_data[..]
}
}
pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata"); let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");

View file

@ -32,8 +32,8 @@ use std::num::NonZeroUsize;
use decoder::DecodeContext; use decoder::DecodeContext;
pub use decoder::{provide, provide_extern}; pub use decoder::{provide, provide_extern};
crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob}; crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob};
pub use encoder::encode_metadata;
use encoder::EncodeContext; use encoder::EncodeContext;
pub use encoder::{encode_metadata, EncodedMetadata};
use rustc_span::hygiene::SyntaxContextData; use rustc_span::hygiene::SyntaxContextData;
mod decoder; mod decoder;

View file

@ -148,17 +148,6 @@ pub enum ExternCrateSource {
Path, Path,
} }
#[derive(Encodable, Decodable)]
pub struct EncodedMetadata {
pub raw_data: Vec<u8>,
}
impl EncodedMetadata {
pub fn new() -> EncodedMetadata {
EncodedMetadata { raw_data: Vec::new() }
}
}
/// The backend's way to give the crate store access to the metadata in a library. /// 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 /// Note that it returns the raw metadata bytes stored in the library file, whether
/// it is compressed, uncompressed, some weird mix, etc. /// it is compressed, uncompressed, some weird mix, etc.