Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Task as a built-in module/type #6836

Merged
merged 41 commits into from
Aug 30, 2024
Merged

Conversation

smores56
Copy link
Collaborator

@smores56 smores56 commented Jun 25, 2024

This change moves the Task opaque IO type from platform-specific implementations to the standard library of Roc. This PR is ready for review, barring final testing by building a pre-release of basic-cli using the twin basic-cli PR. The high level changes are:

  • Copied the Task module from the basic-cli platform to crates/compiler/builtins/roc/Task.roc
  • Consolidated Task and Effect into just the Task opaque type with definition Task ok err := {} -> Result ok err, which is the old type for Effect a : {} -> a that Task ok err : Effect (Result ok err) wrapped
  • Removed the Effect generation code, as everything should use Task directly
    • This includes the generates Effect with [after, map, ...] clause of the hosted module header, which is a breaking change
    • FFI definitions on the host side need to return RocResults now, and FFI type declarations on the Roc side need to always have Task return types
    • Removed generation of the Effect.after, Effect.map, etc. functions as they were needed to glue Effect to Task, but are no longer needed now that those types have been combined
  • Renamed hosted modules that contain FFI Roc declarations from Effect.roc to PlatformTask.roc to distinguish their behavior from the old approach and to give a name more descriptive of the new behavior
  • Updated almost of the testing, but until basic-cli works, that is on hold

@lukewilliamboswell
Copy link
Collaborator

It looks like there is a genuine issue with the False interpreter.

(nix:nix-shell-env) 192-168-1-103:false-interpreter luke$ roc build False.roc
🔨 Rebuilding platform...
0 errors and 0 warnings found in 940 ms
 while successfully building:

    False
(nix:nix-shell-env) 192-168-1-103:false-interpreter luke$ ./False examples/sqrt.false
Ran into problem:
examples/sqrt.false

@ageron
Copy link
Contributor

ageron commented Jul 29, 2024

Task.sequence runs tasks in reverse order, please see roc-lang/basic-cli#235

@Anton-4

This comment was marked as outdated.

@Anton-4 Anton-4 self-assigned this Aug 21, 2024
sort.roc Outdated Show resolved Hide resolved
Copy link
Collaborator

@Anton-4 Anton-4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sort.roc file is the only thing that needs to be addressed/clarified, all good for the rest 🎉

@Anton-4 Anton-4 removed their assignment Aug 26, 2024
Anton-4
Anton-4 previously approved these changes Aug 27, 2024
@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 28, 2024

I"m hitting some issues with d3732b4:

❯ ./target/release/roc crates/cli/tests/benchmarks/testAStar.roc 

── NAMING PROBLEM in crates/cli/tests/benchmarks/testAStar.roc ─────────────────

This annotation does not match the definition immediately following
it:

6│>  main : Task {} []
7│>  main =
8│>      PlatformTasks.putLine (showBool test1)
9│>          |> Task.mapErr! \_ -> crash "unreachable"

Is it a typo? If not, put either a newline or comment between them.


── UNRECOGNIZED NAME in crates/cli/tests/benchmarks/testAStar.roc ──────────────

Nothing is named `#!1_expr` in this scope.

8│>      PlatformTasks.putLine (showBool test1)
9│>          |> Task.mapErr! \_ -> crash "unreachable"

Did you mean one of these?

    Integer
    Hasher
    Box
    Signed16

────────────────────────────────────────────────────────────────────────────────

2 errors and 3 warnings found in 16 ms
.

You can run the program anyway with roc run crates/cli/tests/benchmarks/testAStar.roc

After I removed the type annotation on main, I hit:


roc on  builtin-task is 📦 v0.0.1 via 🦀 v1.77.2 via ❄  impure (nix-shell-env) 
❯ ./target/release/roc crates/cli/tests/benchmarks/testAStar.roc 
🔨 Rebuilding platform...
True
Roc standard library crashed with message

    voided tag constructor is unreachable

Shutting down

I tired several things without success, I"m going to revert the last commit for now.

@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 28, 2024

Currently stuck on:

❯ ./target/release/roc examples/cli/false-interpreter/False.roc examples/cli/false-interpreter/examples/sqrt.false 
🔨 Rebuilding platform...
memory allocation of 93824993832009 bytes failed

This is the only remaining test failure (when doing cargo test --release).

@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 28, 2024

Lol, the valgrind errors:

==217577== ERROR SUMMARY: 2963963 errors from 128 contexts (suppressed: 0 from 0)

@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 28, 2024

I can continue investigating on Friday.
If anyone else wants to take a stab; I recommend stepping through the False executable with IDA free, side-by-side with the version on main.

@smores56
Copy link
Collaborator Author

We reduced all tests failures down to the same issue. After removing unsized tasks from the false-interpreter platform (the platform of the failing test), we still got a failure. Namely, the host returns Ok(0), but Roc receives a Err {}, and we crash. The generated LLVM seems correct, so we are under the assumption that there is some lambda set issue here. The test has been therefore disabled for now, and we plan to revisit this once the lambda set fix is introduced.

If all tests pass, I vote that we call this good and merge, but I leave the final call to you @Anton-4.

@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 30, 2024

All tests should pass now 🤞

@Anton-4 Anton-4 mentioned this pull request Aug 30, 2024
11 tasks
Copy link
Collaborator

@Anton-4 Anton-4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@Anton-4 Anton-4 merged commit e619f60 into roc-lang:main Aug 30, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants