roc/crates/compiler
Joshua Warner ed62bcc15a
Fix a bunch of parser/formatter bugs found in fuzzing
Notably:
* Unified how parens are formatted between (1) when we have a ParensAround, and (2) when we've decided an Apply needs to have parens
* Made unary minus require the be indented to the same level as any other expression continuation. (it used to accidentally have rules meant for binary operators applied)
* Don't apply extra indent to the backpassing continuation in the case that the call does itself require indentation
* Make `try@foo` correctly parse as `try @foo`, so that formatting doesn't change the tree when it adds that space
* Detect more cases where we need to outdent trailing e.g. {} blocks in applies
* Approximately a bagillion other things, 90% of which I added tests for, and none of which affected the formatting of examples or builtins
2024-11-29 16:25:59 -08:00
..
alias_analysis Remove unused RuntimeErrorFunction variant from roc_mono::ir::Expr 2024-11-28 20:11:56 +00:00
build restore --no-link build pipeline 2024-11-21 16:20:05 +11:00
builtins Fix division of zero by zero for Dec 2024-11-27 23:38:21 +00:00
can Fix a bunch of parser/formatter bugs found in fuzzing 2024-11-29 16:25:59 -08:00
checkmate WIP 2024-11-11 10:22:58 +11:00
checkmate_schema WIP 2024-11-11 10:22:58 +11:00
collections Merge branch 'main' into specialize-exprs 2024-11-23 01:48:51 -03:00
constrain Remove unused TypedHole variant from roc_can::expr::Expr 2024-11-28 20:11:37 +00:00
debug_flags
derive WIP 2024-11-11 10:22:58 +11:00
derive_key WIP 2024-11-11 10:22:58 +11:00
exhaustive
fmt Fix a bunch of parser/formatter bugs found in fuzzing 2024-11-29 16:25:59 -08:00
gen_dev Merge pull request #7258 from JRI98/remove_unused_typedhole_variant 2024-11-29 00:19:49 -05:00
gen_llvm Merge pull request #7258 from JRI98/remove_unused_typedhole_variant 2024-11-29 00:19:49 -05:00
gen_wasm Remove unused RuntimeErrorFunction variant from roc_mono::ir::Expr 2024-11-28 20:11:56 +00:00
ident
late_solve
load Allow suffixed pure functions that are exposed to the host 2024-11-27 14:06:37 -03:00
load_internal Allow suffixed pure functions that are exposed to the host 2024-11-27 14:06:37 -03:00
lower_params Remove unused TypedHole variant from roc_can::expr::Expr 2024-11-28 20:11:37 +00:00
module rename Str.split 2024-11-15 21:12:23 -06:00
mono Remove unused RuntimeErrorFunction variant from roc_mono::ir::Expr 2024-11-28 20:11:56 +00:00
parse Fix a bunch of parser/formatter bugs found in fuzzing 2024-11-29 16:25:59 -08:00
problem Remove unused malformed related variants 2024-11-14 10:23:06 +00:00
region
roc_target back to old architecture display 2024-11-20 20:04:25 +01:00
serialize
solve Add doc comment to SolveConfig.host_exposed_symbols 2024-11-27 14:15:08 -03:00
solve_problem Merge branch 'main' into specialize-exprs 2024-11-23 01:48:51 -03:00
solve_schema
specialize_types Remove unused TypedHole variant from roc_can::expr::Expr 2024-11-28 20:11:37 +00:00
test_derive Allow suffixed pure functions that are exposed to the host 2024-11-27 14:06:37 -03:00
test_gen Merge pull request #7250 from shua/fracdec 2024-11-29 10:16:17 +11:00
test_mono Properly type constrain all function types 2024-11-21 04:09:47 -08:00
test_mono_macros
test_solve_helpers
test_syntax Fix a bunch of parser/formatter bugs found in fuzzing 2024-11-29 16:25:59 -08:00
types Use "opaques" instead of "opaque types" in reporting 2024-11-25 19:32:08 -03:00
uitest WIP 2024-11-11 10:22:58 +11:00
unify WIP 2024-11-11 10:22:58 +11:00
work
worker Prevent panics in worker threads from causing deadlocks 2024-11-13 20:30:56 -08: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.