Elm Exactly
Results / elm /

CompilerIssue2106FoldlExtensibleRecordHangTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule s-exp-app

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/compiler#2106

A `foldl` whose step function extends an extensible-record type parameter must be
rejected with a type error, not hang the compiler.

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

`foldl withWindow Room windows` needs `Room a` and `Room { a | withWindow : () }` to be the
same type, which would make the record type infinite. Elm 0.19.1 instead hangs while its memory
grows without bound, or crashes.

The issue's own program used the library function `List.foldl`; this version reproduces the same
bug with a local `foldl` of the same type in its place.

Results

elm-0.19.1

fail
compiler used more than 4096 MB of memory
Dependencies ready!
Compiling ...

elm-0.19.2

fail
compiler used more than 4096 MB of memory
Dependencies ready!
Compiling ...

elm-0.19.3

fail
compiler used more than 4096 MB of memory
Dependencies ready!
Compiling ...

lamdera-1.5.0

fail
compiler used more than 4096 MB of memory
Verifying dependencies (10/10)

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2106FoldlExtensibleRecordHangTest exposing (main)
{-| A `foldl` whose step function extends an extensible-record type parameter must be
rejected with a type error, not hang the compiler.
<https://github.com/elm/compiler/issues/2106>
`foldl withWindow Room windows` needs `Room a` and `Room { a | withWindow : () }` to be the
same type, which would make the record type infinite. Elm 0.19.1 instead hangs while its memory
grows without bound, or crashes.
The issue's own program used the library function `List.foldl`; this version reproduces the same
bug with a local `foldl` of the same type in its place.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-exp-app
-- COMPILE-ERROR: a type error, not a hang
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: HasCallStack
import Html
type Room a = Room
type Window = Window
foldl : (a -> b -> b) -> b -> List a -> b
foldl f acc list =
case list of
[] ->
acc
x :: rest ->
foldl f (f x acc) rest
withWindow : Window -> Room a -> Room { a | withWindow : () }
withWindow window room =
Room
withWindows : List Window -> Room a -> Room { a | withWindow : () }
withWindows windows room =
foldl withWindow Room windows
main =
Html.text ""

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Lean has the program as written, in source syntax, and proves what the static semantics says of it (below). See the Lean mechanisation for which tests are in Lean, and why.

Static semantics: Lean proves that the program as written is not legal, so a compiler must reject it (refuse_elm_CompilerIssue2106FoldlExtensibleRecordHangTest, in StandardElmMech/Certs/). The proved inference W fails on a module of the program, and W fails only where no derivation exists (plan step 11) (Stat.not_legal_of_wRefutes). It holds for every derivation, with no hypothesis about principality.