elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.52k stars 662 forks source link

elm-19: thread blocked indefinitely in an MVar operation #1789

Open bburdette opened 6 years ago

bburdette commented 6 years ago

I was trying to make some code more generic and ran into this:

elm-19: You ran into a compiler bug. Here are some details for the developers:
[00] 
[00]     ? [rank = 1]
[00] 
[00] Please create an <http://sscce.org/> and then report it
[00] at <https://github.com/elm/compiler/issues>
[00] 
[00] 
[00] CallStack (from HasCallStack):
[00]   error, called at compiler/src/Type/Solve.hs:205:15 in main:Type.Solve
[00] elm-19: thread blocked indefinitely in an MVar operation
[00] (error exit: exit status 1)

So, here's the minimal example that produces the error. Depends on elm-ui v 1.0.0.

Minimal.elm.txt

akoppela commented 5 years ago
module Main exposing (main)

import Platform

type Form model formData
    = SimpleForm (model -> formData)
    | AdvancedForm (model -> Bool)

initForm : Form model formData -> model -> Maybe formData
initForm formHelper model =
    case formHelper of
        SimpleForm toForm ->
            toForm model

        AdvancedForm _ ->
            Nothing

type alias Model internalModel formData =
    { internalModel : internalModel
    , form : formData
    }

processAction : Form internalModel formData -> Model internalModel formData -> Model internalModel formData
processAction formHelper model =
    { model | form = initForm formHelper model.internalModel }

main : Program () () ()
main =
    Platform.worker
        { init = \_ -> ( (), Cmd.none )
        , update = \_ _ -> ( (), Cmd.none )
        , subscriptions = \_ -> Sub.none
        }

Another example. The issue is that toForm model should be Just (toForm model).

jonathanfishbein1 commented 5 years ago

I'm getting something similar

type Vector a
    = Vector (List a)

type Matrix a
    = Matrix (List (Vector.Vector a))

multiplyComplexMatrices : Matrix (Vector.Vector (ComplexNumbers.ComplexNumberCartesian number)) -> Matrix (Vector.Vector (ComplexNumbers.ComplexNumberCartesian number)) -> Matrix (Vector.Vector (ComplexNumbers.ComplexNumberCartesian number))
multiplyComplexMatrices matrixOne matrixTwo =
    liftA2 Vector.multiplyComplexVectors matrixOne (transpose matrixTwo)

apply : Matrix (a -> b) -> Matrix a -> Matrix b
apply (Matrix fMatrix) (Matrix matrix) =
    Matrix <| List.map2 (\fVector xVector -> Vector.apply fVector xVector) fMatrix matrix

liftA2 : (a -> b -> c) -> Matrix a -> Matrix b -> Matrix c
liftA2 f a b =
    apply (map f a) b

transpose : Matrix a -> Matrix a
transpose (Matrix matrix) =
    matrix
        |> List.map (\(Vector.Vector x) -> x)
        |> List.Extra.transpose
        |> List.map (\x -> Vector.Vector x)
        |> Matrix

map : (a -> b) -> Matrix a -> Matrix b
map f (Matrix matrix) =
    Matrix <| List.map (Vector.map f) matrix

{-| Vector map
-}
map : (a -> b) -> Vector a -> Vector b
map f (Vector vector) =
    Vector <| List.map f vector

ComplexNumber package here

https://package.elm-lang.org/packages/jonathanfishbein1/complex-numbers/latest/ComplexNumbers

matheus23 commented 5 years ago

Hi! I'm interested in automatic reduction of elm codebases, so one does not have to do it by hand, like you did.

I'm working on elm-reduce, which is something similar to creduce as my bachelor's thesis, and I need as much test-data for it as possible.

I would love to get into contact with you, but two of you don't have emails listed on your profile. Would you mind sending me a mail? (You can find the address in my profile)

bilus commented 5 years ago

Getting the exact same error when using Monocle.Lens. :| It's killing me. I can prepare a simple case if what's above isn't enough.

tankorsmash commented 2 years ago

I had a similar issue where there was a compiler crash with the MVar issue:

$ elm make .\src\Main.elm --output=/dev/null
Compiling ...elm.exe: .\\Data\\Vector\\Generic\\Mutable.hs:703 (modify): index out of bounds (3,3)
CallStack (from HasCallStack):
  error, called at .\\Data\\Vector\\Internal\\Check.hs:87:5 in vector-0.12.0.1-GC2xzdMF0QQGz7ZCcRBJRL:Data.Vector.Internal.Check

The issue seemed to be that the Elm compiler couldn't figure out the Elm error in my code and crashed, because fixing the issue also made the compile work.

I tried to make an ellie of it, but I couldn't make up an example that was able to reproduce it. It would be on line 70 of this successfully-compiling ellie, if looking at this gives any sort of hint (as unlikely as it is though, since I couldn't reproduce it outside my codebase), where I had foo2 = getLocations m while it should have been foo2 = getLocations m.locations.

I do have a branch saved that reproduces in my 6k line project, if someone on the dev team would like access, please let me know.