Skip to content

Frontend: a module reached from the prelude closure and from the root carries two path spellings; Sema's module index and the bundle interface emitter compare spellings, not canonical keys #954

Closed

Description

@ehartford

Found in batch C4 (wo-c4): once lib/std/regex.w imports std.re.* (the prelude closure now reaches the pcre2 corpus), the bundle build with build /abs/lib/std/re/bundle.w --emit-obj --bundle-corpus std/re --emit-bundle-interface x.wi fails with

error: bundle interface: <embedded-std>/std/re/defs.w: not in Sema's module graph (lib/std/re/defs.w)

for every corpus module that has declarations (the use-only modules render). The same command with a RELATIVE root path succeeds, and so does --no-prelude.

Root cause (exact lines). One module, two spellings:

  • src/compiler/Frontend.w:1401 (expand_prelude_closure_frontend, Compiler: serialized prelude snapshot keyed by compiler fingerprint (study delta 6) #682-inc1): the prelude closure is parsed ahead of the root; resolve_module_path_frontend(ppname, decl_source_dir_frontend(pi)) resolves std.re.defs from an embedded module through the root fallback to the tree-relative spelling lib/std/re/defs.w, and parse_imported_file_frontend (Frontend.w:2474) appends every declaration's decl_source_paths entry with that spelling.
  • src/Resolve.w:288-301 (reserve_module): identity is keyed on the canonical form (with check cannot reliably check arbitrary source files #592) but the stored module_paths entry keeps the first-seen spelling — the root's own use std.re.defs, resolved against the root's absolute directory: /…/lib/std/re/defs.w.
  • Consumers compare spellings: src/Sema.w:1582-1589 keys module_index_by_path by the Resolve spelling; src/compiler/BundleInterfaceEmit.w:1038 looks the decl spelling up in it and reports the module as missing; src/Sema.w:2613 and :2767 (module_visible_no_prelude, the tiered visibility walk) do the same lookup with current_module_path (the decl spelling) and, when it misses, return 1 — a silent permissive fallback, so a spelling mismatch makes private declarations visible across modules.

Verified with a temporary diagnostic printing sema.module_paths at the emitter's miss: the graph holds /Users/…/c4/lib/std/re/defs.w while decl_source_paths holds lib/std/re/defs.w.

Blast radius. Any compile whose root is given by an absolute path and whose prelude closure reaches a tree-resolved module before the root imports it. Consumers of the embedded interface are unaffected (both routes yield <embedded-std>/std/re/…); bundle builds, wo-drift rebuilds and any --bundle-corpus compile are.

Fix. Key module_index_by_path (and the visibility caches) by resolve_canonical_module_key(path) and look up with the canonical key at every site, the identity rule Resolve.reserve_module already applies; the emitter then finds every corpus module regardless of who imported it first. The permissive return 1 at Sema.w:2769 should not survive that change.

Workaround in C4. build/wo.w compiles the corpus with --no-prelude (as rt/regex_runtime.w always was): the object and the interface are byte-identical with and without the prelude (verified cmp against the seed-built artifacts, fingerprint 0257a06a… on both passes).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce.

    The bundle build from an absolute root path, with the prelude, succeeds:

    $ with build /…/lib/std/engines/pcre2/bundle.w --emit-obj --bundle-corpus std/engines/pcre2 --emit-bundle-interface x.wi -o x.o
    warning: bundle interface: 37 generic function(s) not exported at Level 0 …
    rc=0   (x.wi 149921 bytes)
    

    da47ab3 builds bundles without the prelude, and the permissive fallback named in the report is gone: module_visible_no_prelude in src/Sema.w now returns 0 when the current module is not in module_index_by_path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions