Move EncodedMetadata to rustc_metadata.
This commit is contained in:
parent
df54d3980b
commit
b244b98e7c
17 changed files with 39 additions and 32 deletions
|
@ -3706,6 +3706,7 @@ dependencies = [
|
|||
"rustc_incremental",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_metadata",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
|
|
|
@ -6,8 +6,8 @@ use std::path::PathBuf;
|
|||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
|
||||
use rustc_session::cgu_reuse_tracker::CguReuse;
|
||||
use rustc_session::config::{DebugInfo, OutputType};
|
||||
|
|
|
@ -30,8 +30,8 @@ use std::any::Any;
|
|||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::CodegenResults;
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_session::config::OutputFilenames;
|
||||
use rustc_session::Session;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use object::write::{Object, StandardSegment, Symbol, SymbolSection};
|
||||
use object::{SectionKind, SymbolFlags, SymbolKind, SymbolScope};
|
||||
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
||||
// 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;
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ use rustc_codegen_ssa::mono_item::MonoItemExt;
|
|||
use rustc_codegen_ssa::traits::*;
|
||||
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
|
||||
use rustc_data_structures::small_c_str::SmallCStr;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::middle::exported_symbols;
|
||||
use rustc_middle::mir::mono::{Linkage, Visibility};
|
||||
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 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 llconst = common::struct_in_context(metadata_llcx, &[llmeta], false);
|
||||
|
|
|
@ -27,8 +27,8 @@ use rustc_codegen_ssa::ModuleCodegen;
|
|||
use rustc_codegen_ssa::{CodegenResults, CompiledModule};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{ErrorReported, FatalError, Handler};
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest};
|
||||
use rustc_session::Session;
|
||||
|
|
|
@ -32,6 +32,7 @@ rustc_hir = { path = "../rustc_hir" }
|
|||
rustc_incremental = { path = "../rustc_incremental" }
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_metadata = { path = "../rustc_metadata" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
|
|||
// metadata in rlib files is wrapped in a "dummy" object file for
|
||||
// the target platform so the rlib can be processed entirely by
|
||||
// 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));
|
||||
|
||||
// After adding all files to the archive, we need to update the
|
||||
|
|
|
@ -21,8 +21,8 @@ use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
|||
use rustc_incremental::{
|
||||
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::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportLevel;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::cgu_reuse_tracker::CguReuseTracker;
|
||||
|
|
|
@ -18,8 +18,8 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::middle::lang_items;
|
||||
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
|
||||
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
||||
|
|
|
@ -158,7 +158,7 @@ pub struct CodegenResults {
|
|||
pub modules: Vec<CompiledModule>,
|
||||
pub allocator_module: Option<CompiledModule>,
|
||||
pub metadata_module: Option<CompiledModule>,
|
||||
pub metadata: rustc_middle::middle::cstore::EncodedMetadata,
|
||||
pub metadata: rustc_metadata::EncodedMetadata,
|
||||
pub crate_info: CrateInfo,
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ use crate::{CodegenResults, ModuleCodegen};
|
|||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
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::query::Providers;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
|
|
|
@ -16,10 +16,9 @@ use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
|||
use rustc_hir::Crate;
|
||||
use rustc_lint::LintStore;
|
||||
use rustc_metadata::creader::CStore;
|
||||
use rustc_metadata::encode_metadata;
|
||||
use rustc_metadata::{encode_metadata, EncodedMetadata};
|
||||
use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::DepGraph;
|
||||
use rustc_middle::middle;
|
||||
use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
|
||||
|
@ -978,7 +977,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
|
|||
fn encode_and_write_metadata(
|
||||
tcx: TyCtxt<'_>,
|
||||
outputs: &OutputFilenames,
|
||||
) -> (middle::cstore::EncodedMetadata, bool) {
|
||||
) -> (EncodedMetadata, bool) {
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
enum MetadataKind {
|
||||
None,
|
||||
|
@ -1001,7 +1000,7 @@ fn encode_and_write_metadata(
|
|||
.unwrap_or(MetadataKind::None);
|
||||
|
||||
let metadata = match metadata_kind {
|
||||
MetadataKind::None => middle::cstore::EncodedMetadata::new(),
|
||||
MetadataKind::None => EncodedMetadata::new(),
|
||||
MetadataKind::Uncompressed | MetadataKind::Compressed => encode_metadata(tcx),
|
||||
};
|
||||
|
||||
|
@ -1021,7 +1020,7 @@ fn encode_and_write_metadata(
|
|||
.tempdir_in(out_filename.parent().unwrap())
|
||||
.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_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) {
|
||||
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
||||
}
|
||||
|
|
|
@ -30,5 +30,4 @@ pub mod creader;
|
|||
pub mod dynamic_lib;
|
||||
pub mod locator;
|
||||
|
||||
pub use rmeta::encode_metadata;
|
||||
pub use rmeta::METADATA_HEADER;
|
||||
pub use rmeta::{encode_metadata, EncodedMetadata, METADATA_HEADER};
|
||||
|
|
|
@ -18,7 +18,7 @@ use rustc_hir::{AnonConst, GenericParamKind};
|
|||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_index::vec::Idx;
|
||||
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::exported_symbols::{
|
||||
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
|
||||
// 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 {
|
||||
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ use std::num::NonZeroUsize;
|
|||
use decoder::DecodeContext;
|
||||
pub use decoder::{provide, provide_extern};
|
||||
crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob};
|
||||
pub use encoder::encode_metadata;
|
||||
use encoder::EncodeContext;
|
||||
pub use encoder::{encode_metadata, EncodedMetadata};
|
||||
use rustc_span::hygiene::SyntaxContextData;
|
||||
|
||||
mod decoder;
|
||||
|
|
|
@ -148,17 +148,6 @@ pub enum ExternCrateSource {
|
|||
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.
|
||||
/// Note that it returns the raw metadata bytes stored in the library file, whether
|
||||
/// it is compressed, uncompressed, some weird mix, etc.
|
||||
|
|
Loading…
Add table
Reference in a new issue