about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-03-02 00:50:11 +0100
committerGitHub <noreply@github.com>2021-03-02 00:50:11 +0100
commit9a0ac7cb5feed93eb0b05468c07c2bb8cdea234b (patch)
tree7ff49eb9ee43279a44b290f0678ca87502557209
parent0c6b69aa70d63976f119af1949820af13fdd491b (diff)
parentbd51dea6934d5c583fe9c8bc806e6287cac43f90 (diff)
downloadrust-9a0ac7cb5feed93eb0b05468c07c2bb8cdea234b.tar.gz
rust-9a0ac7cb5feed93eb0b05468c07c2bb8cdea234b.zip
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.
-rw-r--r--library/core/src/num/dec2flt/table.rs2
-rwxr-xr-xsrc/etc/dec2flt_table.py2
2 files changed, 2 insertions, 2 deletions
diff --git a/library/core/src/num/dec2flt/table.rs b/library/core/src/num/dec2flt/table.rs
index 1bd94ffa04e..97b497e81e0 100644
--- a/library/core/src/num/dec2flt/table.rs
+++ b/library/core/src/num/dec2flt/table.rs
@@ -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,
diff --git a/src/etc/dec2flt_table.py b/src/etc/dec2flt_table.py
index 9bbcaf7c4cc..ad2292e8571 100755
--- a/src/etc/dec2flt_table.py
+++ b/src/etc/dec2flt_table.py
@@ -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))