roc/crates/compiler
Ayaz Hafiz 561f3d9711
Store lambda set variables as flex inference variables
This is actually correct - the rigid approach is not. Lambda set
variables should be inferred in-scope.
2025-01-05 23:54:37 -05:00
..
alias_analysis clarify todo about renabling morphic and perf 2024-12-14 10:31:05 -08:00
build cli: add --verbose flag to CMD_BUILD 2024-12-31 11:57:59 +01:00
builtins fix tests 2025-01-01 13:35:08 -08:00
can Unify let-introduction in a single path 2025-01-05 23:54:37 -05:00
checkmate replace cargo deps with workspace in checkmate, constrain, derive 2024-11-29 11:15:26 +11:00
checkmate_schema Remove unused code 2024-12-05 09:18:52 +00:00
collections Remove unused code 2024-12-05 09:18:52 +00:00
constrain Store lambda set variables as flex inference variables 2025-01-05 23:54:37 -05:00
debug_flags
derive replace cargo deps with workspace in checkmate, constrain, derive 2024-11-29 11:15:26 +11:00
derive_key replace cargo deps with workspace in derive_key, exhaustive, fmt, gen_dev, gen_llvm 2024-11-29 11:17:42 +11:00
exhaustive replace cargo deps with workspace in derive_key, exhaustive, fmt, gen_dev, gen_llvm 2024-11-29 11:17:42 +11:00
fmt Fix unstable formatting with nested applies 2025-01-02 17:59:12 -06:00
gen_dev compiler: bump object to 0.36.7 2024-12-31 16:17:38 +01:00
gen_llvm add missing compiler rt function 2024-12-11 18:00:46 -08:00
gen_wasm Merge pull request #7314 from shua/wrapped 2024-12-09 11:19:58 +11:00
ident
late_solve replace cargo deps with workspace in gen_wasm, late_solve, load, load_internal 2024-11-29 11:21:57 +11:00
load Unify let-introduction in a single path 2025-01-05 23:54:37 -05:00
load_internal Add unit test 2024-12-26 10:56:48 -06:00
lower_params Use new try impl for ? operator 2024-12-05 02:13:13 -08:00
module Parens and Commas application syntax 2025-01-02 16:49:08 -06:00
mono fixed drop specialization assert for unreachable switch branches on unions 2024-12-16 14:38:36 -08:00
parse Move comment to correct location and make line comment 2025-01-02 17:59:32 -06:00
problem Remove backpassing 2025-01-01 17:44:56 -08:00
region
roc_target replace cargo deps with workspace in lower_parms, module, mono, parse, problem, roc_target, serialize, solve, solve_problem, specialize_types, test_* 2024-11-29 11:29:04 +11:00
serialize replace cargo deps with workspace in lower_parms, module, mono, parse, problem, roc_target, serialize, solve, solve_problem, specialize_types, test_* 2024-11-29 11:29:04 +11:00
solve Unify let-introduction in a single path 2025-01-05 23:54:37 -05:00
solve_problem Use new try impl for ? operator 2024-12-05 02:13:13 -08:00
solve_schema
specialize_types Test multiple patterns per branch 2024-12-14 19:34:29 -03:00
test_derive replace cargo deps with workspace in lower_parms, module, mono, parse, problem, roc_target, serialize, solve, solve_problem, specialize_types, test_* 2024-11-29 11:29:04 +11:00
test_gen Add Num.fromBool 2024-12-24 10:10:20 -05:00
test_mono Add Num.fromBool 2024-12-24 10:10:20 -05:00
test_mono_macros
test_solve_helpers replace cargo deps with workspace in test_solve_helpers, test_syntax, types, uitest, unify, work, worker 2024-11-29 11:31:48 +11:00
test_syntax Address review feedback 2025-01-02 17:59:09 -06:00
types Initial working version of proper try keyword 2024-12-04 02:31:59 -08:00
uitest Store lambda set variables as flex inference variables 2025-01-05 23:54:37 -05:00
unify Convert unused dbg!()s to eprintln!()s 2024-12-01 23:10:35 -05:00
work replace cargo deps with workspace in test_solve_helpers, test_syntax, types, uitest, unify, work, worker 2024-11-29 11:31:48 +11:00
worker replace cargo deps with workspace in test_solve_helpers, test_syntax, types, uitest, unify, work, worker 2024-11-29 11:31:48 +11:00
DESIGN.md Remove backpassing 2025-01-01 17:44:56 -08:00
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.