Source context

Program Rust

body

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

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, accumulator

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[rust_loop_body]
def num.imp.dec2flt.parse.try_parse_digits_loop0.body
  (s : Slice Std.U8) (x : Std.U64) :
  Result (ControlFlow ((Slice Std.U8) × Std.U64) ((Slice Std.U8) × Std.U64))
  := do
  let i := Slice.len s
  if i >= 8#usize
  then
    let chunk ←
      SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.read_u64 s
    let b ← num.imp.dec2flt.common.is_8digits chunk
    if b
    then
      let i1 ← lift (core.num.U64.wrapping_mul x 100000000#u64)
      let i2 ← num.imp.dec2flt.parse.parse_8digits chunk
      let x1 ← lift (core.num.U64.wrapping_add i1 i2)
      let s1 ←
        core.slice.index.Slice.index
          (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
          { start := 8#usize }
      ok (cont (s1, x1))
    else ok (done (s, x))
  else ok (done (s, x))
Operations used here

read_u64 · Program Rust

is_8digits · Program Rust

parse_8digits · Program Rust

Other extracted objects at this span

num.imp.dec2flt.parse.try_parse_digits_loop0

Source details
Declarationnum.imp.dec2flt.parse.try_parse_digits_loop0.body
Filenum/imp/../../dec2flt/parse.rs
Lines33:4–44:5
Program versionOriginal program