Elm Exactly
Results / elm /

CompilerIssue1890RecordUpdateMutualRecursionCrashTest

Tags:elm19-bug-fixelm-spec

Checks, in A Standard Definition of Elm?:rule sm-topdec-valuerule s-atexp-update

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 passlamdera-1.5.0 pass

Issue: elm/compiler#1890

Mutually recursive unannotated functions with a record update crash the compiler.

<https://github.com/elm/compiler/issues/1890>

Elm 0.19.1 crashes ("index out of bounds") on this valid program; it should compile.
The test expects the program to run and log the unchanged record `{ x = (), y = () }`.

Fixed in Elm 0.19.3.

Results

elm-0.19.1

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...elm: ./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.3-c437ec060b3fdd8eecce3c5fd7ada7fe6d6f6ed56dbc08f484769fe155c657df:Data.Vector.Internal.Check

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   thread blocked indefinitely in an MVar operation

These errors are usually pretty confusing, so start by asking around on one of
forums listed at https://elm-lang.org/community to see if anyone can get you
unstuck quickly.

-- REQUEST ---------------------------------------------------------------------

If you are feeling up to it, please try to get your code down to the smallest
version that still triggers this message. Ideally in a single Main.elm and
elm.json file.

From there open a NEW issue at https://github.com/elm/compiler/issues with your
reduced example pasted in directly. (Not a link to a repo or gist!) Do not worry
about if someone else saw something similar. More examples is better!

This kind of error is usually tied up in larger architectural choices that are
hard to change, so even when we have a couple good examples, it can take some
time to resolve in a solid way.elm: thread blocked indefinitely in an MVar operation

elm-0.19.2

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...elm: index out of bounds (3,3)
CallStack (from HasCallStack):
  error, called at src/Data/Vector/Internal/Check.hs:103:12 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Internal.Check
  checkError, called at src/Data/Vector/Internal/Check.hs:109:17 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Internal.Check
  check, called at src/Data/Vector/Internal/Check.hs:122:5 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Internal.Check
  checkIndex, called at src/Data/Vector/Generic/Mutable.hs:680:16 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Generic.Mutable
  modify, called at src/Data/Vector/Mutable.hs:471:10 in vector-0.13.2.0-c5f5d3d65d4bbfa8d70b583d7f12b14f53d5d0d4dd455f21b70f9090be728c57:Data.Vector.Mutable

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   thread blocked indefinitely in an MVar operation

These errors are usually pretty confusing, so start by asking around on one of
forums listed at https://elm-lang.org/community to see if anyone can get you
unstuck quickly.

-- REQUEST ---------------------------------------------------------------------

If you are feeling up to it, please try to get your code down to the smallest
version that still triggers this message. Ideally in a single Main.elm and
elm.json file.

From there open a NEW issue at https://github.com/elm/compiler/issues with your
reduced example pasted in directly. (Not a link to a repo or gist!) Do not worry
about if someone else saw something similar. More examples is better!

This kind of error is usually tied up in larger architectural choices that are
hard to change, so even when we have a couple good examples, it can take some
time to resolve in a solid way.elm: thread blocked indefinitely in an MVar operation

elm-0.19.3

passran in 70 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
result: { x = (), y = () }

lamdera-1.5.0

passran in 64 ms
Output
result: { x = (), y = () }

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm/CompilerIssue1890RecordUpdateMutualRecursionCrashTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CompilerIssue1890RecordUpdateMutualRecursionCrashTest exposing (..)
{-| Mutually recursive unannotated functions with a record update crash the compiler.
<https://github.com/elm/compiler/issues/1890>
Elm 0.19.1 crashes ("index out of bounds") on this valid program; it should compile.
The test expects the program to run and log the unchanged record `{ x = (), y = () }`.
Fixed in Elm 0.19.3.
-}
-- TAGS: elm19-bug-fix
-- TAGS: elm-spec, sm-topdec-value, s-atexp-update
-- CHECK: result: { x = (), y = () }
import Html exposing (text)
type alias Model =
{ x : ()
, y : ()
}
firstMethod model =
let
_ =
model.y
in
addResourceToModel model
addResourceToModel model =
case Nothing of
Nothing ->
model
Just _ ->
let
_ =
firstMethod model
in
{ model | x = () }
main =
let
_ =
Debug.log "result" (firstMethod { x = (), y = () })
in
text "done"

Lean translation

This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest, in StandardElmMech/Generated/Elm_CombinatorSP.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.

CheckExpected (CHECK)Lean evaluatorProved by
result{ x = (), y = () }{ x = (), y = () }t_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest
/-- tests/elm/src/CompilerIssue1890RecordUpdateMutualRecursionCrashTest.elm -/
def g_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest : Program := {
  name := "CompilerIssue1890RecordUpdateMutualRecursionCrashTest", source := "tests/elm/src",
  exposing := .all, imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [("Model", some ["x", "y"])],
  defs := [
    .fn "firstMethod" [pv "model"] (letDefs [.pat pw (.atexp (access (A (v "model")) "y"))] (ap (v "addResourceToModel") [v "model"])),
    .fn "addResourceToModel" [pv "model"] (caseOf (c "Nothing") [(P (pcA "Nothing"), v "model"), (pcon "Just" [pw], letDefs [.pat pw (ap (v "firstMethod") [v "model"])] (updE "model" [("x", .atexp .unit)]))]),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "result", .atexp (.paren (ap (v "firstMethod") [recE [("x", .atexp .unit), ("y", .atexp .unit)]]))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "result: { x = (), y = () }" .data ] }

Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.

Static semantics (Chapters 4, 5 and 9): legal_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CompilerIssue1890RecordUpdateMutualRecursionCrashTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.