You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When two imported modules define a function with the same name, the compiler now correctly reports a collision error (E608, added in #110). However, there is currently no way to resolve the collision without renaming one of the source declarations.
Module-qualified calls (math::abs(42)) exist in the grammar and are parsed as ModuleCall nodes, but the codegen desugars them to bare FnCall nodes (discarding the module path) because all imported functions are compiled into a single flat WASM namespace. This means qualified calls cannot disambiguate colliding names.
Proposed solution
Implement name mangling so that math::abs(42) compiles to call $math.abs instead of call $abs. This would allow two modules to define functions with the same bare name as long as callers use qualified syntax.
Design considerations
Vera has a strong one-canonical-form principle: every construct should have exactly one representation. Name mangling introduces a tension here -- abs(42) and math::abs(42) would both be valid ways to call the same function (when there is no collision). The implementation should consider:
Whether bare calls should still work when there is no ambiguity (likely yes, for ergonomics)
Whether the mangled name should be visible to the user (likely no -- it is an internal WASM detail)
How this interacts with WASM exports (public functions are currently exported by bare name)
Whether this changes the flat compilation model or is purely an internal naming strategy
Current state
context.py line 214-222: ModuleCall desugars to bare FnCall, module path discarded
codegen/core.py Pass 2.5: uses imported_seen set keyed by bare name
Summary
When two imported modules define a function with the same name, the compiler now correctly reports a collision error (E608, added in #110). However, there is currently no way to resolve the collision without renaming one of the source declarations.
Module-qualified calls (
math::abs(42)) exist in the grammar and are parsed asModuleCallnodes, but the codegen desugars them to bareFnCallnodes (discarding the module path) because all imported functions are compiled into a single flat WASM namespace. This means qualified calls cannot disambiguate colliding names.Proposed solution
Implement name mangling so that
math::abs(42)compiles tocall $math.absinstead ofcall $abs. This would allow two modules to define functions with the same bare name as long as callers use qualified syntax.Design considerations
Vera has a strong one-canonical-form principle: every construct should have exactly one representation. Name mangling introduces a tension here --
abs(42)andmath::abs(42)would both be valid ways to call the same function (when there is no collision). The implementation should consider:publicfunctions are currently exported by bare name)Current state
context.pyline 214-222:ModuleCalldesugars to bareFnCall, module path discardedcodegen/core.pyPass 2.5: usesimported_seenset keyed by bare nameReferences