Program Rust
try_parse_digits
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
27 }28 29 /// Parse digits until a non-digit character is found.30 fn try_parse_digits(mut s: &[u8], mut x: u64) -> (&[u8], u64) {31 // may cause overflows, to be handled later32 33 while s.len() >= 8 {34 // `chunk` is the source's local `num` under a nonconflicting name.35 // The rename has no Rust effect and prevents the Lean backend from36 // resolving `num.imp...` as a field projection on this local value.37 let chunk = s.read_u64();38 if is_8digits(chunk) {39 x = x.wrapping_mul(1_0000_0000).wrapping_add(parse_8digits(chunk));40 s = &s[8..];41 } else {42 break;43 }44 }45 46 // This is the removed `ByteSlice::parse_digits` call specialized to its47 // only parser use: identical wrapping digit classification, accumulator48 // update, and first-nondigit stop, without an unsupported closure state.49 let mut count = 0;50 while count < s.len() && s[count].wrapping_sub(b'0') < 10 {51 let digit = s[count].wrapping_sub(b'0');52 x = x.wrapping_mul(10).wrapping_add(digit as _);53 count += 1;54 }55 s = &s[count..];56 57 (s, x)58 }59 60 /// Parse up to 19 digits (the max that can be stored in a 64-bit integer).61 fn try_parse_19digits(s_ref: &mut &[u8], x: &mut u64) {Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
def num.imp.dec2flt.parse.try_parse_digits
(s : Slice Std.U8) (x : Std.U64) : Result ((Slice Std.U8) × Std.U64) := do
let (s1, x1) ← num.imp.dec2flt.parse.try_parse_digits_loop0 s x
let (x2, count) ←
num.imp.dec2flt.parse.try_parse_digits_loop1 s1 x1 0#usize
let s2 ←
core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s1
{ start := count }
ok (s2, x2)Source details
| Declaration | num.imp.dec2flt.parse.try_parse_digits |
|---|---|
| File | num/imp/../../dec2flt/parse.rs |
| Lines | 30:0–58:1 |
| Program version | Preparation 1 |