Skip to content

One @unsafe law fill in a file PROOF.bend imports silently proves every law: bend PROOF.bend prints a clean "All terms check." (regression from #848) #1001

Closed

Description

@jasisz

What you did

Three files in one directory:

# LAWS.bend
import Base

law false_law:
  {1n == 0n : Nat}
# Helper.bend
import ./LAWS.bend as Laws

@unsafe def Laws.false_law():
  Laws.false_law()
# PROOF.bend
import ./Helper.bend as H
bend PROOF.bend; echo exit=$?

What happened

All terms check.
exit=0

The verdict is unsound: LAWS.false_law : {1n == 0n : Nat} holds only because an @unsafe self-call skips the termination check, yet bend reports every term as checked and prints no unsafe note. LAWS.bend is imported (through Helper), so the "PROOF.bend must import ./LAWS.bend" check passes, and no law is open, so there is no TODO error.

The false law is then an ordinary hypothesis for every other law. With a second law in LAWS.bend

law succ_is_id:
  for +n: Nat
  {1n+n == n : Nat}

and its proof added to Helper.bend, derived from false_law with no further @unsafe:

def disc(n: Nat) -> Type:
  match n:
    case 0n:
      Empty
    case 1n+p:
      Unit

def boom() -> Empty:
  %Laws.false_law() : disc(_)
  Unit{}

def ex(+n: Nat, e: Empty) -> {1n+n == n : Nat}:
  match e:

def Laws.succ_is_id(n):
  ex(n, boom())

bend PROOF.bend still prints a clean All terms check. (exit 0). One @unsafe line in a file PROOF.bend imports closes every law of LAWS.bend without a note.

The report itself works when it starts from the right place. The unsafe fill written in PROOF.bend instead gives

All terms check, but 1 def relies on unsafe or foreign code:
- LAWS.false_law

and the derivation written in PROOF.bend (the unsafe fill still in Helper) gives

All terms check, but 2 defs rely on unsafe or foreign code:
- boom
- LAWS.succ_is_id

This is a regression. Running the first repro (false_law only) across commits:

commit verdict
5e565504 (the #776 fix) All terms check, with 1 unsafe annotation.
f1d23d3c~1 All terms check, with 1 unsafe annotation.
f1d23d3c (the #848 fix) All terms check.
a4952426 (2.0.25) All terms check.

Since f1d23d3c, cli_report walks the references of the root file's own entries (book.order.slice(n0)), so "an imported @unsafe def the file never calls" stays silent. A law fill is not a call, though: it closes a claim of LAWS.bend from whichever file holds it, and the root never refers to it. The fill is pushed to book.order inside Helper's range, so the walk never starts there.

WONTFIX says of #776 and #805: "read the note, not the exit code". Here there is no note, so the gate the guide describes ("bend PROOF.bend is the gate: it fails while any law is open or false") reports success for a false law with no signal at all.

A possible fix: seed the walk with every law of the book that was filled outside Base (or at least every law of LAWS.bend when the root is PROOF.bend), not only the root's entries.

The file

See above (LAWS.bend, Helper.bend, PROOF.bend).

bend --version

bend 2.0.25 (main @ a495242)

uname -sm

Darwin arm64

clang --version (the first line)

Apple clang version 21.0.0 (clang-2100.0.123.102)

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions