Skip to content

Commit 4ecfb7f

Browse files
authored
Rollup merge of rust-lang#109984 - scottmcm:less-float, r=Nilstrieb
Remove f32 & f64 from MemDecoder/MemEncoder r? ```@Nilstrieb``` since they said (maybe joked) on discord that it's a bug if the compiler uses f32 anywhere 🙃
2 parents dbc2941 + 5cb23e4 commit 4ecfb7f

File tree

6 files changed

+14
-76
lines changed

6 files changed

+14
-76
lines changed

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
112112
emit_i8(i8);
113113

114114
emit_bool(bool);
115-
emit_f64(f64);
116-
emit_f32(f32);
117115
emit_char(char);
118116
emit_str(&str);
119117
emit_raw_bytes(&[u8]);

Diff for: compiler/rustc_middle/src/ty/codec.rs

-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,6 @@ macro_rules! implement_ty_decoder {
511511
read_isize -> isize;
512512

513513
read_bool -> bool;
514-
read_f64 -> f64;
515-
read_f32 -> f32;
516514
read_char -> char;
517515
read_str -> &str;
518516
}

Diff for: compiler/rustc_query_impl/src/on_disk_cache.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,6 @@ impl<'a, 'tcx> Encoder for CacheEncoder<'a, 'tcx> {
10461046
emit_i8(i8);
10471047

10481048
emit_bool(bool);
1049-
emit_f64(f64);
1050-
emit_f32(f32);
10511049
emit_char(char);
10521050
emit_str(&str);
10531051
emit_raw_bytes(&[u8]);

Diff for: compiler/rustc_serialize/src/opaque.rs

-36
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,6 @@ impl Encoder for MemEncoder {
122122
self.emit_u8(if v { 1 } else { 0 });
123123
}
124124

125-
#[inline]
126-
fn emit_f64(&mut self, v: f64) {
127-
let as_u64: u64 = v.to_bits();
128-
self.emit_u64(as_u64);
129-
}
130-
131-
#[inline]
132-
fn emit_f32(&mut self, v: f32) {
133-
let as_u32: u32 = v.to_bits();
134-
self.emit_u32(as_u32);
135-
}
136-
137125
#[inline]
138126
fn emit_char(&mut self, v: char) {
139127
self.emit_u32(v as u32);
@@ -500,18 +488,6 @@ impl Encoder for FileEncoder {
500488
self.emit_u8(if v { 1 } else { 0 });
501489
}
502490

503-
#[inline]
504-
fn emit_f64(&mut self, v: f64) {
505-
let as_u64: u64 = v.to_bits();
506-
self.emit_u64(as_u64);
507-
}
508-
509-
#[inline]
510-
fn emit_f32(&mut self, v: f32) {
511-
let as_u32: u32 = v.to_bits();
512-
self.emit_u32(as_u32);
513-
}
514-
515491
#[inline]
516492
fn emit_char(&mut self, v: char) {
517493
self.emit_u32(v as u32);
@@ -642,18 +618,6 @@ impl<'a> Decoder for MemDecoder<'a> {
642618
value != 0
643619
}
644620

645-
#[inline]
646-
fn read_f64(&mut self) -> f64 {
647-
let bits = self.read_u64();
648-
f64::from_bits(bits)
649-
}
650-
651-
#[inline]
652-
fn read_f32(&mut self) -> f32 {
653-
let bits = self.read_u32();
654-
f32::from_bits(bits)
655-
}
656-
657621
#[inline]
658622
fn read_char(&mut self) -> char {
659623
let bits = self.read_u32();

Diff for: compiler/rustc_serialize/src/serialize.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ use std::sync::Arc;
2222
/// be processed or ignored, whichever is appropriate. Then they should provide
2323
/// a `finish` method that finishes up encoding. If the encoder is fallible,
2424
/// `finish` should return a `Result` that indicates success or failure.
25+
///
26+
/// This current does not support `f32` nor `f64`, as they're not needed in any
27+
/// serialized data structures. That could be changed, but consider whether it
28+
/// really makes sense to store floating-point values at all.
29+
/// (If you need it, revert <https://github.com/rust-lang/rust/pull/109984>.)
2530
pub trait Encoder {
2631
// Primitive types:
2732
fn emit_usize(&mut self, v: usize);
@@ -37,8 +42,6 @@ pub trait Encoder {
3742
fn emit_i16(&mut self, v: i16);
3843
fn emit_i8(&mut self, v: i8);
3944
fn emit_bool(&mut self, v: bool);
40-
fn emit_f64(&mut self, v: f64);
41-
fn emit_f32(&mut self, v: f32);
4245
fn emit_char(&mut self, v: char);
4346
fn emit_str(&mut self, v: &str);
4447
fn emit_raw_bytes(&mut self, s: &[u8]);
@@ -58,6 +61,11 @@ pub trait Encoder {
5861
// top-level invocation would also just panic on failure. Switching to
5962
// infallibility made things faster and lots of code a little simpler and more
6063
// concise.
64+
///
65+
/// This current does not support `f32` nor `f64`, as they're not needed in any
66+
/// serialized data structures. That could be changed, but consider whether it
67+
/// really makes sense to store floating-point values at all.
68+
/// (If you need it, revert <https://github.com/rust-lang/rust/pull/109984>.)
6169
pub trait Decoder {
6270
// Primitive types:
6371
fn read_usize(&mut self) -> usize;
@@ -73,8 +81,6 @@ pub trait Decoder {
7381
fn read_i16(&mut self) -> i16;
7482
fn read_i8(&mut self) -> i8;
7583
fn read_bool(&mut self) -> bool;
76-
fn read_f64(&mut self) -> f64;
77-
fn read_f32(&mut self) -> f32;
7884
fn read_char(&mut self) -> char;
7985
fn read_str(&mut self) -> &str;
8086
fn read_raw_bytes(&mut self, len: usize) -> &[u8];
@@ -143,8 +149,6 @@ direct_serialize_impls! {
143149
i64 emit_i64 read_i64,
144150
i128 emit_i128 read_i128,
145151

146-
f32 emit_f32 read_f32,
147-
f64 emit_f64 read_f64,
148152
bool emit_bool read_bool,
149153
char emit_char read_char
150154
}

Diff for: compiler/rustc_serialize/tests/opaque.rs

+4-28
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ struct Struct {
2222

2323
l: char,
2424
m: String,
25-
n: f32,
26-
o: f64,
2725
p: bool,
2826
q: Option<u32>,
2927
}
@@ -119,24 +117,6 @@ fn test_bool() {
119117
check_round_trip(vec![false, true, true, false, false]);
120118
}
121119

122-
#[test]
123-
fn test_f32() {
124-
let mut vec = vec![];
125-
for i in -100..100 {
126-
vec.push((i as f32) / 3.0);
127-
}
128-
check_round_trip(vec);
129-
}
130-
131-
#[test]
132-
fn test_f64() {
133-
let mut vec = vec![];
134-
for i in -100..100 {
135-
vec.push((i as f64) / 3.0);
136-
}
137-
check_round_trip(vec);
138-
}
139-
140120
#[test]
141121
fn test_char() {
142122
let vec = vec!['a', 'b', 'c', 'd', 'A', 'X', ' ', '#', 'Ö', 'Ä', 'µ', '€'];
@@ -200,8 +180,6 @@ fn test_struct() {
200180

201181
l: 'x',
202182
m: "abc".to_string(),
203-
n: 20.5,
204-
o: 21.5,
205183
p: false,
206184
q: None,
207185
}]);
@@ -222,8 +200,6 @@ fn test_struct() {
222200

223201
l: 'y',
224202
m: "def".to_string(),
225-
n: -20.5,
226-
o: -21.5,
227203
p: true,
228204
q: Some(1234567),
229205
}]);
@@ -232,15 +208,15 @@ fn test_struct() {
232208
#[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
233209
enum Enum {
234210
Variant1,
235-
Variant2(usize, f32),
211+
Variant2(usize, u32),
236212
Variant3 { a: i32, b: char, c: bool },
237213
}
238214

239215
#[test]
240216
fn test_enum() {
241217
check_round_trip(vec![
242218
Enum::Variant1,
243-
Enum::Variant2(1, 2.5),
219+
Enum::Variant2(1, 25),
244220
Enum::Variant3 { a: 3, b: 'b', c: false },
245221
Enum::Variant3 { a: -4, b: 'f', c: true },
246222
]);
@@ -269,8 +245,8 @@ fn test_hash_map() {
269245

270246
#[test]
271247
fn test_tuples() {
272-
check_round_trip(vec![('x', (), false, 0.5f32)]);
273-
check_round_trip(vec![(9i8, 10u16, 1.5f64)]);
248+
check_round_trip(vec![('x', (), false, 5u32)]);
249+
check_round_trip(vec![(9i8, 10u16, 15i64)]);
274250
check_round_trip(vec![(-12i16, 11u8, 12usize)]);
275251
check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]);
276252
check_round_trip(vec![(String::new(), "some string".to_string())]);

0 commit comments

Comments
 (0)