You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nat.read("7") in a checked equality never finishes: every digit is compared against a unary 2^48 - 1 #1008
After two minutes the check had still not finished, using a full core. Evaluating Nat.read("7") with term_snf hangs the same way. U32.read("7") evaluates in about 0.2 s, and the compiled program prints 7 immediately.
where Nat.read.max() is Nat.mul(U32.to_nat(16777215), U32.to_nat(16777217)), that is, 2^48 − 1. The checker's Nat is unary, so computing that bound and dividing it by ten means building and walking about 2.8 × 10^14 successors, and this happens for every digit, including the first one of "7". The runtime lanes do this with native integers, which is why the program itself is instant.
As a result, no law that mentions Nat.read on a concrete string can be closed by evaluation. For example, {Nat.read(Nat.show(n)) == Some{n}} cannot be checked at n = 7n, and a law about a parser built on Nat.read cannot be tested on an example.
A related surprise: the same bound makes Nat.read return None{} for any input above 2^48 − 1 (Nat.read("281474976710656") is None{} on the runtime too). So Nat.read(Nat.show(n)) == Some{n} is false for large n, even though Nat is unbounded. Neither the bound nor the checker cost is documented next to Nat.read.
Expected behavior
The check should finish quickly on small inputs. One way would be for the overflow guard to compare the digit count, or to use a bound that is cheap to evaluate in unary, rather than dividing 2^48 − 1 on every step. If the 2^48 − 1 cap is intended, a comment next to Nat.read saying so would help readers of laws that use it.
Version
bend 2.0.26
commit 6a77e124
Bun 1.4.2
Darwin arm64
I resolved a similar situation involving the verification of a program operating on u32 values by replacing them with a word of arbitrary bit-width. Compliance with the specification can be proven in the general case; mapping this to a concrete type is a separate task.
Activity
yalexey-jcode commentedon Sep 23, 2026
I resolved a similar situation involving the verification of a program operating on
u32values by replacing them with a word of arbitrary bit-width. Compliance with the specification can be proven in the general case; mapping this to a concrete type is a separate task.Nat.read compares its bound as fifteen digits, so a checked read of 7…