Skip to content

The native lane skips an argument that bend file.bend and the JS lane evaluate, when the call's selector is a literal: one prints 100, the others stop with the Nat message #2181

Open

Description

@nicolas-abril

What you did

bend drop.bend, bend drop.bend -o drop.js && node drop.js, and bend drop.bend -o drop && ./drop, built from main 8c329c1b.

What happened

The file checks (ALL PROOFS CHECK). bend file.bend and the JS lane stop the program; the native executable prints a result.

$ bend drop.bend
bend: a Nat past the largest immediate 2^48-1

$ bend drop.bend -o drop.js && node drop.js
bend: a Nat past the largest immediate 2^48-1

$ bend drop.bend -o drop && ./drop
100

pick(boom(k), 0n, 100n) never reads its first argument, and boom(k) goes past the Nat limit. The C lane never runs boom; the JS lane does.

It depends on the selector being a literal:

call bend file.bend JS C
pick(boom(k), 0n, 100n) stops stops 100
pick(boom(k), Nat.sub(k, k), 100n) (a run-time zero) stops stops stops
the same call, with pick rewritten to return z without a match stops stops stops
x : Nat = boom(k) as an unused let, then print 100n 100 100 100

So the C lane skips the argument only where it can unfold pick at compile time. That is my reading of the table; I did not trace it in comp.ts.

I am not saying which answer is the right one, only that the lanes differ on a checked program. #775 was the same shape with a difference in cost only, and #1726 to #1729 went the other way (the native lane evaluated an overflowing call the result did not need).

The file

import Base

# stops the program: a Nat past 2^48 - 1
def boom(+k: Nat) -> Nat:
  Nat.mul(Nat.mul(k, k), Nat.mul(k, k))

def pick(x: Nat, y: Nat, z: Nat) -> Nat:
  match y:
    case 0n:
      z
    case 1n+p:
      x

def main() -> IO(Unit):
  do IO<Unit>:
    args : List<String> <- IO.args()
    +k : Nat = Nat.add(100000n, List.length(&1, String, args))
    IO.print(Nat.show(pick(boom(k), 0n, 100n)))

bend version

bend 2.0.40 (main 8c329c1b)

uname -sm

Darwin arm64

clang --version (the first line)

Apple clang version 17.0.0 (clang-1700.6.4.2)

Found while testing #2180.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. YidaWeng commented on Nov 17, 2026

    @YidaWeng
    Contributor

    I'm working on this: make emit_unfold refuse a fold when the chosen arm does not use a live, non-constant argument, so the call is emitted normally and evaluates that argument like the interpreter and JS lanes do. Plan: a regression test for pick(boom(k), 0n, 100n) plus a run-time-zero control. If someone is already on it, please say so and I'll stop.

  3. nicolas-abril commented on Nov 23, 2026

    @nicolas-abril
    CollaboratorAuthor

    I think the native lane is right here: pick(boom(k), 0n, 100n) is 100. The Nat wall is a runtime limit, not part of the semantics, and a lane may skip work the result doesn't need. Unused parameters are erased, and the checker assumes dead code isn't run, so it only guarantees that live code halts. That matches #1730 (the fix for #1726–#1729) and the unused-let row of the table above.

    So #2199, which makes C evaluate the argument by refusing the unfold, goes the wrong way. If we want the lanes to agree, the interpreter and JS lanes should skip the argument instead. That's tied to the still-open strict-evaluation question from #775.

  4. nicolas-abril commented on Nov 23, 2026

    @nicolas-abril
    CollaboratorAuthor

    To be explicit about the scope here: the JS lane should agree with C and skip the argument (print 100). The interpreter should ideally agree too, but that's more complicated and may be out of scope for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions