Move encode_metadata out of CrateStore.

This commit is contained in:
Camille GILLOT 2020-11-14 01:59:00 +01:00
parent 11491938f8
commit df54d3980b
9 changed files with 14 additions and 21 deletions

View File

@ -96,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
stack = &stack[..index + REPORT_SYMBOL_NAMES.len()];
}
const ENCODE_METADATA: &str = "rustc_middle::ty::context::TyCtxt::encode_metadata";
const ENCODE_METADATA: &str = "rustc_metadata::encode_metadata";
if let Some(index) = stack.find(ENCODE_METADATA) {
stack = &stack[..index + ENCODE_METADATA.len()];
}

View File

@ -7,7 +7,11 @@ use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::ty::TyCtxt;
// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112
pub(crate) fn new_metadata_object(tcx: TyCtxt<'_>, cgu_name: &str, metadata: &EncodedMetadata) -> Vec<u8> {
pub(crate) fn new_metadata_object(
tcx: TyCtxt<'_>,
cgu_name: &str,
metadata: &EncodedMetadata,
) -> Vec<u8> {
use snap::write::FrameEncoder;
use std::io::Write;

View File

@ -16,6 +16,7 @@ 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_middle::arena::Arena;
use rustc_middle::dep_graph::DepGraph;
use rustc_middle::middle;
@ -1001,7 +1002,7 @@ fn encode_and_write_metadata(
let metadata = match metadata_kind {
MetadataKind::None => middle::cstore::EncodedMetadata::new(),
MetadataKind::Uncompressed | MetadataKind::Compressed => tcx.encode_metadata(),
MetadataKind::Uncompressed | MetadataKind::Compressed => encode_metadata(tcx),
};
let _prof_timer = tcx.sess.prof.generic_activity("write_crate_metadata");

View File

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

View File

@ -1,7 +1,6 @@
use crate::creader::{CStore, LoadedMacro};
use crate::foreign_modules;
use crate::native_libs;
use crate::rmeta::encoder;
use rustc_ast as ast;
use rustc_data_structures::stable_map::FxHashMap;
@ -10,7 +9,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
use rustc_middle::hir::exports::Export;
use rustc_middle::middle::cstore::ForeignModule;
use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata};
use rustc_middle::middle::cstore::{CrateSource, CrateStore};
use rustc_middle::middle::exported_symbols::ExportedSymbol;
use rustc_middle::middle::stability::DeprecationEntry;
use rustc_middle::ty::query::Providers;
@ -511,8 +510,4 @@ impl CrateStore for CStore {
fn expn_hash_to_expn_id(&self, cnum: CrateNum, index_guess: u32, hash: ExpnHash) -> ExpnId {
self.get_crate_data(cnum).expn_hash_to_expn_id(index_guess, hash)
}
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata {
encoder::encode_metadata(tcx)
}
}

View File

@ -2101,7 +2101,9 @@ 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.
pub(super) fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
// Since encoding metadata is not in a query, and nothing is cached,
// there's no need to do dep-graph tracking for any of it.
tcx.dep_graph.assert_ignored();

View File

@ -32,6 +32,7 @@ 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;
use rustc_span::hygiene::SyntaxContextData;

View File

@ -2,8 +2,6 @@
//! are *mostly* used as a part of that interface, but these should
//! probably get a better home if someone can find one.
use crate::ty::TyCtxt;
use rustc_ast as ast;
use rustc_data_structures::sync::{self, MetadataRef};
use rustc_hir::def_id::{CrateNum, DefId, StableCrateId, LOCAL_CRATE};
@ -204,9 +202,6 @@ pub trait CrateStore: std::fmt::Debug {
/// Fetch a DefId from a DefPathHash for a foreign crate.
fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId;
fn expn_hash_to_expn_id(&self, cnum: CrateNum, index_guess: u32, hash: ExpnHash) -> ExpnId;
// utility functions
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
}
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;

View File

@ -7,7 +7,6 @@ use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
use crate::middle;
use crate::middle::cstore::EncodedMetadata;
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath, ObjectLifetimeDefault};
use crate::middle::stability;
use crate::mir::interpret::{self, AllocId, Allocation, ConstValue, Scalar};
@ -1324,11 +1323,6 @@ impl<'tcx> TyCtxt<'tcx> {
)
}
pub fn encode_metadata(self) -> EncodedMetadata {
let _prof_timer = self.prof.verbose_generic_activity("generate_crate_metadata");
self.untracked_resolutions.cstore.encode_metadata(self)
}
/// Note that this is *untracked* and should only be used within the query
/// system if the result is otherwise tracked through queries
pub fn cstore_untracked(self) -> &'tcx ty::CrateStoreDyn {