Stream: bugs

Topic: roc test crash


view this post on Zulip drew (Oct 22 2024 at 01:41):

within https://github.com/drewolson/aoc-roc, the following command works:

view this post on Zulip drew (Oct 22 2024 at 01:41):

$ roc test Aoc/Year2023/Day14.roc
0 failed and 2 passed in 368 ms.

view this post on Zulip drew (Oct 22 2024 at 01:41):

but this command crashes

view this post on Zulip drew (Oct 22 2024 at 01:41):

$ roc test Aoc/Year2023/Day09.roc
thread 'main' panicked at crates/compiler/load_internal/src/file.rs:373:85:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
^C

view this post on Zulip drew (Oct 22 2024 at 01:41):

for the life of me i can't spot a reason why

view this post on Zulip drew (Oct 22 2024 at 01:42):

roc test without arguments works fine

view this post on Zulip drew (Oct 22 2024 at 01:42):

$ roc test
0 failed and 5 passed in 423 ms.

view this post on Zulip Luke Boswell (Oct 22 2024 at 02:03):

I'm guessing a bug in the implementation of that feature for roc test to take a file path as an argument

view this post on Zulip Luke Boswell (Oct 22 2024 at 02:04):

Indeed it is a bit strange

view this post on Zulip Luke Boswell (Oct 22 2024 at 02:04):

If you can try a debug build of the compiler it might give you more information

view this post on Zulip drew (Oct 22 2024 at 02:04):

i’ll give it a shot later, thanks

view this post on Zulip drew (Nov 26 2024 at 15:46):

any updates on https://github.com/roc-lang/roc/issues/7175? i'd love to try roc for aoc this year, but the LSP constantly crashes when opening files in my multi-file project. happy to wait until next year if it's not the right time.

view this post on Zulip drew (Nov 26 2024 at 15:47):

though it look like roc check no longer fails on this file, so that's good!

view this post on Zulip Anton (Nov 26 2024 at 16:10):

I can take a look at it after I'm done with the breaking changes update, although others are welcome to investigate this high priority issue

view this post on Zulip Anthony Bullard (Nov 28 2024 at 14:28):

Looks like it may be an issue with something holding an extra reference to an Arc that contains the module ids. When i finish up the snake_case work I can take a look

view this post on Zulip Anthony Bullard (Nov 28 2024 at 14:47):

Any pointers you can give on tracking down these sort of references would be helpful.

view this post on Zulip Anton (Nov 28 2024 at 14:52):

Looking at the authors of the surrounding code, it's possible that @Ayaz Hafiz, @Richard Feldman or @Folkert de Vries have some good tips.

view this post on Zulip Anthony Bullard (Nov 28 2024 at 15:13):

Ok, checking this locally it looks like I'm seeing a different error with the latest. Now the issue is that there is a dependency that hasn't been solved when type checking completes.

These are the steps that are not Done at this stage:

Step(pf.PlatformTasks, SolveTypes): NotStarted,
Step(pf., SolveTypes): NotStarted,
Step(pf.Stderr, SolveTypes): NotStarted,
Step(pf., CanonicalizeAndConstrain): NotStarted,
Step(pf.Stderr, CanonicalizeAndConstrain): NotStarted,
Step(pf.PlatformTasks, CanonicalizeAndConstrain): Pending,
Step(pf.InternalHttp, SolveTypes): Pending,
Step(pf.InternalCommand, SolveTypes): Pending,
Step(pf.InternalPath, SolveTypes): Pending,

view this post on Zulip Anthony Bullard (Nov 28 2024 at 16:56):

It seems that it is adding the platform modules to be solved, but since they are never used in checking this leaf module, we never typecheck. It seems that we should only add a Canonicalize/SolveTypes Steps when the module is required.

view this post on Zulip Anthony Bullard (Nov 30 2024 at 12:58):

I'm really struggling with this. It seems that the use case is valid (single file checking), but when we decide to add the msgs for the platform modules, we don't know if the file we are checking even needs them. So the solutions I see are:

I'd like to get some thoughts from some of the core team on this. @Anton @Brendan Hansknecht @Richard Feldman (Sorry, I don't know all who's on the core team).

view this post on Zulip Anthony Bullard (Nov 30 2024 at 16:58):

Regardless, I'd probably need a little walk through to understand all the things I need to think about regarding this

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 17:37):

So the issue is that to check the validity of a single roc file, we also have to check the platform in order to fully solve the type information?

Also, which specific messages are problematic, do you have an example?

view this post on Zulip Anthony Bullard (Nov 30 2024 at 17:43):

So in file.rs::update when we determine that have finished all type checking because the root_id equals the module_id and some other things, the platform modules have not been solved and we hit an assert that checks that and blows up.

thread 'main' panicked at crates/compiler/load_internal/src/file.rs:2532:17:
assertion failed: state.dependencies.solved_all()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If you ignore this like I'm doing right now when the root type is a module, you get the original issue where there are outstanding references (Arc clones) to state.derived module.

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Outstanding references to the derived module
Location: crates/compiler/load_internal/src/file.rs:3325:29

view this post on Zulip Anthony Bullard (Nov 30 2024 at 17:44):

We don't need to (from a functional standpoint) check the platform since it's not used. But this assert makes us have to (probably to ensure all check errors are returned).

view this post on Zulip Anthony Bullard (Nov 30 2024 at 17:46):

It seems like the check is there to prevent this latter message from happening (clearing all the work will cause all of the clones to be dropped).

view this post on Zulip Anthony Bullard (Nov 30 2024 at 17:46):

It's a lot of different concepts to swim through when I get about 30mins at a time to look into it.

view this post on Zulip drew (Nov 30 2024 at 23:21):

if it helps, i still get the error on this repo https://github.com/drewolson/aoc-roc

view this post on Zulip drew (Nov 30 2024 at 23:21):

roc build works

view this post on Zulip drew (Nov 30 2024 at 23:21):

however roc check Aoc/Year2023/Day09.roc errors

view this post on Zulip drew (Nov 30 2024 at 23:21):

(and therefore i get persistent LSP errors)

view this post on Zulip drew (Nov 30 2024 at 23:21):

i'm on the latest roc, parser, and basic-cli

view this post on Zulip drew (Nov 30 2024 at 23:21):

$ roc --version
roc nightly pre-release, built from commit d72da8eb0fb on Fri Nov 29 09:25:13 UTC 2024

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:06):

It sounds silly but add an import for any module from your platform to the file and it’s good to go

view this post on Zulip drew (Dec 01 2024 at 00:07):

sorry can you explain that more?

view this post on Zulip drew (Dec 01 2024 at 00:11):

you're saying i should import a platform function?

view this post on Zulip drew (Dec 01 2024 at 00:12):

adding import pf.Stdout still has the same error

view this post on Zulip drew (Dec 01 2024 at 00:16):

i'd be more than happy to do a workaround for now if i can have working LSP for advent of code :smile:

view this post on Zulip drew (Dec 01 2024 at 00:21):

ok weird, this did work for the LSP! but the command line roc check still fails

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:26):

That’s weird. The roc check will fail now because you have an unused import, but it shouldn’t crash

view this post on Zulip drew (Dec 01 2024 at 00:27):

$ roc check Aoc/Year2023/Day09.roc
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Outstanding references to the derived module
Location: crates/compiler/load_internal/src/file.rs:3311:29

view this post on Zulip drew (Dec 01 2024 at 00:27):

$ head Aoc/Year2023/Day09.roc
module [part1, part2]

import pf.Stdout

nextVal : List I64 -> I64
nextVal = \l ->
    if List.all l \n -> n == 0 then
        0
    else
        diffs = List.map2 l (List.dropFirst l 1) \a, b -> b - a

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:27):

Interesting

view this post on Zulip drew (Dec 01 2024 at 00:27):

but weirdly the LSP now works

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:27):

Take that as a win I guess

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:27):

I’m less worried about the single file chdckt

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:27):

I’m less worried about the single file check

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:28):

But the LSP working is inportant

view this post on Zulip drew (Dec 01 2024 at 00:28):

roc check does work

view this post on Zulip drew (Dec 01 2024 at 00:28):

with no arguments

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:28):

Yes because main.roc probably uses a platform import

view this post on Zulip drew (Dec 01 2024 at 00:28):

actually roc check works before any changes

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:29):

Yes

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:30):

During a run of check _something_ has to import from platform

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:30):

That’s the bug I’m trying to fix

view this post on Zulip Anthony Bullard (Dec 01 2024 at 00:55):

I doubt I’ll have much time tonight to work on this, but if I have a commit with a fix, I’ll share the SHA here

view this post on Zulip Anthony Bullard (Dec 01 2024 at 01:58):

I think I have a fix

view this post on Zulip Anthony Bullard (Dec 01 2024 at 01:58):

Let me get a PR together

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:01):

Don't have time for that, here's a patch that you can git apply if you have a local repo:

diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs
index ff7ce3a50c..ba8c47c95f 100644
--- a/crates/compiler/load_internal/src/file.rs
+++ b/crates/compiler/load_internal/src/file.rs
@@ -658,7 +658,7 @@ struct CanAndCon {
     module_docs: Option<ModuleDocumentation>,
 }

-#[derive(Debug)]
+#[derive(Debug, PartialEq, Eq)]
 enum PlatformPath<'a> {
     NotSpecified,
     Valid(To<'a>),
@@ -1141,7 +1141,6 @@ impl<'a> LoadStart<'a> {

         // Load the root module synchronously; we can't proceed until we have its id.
         let root_start_time = Instant::now();
-
         let load_result = load_filename(
             arena,
             filename.clone(),
@@ -1286,7 +1285,6 @@ fn handle_root_type<'a>(
                 if let (Some(main_path), Some(cache_dir)) = (main_path.clone(), cache_dir) {
                     let mut messages = Vec::with_capacity(4);
                     messages.push(header_output.msg);
-
                     load_packages_from_main(
                         arena,
                         src_dir.clone(),
@@ -2245,7 +2243,9 @@ fn update<'a>(

                     // If we're building an app module, and this was the platform
                     // specified in its header's `to` field, record it as our platform.
-                    if state.opt_platform_shorthand == Some(config_shorthand) {
+                    if state.opt_platform_shorthand == Some(config_shorthand)
+                        || state.platform_path == PlatformPath::RootIsModule
+                    {
                         debug_assert!(state.platform_data.is_none());

                         state.platform_data = Some(PlatformData {
@@ -2339,7 +2339,6 @@ fn update<'a>(
                 extend_module_with_builtin_import(parsed, ModuleId::INSPECT);
                 extend_module_with_builtin_import(parsed, ModuleId::TASK);
             }
-
             state
                 .module_cache
                 .imports

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:05):

Created a PR after all :-) https://github.com/roc-lang/roc/pull/7283

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:06):

Going to run tests on it locally, pushed it up fast so you can test @drew

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:06):

But on my local I created your minimal repro and it is fixed.

view this post on Zulip drew (Dec 01 2024 at 02:07):

nice!!

view this post on Zulip drew (Dec 01 2024 at 02:07):

thanks :folded_hands:

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:07):

I'm going to assume I've made a mistake here and some tests will fail, or it will fail on a larger test case.

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:08):

@Luke Boswell If you have a moment to take a look at that PR and see if there isn't something obvious I'm going to mess up here?

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:09):

Do you have commit signing setup?

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:10):

I don't see anything obvious :smiley:

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:10):

Thanks for submitting this :heart:

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:12):

I’m not setup for it, but I can of needed

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:12):

If needed.

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:13):

I’m waiting for my test run locally to complete

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:13):

We can only have a single platform right?

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:13):

Yeah that's correct

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:16):

This was so much easier than it looked at first

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:17):

So if we have PlatformPath::RootIsModule we give it a fake platform_data?

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:17):

Is that basically all it was?

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:20):

No I’d root is module we give it the actual platform data from the platform found in main.roc

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:20):

*if root is

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:21):

Sorry on my phone , can’t edit

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:22):

Nice, works well

view this post on Zulip Anthony Bullard (Dec 01 2024 at 02:29):

If you need to sign the commit let me know and I’ll try to get that done tonight

view this post on Zulip Luke Boswell (Dec 01 2024 at 02:46):

We can merge this one I think. But if you plan on contributing more, please set it up when you can :smiley:

view this post on Zulip Anthony Bullard (Dec 01 2024 at 04:08):

All tests passed locally

view this post on Zulip drew (Dec 01 2024 at 04:48):

thanks for fixing and merging this! much appreciated.


Last updated: Jul 06 2025 at 12:14 UTC