-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
With default optimization (-O2), Tolk rewrites slice.skipBits(0) into 0 LDU + NIP in the generated Fift. 0 LDU is not a valid instruction encoding and fift fails to interpret the produced .fif, so code that should be a no-op becomes uncompilable at the assembler stage.
Reproduction
Create /tmp/tolk_skipbits0_invalid_ldu.tolk:
tolk 1.0
fun onInternalMessage() { return 0; }
@method_id(100)
fun skip0_single(): int {
var s: slice = beginCell().endCell().beginParse();
s.skipBits(0);
s.assertEnd();
return 123;
}
Compile (default -O2):
./artifacts/tolk /tmp/tolk_skipbits0_invalid_ldu.tolk > /tmp/tolk_skipbits0_invalid_ldu.fifCreate /tmp/tolk_skipbits0_invalid_ldu_runner.fif:
"/tmp/tolk_skipbits0_invalid_ldu.fif" include <s constant code
100 code 1 runvmx .s cr { drop } depth 1- times
Run (fails while interpreting the generated .fif):
./artifacts/fift -I artifacts/lib /tmp/tolk_skipbits0_invalid_ldu_runner.fifObserved output
fift errors out with:
LDU:integer does not fit into cell
Expected behavior
skipBits(0) should be a no-op and the program should assemble and run, returning 123 0.
Codegen evidence
In the generated .fif, the optimizer emits:
0 LDU
NIP
Analysis
The optimizer rewrite for MY_skip_bits does not special-case total_skip_bits == 0 and produces 0 LDU, which is invalid. This rewrite should emit a no-op when skipping 0 bits.