Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ pure-extern semantics (Closes #332) (#338)

==== Fixed

* fix(modules,codegen): same-named functions in two modules no longer
collapse to one in a flattened program (Bun-ESM, JS and the other
non-Wasm backends). Every function and constant of an imported module is
carried under a module-qualified name (`__mod_<len-prefixed path>__<name>`,
replacing `__priv_…`), so `Lib.A.label` and `Lib.B.label` stay distinct,
public or private, also when they arrive transitively. The root module's
own names, the names it imports, and extern (host) names are unchanged.
Defence in depth: the flattener refuses two different top-level bindings of
one name (E0206), and the Bun-ESM and JS emitters refuse a second top-level
binding of a JS name (Bun keeps the last of two same-named `function`s
silently). Two enums' identical constructors are emitted once; differing
ones are refused. Trait impl methods sharing a name are now refused on
Bun-ESM instead of silently replacing one another (`stdlib/traits.affine`).
Rebuild compiled output (Closes #801)
* fix(vscode-smoke): SKIP cleanly when @hyperpolymath/affine-vscode is
unpublished (#381)
* fix(governance): rename CLAUDE.md TypeScript exemptions heading to
Expand Down
2 changes: 1 addition & 1 deletion docs/COMPLETION-PLAN.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ All were observed by RUN unless marked otherwise. The maps confirm that H1–H4
. H18. The interpreter fails when dereferencing refs returned through calls ("Expected reference type"). The session lead reproduced this on two #554 fixtures.
. H19 (typed-wasm). No L5 index guard: `get_player_hp(0,150)` reads an adjacent region. `where` constraints are discarded. Malformed `session` blocks are silently ignored.
. H23 (found and fixed 2026-11-09, checking and running metadatastician/kyq; numbered H20 in #788, renumbered because #787 assigned H20–H22). A module file found for `A.B` that declares `module A;` was accepted as `A.B`, so `use A.Nonexistent::*` type-checked and imported `A`'s exports; it is now a `ModuleDeclMismatch` load error. *Round 2 (2026-11-16):* a nested candidate (`dir/A/B.affine`) is now searched in every directory before any parent-module fallback, and a module whose load fails is no longer left marked as loading (which reported a later import of it as a cycle). Anchor: `test/test_module_root_flatten.ml`.
. H24 (found and fixed 2026-11-09; numbered H21 in #788). `eval` ran the unflattened program, so no imported function was bound at run time; flattening also emitted a selected function before the private helpers it calls and carried no helpers for glob or plain imports. `eval` now flattens, every import kind carries its helpers, and they are emitted in the imported module's declaration order. *Round 2 (2026-11-16):* two modules with a same-named private helper no longer collide: every private helper carried into a flattened program is renamed `__priv_<Module>__<name>` with a capture-avoiding substitution (the module path is length-prefixed, so `A_B.C` and `A.B_C` cannot share a name), and an aliased import emits the original before the alias. *Round 3 (2026-11-16):* a public declaration carried only for the module's own callers (the original of an alias, or a helper only a selected function calls) gets an internal name too, so two modules' `helper`s cannot replace one another; aliasing a mutable binding, which would make a second copy, and an unresolvable name collision are structured flattening errors (diagnostic E0206), not exceptions. Only the root program's `main` is run. Anchor: `test/test_module_root_flatten.ml`.
. H24 (found and fixed 2026-11-09; numbered H21 in #788). `eval` ran the unflattened program, so no imported function was bound at run time; flattening also emitted a selected function before the private helpers it calls and carried no helpers for glob or plain imports. `eval` now flattens, every import kind carries its helpers, and they are emitted in the imported module's declaration order. *Round 2 (2026-11-16):* two modules with a same-named private helper no longer collide: every private helper carried into a flattened program is renamed `__priv_<Module>__<name>` with a capture-avoiding substitution (the module path is length-prefixed, so `A_B.C` and `A.B_C` cannot share a name), and an aliased import emits the original before the alias. *Round 3 (2026-11-16):* a public declaration carried only for the module's own callers (the original of an alias, or a helper only a selected function calls) gets an internal name too, so two modules' `helper`s cannot replace one another; aliasing a mutable binding, which would make a second copy, and an unresolvable name collision are structured flattening errors (diagnostic E0206), not exceptions. *Round 4 (2026-11-19, #801):* the per-case renaming above still let two modules' public declarations of one name meet when they arrived through other modules' imports (`X` uses `A.f`, `Y` uses `B.f`; the flattened program kept one `f` and Bun ran it for both). Every function and constant of an imported module, public or private, now carries a module-qualified name `__mod_<Module>__<name>` (length-prefixed as before; `__priv_` is gone), the root keeps its own and its imported names, externs keep their host names, and the flattener and the JS emitters refuse two different top-level bindings of one name. Only the root program's `main` is run. Anchor: `test/test_module_root_flatten.ml`.
. H25 (found and fixed 2026-11-09; numbered H22 in #788). The interpreter had no `++` on arrays and no `==`/`!=` beyond Int, Float, String and Bool, though the checker accepts them; it now uses the structural `Value.value_eq`. H7 (`let mut`) is unchanged. Anchor: `test/test_module_root_flatten.ml`.

== 2. Target architecture
Expand Down
31 changes: 29 additions & 2 deletions docs/SOUNDNESS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Freshness stamp — a real main-ancestor commit (survives squash-merge); advance
// it (and --reseal) in any change that touches a soundness path. See "Keeping
// this honest" and tools/check-soundness-ledger.sh (property 4).
:ground-truth-sha: 65c2ae3
:ground-truth-date: 2026-06-21
:ground-truth-sha: 70379fe
:ground-truth-date: 2026-11-19
:stamp-verified-by: tools/check-soundness-ledger.sh
:toc: macro
:toclevels: 2
Expand Down Expand Up @@ -211,6 +211,33 @@ pinned residual).)
`test_stub_backend_return_fenced` (positive check: asserts
`Lean_codegen.codegen_lean` returns `Error` on the early-`return` program — it was
`Ok`; the check would fail if the silent drop regressed).

| #801
| Two modules' top-level functions or constants of one name stay distinct in
the flattened program every non-Wasm backend compiles: each imported
module's declarations, public and private, carry a module-qualified name, so
`Lib.A`'s code calls `Lib.A.label` (it called `Lib.B.label`, silently, also
when the two arrived through other modules' imports). The flattener refuses
two different bindings of one name (E0206), and the Bun-ESM and JS emitters
refuse a second top-level binding of a JS name: Bun keeps the last of two
same-named `function`s without complaint, so this is the loud backstop. The
Wasm backend links imports by module and name and was not affected.
| `fixed`
| `test_801_same_name_in_two_modules` + `test_801_transitive_public_and_const`
(interpreter and Bun-ESM, run) + `test_801_planted_collision_refused` (the
backstop refuses a planted collision in the flattener and in both JS
emitters); `tests/codegen-bun/same_name_modules` runs #801's reproduction
under Bun.

| #801 (impl methods)
| Trait impl methods are emitted as free functions under their own names on
Bun-ESM (trait dispatch is not lowered there), so `impl Eq for Int` and
`impl Eq for Bool` gave two `function eq`s and Bun silently kept `Bool`'s.
The emitter now refuses the program. `stdlib/traits.affine` is refused for
this reason until impl methods get distinct names.
| `loud-fail`
| `test_801_impl_methods_refused` (the AOT smoke pins `traits.affine`'s refusal
in `expected_refusals`).
|===

== Still open — read before claiming "sound"
Expand Down
Loading
Loading