roc/crates/compiler
2023-06-02 15:23:05 -07:00
..
alias_analysis Convert LayoutRepr::Struct into a tuple variant 2023-05-16 11:58:16 -05:00
arena_pool run a toml formatter and then clean it up a bit 2023-03-06 19:47:57 -08:00
build Update --prebuilt-platform usage in comments and error messages. 2023-05-15 12:53:58 -04:00
builtins add more impls and memcpy 2023-06-02 15:23:05 -07:00
can Implement hash for Dec 2023-05-26 11:38:30 -05:00
collections Function to get index from SoA slice 2023-04-10 15:43:30 -05:00
constrain s/loc_guard/loc_pattern 2023-05-24 13:12:47 -05:00
debug_flags Rename ROC_VERIFY_OCCURS_RECURSION flag 2023-05-02 17:00:58 -05:00
derive rust update, nix update, clippy fixes 2023-04-22 14:51:01 +02:00
derive_key Implement hash for Dec 2023-05-26 11:38:30 -05:00
exhaustive run a toml formatter and then clean it up a bit 2023-03-06 19:47:57 -08:00
fmt Format multiline reecord builder fields nicely 2023-05-17 12:48:37 -03:00
gen_dev nullable unwrapped for the dev backend 2023-06-01 00:02:38 +02:00
gen_llvm Stop using llvm instrinsics that just call libc 2023-05-31 20:00:04 -07:00
gen_wasm Implement hash for Dec 2023-05-26 11:38:30 -05:00
ident run a toml formatter and then clean it up a bit 2023-03-06 19:47:57 -08:00
late_solve Make sure to report error rather than descending as appropriate 2023-03-22 17:08:43 -05:00
load replace panic! with internal_error! in compiler modules 2023-05-03 22:11:21 +02:00
load_internal Merge branch 'main' into record-update-index-top 2023-05-30 10:47:19 +02:00
module Add update to symbols table and auto generate test_mono 2023-05-30 09:07:15 +02:00
mono nullable unwrapped for the dev backend 2023-06-01 00:02:38 +02:00
parse Track spaces between : and <- in record builders 2023-05-17 11:49:06 -03:00
problem Unapplied record builder error 2023-05-08 20:16:38 -03:00
region rust update, nix update, clippy fixes 2023-04-22 14:51:01 +02:00
roc_target change wasi object file to .wasm 2023-04-26 12:51:09 -07:00
serialize run a toml formatter and then clean it up a bit 2023-03-06 19:47:57 -08:00
solve Correctly introduce new recursion variables at the correct rank 2023-05-01 13:14:59 -05:00
solve_problem Switch to PathBuf to avoid Path turning into a fat pointer. Avoids growing Constraints 2023-04-09 21:14:05 -07:00
test_derive Merge pull request #5179 from roc-lang/i5143-tuple-abilities 2023-03-25 15:51:39 -05:00
test_gen nullable unwrapped for the dev backend 2023-06-01 00:02:38 +02:00
test_mono Generate tests 2023-06-01 18:40:31 +02:00
test_mono_macros Crash at runtime rather than panicking when if condition is erroneous 2023-05-01 15:48:05 -05:00
test_solve_helpers Print variables if asked to 2023-05-02 13:08:58 -05:00
test_syntax Format multiline reecord builder fields nicely 2023-05-17 12:48:37 -03:00
types Correctly copy non-generalized imports as non-generalized 2023-05-24 14:12:24 -05:00
uitest Merge branch 'main' into record-update-index-top 2023-05-30 10:47:19 +02:00
unify Correct occurs cycle under alias argument but not alias real var 2023-05-02 17:00:58 -05:00
DESIGN.md Start a section on canonicalization 2023-03-13 14:07:42 +00:00
README.md Start working on new compiler design documentation 2023-03-11 11:40:53 -05:00

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.