Skip to content

Conversation

@Anton-4
Copy link
Collaborator

@Anton-4 Anton-4 commented Dec 15, 2025

Issue cause

• The roc build executable is running through the portable serialized ModuleEnv path. That path drops the module identity the interpreter needs for method dispatch.

  • roc build writes a portable serialized blob (SERIALIZED_FORMAT_MAGIC)
    (src/cli/main.zig:2670). The built executable loads it via
    setupModuleEnvFromSerialized
    (src/interpreter_shim/main.zig:396, src/interpreter_shim/main.zig:629).

  • During portable deserialization,
    ModuleEnv.Serialized.deserialize sets module_name_idx to Ident.Idx.NONE
    (src/canonicalize/ModuleEnv.zig:2054), even though the serialized struct
    reserves space for “interned during deserialization”
    (src/canonicalize/ModuleEnv.zig:1962).

  • At runtime, nominal types translate their origin_module into the
    interpreter’s runtime_layout_store.env ident space by string-inserting
    the module name (src/eval/interpreter.zig:8938–8941). As a result, Animal
    ends up with an origin_module ident representing the app module’s name.

  • When evaluating dog == cat, the interpreter tries to resolve the is_eq
    method via resolveMethodFunction. This starts by mapping
    origin_module → ModuleEnv using getModuleEnvForOrigin
    (src/eval/interpreter.zig:7734). In the build/shim case, the app module is
    not in imports, so the only intended match is the “app module” check
    (src/eval/interpreter.zig:7755–7761) or translated_module_envs.

  • However, Interpreter.initWithModuleEnvs skips populating
    translated_app_module and translated_module_envs for any env whose
    module_name_idx is NONE (src/eval/interpreter.zig:536–603).

    Result: getModuleEnvForOrigin returns null for the app module, and
    resolveMethodFunction fails with MethodLookupFailed.

• Why it only happens with build:

  • The built executable uses the portable deserialization path described
    above.

  • ./zig-out/bin/roc ./file.roc goes through a path where module envs retain
    a valid module_name_idx. The origin-module → env mapping works, and the
    failure is avoided.

Fix

Insert valid module_name_idx values in interpreter_shim/main.zig after enableRuntimeInserts makes the interners writable, but before Interpreter.init is called.

@Anton-4 Anton-4 enabled auto-merge (squash) December 15, 2025 18:44
Signed-off-by: Anton-4 <17049058+Anton-4@users.noreply.github.com>
@lukewilliamboswell
Copy link
Collaborator

@Anton-4 I merged this into #8629 because I'm working on similar issues in that branch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants