Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_idxvalues in interpreter_shim/main.zig afterenableRuntimeInsertsmakes the interners writable, but beforeInterpreter.initis called.