0xPolygonMiden / compiler

Compiler from MidenIR to Miden Assembly
MIT License
63 stars 21 forks source link

Assembler cannot resolve `::std::math::u64::checked_lte` #239

Closed greenhat closed 2 months ago

greenhat commented 2 months ago

While working on #230 the assembler returned the following error:

VM assembly error:
  x assembly failed
  help: see diagnostics for details

Error:   x undefined procedure
    ,-[abi_transform_tx_kernel_get_inputs_4:67:32]
 66 |         push.4294967295.1
 67 |         exec.::std::math::u64::checked_lte
    :                                ^^^^^|^^^^^
    :                                     `-- unable to resolve this reference to its definition
 68 |         assert
    `----
Error:   x name resolution cannot proceed
    ,-[./asm/math/u64.masm:33:6]
 32 | #! The input values are assumed to be represented using 32 bit limbs, but this is not checked.
 33 | #! Stack transition looks as follows:
    :      ^^^^^|^^^^^
    :           `-- this name cannot be resolved
 34 | #! [b_hi, b_lo, a_hi, a_lo, ...] -> [c_hi, c_lo, ...], where c = (a + b) % 2^64
    `----
greenhat commented 2 months ago

@bitwalker The checked variants were removed in https://github.com/0xPolygonMiden/miden-vm/pull/1142 Do we want to keep using the checked variants as intrinsics or switch to unchecked variants?

bitwalker commented 2 months ago

@greenhat We should replace the use of checked_* with the unchecked variant, but prefix the call with a call to std::math::u64::u32assert4 to check the inputs as expected.

For arithmetic operations, we should do the same, but additionally use the overflowing variants for the actual op (rather than unchecked), and assert that no overflow occurs.

bitwalker commented 2 months ago

Fixed in #242