Source context

Program Rust

body

This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.

47     // 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)

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[rust_loop_body]
def num.imp.dec2flt.parse.try_parse_digits_loop1.body
  (s : Slice Std.U8) (x : Std.U64) (count : Std.Usize) :
  Result (ControlFlow (Std.U64 × Std.Usize) (Std.U64 × Std.Usize))
  := do
  let i := Slice.len s
  if count < i
  then
    let i1 ← Slice.index_usize s count
    let i2 ← lift (core.num.U8.wrapping_sub i1 48#u8)
    if i2 < 10#u8
    then
      let digit ← lift (core.num.U8.wrapping_sub i1 48#u8)
      let i3 ← lift (core.num.U64.wrapping_mul x 10#u64)
      let i4 ← lift (UScalar.cast .U64 digit)
      let x1 ← lift (core.num.U64.wrapping_add i3 i4)
      let count1 ← count + 1#usize
      ok (cont (x1, count1))
    else ok (done (x, count))
  else ok (done (x, count))
Other extracted objects at this span

num.imp.dec2flt.parse.try_parse_digits_loop1

Source details
Declarationnum.imp.dec2flt.parse.try_parse_digits_loop1.body
Filenum/imp/../../dec2flt/parse.rs
Lines50:4–54:5
Program versionOriginal program