Skip to content

Commit c021ba4

Browse files
Delete Decoder::read_struct
1 parent a421b63 commit c021ba4

File tree

5 files changed

+77
-101
lines changed

5 files changed

+77
-101
lines changed

compiler/rustc_macros/src/serialize.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@ fn decodable_body(
4242
}
4343
let ty_name = s.ast().ident.to_string();
4444
let decode_body = match s.variants() {
45-
[vi] => {
46-
let construct = vi.construct(|field, index| decode_field(field, index, true));
47-
quote! {
48-
::rustc_serialize::Decoder::read_struct(
49-
__decoder,
50-
|__decoder| { #construct },
51-
)
52-
}
53-
}
45+
[vi] => vi.construct(|field, index| decode_field(field, index, true)),
5446
variants => {
5547
let match_inner: TokenStream = variants
5648
.iter()

compiler/rustc_query_system/src/dep_graph/serialized.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,26 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
122122
let mut edge_list_data = Vec::with_capacity(edge_count);
123123

124124
for _index in 0..node_count {
125-
d.read_struct(|d| {
126-
let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
127-
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
128-
debug_assert_eq!(_i.index(), _index);
129-
130-
let fingerprint: Fingerprint =
131-
d.read_struct_field("fingerprint", Decodable::decode);
132-
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
133-
debug_assert_eq!(_i.index(), _index);
134-
135-
d.read_struct_field("edges", |d| {
136-
d.read_seq(|d, len| {
137-
let start = edge_list_data.len().try_into().unwrap();
138-
for _ in 0..len {
139-
let edge = d.read_seq_elt(Decodable::decode);
140-
edge_list_data.push(edge);
141-
}
142-
let end = edge_list_data.len().try_into().unwrap();
143-
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
144-
debug_assert_eq!(_i.index(), _index);
145-
})
125+
let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
126+
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
127+
debug_assert_eq!(_i.index(), _index);
128+
129+
let fingerprint: Fingerprint = d.read_struct_field("fingerprint", Decodable::decode);
130+
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
131+
debug_assert_eq!(_i.index(), _index);
132+
133+
d.read_struct_field("edges", |d| {
134+
d.read_seq(|d, len| {
135+
let start = edge_list_data.len().try_into().unwrap();
136+
for _ in 0..len {
137+
let edge = d.read_seq_elt(Decodable::decode);
138+
edge_list_data.push(edge);
139+
}
140+
let end = edge_list_data.len().try_into().unwrap();
141+
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
142+
debug_assert_eq!(_i.index(), _index);
146143
})
147-
});
144+
})
148145
}
149146

150147
let index: FxHashMap<_, _> =

compiler/rustc_serialize/src/serialize.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,6 @@ pub trait Decoder {
210210
f(self, disr)
211211
}
212212

213-
#[inline]
214-
fn read_struct<T, F>(&mut self, f: F) -> T
215-
where
216-
F: FnOnce(&mut Self) -> T,
217-
{
218-
f(self)
219-
}
220-
221213
#[inline]
222214
fn read_struct_field<T, F>(&mut self, _f_name: &str, f: F) -> T
223215
where

compiler/rustc_span/src/def_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ impl<E: Encoder> Encodable<E> for DefId {
299299

300300
impl<D: Decoder> Decodable<D> for DefId {
301301
default fn decode(d: &mut D) -> DefId {
302-
d.read_struct(|d| DefId {
302+
DefId {
303303
krate: d.read_struct_field("krate", Decodable::decode),
304304
index: d.read_struct_field("index", Decodable::decode),
305-
})
305+
}
306306
}
307307
}
308308

compiler/rustc_span/src/lib.rs

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -979,12 +979,10 @@ impl<E: Encoder> Encodable<E> for Span {
979979
}
980980
impl<D: Decoder> Decodable<D> for Span {
981981
default fn decode(s: &mut D) -> Span {
982-
s.read_struct(|d| {
983-
let lo = d.read_struct_field("lo", Decodable::decode);
984-
let hi = d.read_struct_field("hi", Decodable::decode);
982+
let lo = s.read_struct_field("lo", Decodable::decode);
983+
let hi = s.read_struct_field("hi", Decodable::decode);
985984

986-
Span::new(lo, hi, SyntaxContext::root(), None)
987-
})
985+
Span::new(lo, hi, SyntaxContext::root(), None)
988986
}
989987
}
990988

@@ -1440,65 +1438,62 @@ impl<S: Encoder> Encodable<S> for SourceFile {
14401438

14411439
impl<D: Decoder> Decodable<D> for SourceFile {
14421440
fn decode(d: &mut D) -> SourceFile {
1443-
d.read_struct(|d| {
1444-
let name: FileName = d.read_struct_field("name", |d| Decodable::decode(d));
1445-
let src_hash: SourceFileHash =
1446-
d.read_struct_field("src_hash", |d| Decodable::decode(d));
1447-
let start_pos: BytePos = d.read_struct_field("start_pos", |d| Decodable::decode(d));
1448-
let end_pos: BytePos = d.read_struct_field("end_pos", |d| Decodable::decode(d));
1449-
let lines: Vec<BytePos> = d.read_struct_field("lines", |d| {
1450-
let num_lines: u32 = Decodable::decode(d);
1451-
let mut lines = Vec::with_capacity(num_lines as usize);
1452-
1453-
if num_lines > 0 {
1454-
// Read the number of bytes used per diff.
1455-
let bytes_per_diff: u8 = Decodable::decode(d);
1456-
1457-
// Read the first element.
1458-
let mut line_start: BytePos = Decodable::decode(d);
1459-
lines.push(line_start);
1460-
1461-
for _ in 1..num_lines {
1462-
let diff = match bytes_per_diff {
1463-
1 => d.read_u8() as u32,
1464-
2 => d.read_u16() as u32,
1465-
4 => d.read_u32(),
1466-
_ => unreachable!(),
1467-
};
1441+
let name: FileName = d.read_struct_field("name", |d| Decodable::decode(d));
1442+
let src_hash: SourceFileHash = d.read_struct_field("src_hash", |d| Decodable::decode(d));
1443+
let start_pos: BytePos = d.read_struct_field("start_pos", |d| Decodable::decode(d));
1444+
let end_pos: BytePos = d.read_struct_field("end_pos", |d| Decodable::decode(d));
1445+
let lines: Vec<BytePos> = d.read_struct_field("lines", |d| {
1446+
let num_lines: u32 = Decodable::decode(d);
1447+
let mut lines = Vec::with_capacity(num_lines as usize);
1448+
1449+
if num_lines > 0 {
1450+
// Read the number of bytes used per diff.
1451+
let bytes_per_diff: u8 = Decodable::decode(d);
1452+
1453+
// Read the first element.
1454+
let mut line_start: BytePos = Decodable::decode(d);
1455+
lines.push(line_start);
1456+
1457+
for _ in 1..num_lines {
1458+
let diff = match bytes_per_diff {
1459+
1 => d.read_u8() as u32,
1460+
2 => d.read_u16() as u32,
1461+
4 => d.read_u32(),
1462+
_ => unreachable!(),
1463+
};
14681464

1469-
line_start = line_start + BytePos(diff);
1465+
line_start = line_start + BytePos(diff);
14701466

1471-
lines.push(line_start);
1472-
}
1467+
lines.push(line_start);
14731468
}
1474-
1475-
lines
1476-
});
1477-
let multibyte_chars: Vec<MultiByteChar> =
1478-
d.read_struct_field("multibyte_chars", |d| Decodable::decode(d));
1479-
let non_narrow_chars: Vec<NonNarrowChar> =
1480-
d.read_struct_field("non_narrow_chars", |d| Decodable::decode(d));
1481-
let name_hash: u128 = d.read_struct_field("name_hash", |d| Decodable::decode(d));
1482-
let normalized_pos: Vec<NormalizedPos> =
1483-
d.read_struct_field("normalized_pos", |d| Decodable::decode(d));
1484-
let cnum: CrateNum = d.read_struct_field("cnum", |d| Decodable::decode(d));
1485-
SourceFile {
1486-
name,
1487-
start_pos,
1488-
end_pos,
1489-
src: None,
1490-
src_hash,
1491-
// Unused - the metadata decoder will construct
1492-
// a new SourceFile, filling in `external_src` properly
1493-
external_src: Lock::new(ExternalSource::Unneeded),
1494-
lines,
1495-
multibyte_chars,
1496-
non_narrow_chars,
1497-
normalized_pos,
1498-
name_hash,
1499-
cnum,
15001469
}
1501-
})
1470+
1471+
lines
1472+
});
1473+
let multibyte_chars: Vec<MultiByteChar> =
1474+
d.read_struct_field("multibyte_chars", |d| Decodable::decode(d));
1475+
let non_narrow_chars: Vec<NonNarrowChar> =
1476+
d.read_struct_field("non_narrow_chars", |d| Decodable::decode(d));
1477+
let name_hash: u128 = d.read_struct_field("name_hash", |d| Decodable::decode(d));
1478+
let normalized_pos: Vec<NormalizedPos> =
1479+
d.read_struct_field("normalized_pos", |d| Decodable::decode(d));
1480+
let cnum: CrateNum = d.read_struct_field("cnum", |d| Decodable::decode(d));
1481+
SourceFile {
1482+
name,
1483+
start_pos,
1484+
end_pos,
1485+
src: None,
1486+
src_hash,
1487+
// Unused - the metadata decoder will construct
1488+
// a new SourceFile, filling in `external_src` properly
1489+
external_src: Lock::new(ExternalSource::Unneeded),
1490+
lines,
1491+
multibyte_chars,
1492+
non_narrow_chars,
1493+
normalized_pos,
1494+
name_hash,
1495+
cnum,
1496+
}
15021497
}
15031498
}
15041499

0 commit comments

Comments
 (0)