Skip to content

Commit 9a0ac7c

Browse files
Rollup merge of #82676 - dtolnay:powers, r=Mark-Simulacrum
Change twice used large const table to static This table is used twice in core::num::dec2flt::algorithm::power_of_ten. According to the semantics of const, a separate huge definition of the table is inlined at both places. https://github.com/rust-lang/rust/blob/5233edcf1c7ee70ac25e4ec1115c3546f53d8a2d/library/core/src/num/dec2flt/algorithm.rs#L16-L22 Theoretically this gets cleaned up by optimization passes, but in practice I am experiencing a miscompile from LTO on this code. Making the table a static, which would only be defined a single time and not require attention from LTO, eliminates the miscompile and seems semantically more appropriate anyway. A separate bug report on the LTO bug is forthcoming. Original addition of `const` is from #27307.
2 parents 0c6b69a + bd51dea commit 9a0ac7c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/num/dec2flt/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub const MIN_E: i16 = -305;
55
pub const MAX_E: i16 = 305;
66

77
#[rustfmt::skip]
8-
pub const POWERS: ([u64; 611], [i16; 611]) = (
8+
pub static POWERS: ([u64; 611], [i16; 611]) = (
99
[
1010
0xe0b62e2929aba83c,
1111
0x8c71dcd9ba0b4926,

src/etc/dec2flt_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def print_proper_powers():
113113
print()
114114
print("#[rustfmt::skip]")
115115
typ = "([u64; {0}], [i16; {0}])".format(len(powers))
116-
print("pub const POWERS: ", typ, " = (", sep='')
116+
print("pub static POWERS: ", typ, " = (", sep='')
117117
print(" [")
118118
for z in powers:
119119
print(" 0x{:x},".format(z.sig))

0 commit comments

Comments
 (0)