Skip to content

Commit

Permalink
Merge remote-tracking branch 'remote/main' into annotate-type-signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewilliamboswell committed Jan 9, 2025
2 parents 37cd04c + ee54aca commit d9d2ce8
Show file tree
Hide file tree
Showing 157 changed files with 430 additions and 14,387 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions crates/cli/tests/benchmarks/platform/PlatformTasks.roc

This file was deleted.

10 changes: 5 additions & 5 deletions crates/compiler/builtins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ You can run your new tests locally using `cargo test-gen-llvm`. You can add a fi

### module/src/symbol.rs

Towards the bottom of `symbol.rs` there is a `define_builtins!` macro being used that takes many modules and function names. The first level (`List`, `Int` ..) is the module name, and the second level is the function or value name (`reverse`, `rem` ..). If you wanted to add a `Int` function called `addTwo` go to `2 Int: "Int" => {` and inside that case add to the bottom `38 INT_ADD_TWO: "addTwo"` (assuming there are 37 existing ones).
Towards the bottom of `symbol.rs` there is a `define_builtins!` macro being used that takes many modules and function names. The first level (`List`, `Int` ..) is the module name, and the second level is the function or value name (`reverse`, `rem` ..). If you wanted to add a `Int` function called `add_two` go to `2 Int: "Int" => {` and inside that case add to the bottom `38 INT_ADD_TWO: "add_two"` (assuming there are 37 existing ones).

Some of these have `#` inside their name (`first#list`, `#lt` ..). This is a trick we are doing to hide implementation details from Roc programmers. To a Roc programmer, a name with `#` in it is invalid, because `#` means everything after it is parsed to a comment. We are constructing these functions manually, so we are circumventing the parsing step and don't have such restrictions. We get to make functions and values with `#` which as a consequence are not accessible to Roc programmers. Roc programmers simply cannot reference them.

But we can use these values and some of these are necessary for implementing builtins. For example, `List.get` returns tags, and it is not easy for us to create tags when composing LLVM. What is easier however, is:

- ..writing `List.#getUnsafe` that has the dangerous signature of `List elem, U64 -> elem` in LLVM
- ..writing `List elem, U64 -> Result elem [OutOfBounds]*` in a type safe way that uses `getUnsafe` internally, only after it checks if the `elem` at `U64` index exists.
- ..writing `List.#get_unsafe` that has the dangerous signature of `List elem, U64 -> elem` in LLVM
- ..writing `List elem, U64 -> Result elem [OutOfBounds]*` in a type safe way that uses `get_unsafe` internally, only after it checks if the `elem` at `U64` index exists.

### can/src/builtins.rs

Expand Down Expand Up @@ -123,5 +123,5 @@ But replace `Num.atan`, the return value, and the return type with your new buil

When implementing a new builtin, it is often easy to copy and paste the implementation for an existing builtin. This can take you quite far since many builtins are very similar, but it also risks forgetting to change one small part of what you copy and pasted and losing a lot of time later on when you cant figure out why things don't work. So, speaking from experience, even if you are copying an existing builtin, try and implement it manually without copying and pasting. Two recent instances of this (as of September 7th, 2020):

- `List.keepIf` did not work for a long time because in builtins its `LowLevel` was `ListMap`. This was because I copy and pasted the `List.map` implementation in `builtins.rs
- `List.walkBackwards` had mysterious memory bugs for a little while because in `unique.rs` its return type was `list_type(flex(b))` instead of `flex(b)` since it was copy and pasted from `List.keepIf`.
- `List.keep_if` did not work for a long time because in builtins its `LowLevel` was `ListMap`. This was because I copy and pasted the `List.map` implementation in `builtins.rs
- `List.walk_backwards` had mysterious memory bugs for a little while because in `unique.rs` its return type was `list_type(flex(b))` instead of `flex(b)` since it was copy and pasted from `List.keep_if`.
305 changes: 0 additions & 305 deletions crates/compiler/builtins/roc/Task.roc

This file was deleted.

1 change: 0 additions & 1 deletion crates/compiler/builtins/roc/main.roc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ package [
Hash,
Box,
Inspect,
Task,
] {}
2 changes: 0 additions & 2 deletions crates/compiler/builtins/src/roc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn module_source(module_id: ModuleId) -> &'static str {
ModuleId::DECODE => DECODE,
ModuleId::HASH => HASH,
ModuleId::INSPECT => INSPECT,
ModuleId::TASK => TASK,
_ => internal_error!(
"ModuleId {:?} is not part of the standard library",
module_id
Expand All @@ -36,4 +35,3 @@ const ENCODE: &str = include_str!("../roc/Encode.roc");
const DECODE: &str = include_str!("../roc/Decode.roc");
const HASH: &str = include_str!("../roc/Hash.roc");
const INSPECT: &str = include_str!("../roc/Inspect.roc");
const TASK: &str = include_str!("../roc/Task.roc");
1 change: 0 additions & 1 deletion crates/compiler/can/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ soa.workspace = true

[dev-dependencies]
indoc.workspace = true
insta.workspace = true
pretty_assertions.workspace = true
test_compile.workspace = true
9 changes: 1 addition & 8 deletions crates/compiler/can/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::annotation::IntroducedVariables;
use crate::annotation::OwnedNamedOrAble;
use crate::derive;
use crate::env::Env;
use crate::env::FxMode;
use crate::expr::canonicalize_record;
use crate::expr::get_lookup_symbols;
use crate::expr::AnnotatedMark;
Expand Down Expand Up @@ -3265,13 +3264,7 @@ fn to_pending_value_def<'a>(
))
}
StmtAfterExpr => PendingValue::StmtAfterExpr,
Stmt(expr) => {
if env.fx_mode == FxMode::Task {
internal_error!("a Stmt was not desugared correctly, should have been converted to a Body(...) in desguar")
}

PendingValue::Def(PendingValueDef::Stmt(expr))
}
Stmt(expr) => PendingValue::Def(PendingValueDef::Stmt(expr)),
}
}

Expand Down
Loading

0 comments on commit d9d2ce8

Please sign in to comment.