roc/src
Luke Boswell 132658fa15
fix: transitive module imports in compile-time evaluation
Fix "TypeMismatch in body evaluation" panic when platform modules make
transitive calls (e.g., app → Helper → Core).

Changes:
- Pass sibling modules during platform module compilation so each module
  can resolve imports to previously compiled siblings
- Detect type modules (using `:= [].{}` syntax) and set statement_idx
  for proper qualified name lookup during canonicalization
- Pre-allocate compiled_modules ArrayList to avoid pointer invalidation
  during reallocation
- Add fallback to env.imports.getResolvedModule in evalLookupExternal
  for cross-module calls when current module context has changed
- Fix use-after-free bug in low_level_interp_test.zig by heap-allocating
  imported_envs array
- Add integration test for transitive module imports

Note: Modules must be listed in dependency order in the platform's
exposes list (e.g., if Helper imports Core, Core must come before Helper).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 10:21:46 +11:00
..
base Fix #8517 (#8613) 2025-12-12 11:30:33 +01:00
base58 More cleanups 2025-12-04 08:23:41 -05:00
build Merge remote-tracking branch 'remote/main' into implement-box 2025-12-15 20:01:23 +11:00
builtins Merge remote-tracking branch 'remote/main' into implement-box 2025-12-15 20:01:23 +11:00
bundle Add for clauses to platform modules 2025-12-12 21:21:51 -05:00
canonicalize Merge remote-tracking branch 'remote/main' into implement-box 2025-12-15 20:01:23 +11:00
check fix: skip vars with rank changed by unification during generalization 2025-12-16 08:21:17 +11:00
cli fix: transitive module imports in compile-time evaluation 2025-12-16 10:21:46 +11:00
collections Merge remote-tracking branch 'remote/main' into build-static-lib 2025-12-11 15:40:26 +11:00
compile fix TYPE REDECLARED 2025-12-15 12:03:09 +11:00
eval fix: transitive module imports in compile-time evaluation 2025-12-16 10:21:46 +11:00
fmt Add for clauses to platform modules 2025-12-12 21:21:51 -05:00
fs big cleanup 2025-12-11 11:20:08 +11:00
interpreter_shim fix: transitive module imports in compile-time evaluation 2025-12-16 10:21:46 +11:00
ipc Merge remote-tracking branch 'remote/main' into roc-build 2025-12-09 11:08:22 +11:00
layout Merge remote-tracking branch 'remote/main' into implement-box 2025-12-15 20:01:23 +11:00
lsp Merge branch 'roc-lang:main' into lsp-syntax-parsing 2025-12-09 20:28:46 -05:00
parse Add for clauses to platform modules 2025-12-12 21:21:51 -05:00
playground_wasm add for_clause_alias_statements for platform headers 2025-12-15 10:04:21 +11:00
PROFILING
repl add for_clause_alias_statements for platform headers 2025-12-15 10:04:21 +11:00
reporting Merge remote-tracking branch 'remote/main' into build-static-lib 2025-12-11 15:40:26 +11:00
roc_src
snapshot_tool update tracy hooks 2025-12-15 00:22:16 -08:00
target always use portable serialization when embedding modules 2025-12-11 09:01:53 +11:00
types fix: skip vars with rank changed by unification during generalization 2025-12-16 08:21:17 +11:00
unbundle Fix double-close crash in downloadToFile error handling 2025-12-13 17:51:14 -05:00
watch Add lint for no // ======= comments 2025-12-10 15:31:53 -05:00
flake.lock
flake.nix Fix typo in flake.nix: testscmd -> testcmd 2025-12-05 00:16:21 -05:00
README.md

Roc Compiler (Zig Implementation)

Navigation

Core compiler directories:

  • base/ - Core data structures and utilities shared across the compiler
  • check/ - Main compilation pipeline (parsing, canonicalization, type checking)
  • types/ - Type system definitions and utilities
  • builtins/ - Built-in types, functions, and operations
  • reporting/ - Error reporting and diagnostic formatting
  • collections/ - Efficient data structures used throughout the compiler
  • cache/ - Compilation caching system for faster incremental builds
  • coordinate/ - Cross-module compilation coordination and dependency management
  • eval/ - Runtime evaluation and interpretation system
  • fs/ - Filesystem operations and file I/O utilities
  • layout/ - Memory layout computation and management for code generation
  • serialization/ - Serialization utilities for compiler data structures
  • snapshots/ - Snapshot tests validating compiler behavior across all stages

Status

This table provides a summary of progress for the zig compiler re-write and should be updated with the PR that includes new features.

Str & Num Functions Modules Collections Records & Tuples Recursive Types Static Dispatch
Parse 🔋 🔋 🪫 🪫 🔋 🪫 🚧
Canonicalize 🪫 🪫 🪫 🪫 🪫 🪫 🚧
Resolve Imports 🚧 🚧 🪫 🚧 🚧 🚧 🚧
Check Types 🪫 🚧 🚧 🚧 🚧 🚧
Interpreter
Specialize Types
Lift Functions
Solve Functions
Specialize Functions
Reference Counting
Lower IR
Gen LLVM
  • N/A Not applicable
  • 🚧 Work Started
  • 🪫 Tests Passing
  • 🔋 Polished

Fast Feedback Loop

The roc zig compiler can have a very fast feedback loop. We support zigs incremental compilation and watch mode. By avoiding generating final executables, we can build and typecheck much much faster.

Try it with zig build -Dno-bin -fincremental --watch

Expanding to ZLS

This fast config can also be used with zls. Simply follow these steps:

  1. run zls --version and make sure it is 0.15.0 (this is still used for zig 0.15.2).
  2. run zls env and grab the config_file path.
  3. Edit the config file to include
{
  "enable_build_on_save": true,
  "build_on_save_args": ["-Dno-bin", "-fincremental"]
}
  1. Advised, also changing the cache dir, I use --cache-dir .zig-cache/zls. Otherwise, zig commands run manually can lead to the lsp breaking and requiring a restart.
  2. Optionally, add -Dfuzz above as well to get type checking of fuzz scripts as well.
  3. Note, I had to fully delete my .zig-cache to get zls to start. Make sure to check the logs if you aren't getting type failures.
  4. Enjoy better lsp results.

Simply testing feedback loop

Sadly, this is not nearly as fast due to building binaries. One day, we will get dev zig backends, and it should be fast.

Try it with zig build test -fincremental --watch

Overview

Zig Dependency Graph