diff options
| author | Ben Kimock <kimockb@gmail.com> | 2023-04-29 21:51:32 -0400 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2023-09-04 12:16:50 -0400 |
| commit | 94fe18f84be026b8e56e81e02545dafc6cfe7378 (patch) | |
| tree | fb2d6cc76a050268a1d5432afbd576e2deee0669 /compiler/rustc_middle/src | |
| parent | bf1e3f31f95c0f75b9bf51a58e8684f750f919f2 (diff) | |
| download | rust-94fe18f84be026b8e56e81e02545dafc6cfe7378.tar.gz rust-94fe18f84be026b8e56e81e02545dafc6cfe7378.zip | |
Use a specialized varint + bitpacking scheme for DepGraph encoding
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/dep_graph/mod.rs | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index afcf08395bb..78a0f82db13 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -97,7 +97,7 @@ macro_rules! define_dep_nodes { // discriminants of the variants have been assigned consecutively from 0 // so that just the one comparison suffices to check that the u16 can be // transmuted to a DepKind. - const VARIANTS: u16 = { + pub const VARIANTS: u16 = { let deps: &[DepKind] = &[$(DepKind::$variant,)*]; let mut i = 0; while i < deps.len() { diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index f79ce08b8ae..87436f9eeed 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -26,6 +26,7 @@ pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCt impl rustc_query_system::dep_graph::DepKind for DepKind { const NULL: Self = DepKind::Null; const RED: Self = DepKind::Red; + const MAX: u16 = DepKind::VARIANTS - 1; fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}(", node.kind)?; @@ -68,6 +69,21 @@ impl rustc_query_system::dep_graph::DepKind for DepKind { op(icx.task_deps) }) } + + #[track_caller] + #[inline] + fn from_u16(u: u16) -> Self { + if u > Self::MAX { + panic!("Invalid DepKind {u}"); + } + // SAFETY: See comment on DepKind::VARIANTS + unsafe { std::mem::transmute(u) } + } + + #[inline] + fn to_u16(self) -> u16 { + self as u16 + } } impl<'tcx> DepContext for TyCtxt<'tcx> { |
