roc/crates/compiler
Elias Mulhall 14fabdff07 Double the amount of indentation allowed in parser trace debugging
Increase from 36 levels of indentation to 80. This is excessive, but
it's confusing to have a parser test crash just because
parse_debug_trace is enabled.
2024-08-29 07:25:42 -04:00
..
alias_analysis move List.map* into roc 2024-07-13 10:39:56 -07:00
build use macos codesign 2024-08-14 17:01:17 +02:00
builtins Deprecate backpassing to prepare for eventual removal 2024-08-16 22:36:04 -07:00
can Don't use debug formatting to convert Variable into string 2024-08-28 12:51:02 -04:00
checkmate Update stale document references 2024-06-26 02:16:20 -04:00
checkmate_schema
collections Replace ScopeModules/modules VecMap with 2 Vecs 2024-07-05 22:05:33 -03:00
constrain Move unexpected params warning to solve 2024-07-06 21:36:26 -03:00
debug_flags
derive fix example, update mono 2024-04-13 14:26:17 +02:00
derive_key Change docs/errors from "optional" to "default value" record fields 2024-04-03 08:55:35 -07:00
exhaustive
fmt Update parser AST to support dbg as both a statment and expression 2024-08-28 11:53:44 -04:00
gen_dev get native dev backend working 2024-07-21 20:07:52 -07:00
gen_llvm ensure alignment is never 0. Must be at least 1. 2024-08-25 11:48:46 -07:00
gen_wasm get wasm dev backend working 2024-07-21 19:53:36 -07:00
ident
late_solve
load Remove error handling for dbg in expression position 2024-08-28 11:53:44 -04:00
load_internal update to basic-cli 0.14 2024-08-23 15:50:05 +02:00
module Merge pull request #7005 from smores56/deprecate-backpassing 2024-08-18 08:08:29 -04:00
mono add roc check tip 2024-08-27 20:29:12 +02:00
parse Double the amount of indentation allowed in parser trace debugging 2024-08-29 07:25:42 -04:00
problem Deprecate backpassing to prepare for eventual removal 2024-08-16 22:36:04 -07:00
region
roc_target Use roc_target over target_lexicon 2024-03-31 10:50:26 -07:00
serialize
solve cargo fmt --all 2024-08-28 11:53:44 -04:00
solve_problem Always use "MODULE PARAMS" term in errors 2024-07-06 22:07:29 -03:00
solve_schema
test_derive Fix importing of module params vars 2024-07-02 22:48:47 -03:00
test_gen Merge pull request #7005 from smores56/deprecate-backpassing 2024-08-18 08:08:29 -04:00
test_mono Allow dbg expression inside string interpolation 2024-08-28 11:53:44 -04:00
test_mono_macros
test_solve_helpers Handle root type when loading from str 2024-06-08 19:46:41 -03:00
test_syntax Parse dbg in expression position 2024-08-28 11:53:44 -04:00
types Merge branch 'main' into typecheck-module-params 2024-08-07 18:55:33 -03:00
uitest Merge branch 'main' into typecheck-module-params 2024-08-07 18:55:33 -03:00
unify use dead_code for Both 2024-07-05 14:17:52 +02:00
work Delete worker.rs for now 2024-06-17 22:25:15 -04:00
worker clippy 2024-06-17 22:25:15 -04:00
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.