roc/crates/compiler
2024-01-26 16:05:56 -05:00
..
alias_analysis add List.clone 2024-01-20 20:29:07 +01:00
build add --fuzz option to roc 2024-01-25 15:42:18 -08:00
builtins Update ListLen and ListGetUnsafe to not use Nat 2024-01-26 16:05:56 -05:00
can Merge remote-tracking branch 'origin/main' into str-unicode 2024-01-21 12:30:16 -05:00
checkmate Consolidate gitignore 2024-01-10 22:16:04 -05:00
checkmate_schema
collections crate upgrades for ahash issue 2023-12-30 16:16:22 +01:00
constrain add src and location to dbg 2023-12-02 21:18:31 -08:00
debug_flags
derive Merge branch 'main' into clippy-1.74 2023-12-02 20:09:06 -06:00
derive_key misc cleanup suggestions 2023-11-28 16:40:43 -08:00
exhaustive fix indexing 2023-11-20 21:09:12 -08:00
fmt Parse deprecated interpolation syntax differently 2024-01-06 21:49:00 -05:00
gen_dev Merge remote-tracking branch 'origin/main' into str-unicode 2024-01-21 12:30:16 -05:00
gen_llvm Update ListLen and ListGetUnsafe to not use Nat 2024-01-26 16:05:56 -05:00
gen_wasm Update ListLen and ListGetUnsafe to not use Nat 2024-01-26 16:05:56 -05:00
ident
late_solve
load use subs caching on windows 2024-01-21 22:00:17 +11:00
load_internal Fix repro for nasty import bug 2024-01-26 16:01:08 -05:00
module isApproxEq function 2024-01-23 21:06:35 -05:00
mono Merge remote-tracking branch 'origin/main' into str-unicode 2024-01-21 12:30:16 -05:00
parse Merge pull request #6361 from faldor20/fix-lang-server-hang 2024-01-21 22:06:48 -05:00
problem
region
roc_target typo and clippy 2023-11-06 21:04:50 -08:00
serialize
solve fix clippy unnecessary hashes 2024-01-01 16:38:36 +01:00
solve_problem
solve_schema
test_derive add missing ToInspector case 2023-11-28 16:40:40 -08:00
test_gen Fix some tests 2024-01-26 16:00:33 -05:00
test_mono Update mono tests 2024-01-26 16:04:16 -05:00
test_mono_macros
test_solve_helpers
test_syntax Update to basic-cli 0.8.1 2024-01-26 16:02:30 -05:00
types Merge branch 'main' into clippy-1.74 2023-12-02 20:09:06 -06:00
uitest Update mono tests 2024-01-26 16:04:16 -05:00
unify
DESIGN.md
README.md

The Roc Compiler

For an overview of the design and architecture of the compiler, see DESIGN.md. If you want to dive into the implementation or get some tips on debugging the compiler, see below

Getting started with the code

The compiler contains a lot of code! If you're new to the project it can be hard to know where to start. It's useful to have some sort of "main entry point", or at least a "good place to start" for each of the main phases.

After you get into the details, you'll discover that some parts of the compiler have more than one entry point. And things can be interwoven together in subtle and complex ways, for reasons to do with performance, edge case handling, etc. But if this is "day one" for you, and you're just trying to get familiar with things, this should be "good enough".

The compiler is invoked from the CLI via build_file in cli/src/build.rs

Phase Entry point / main functions
Compiler entry point load/src/file.rs: load, load_and_monomorphize
Parse header parse/src/module.rs: parse_header
Parse definitions parse/src/module.rs: module_defs
Canonicalize can/src/def.rs: canonicalize_defs
Type check solve/src/module.rs: run_solve
Gather types to specialize mono/src/ir.rs: PartialProc::from_named_function
Solve specialized types mono/src/ir.rs: from_can, with_hole
Insert reference counting mono/src/ir.rs: Proc::insert_refcount_operations
Code gen (optimized but slow) gen_llvm/src/llvm/build.rs: build_procedures
Code gen (unoptimized but fast, CPU) gen_dev/src/object_builder.rs: build_module
Code gen (unoptimized but fast, Wasm) gen_wasm/src/lib.rs: build_module

For a more detailed understanding of the compilation phases, see the Phase, BuildTask, and Msg enums in load/src/file.rs.

Debugging the compiler

Please see the debug flags for information on how to ask the compiler to emit debug information during various stages of compilation.

There are some goals for more sophisticated debugging tools:

General Tips

Miscompilations

If you observe a miscomplication, you may first want to check the generated mono IR for your code - maybe there was a problem during specialization or layout generation. One way to do this is to add a test to test_mono/src/tests.rs and run the tests with cargo test -p test_mono; this will write the mono IR to a file.

Typechecking errors

First, try to minimize your reproduction into a test that fits in solve_expr.

Once you've done this, check out the ROC_PRINT_UNIFICATIONS debug flag. It will show you where type unification went right and wrong. This is usually enough to figure out a fix for the bug.

If that doesn't work and you know your error has something to do with ranks, you may want to instrument deep_copy_var_help in solve.

If that doesn't work, chatting on Zulip is always a good strategy.