roc/crates/compiler
2024-10-21 22:10:42 -04:00
..
alias_analysis remove single entrypoint 2024-10-07 21:16:30 -07:00
build remove single entrypoint 2024-10-07 21:16:30 -07:00
builtins fix typo in Dict.update docs 2024-10-15 13:19:36 -04:00
can Do some checked SoA stuff 2024-10-21 22:10:42 -04:00
checkmate Bump cookie and express in /crates/compiler/checkmate/www 2024-10-12 22:04:06 +00:00
checkmate_schema
collections Do some checked SoA stuff 2024-10-21 22:10:42 -04:00
constrain Do some checked SoA stuff 2024-10-21 22:10:42 -04:00
debug_flags
derive Convert over Subs to use the new soa crate 2024-10-10 00:30:35 -04:00
derive_key Revert "Try out converting subs to use soa stuff directly" 2024-10-10 00:06:25 -04:00
exhaustive
fmt Merge pull request #7151 from hrishisd/deprecate-old-str-interpolation 2024-10-09 11:21:18 +11:00
gen_dev gen_dev-x86_64 extend Num.neg to all Signed and Unsigned int sizes 2024-10-07 23:43:58 +02:00
gen_llvm remove single entrypoint 2024-10-07 21:16:30 -07:00
gen_wasm
ident
late_solve
load Remove deprecated string interpolation syntax 2024-10-08 16:31:22 -04:00
load_internal Enable multiple functions exposed to the host 2024-10-07 21:16:30 -07:00
lower_params Fix zero-arity home value def var 2024-09-01 19:11:56 -03:00
module Merge remote-tracking branch 'remote/main' into str-dropping 2024-09-29 14:31:04 +10:00
mono Revert "Try out converting subs to use soa stuff directly" 2024-10-10 00:06:25 -04:00
parse Do some checked SoA stuff 2024-10-21 22:10:42 -04:00
problem Remove old record builder syntax 2024-09-21 04:44:44 -07:00
region
roc_target
serialize
solve Do some checked SoA stuff 2024-10-21 22:10:42 -04:00
solve_problem Merge attempt 2024-08-19 23:34:05 -07:00
solve_schema
test_derive Convert over Subs to use the new soa crate 2024-10-10 00:30:35 -04:00
test_gen Merge pull request #7146 from HajagosNorbert/hajagosnorbert/neg_int 2024-10-11 08:57:46 -07:00
test_mono update mono tests 2024-09-29 15:06:15 +10:00
test_mono_macros
test_solve_helpers
test_syntax Merge pull request #7151 from hrishisd/deprecate-old-str-interpolation 2024-10-09 11:21:18 +11:00
types Do some checked SoA stuff 2024-10-21 22:10:42 -04:00
uitest update mono tests 2024-09-29 16:29:15 +10:00
unify Convert over Subs to use the new soa crate 2024-10-10 00:30:35 -04:00
work
worker
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.