mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +00:00
Delete Decoder::read_struct
This commit is contained in:
parent
a421b631ba
commit
c021ba48a7
@ -42,15 +42,7 @@ fn decodable_body(
|
|||||||
}
|
}
|
||||||
let ty_name = s.ast().ident.to_string();
|
let ty_name = s.ast().ident.to_string();
|
||||||
let decode_body = match s.variants() {
|
let decode_body = match s.variants() {
|
||||||
[vi] => {
|
[vi] => vi.construct(|field, index| decode_field(field, index, true)),
|
||||||
let construct = vi.construct(|field, index| decode_field(field, index, true));
|
|
||||||
quote! {
|
|
||||||
::rustc_serialize::Decoder::read_struct(
|
|
||||||
__decoder,
|
|
||||||
|__decoder| { #construct },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variants => {
|
variants => {
|
||||||
let match_inner: TokenStream = variants
|
let match_inner: TokenStream = variants
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -122,29 +122,26 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
|
|||||||
let mut edge_list_data = Vec::with_capacity(edge_count);
|
let mut edge_list_data = Vec::with_capacity(edge_count);
|
||||||
|
|
||||||
for _index in 0..node_count {
|
for _index in 0..node_count {
|
||||||
d.read_struct(|d| {
|
let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
|
||||||
let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
|
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
|
||||||
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
|
debug_assert_eq!(_i.index(), _index);
|
||||||
debug_assert_eq!(_i.index(), _index);
|
|
||||||
|
|
||||||
let fingerprint: Fingerprint =
|
let fingerprint: Fingerprint = d.read_struct_field("fingerprint", Decodable::decode);
|
||||||
d.read_struct_field("fingerprint", Decodable::decode);
|
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
|
||||||
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
|
debug_assert_eq!(_i.index(), _index);
|
||||||
debug_assert_eq!(_i.index(), _index);
|
|
||||||
|
|
||||||
d.read_struct_field("edges", |d| {
|
d.read_struct_field("edges", |d| {
|
||||||
d.read_seq(|d, len| {
|
d.read_seq(|d, len| {
|
||||||
let start = edge_list_data.len().try_into().unwrap();
|
let start = edge_list_data.len().try_into().unwrap();
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
let edge = d.read_seq_elt(Decodable::decode);
|
let edge = d.read_seq_elt(Decodable::decode);
|
||||||
edge_list_data.push(edge);
|
edge_list_data.push(edge);
|
||||||
}
|
}
|
||||||
let end = edge_list_data.len().try_into().unwrap();
|
let end = edge_list_data.len().try_into().unwrap();
|
||||||
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
|
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
|
||||||
debug_assert_eq!(_i.index(), _index);
|
debug_assert_eq!(_i.index(), _index);
|
||||||
})
|
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let index: FxHashMap<_, _> =
|
let index: FxHashMap<_, _> =
|
||||||
|
@ -210,14 +210,6 @@ pub trait Decoder {
|
|||||||
f(self, disr)
|
f(self, disr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn read_struct<T, F>(&mut self, f: F) -> T
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut Self) -> T,
|
|
||||||
{
|
|
||||||
f(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read_struct_field<T, F>(&mut self, _f_name: &str, f: F) -> T
|
fn read_struct_field<T, F>(&mut self, _f_name: &str, f: F) -> T
|
||||||
where
|
where
|
||||||
|
@ -299,10 +299,10 @@ impl<E: Encoder> Encodable<E> for DefId {
|
|||||||
|
|
||||||
impl<D: Decoder> Decodable<D> for DefId {
|
impl<D: Decoder> Decodable<D> for DefId {
|
||||||
default fn decode(d: &mut D) -> DefId {
|
default fn decode(d: &mut D) -> DefId {
|
||||||
d.read_struct(|d| DefId {
|
DefId {
|
||||||
krate: d.read_struct_field("krate", Decodable::decode),
|
krate: d.read_struct_field("krate", Decodable::decode),
|
||||||
index: d.read_struct_field("index", Decodable::decode),
|
index: d.read_struct_field("index", Decodable::decode),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -979,12 +979,10 @@ impl<E: Encoder> Encodable<E> for Span {
|
|||||||
}
|
}
|
||||||
impl<D: Decoder> Decodable<D> for Span {
|
impl<D: Decoder> Decodable<D> for Span {
|
||||||
default fn decode(s: &mut D) -> Span {
|
default fn decode(s: &mut D) -> Span {
|
||||||
s.read_struct(|d| {
|
let lo = s.read_struct_field("lo", Decodable::decode);
|
||||||
let lo = d.read_struct_field("lo", Decodable::decode);
|
let hi = s.read_struct_field("hi", Decodable::decode);
|
||||||
let hi = d.read_struct_field("hi", Decodable::decode);
|
|
||||||
|
|
||||||
Span::new(lo, hi, SyntaxContext::root(), None)
|
Span::new(lo, hi, SyntaxContext::root(), None)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1440,65 +1438,62 @@ impl<S: Encoder> Encodable<S> for SourceFile {
|
|||||||
|
|
||||||
impl<D: Decoder> Decodable<D> for SourceFile {
|
impl<D: Decoder> Decodable<D> for SourceFile {
|
||||||
fn decode(d: &mut D) -> SourceFile {
|
fn decode(d: &mut D) -> SourceFile {
|
||||||
d.read_struct(|d| {
|
let name: FileName = d.read_struct_field("name", |d| Decodable::decode(d));
|
||||||
let name: FileName = d.read_struct_field("name", |d| Decodable::decode(d));
|
let src_hash: SourceFileHash = d.read_struct_field("src_hash", |d| Decodable::decode(d));
|
||||||
let src_hash: SourceFileHash =
|
let start_pos: BytePos = d.read_struct_field("start_pos", |d| Decodable::decode(d));
|
||||||
d.read_struct_field("src_hash", |d| Decodable::decode(d));
|
let end_pos: BytePos = d.read_struct_field("end_pos", |d| Decodable::decode(d));
|
||||||
let start_pos: BytePos = d.read_struct_field("start_pos", |d| Decodable::decode(d));
|
let lines: Vec<BytePos> = d.read_struct_field("lines", |d| {
|
||||||
let end_pos: BytePos = d.read_struct_field("end_pos", |d| Decodable::decode(d));
|
let num_lines: u32 = Decodable::decode(d);
|
||||||
let lines: Vec<BytePos> = d.read_struct_field("lines", |d| {
|
let mut lines = Vec::with_capacity(num_lines as usize);
|
||||||
let num_lines: u32 = Decodable::decode(d);
|
|
||||||
let mut lines = Vec::with_capacity(num_lines as usize);
|
|
||||||
|
|
||||||
if num_lines > 0 {
|
if num_lines > 0 {
|
||||||
// Read the number of bytes used per diff.
|
// Read the number of bytes used per diff.
|
||||||
let bytes_per_diff: u8 = Decodable::decode(d);
|
let bytes_per_diff: u8 = Decodable::decode(d);
|
||||||
|
|
||||||
|
// Read the first element.
|
||||||
|
let mut line_start: BytePos = Decodable::decode(d);
|
||||||
|
lines.push(line_start);
|
||||||
|
|
||||||
|
for _ in 1..num_lines {
|
||||||
|
let diff = match bytes_per_diff {
|
||||||
|
1 => d.read_u8() as u32,
|
||||||
|
2 => d.read_u16() as u32,
|
||||||
|
4 => d.read_u32(),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
line_start = line_start + BytePos(diff);
|
||||||
|
|
||||||
// Read the first element.
|
|
||||||
let mut line_start: BytePos = Decodable::decode(d);
|
|
||||||
lines.push(line_start);
|
lines.push(line_start);
|
||||||
|
|
||||||
for _ in 1..num_lines {
|
|
||||||
let diff = match bytes_per_diff {
|
|
||||||
1 => d.read_u8() as u32,
|
|
||||||
2 => d.read_u16() as u32,
|
|
||||||
4 => d.read_u32(),
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
line_start = line_start + BytePos(diff);
|
|
||||||
|
|
||||||
lines.push(line_start);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lines
|
|
||||||
});
|
|
||||||
let multibyte_chars: Vec<MultiByteChar> =
|
|
||||||
d.read_struct_field("multibyte_chars", |d| Decodable::decode(d));
|
|
||||||
let non_narrow_chars: Vec<NonNarrowChar> =
|
|
||||||
d.read_struct_field("non_narrow_chars", |d| Decodable::decode(d));
|
|
||||||
let name_hash: u128 = d.read_struct_field("name_hash", |d| Decodable::decode(d));
|
|
||||||
let normalized_pos: Vec<NormalizedPos> =
|
|
||||||
d.read_struct_field("normalized_pos", |d| Decodable::decode(d));
|
|
||||||
let cnum: CrateNum = d.read_struct_field("cnum", |d| Decodable::decode(d));
|
|
||||||
SourceFile {
|
|
||||||
name,
|
|
||||||
start_pos,
|
|
||||||
end_pos,
|
|
||||||
src: None,
|
|
||||||
src_hash,
|
|
||||||
// Unused - the metadata decoder will construct
|
|
||||||
// a new SourceFile, filling in `external_src` properly
|
|
||||||
external_src: Lock::new(ExternalSource::Unneeded),
|
|
||||||
lines,
|
|
||||||
multibyte_chars,
|
|
||||||
non_narrow_chars,
|
|
||||||
normalized_pos,
|
|
||||||
name_hash,
|
|
||||||
cnum,
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
lines
|
||||||
|
});
|
||||||
|
let multibyte_chars: Vec<MultiByteChar> =
|
||||||
|
d.read_struct_field("multibyte_chars", |d| Decodable::decode(d));
|
||||||
|
let non_narrow_chars: Vec<NonNarrowChar> =
|
||||||
|
d.read_struct_field("non_narrow_chars", |d| Decodable::decode(d));
|
||||||
|
let name_hash: u128 = d.read_struct_field("name_hash", |d| Decodable::decode(d));
|
||||||
|
let normalized_pos: Vec<NormalizedPos> =
|
||||||
|
d.read_struct_field("normalized_pos", |d| Decodable::decode(d));
|
||||||
|
let cnum: CrateNum = d.read_struct_field("cnum", |d| Decodable::decode(d));
|
||||||
|
SourceFile {
|
||||||
|
name,
|
||||||
|
start_pos,
|
||||||
|
end_pos,
|
||||||
|
src: None,
|
||||||
|
src_hash,
|
||||||
|
// Unused - the metadata decoder will construct
|
||||||
|
// a new SourceFile, filling in `external_src` properly
|
||||||
|
external_src: Lock::new(ExternalSource::Unneeded),
|
||||||
|
lines,
|
||||||
|
multibyte_chars,
|
||||||
|
non_narrow_chars,
|
||||||
|
normalized_pos,
|
||||||
|
name_hash,
|
||||||
|
cnum,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user