Skip to content

compiled_mono_bases cross-module name-collision in template-warning suppression #661

@aallan

Description

@aallan

Summary

PR #659's template-warning suppression pass in vera/codegen/core.py::compile_program keys compiled_mono_bases on bare base function names. If two modules in the same compile unit declare a forall<T> function with the same name, the suppression set conflates them — if either compiles, BOTH templates' warnings get suppressed.

Reproducer (hypothetical)

-- prelude:
private forall<T> fn map(@Option<T>, ...) -> ...

-- user module:
public forall<T> fn map(@Array<T>, ...) -> ...

If only one of these has working mono clones in the user's program, the other's template warning gets suppressed too (because compiled_mono_bases contains "map" without module disambiguation).

Current mitigations

  • Today's user-vs-prelude namespace separation: users can't redeclare prelude names like option_map, etc. But user-defined module imports CAN share names.
  • The failure mode is "warning suppressed when it shouldn't be" — not a runtime bug. The actual functions still compile correctly; users just lose the per-function diagnostic.

Source location

vera/codegen/core.py around lines 500-580. The relevant code:

compiled_mono_bases: set[str] = set()
for mdecl in mono_decls:
    orig_name = mdecl.name.split("$")[0]
    # ... compile ...
    if fn_wat is not None:
        compiled_mono_bases.add(orig_name)

orig_name is the bare base name ("map" from "map$Int"). No module qualification.

Suggested fix

Key on (module, name) rather than just name. Requires tracking module attribution through Pass 1.5's mono-decl synthesis. Alternatively, scope the suppression to the current program's forall_decl_names set only (which excludes imported module declarations).

Investigation context

Surfaced as F4 in the multi-agent review of PR #659. Not blocking for #659 — the failure mode is benign (silenced warning) and only reachable when users intentionally shadow names across modules.

Acceptance criteria

  • Reproducer (two modules each declaring forall<T> fn shared_name) compiles correctly, and BOTH templates emit warnings if their mono clones don't compile
  • Existing 4 tests in tests/test_codegen.py::TestGenericMonoSuffixFromSlotRef604 still pass

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions