Repository navigation
Description
Summary
BendTT name escaping is not injective for constructor labels. Two distinct
Bend source constructors can therefore become the same semantic label in the
generated BendTT book.
For example, a literal source substring _2d_ collides with the encoding of
-, and _2f_ collides with /.
Top-level BendTT definition names go through fresh, so one colliding
definition receives an underscore suffix. Constructor labels do not go
through fresh. In the reproduction below, two nominally distinct source
datatypes consequently receive structurally identical BendTT bodies.
I did not derive a proof of Empty from this. I am reporting it as a
translation correctness and hardening issue, not as a bounty claim.
Version
bend 2.0.32
v2.0.32 commit 573002f01ec6c52416d44489543f69a9625facf8
Linux x86-64 release binary
Reproduction
Create this layout:
name-collision/
main.bend
a-b/
lib.bend
name-collision/a-b/lib.bend:
type Good is Data:
K{}name-collision/main.bend:
import ./a-b/lib.bend as Far
type a_2d_b_2f_lib.Good is Data:
a_2d_b_2f_lib.K{}
def imported() -> Far.Good:
Far.K{}
def local() -> a_2d_b_2f_lib.Good:
a_2d_b_2f_lib.K{}Run:
bend name-collision/main.bend --verdict
bend name-collision/main.bend -o /tmp/name-collision.bendttThe verdict is:
ALL PROOFS CHECK
The relevant generated BendTT is:
a_2d_b_2f_lib.Good.arms : ∀x0 : <a_2d_b_2f_lib.K> -> *2 =
λ{.a_2d_b_2f_lib.K: <()>; λ{}}
a_2d_b_2f_lib.Good : *2 =
Σx0 : <a_2d_b_2f_lib.K> -> (a_2d_b_2f_lib.Good.arms x0)
a_2d_b_2f_lib.Good_.arms : ∀x0 : <a_2d_b_2f_lib.K> -> *2 =
λ{.a_2d_b_2f_lib.K: <()>; λ{}}
a_2d_b_2f_lib.Good_ : *2 =
Σx0 : <a_2d_b_2f_lib.K> -> (a_2d_b_2f_lib.Good_.arms x0)
imported : a_2d_b_2f_lib.Good =
(.a_2d_b_2f_lib.K, ())
local : a_2d_b_2f_lib.Good_ =
(.a_2d_b_2f_lib.K, ())
The two source constructors are:
a-b/lib.K
a_2d_b_2f_lib.K
Both become the BendTT label:
a_2d_b_2f_lib.K
Cause
name_tt
leaves _ and hexadecimal-looking text unchanged while replacing unsupported
characters with _hex_:
function name_tt(k: Name): string {
return k.replace(/[^A-Za-z0-9_.]|^[.0-9]/g, (c) => "_" + (c.codePointAt(0) ?? 0).toString(16) + "_");
}Datatype enum labels and match arms use that value directly. Mutually
recursive group selector labels use the same encoding, so the same collision
class appears possible there.
This seems closely related to the uniqueness work in #1042, but it occurs in
the Bend-to-BendTT proof translation rather than the source name table or
runtime identifiers.
Expected behavior
Distinct canonical Bend constructor names should produce distinct BendTT
labels, or the translator should reject a collision.
Suggested fix
Use an injective encoding for semantic labels and apply one canonical mapping
consistently to:
- datatype enum labels;
- constructor tuples;
- match arms;
- mutually recursive group selectors.
One simple encoding is a length-prefixed hexadecimal encoding of every UTF-8
byte, including underscores. A per-book Map<Name, string> that allocates
unique labels would also work if every label-emitting path uses it.
The exact two-file example above would make a useful regression test. The
generated constructor labels should differ. Related cases include _2f_
versus /, hyphenated package namespaces, and group member selectors.
Activity
Vacrin commentedon Sep 30, 2026
Two more consequences of
name_ttnot being injective(safe.ts#L484-L486:
_is never escaped, soa-b→a_2d_b, the same asname_tt("a_2d_b")). Def names are made uniqueafterwards by
fresh; labels aren't.1. A group selector with two colliding members is unparsable. A mutually recursive group whose
members are
L.k(froma-b.bend, imported asL) and a locala_2d_b.kgets the selector enum<a_2d_b.k, a_2d_b.k>:Renaming the helper
a_2d_b.ktohpasses--verdict.2. With a selector misroute, the collision becomes a silent PASS. In #1212 , safe.ts routes a call
through a group the callee isn't a member of. Normally the label falls outside the enum and the kernel
rejects it. When the non-member's name collides with a real member's under
name_tt, the label landsinside the enum and the kernel accepts:
fb3.bendthere PASSes--verdictwhile the certified bookcomputes
main == Trueand bend2 runs it toFalse.Constructor labels share the same way (
(.a_2d_b.C, ())for two different constructors); that'ssound on its own, since bend2 is nominal and the kernel keeps the types apart through their stuck
*.armsheads, but it removes a layer of defense.fix(verdict): BendTT labels spell the canonical key injectively (bend…
fix(verdict): BendTT labels spell the canonical key injectively (#1131,