roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.46k stars 313 forks source link

Importing Custom Ability Panics Compile #6702

Open benplotke opened 6 months ago

benplotke commented 6 months ago

Steps to Reproduce

  1. Create SortAbility.roc with contents:
    
    module [
    Comparison,
    Sort,
    ]

Comparison : [LessThan, Equal, GreaterThan] Sort implements compare : a, a -> Comparison where a implements Sort

2. In the same directory, create ImportAbility.roc with contents:

module [ ]

import SortAbility

3. run `roc test AbilityImport.roc`
### Expected Results
Nothing
### Actual

~/docs/code/roc/OrderedCollections $ ~/roc/roc_ben-build-2024-05-02-798dd77/roc test AbilityImport.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 thread '' panicked at crates/compiler/load_internal/src/file.rs:4535:29: Import ability member SortAbility.compare not available stack backtrace: 0: rust_begin_unwind at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5 1: core::panicking::panic_fmt at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14 2: import_variable_for_symbol at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:4535:29 3: roc_load_internal::file::add_imports::{{closure}} at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:4429:17 4: roc_can::abilities::IAbilitiesStore::resolve_for_module::{{closure}} at /home/ben/roc/roc-src/crates/compiler/can/src/abilities.rs:621:44 5: core::iter::adapters::map::map_fold::{{closure}} at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/iter/adapters/map.rs:84:28 6: core::iter::traits::iterator::Iterator::fold at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/iter/traits/iterator.rs:2639:21 7: fold<(roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData), std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>, (), core::iter::traits::iterator::Iterator::for_each::call::{closure_env#0}<(roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData), hashbrown::map::{impl#95}::extend::{closure_env#0}<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData, core::hash::BuildHasherDefault, alloc::alloc::Global, core::iter::adapters::map::Map<std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>>>>> at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/iter/adapters/map.rs:124:9 8: for_each<core::iter::adapters::map::Map<std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>>, hashbrown::map::{impl#95}::extend::{closure_env#0}<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData, core::hash::BuildHasherDefault, alloc::alloc::Global, core::iter::adapters::map::Map<std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>>>> at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/iter/traits/iterator.rs:857:9 9: extend<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData, core::hash::BuildHasherDefault, alloc::alloc::Global, core::iter::adapters::map::Map<std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>>> at /cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.0/src/map.rs:6455:9 10: extend<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData, core::hash::BuildHasherDefault, core::iter::adapters::map::Map<std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>>> at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/collections/hash/map.rs:3038:9 11: from_iter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData, core::hash::BuildHasherDefault, core::iter::adapters::map::Map<std::collections::hash::map::IntoIter<roc_module::symbol::Symbol, roc_can::abilities::AbilityMemberData>, roc_can::abilities::{impl#7}::resolve_for_module::{closure_env#0}<roc_load_internal::file::add_imports::Ctx, roc_load_internal::file::add_imports::{closure_env#0}, roc_load_internal::file::add_imports::{closure_env#1}>>> at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/collections/hash/map.rs:3023:13 12: core::iter::traits::iterator::Iterator::collect at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/iter/traits/iterator.rs:2053:9 13: roc_can::abilities::IAbilitiesStore::resolve_for_module at /home/ben/roc/roc-src/crates/compiler/can/src/abilities.rs:605:31 14: add_imports at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:4417:27 15: run_solve_solve at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:4604:47 16: roc_load_internal::file::run_solve at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:4765:13 17: roc_load_internal::file::run_task at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:6144:17 18: worker_task at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:2091:34 19: roc_load_internal::file::load_multi_threaded::{{closure}}::{{closure}} at /home/ben/roc/roc-src/crates/compiler/load_internal/src/file.rs:1831:25 20: crossbeam_utils::thread::ScopedThreadBuilder::spawn::{{closure}} at /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-utils-0.8.16/src/thread.rs:440:31 21: core::ops::function::FnOnce::call_once{{vtable.shim}} at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5 22: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9 note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

tannerntannern commented 2 days ago

I just ran into this issue today, using

roc nightly pre-release, built from commit c95fdd6 on Mi 13 Nov 2024 11:26:07 UTC

Does anyone have context on what this error means? Does it mean importing custom abilities isn't allowed? Does it mean that it's not yet implemented by the compiler? Does it mean the import or ability definition is somehow malformed?

benplotke commented 2 days ago

I don't know what causes the issue, but, as a temporary solution, I got around it by copy pasting the ability directly into the section of code I was using it in. For example

tannerntannern commented 2 days ago

Unfortunately, that doesn't work for my case because I want to expose the ability as part of a package/platform. The ability must be imported.

benplotke commented 2 days ago

Yeah, it's a really basic hole in the functionally. I just got to learn Rust and the Roc compiler and then I can fix it😉. I should probably stop making noise in the comments and wait for someone who actually knows something to chime in