Skip to content

Commit 61d483c

Browse files
committed
Move encode_metadata out of CrateStore.
1 parent 603ab5b commit 61d483c

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

compiler/rustc_interface/src/callbacks.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
use rustc_errors::{Diagnostic, TRACK_DIAGNOSTICS};
1313
use rustc_middle::ty::tls;
14+
use rustc_middle::ty::TyCtxt;
1415
use std::fmt;
1516

1617
/// This is a callback from librustc_ast as it cannot access the implicit state
@@ -57,5 +58,7 @@ fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) ->
5758
pub fn setup_callbacks() {
5859
rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
5960
rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
61+
rustc_middle::ty::ENCODE_METADATA
62+
.swap(&(rustc_metadata::encode_metadata as fn(TyCtxt<'_>) -> _));
6063
TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_)));
6164
}

compiler/rustc_metadata/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ mod rmeta;
3434
pub mod creader;
3535
pub mod dynamic_lib;
3636
pub mod locator;
37+
38+
pub use rmeta::encode_metadata;

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::creader::{CStore, LoadedMacro};
22
use crate::foreign_modules;
33
use crate::link_args;
44
use crate::native_libs;
5-
use crate::rmeta::{self, encoder};
5+
use crate::rmeta;
66

77
use rustc_ast as ast;
88
use rustc_ast::expand::allocator::AllocatorKind;
@@ -14,7 +14,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}
1414
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
1515
use rustc_middle::hir::exports::Export;
1616
use rustc_middle::middle::cstore::ForeignModule;
17-
use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata};
17+
use rustc_middle::middle::cstore::{CrateSource, CrateStore};
1818
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1919
use rustc_middle::middle::stability::DeprecationEntry;
2020
use rustc_middle::ty::query::Providers;
@@ -512,10 +512,6 @@ impl CrateStore for CStore {
512512
result
513513
}
514514

515-
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata {
516-
encoder::encode_metadata(tcx)
517-
}
518-
519515
fn metadata_encoding_version(&self) -> &[u8] {
520516
rmeta::METADATA_HEADER
521517
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
20022002
// will allow us to slice the metadata to the precise length that we just
20032003
// generated regardless of trailing bytes that end up in it.
20042004

2005-
pub(super) fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
2005+
pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
20062006
// Since encoding metadata is not in a query, and nothing is cached,
20072007
// there's no need to do dep-graph tracking for any of it.
20082008
tcx.dep_graph.assert_ignored();

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::num::NonZeroUsize;
3030
use decoder::DecodeContext;
3131
pub use decoder::{provide, provide_extern};
3232
crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob};
33+
pub use encoder::encode_metadata;
3334
use encoder::EncodeContext;
3435
use rustc_span::hygiene::SyntaxContextData;
3536

compiler/rustc_middle/src/middle/cstore.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ pub trait CrateStore {
203203
fn crates_untracked(&self) -> Vec<CrateNum>;
204204

205205
// utility functions
206-
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
207206
fn metadata_encoding_version(&self) -> &[u8];
208207
fn allocator_kind(&self) -> Option<AllocatorKind>;
209208
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_data_structures::stable_hasher::{
3535
use rustc_data_structures::steal::Steal;
3636
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
3737
use rustc_data_structures::unhash::UnhashMap;
38+
use rustc_data_structures::AtomicRef;
3839
use rustc_errors::ErrorReported;
3940
use rustc_hir as hir;
4041
use rustc_hir::def::{DefKind, Res};
@@ -979,6 +980,12 @@ pub struct GlobalCtxt<'tcx> {
979980
output_filenames: Arc<OutputFilenames>,
980981
}
981982

983+
fn dummy_encode_metadata(_: TyCtxt<'_>) -> EncodedMetadata {
984+
panic!("Unregistered callback to `encode_metadata`.")
985+
}
986+
pub static ENCODE_METADATA: AtomicRef<fn(TyCtxt<'_>) -> EncodedMetadata> =
987+
AtomicRef::new(&(dummy_encode_metadata as fn(TyCtxt<'_>) -> _));
988+
982989
impl<'tcx> TyCtxt<'tcx> {
983990
pub fn typeck_opt_const_arg(
984991
self,
@@ -1279,7 +1286,7 @@ impl<'tcx> TyCtxt<'tcx> {
12791286

12801287
pub fn encode_metadata(self) -> EncodedMetadata {
12811288
let _prof_timer = self.prof.verbose_generic_activity("generate_crate_metadata");
1282-
self.cstore.encode_metadata(self)
1289+
(*ENCODE_METADATA)(self)
12831290
}
12841291

12851292
// Note that this is *untracked* and should only be used within the query

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ mod list;
119119
mod structural_impls;
120120
mod sty;
121121

122+
pub use context::ENCODE_METADATA;
123+
122124
// Data types
123125

124126
pub struct ResolverOutputs {

0 commit comments

Comments
 (0)