gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.42k stars 723 forks source link

Fatal compiler bug when using `gleam add` #3201

Closed maxdeviant closed 3 months ago

maxdeviant commented 3 months ago

I am able to consistently reproduce a fatal compiler bug when using gleam add in certain projects:

  Resolving versions
error: Fatal compiler bug!

This is a bug in the Gleam compiler, sorry!

Please report this crash to https://github.com/gleam-lang/gleam/issues/new
and include this error message with your report.

Panic: /private/tmp/nix-build-gleam-1.1.0.drv-0/gleam-1.1.0-vendor.tar.gz/pubgrub/src/internal/partial_solution.rs:131
    add_derivation should not be called after a decision
Gleam version: 1.1.0
Operating system: macos

If you can also share your code and say what file you were editing or any
steps to reproduce the crash that would be a great help.

You may also want to try again with the `GLEAM_LOG=trace` environment
variable set.

I have an example project that reproduces this issue.

Reproduction Steps

This is the minimal set of steps I've found to reproduce the issue in a brand new project:

  1. gleam new my_project
  2. gleam remove gleeunit
  3. gleam add --dev startest
  4. gleam add wisp 💥

I was initially seeing this in Gleam v1.1.0, but I am also able to reproduce on the latest main (6f9ffa3c0f03c6ff16ed52eb2e508a11bfc0228d).

Related Issues

It's very possible these might all be the same issue.

maxdeviant commented 3 months ago

I built the compiler from source at 6f9ffa3c0f03c6ff16ed52eb2e508a11bfc0228d with this patch applied:

diff --git a/compiler-cli/src/panic.rs b/compiler-cli/src/panic.rs
index 020ed2bf..9a5bc270 100644
--- a/compiler-cli/src/panic.rs
+++ b/compiler-cli/src/panic.rs
@@ -2,9 +2,9 @@
 use std::panic::PanicInfo;

 pub fn add_handler() {
-    std::panic::set_hook(Box::new(move |info: &PanicInfo<'_>| {
-        print_compiler_bug_message(info)
-    }));
+    // std::panic::set_hook(Box::new(move |info: &PanicInfo<'_>| {
+    //     print_compiler_bug_message(info)
+    // }));
 }

 fn print_compiler_bug_message(info: &PanicInfo<'_>) {

Running that build of the compiler against my reproduction project using RUST_BACKTRACE=1 produces the following backtrace:

λ RUST_BACKTRACE=1 ~/projects/gleam/target/debug/gleam add wisp
  Resolving versions
thread 'main' panicked at /Users/maxdeviant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pubgrub-0.2.1/src/internal/partial_solution.rs:131:25:
add_derivation should not be called after a decision
stack backtrace:
   0: std::panicking::begin_panic
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:686:12
   1: pubgrub::internal::partial_solution::PartialSolution<P,V>::add_derivation
             at /Users/maxdeviant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pubgrub-0.2.1/src/internal/partial_solution.rs:131:25
   2: pubgrub::internal::core::State<P,V>::unit_propagation
             at /Users/maxdeviant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pubgrub-0.2.1/src/internal/core.rs:124:25
   3: pubgrub::solver::resolve
             at /Users/maxdeviant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pubgrub-0.2.1/src/solver.rs:95:9
   4: gleam_core::dependency::resolve_versions
             at /Users/maxdeviant/projects/gleam/compiler-core/src/dependency.rs:56:20
   5: gleam::dependencies::resolve_versions
             at /Users/maxdeviant/projects/gleam/compiler-cli/src/dependencies.rs:709:20
   6: gleam::dependencies::get_manifest
             at /Users/maxdeviant/projects/gleam/compiler-cli/src/dependencies.rs:520:24
   7: gleam::dependencies::download
             at /Users/maxdeviant/projects/gleam/compiler-cli/src/dependencies.rs:164:40
   8: gleam::add::command
             at /Users/maxdeviant/projects/gleam/compiler-cli/src/add.rs:15:20
   9: gleam::main
             at /Users/maxdeviant/projects/gleam/compiler-cli/src/main.rs:495:43
  10: core::ops::function::FnOnce::call_once
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
maxdeviant commented 3 months ago

I was able to reproduce the issue in a standalone Rust project using pubgrub directly and have opened an issue with them: https://github.com/pubgrub-rs/pubgrub/issues/222.

My reproduction is available here.