Skip to content

Commit

Permalink
Rollup merge of rust-lang#82676 - dtolnay:powers, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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 rust-lang#27307.
  • Loading branch information
GuillaumeGomez authored Mar 1, 2021
2 parents 0c6b69a + bd51dea commit 9a0ac7c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/core/src/num/dec2flt/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub const MIN_E: i16 = -305;
pub const MAX_E: i16 = 305;

#[rustfmt::skip]
pub const POWERS: ([u64; 611], [i16; 611]) = (
pub static POWERS: ([u64; 611], [i16; 611]) = (
[
0xe0b62e2929aba83c,
0x8c71dcd9ba0b4926,
Expand Down
2 changes: 1 addition & 1 deletion src/etc/dec2flt_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def print_proper_powers():
print()
print("#[rustfmt::skip]")
typ = "([u64; {0}], [i16; {0}])".format(len(powers))
print("pub const POWERS: ", typ, " = (", sep='')
print("pub static POWERS: ", typ, " = (", sep='')
print(" [")
for z in powers:
print(" 0x{:x},".format(z.sig))
Expand Down

0 comments on commit 9a0ac7c

Please sign in to comment.