Skip to content

Module-qualified call disambiguation via name mangling #187

@aallan

Description

@aallan

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 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
  • Name collision risk with flat module compilation #110 added collision detection (E608/E609/E610) -- this issue adds collision resolution

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions