-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Replace DepKind
by trait objects
#78314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0a4d948
de76370
de7da7f
e853cc0
57ba8ed
276d0e3
dd9ce3e
9249a52
f74b0b9
f8c6f42
5e3cea6
253da5d
6d818bd
c0ccc7d
908d735
f06e3d9
42baef9
41720af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX}; | |
use rustc_hir::definitions::DefPathHash; | ||
use rustc_hir::HirId; | ||
use rustc_query_system::query::QueryAccessors; | ||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; | ||
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder}; | ||
use rustc_span::symbol::Symbol; | ||
use std::hash::Hash; | ||
|
||
|
@@ -84,6 +84,13 @@ pub trait DepKindTrait: std::fmt::Debug + Sync { | |
|
||
fn has_params(&self) -> bool; | ||
|
||
fn encode_query_results<'a, 'tcx>( | ||
&self, | ||
tcx: TyCtxt<'tcx>, | ||
encoder: &mut query::on_disk_cache::CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
query_result_index: &mut query::on_disk_cache::EncodedQueryResultIndex, | ||
); | ||
|
||
fn force_from_dep_node(&self, tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool; | ||
|
||
fn query_stats(&self, tcx: TyCtxt<'_>) -> Option<query::stats::QueryStats>; | ||
|
@@ -124,6 +131,19 @@ macro_rules! contains_eval_always_attr { | |
($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_eval_always_attr!($attr) | )* false}); | ||
} | ||
|
||
macro_rules! encode_query_results { | ||
([][$variant:ident][$($args:expr),*]) => {{}}; | ||
([cached $($rest:tt)*][$variant:ident][$($args:expr),*]) => {{ | ||
let ret = query::on_disk_cache::encode_query_results::< | ||
query::queries::$variant<'_> | ||
>($($args),*); | ||
match ret { Ok(()) => (), Err(_) => () } | ||
}}; | ||
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$variant:ident][$($args:expr),*]) => { | ||
encode_query_results!([$($($modifiers)*)*][$variant][$($args),*]) | ||
}; | ||
} | ||
|
||
macro_rules! define_dep_kinds { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move this into a new file |
||
(<$tcx:tt> | ||
$( | ||
|
@@ -176,6 +196,16 @@ macro_rules! define_dep_kinds { | |
false | ||
} | ||
|
||
#[inline] | ||
fn encode_query_results<'a, 'tcx>( | ||
&self, | ||
_tcx: TyCtxt<'tcx>, | ||
_encoder: &mut query::on_disk_cache::CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
_query_result_index: &mut query::on_disk_cache::EncodedQueryResultIndex, | ||
) { | ||
encode_query_results!([$($attrs)*][$variant][_tcx, _encoder, _query_result_index]); | ||
} | ||
|
||
#[inline] | ||
fn force_from_dep_node(&self, tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool { | ||
use rustc_query_system::query::force_query; | ||
|
@@ -422,6 +452,15 @@ impl DepKindTrait for dep_kind::Null { | |
false | ||
} | ||
|
||
#[inline] | ||
fn encode_query_results<'a, 'tcx>( | ||
&self, | ||
_tcx: TyCtxt<'tcx>, | ||
_encoder: &mut query::on_disk_cache::CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
_query_result_index: &mut query::on_disk_cache::EncodedQueryResultIndex, | ||
) { | ||
} | ||
|
||
#[inline] | ||
fn force_from_dep_node(&self, _tcx: TyCtxt<'tcx>, _dep_node: &DepNode) -> bool { | ||
// Forcing this makes no sense. | ||
|
@@ -463,6 +502,15 @@ impl DepKindTrait for dep_kind::CrateMetadata { | |
true | ||
} | ||
|
||
#[inline] | ||
fn encode_query_results<'a, 'tcx>( | ||
&self, | ||
_tcx: TyCtxt<'tcx>, | ||
_encoder: &mut query::on_disk_cache::CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
_query_result_index: &mut query::on_disk_cache::EncodedQueryResultIndex, | ||
) { | ||
} | ||
|
||
#[inline] | ||
fn force_from_dep_node(&self, _tcx: TyCtxt<'tcx>, _dep_node: &DepNode) -> bool { | ||
// These are inputs that are expected to be pre-allocated and that | ||
|
@@ -509,6 +557,15 @@ impl DepKindTrait for dep_kind::TraitSelect { | |
false | ||
} | ||
|
||
#[inline] | ||
fn encode_query_results<'a, 'tcx>( | ||
&self, | ||
_tcx: TyCtxt<'tcx>, | ||
_encoder: &mut query::on_disk_cache::CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
_query_result_index: &mut query::on_disk_cache::EncodedQueryResultIndex, | ||
) { | ||
} | ||
|
||
#[inline] | ||
fn force_from_dep_node(&self, _tcx: TyCtxt<'tcx>, _dep_node: &DepNode) -> bool { | ||
// These are anonymous nodes. | ||
|
@@ -555,6 +612,15 @@ impl DepKindTrait for dep_kind::CompileCodegenUnit { | |
true | ||
} | ||
|
||
#[inline] | ||
fn encode_query_results<'a, 'tcx>( | ||
&self, | ||
_tcx: TyCtxt<'tcx>, | ||
_encoder: &mut query::on_disk_cache::CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
_query_result_index: &mut query::on_disk_cache::EncodedQueryResultIndex, | ||
) { | ||
} | ||
|
||
#[inline] | ||
fn force_from_dep_node(&self, _tcx: TyCtxt<'tcx>, _dep_node: &DepNode) -> bool { | ||
// We don't have enough information to reconstruct the query key of these. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,15 +97,15 @@ struct Footer { | |
expn_data: FxHashMap<u32, AbsoluteBytePos>, | ||
} | ||
|
||
type EncodedQueryResultIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>; | ||
pub type EncodedQueryResultIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>; | ||
type EncodedDiagnosticsIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>; | ||
type EncodedDiagnostics = Vec<Diagnostic>; | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable)] | ||
struct SourceFileIndex(u32); | ||
|
||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Encodable, Decodable)] | ||
struct AbsoluteBytePos(u32); | ||
pub struct AbsoluteBytePos(u32); | ||
|
||
impl AbsoluteBytePos { | ||
fn new(pos: usize) -> AbsoluteBytePos { | ||
|
@@ -226,22 +226,10 @@ impl<'sess> OnDiskCache<'sess> { | |
let enc = &mut encoder; | ||
let qri = &mut query_result_index; | ||
|
||
macro_rules! encode_queries { | ||
($($query:ident,)*) => { | ||
$( | ||
encode_query_results::<ty::query::queries::$query<'_>>( | ||
tcx, | ||
enc, | ||
qri | ||
)?; | ||
)* | ||
} | ||
for dk in rustc_middle::dep_graph::DEP_KINDS { | ||
dk.encode_query_results(tcx, enc, qri) | ||
} | ||
|
||
rustc_cached_queries!(encode_queries!); | ||
|
||
Ok(()) | ||
})?; | ||
}); | ||
|
||
// Encode diagnostics. | ||
let diagnostics_index: EncodedDiagnosticsIndex = self | ||
|
@@ -765,7 +753,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [Span] { | |
//- ENCODING ------------------------------------------------------------------- | ||
|
||
/// This trait is a hack to work around specialization bug #55243. | ||
trait OpaqueEncoder: Encoder { | ||
pub trait OpaqueEncoder: Encoder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why move the trait to make it private and then make it public again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This trait is a hack. Ideally, all |
||
fn opaque(&mut self) -> &mut opaque::Encoder; | ||
fn encoder_position(&self) -> usize; | ||
} | ||
|
@@ -782,7 +770,7 @@ impl OpaqueEncoder for opaque::Encoder { | |
} | ||
|
||
/// An encoder that can write the incr. comp. cache. | ||
struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> { | ||
pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> { | ||
tcx: TyCtxt<'tcx>, | ||
encoder: &'a mut E, | ||
type_shorthands: FxHashMap<Ty<'tcx>, usize>, | ||
|
@@ -1005,7 +993,7 @@ impl<'a> Decodable<opaque::Decoder<'a>> for IntEncodedWithFixedSize { | |
} | ||
} | ||
|
||
fn encode_query_results<'a, 'tcx, Q>( | ||
pub fn encode_query_results<'a, 'tcx, Q>( | ||
tcx: TyCtxt<'tcx>, | ||
encoder: &mut CacheEncoder<'a, 'tcx, opaque::Encoder>, | ||
query_result_index: &mut EncodedQueryResultIndex, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this attribute used? I can't find it.
EDIT: Fount it in
encode_query_results
. Can you add a comment documenting this dependency?