summaryrefslogtreecommitdiff
path: root/compiler/rustc_query_system/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-04-26 02:36:42 +0000
committerbors <bors@rust-lang.org>2023-04-26 02:36:42 +0000
commitadaac6b166df57ea5a20d56e4cce503b55aca927 (patch)
tree2a058aa7f4bc9cc6cf3586c7dcb24afa19bdbf86 /compiler/rustc_query_system/src
parent84d4f16728ed2e5a90c800d6d84225be3ca7c3c8 (diff)
parent1f67ba61a985c621cb10ae091aaa5c2b009aa721 (diff)
downloadrust-adaac6b166df57ea5a20d56e4cce503b55aca927.tar.gz
Auto merge of #110634 - saethlin:pointy-decoder, r=cjgillot
Rewrite MemDecoder around pointers not a slice This is basically https://github.com/rust-lang/rust/pull/109910 but I'm being a lot more aggressive. The pointer-based structure means that it makes a lot more sense to absorb more complexity into `MemDecoder`, most of the diff is just complexity moving from one place to another. The primary argument for this structure is that we only incur a single bounds check when doing multi-byte reads from a `MemDecoder`. With the slice-based implementation we need to do those with `data[position..position + len]` , which needs to account for `position + len` wrapping. It would be possible to dodge the first bounds check if we stored a slice that starts at `position`, but that would require updating the pointer and length on every read. This PR also embeds the failure path in a separate function, which means that this PR should subsume all the perf wins observed in https://github.com/rust-lang/rust/pull/109867.
Diffstat (limited to 'compiler/rustc_query_system/src')
-rw-r--r--compiler/rustc_query_system/src/dep_graph/serialized.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs
index 59c1333fb5a..edddfda6242 100644
--- a/compiler/rustc_query_system/src/dep_graph/serialized.rs
+++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs
@@ -94,21 +94,19 @@ impl<'a, K: DepKind + Decodable<MemDecoder<'a>>> Decodable<MemDecoder<'a>>
{
#[instrument(level = "debug", skip(d))]
fn decode(d: &mut MemDecoder<'a>) -> SerializedDepGraph<K> {
- let start_position = d.position();
-
// The last 16 bytes are the node count and edge count.
debug!("position: {:?}", d.position());
- d.set_position(d.data.len() - 2 * IntEncodedWithFixedSize::ENCODED_SIZE);
+ let (node_count, edge_count) =
+ d.with_position(d.len() - 2 * IntEncodedWithFixedSize::ENCODED_SIZE, |d| {
+ debug!("position: {:?}", d.position());
+ let node_count = IntEncodedWithFixedSize::decode(d).0 as usize;
+ let edge_count = IntEncodedWithFixedSize::decode(d).0 as usize;
+ (node_count, edge_count)
+ });
debug!("position: {:?}", d.position());
- let node_count = IntEncodedWithFixedSize::decode(d).0 as usize;
- let edge_count = IntEncodedWithFixedSize::decode(d).0 as usize;
debug!(?node_count, ?edge_count);
- debug!("position: {:?}", d.position());
- d.set_position(start_position);
- debug!("position: {:?}", d.position());
-
let mut nodes = IndexVec::with_capacity(node_count);
let mut fingerprints = IndexVec::with_capacity(node_count);
let mut edge_list_indices = IndexVec::with_capacity(node_count);