Skip to content

Commit a2667d5

Browse files
committed
Complete our safety mitigations in the float writers.
Performance enhancements will soon follow to restore any lost performance in some cases which impacted it up to 3%.
1 parent a7d9583 commit a2667d5

18 files changed

Lines changed: 2 additions & 124 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838

3939
- Support for mips (MIPS), mipsel (MIPS LE), mips64 (MIPS64 BE), and mips64el (MIPS64 LE) on Linux.
4040
- All `_unchecked` API methods, since the performance benefits are dubious and it makes safety invariant checking much harder.
41+
- The `safe` and `nightly` features, since ASM is now supported by the MSRV on stable and opt-in for memory-safe indexing is no longer relevant.
4142

4243
## [0.8.5] 2022-06-06
4344

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ Lexical is highly customizable, and contains numerous other optional features:
139139
<blockquote>With format enabled, the number format is dictated through bitflags and masks packed into a <code>u128</code>. These dictate the valid syntax of parsed and written numbers, including enabling digit separators, requiring integer or fraction digits, and toggling case-sensitive exponent characters.</blockquote>
140140
- **compact**: &ensp; Optimize for binary size at the expense of performance.
141141
<blockquote>This minimizes the use of pre-computed tables, producing significantly smaller binaries.</blockquote>
142-
- **safe**: &ensp; Requires all array indexing to be bounds-checked.
143-
<blockquote>This has limited impact for number parsers, since they use safe indexing except where indexing without bounds checking and can general be shown to be sound. The number writers frequently use unsafe indexing, since we can easily over-estimate the number of digits in the output due to the fixed-length input. We use comprehensive fuzzing, UB detection via miri, and proving local safe invariants to ensure correctness without impacting performance.</blockquote>
144142
- **f16**: &ensp; Add support for numeric conversions to-and-from 16-bit floats.
145143
<blockquote>Adds <code>f16</code>, a half-precision IEEE-754 floating-point type, and <code>bf16</code>, the Brain Float 16 type, and numeric conversions to-and-from these floats. Note that since these are storage formats, and therefore do not have native arithmetic operations, all conversions are done using an intermediate <code>f32</code>.</blockquote>
146144

lexical-benchmark/parse-float/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ power-of-two = ["lexical-util/power-of-two", "lexical-parse-float/power-of-two"]
3030
format = ["lexical-util/format", "lexical-parse-float/format"]
3131
compact = ["lexical-util/compact", "lexical-parse-float/compact"]
3232
asm = []
33-
nightly = ["lexical-parse-float/nightly"]
3433
integers = ["lexical-util/integers"]
3534
floats = ["lexical-util/floats"]
3635
json = []

lexical-benchmark/parse-float/denormal30.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Inline ASM was stabilized in 1.59.0.
2-
// FIXME: Remove when the MSRV for Rustc >= 1.59.0.
3-
#![allow(stable_features)]
4-
#![cfg_attr(feature = "nightly", feature(asm))]
5-
61
mod black_box;
72
use black_box::black_box;
83
use lexical_parse_float::FromLexical;

lexical-benchmark/parse-float/denormal6400.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Inline ASM was stabilized in 1.59.0.
2-
// FIXME: Remove when the MSRV for Rustc >= 1.59.0.
3-
#![allow(stable_features)]
4-
#![cfg_attr(feature = "nightly", feature(asm))]
5-
61
mod black_box;
72
use black_box::black_box;
83
use lexical_parse_float::FromLexical;

lexical-core/Cargo.toml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,6 @@ compact = [
100100
"lexical-parse-integer?/compact",
101101
"lexical-parse-float?/compact"
102102
]
103-
# Ensure only safe indexing is used.
104-
# This is only relevant for the number writers, since the parsers
105-
# are memory safe by default (and only use memory unsafety when
106-
# is the trivial to prove correct).
107-
safe = [
108-
"lexical-write-integer?/safe",
109-
"lexical-write-float?/safe",
110-
"lexical-parse-integer?/safe",
111-
"lexical-parse-float?/safe"
112-
]
113-
# Add support for nightly-only features.
114-
nightly = [
115-
"lexical-write-integer?/nightly",
116-
"lexical-write-float?/nightly",
117-
"lexical-parse-integer?/nightly",
118-
"lexical-parse-float?/nightly"
119-
]
120103
# Enable support for 16-bit floats.
121104
f16 = [
122105
"lexical-util/f16",

lexical-parse-float/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ compact = [
6868
"lexical-util/compact",
6969
"lexical-parse-integer/compact"
7070
]
71-
# Ensure only safe indexing is used. This is effectively a no-op, since all
72-
# examples of potential memory unsafety are trivial to prove safe.
73-
safe = ["lexical-parse-integer/safe"]
74-
# Add support for nightly-only features.
75-
nightly = ["lexical-parse-integer/nightly"]
7671
# Enable support for 16-bit floats.
7772
f16 = ["lexical-util/f16"]
7873

lexical-parse-float/src/bigint.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ use crate::table::get_large_int_power;
1818
/// # Safety
1919
///
2020
/// Safe if `index < array.len()`.
21-
#[cfg(feature = "safe")]
22-
macro_rules! index_unchecked {
23-
($x:ident[$i:expr]) => {
24-
$x[$i]
25-
};
26-
}
27-
28-
#[cfg(not(feature = "safe"))]
2921
macro_rules! index_unchecked {
3022
($x:ident[$i:expr]) => {
3123
// SAFETY: safe if `index < array.len()`.

lexical-parse-float/src/fpu.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//!
77
//! It is therefore also subject to a Apache2.0/MIT license.
88
9-
#![cfg(feature = "nightly")]
109
#![doc(hidden)]
1110

1211
pub use fpu_precision::set_precision;

lexical-parse-float/src/libm.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@
2828
/// # Safety
2929
///
3030
/// Safe if `index < array.len()`.
31-
#[cfg(feature = "safe")]
32-
macro_rules! i {
33-
($x:ident, $i:expr) => {
34-
$x[$i]
35-
};
36-
}
37-
38-
/// Index an array without bounds checking.
39-
///
40-
/// # Safety
41-
///
42-
/// Safe if `index < array.len()`.
43-
#[cfg(not(feature = "safe"))]
4431
macro_rules! i {
4532
($x:ident, $i:expr) => {
4633
unsafe { *$x.get_unchecked($i) }

0 commit comments

Comments
 (0)