Elm Exactly
Results / elm-core /

StandardA81SleepBeyond32BitsTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule p-proc-sleeprule p-proc-killrule p-wait

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 faillamdera-1.5.0 fail
`Process.sleep d` waits at least `d` milliseconds, also when `d` is above 2^31 - 1.

A Standard Definition of Elm?, ruling A81: the action of `Process.sleep d` takes place no sooner
than `d` milliseconds later, for every finite `d`. <https://elm-test-suite.netlify.app/standard/rules/p-proc-sleep>

A process sleeps for 3e9 ms (about 35 days); 200 ms later it is still asleep, and is killed so that
the program can end. Elm 0.19.1 passes the delay to JavaScript's `setTimeout`, which takes a delay
above 2^31 - 1 as 1 ms: the long sleep ends almost at once. (Killing that finished process then
also stops Elm 0.19.1, elm/core #955.)

Results

elm-0.19.1

failran in 254 ms
Unexpected pattern (CHECK-NOT): the long sleep ended
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
(node:28072) TimeoutOverflowWarning: 3000000000 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
(Use `node --trace-warnings ...` to show where the warning was created)
the long sleep ended: ()
checked after 200 ms: ()

elm-0.19.2

failran in 240 ms
Unexpected pattern (CHECK-NOT): the long sleep ended
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
(node:57374) TimeoutOverflowWarning: 3000000000 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
(Use `node --trace-warnings ...` to show where the warning was created)
the long sleep ended: ()
checked after 200 ms: ()

elm-0.19.3

failran in 250 ms
Unexpected pattern (CHECK-NOT): the long sleep ended
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
(node:86817) TimeoutOverflowWarning: 3000000000 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
(Use `node --trace-warnings ...` to show where the warning was created)
the long sleep ended: ()
checked after 200 ms: ()

lamdera-1.5.0

failran in 274 ms
Unexpected pattern (CHECK-NOT): the long sleep ended
--- output ---
(node:115690) TimeoutOverflowWarning: 3000000000 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
(Use `node --trace-warnings ...` to show where the warning was created)
the long sleep ended: ()
checked after 200 ms: ()

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module StandardA81SleepBeyond32BitsTest exposing (main)
{-| `Process.sleep d` waits at least `d` milliseconds, also when `d` is above 2^31 - 1.
A Standard Definition of Elm?, ruling A81: the action of `Process.sleep d` takes place no sooner
than `d` milliseconds later, for every finite `d`. <https://elm-test-suite.netlify.app/standard/rules/p-proc-sleep>
A process sleeps for 3e9 ms (about 35 days); 200 ms later it is still asleep, and is killed so that
the program can end. Elm 0.19.1 passes the delay to JavaScript's `setTimeout`, which takes a delay
above 2^31 - 1 as 1 ms: the long sleep ends almost at once. (Killing that finished process then
also stops Elm 0.19.1, elm/core #955.)
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, p-proc-sleep, p-proc-kill, p-wait
-- CHECK: checked after 200 ms: ()
-- CHECK-NOT: the long sleep ended
import Process
import Task
type Msg
= Spawned Process.Id
| Checked Process.Id
| Killed
longSleep : Task.Task Never ()
longSleep =
Process.sleep 3.0e9
|> Task.andThen
(\_ ->
let
_ =
Debug.log "the long sleep ended" ()
in
Task.succeed ()
)
init : () -> ( (), Cmd Msg )
init _ =
( (), Task.perform Spawned (Process.spawn longSleep) )
update : Msg -> () -> ( (), Cmd Msg )
update msg model =
case msg of
Spawned pid ->
( model, Task.perform (\_ -> Checked pid) (Process.sleep 200) )
Checked pid ->
let
_ =
Debug.log "checked after 200 ms" ()
in
( model, Task.perform (\_ -> Killed) (Process.kill pid) )
Killed ->
( model, Cmd.none )
main : Program () () Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = \_ -> Sub.none
}

Lean translation

This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_core_StandardA81SleepBeyond32BitsTest, in StandardElmMech/Generated/Worker01.lean). Lean evaluates its modules by the rules of Chapter 7, starts it by r:p-init with no flags (null, A72), and runs it by the transitions of Chapter 9 under a host that sends nothing. Its checks become one generated theorem: some execution the book allows, under that host, has a log (the modules', then the start's, then each step's) that meets every check. The theorem trusts the parser and the translator's elaboration ([parse] [elab]), the test basis ([harness]) and the parameters of the basis ([params]), and is proved by the kernel. Not stated: CHECK-NOT: the long sleep ended (finding T1: r:p-wait lets the long sleep end before the kill; not required by the book, theorem t1_a81_long_sleep_may_end).

CheckExpected (CHECK)Lean evaluatorProved by
checked after 200 ms()()t_elm_core_StandardA81SleepBeyond32BitsTest
/-- tests/elm-core/src/StandardA81SleepBeyond32BitsTest.elm -/
def g_elm_core_StandardA81SleepBeyond32BitsTest : Program := {
  name := "StandardA81SleepBeyond32BitsTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Process", "Process", none⟩, ⟨"Task", "Task", none⟩],
  types := [("Msg", [("Spawned", 1), ("Checked", 1), ("Killed", 0)])],
  aliases := [],
  defs := [
    .fn "longSleep" [] (bin "|>" (ap (qv "Process" "sleep") [.atexp (.scon (.float 30 (8)))]) (ap (qv "Task" "andThen") [.atexp (.paren (lams [pw] (letDefs [.pat pw (ap (qv "Debug" "log") [str "the long sleep ended", .atexp .unit])] (ap (qv "Task" "succeed") [.atexp .unit]))))])),
    .fn "init" [pw] (tup2 (.atexp .unit) (ap (qv "Task" "perform") [c "Spawned", .atexp (.paren (ap (qv "Process" "spawn") [v "longSleep"]))])),
    .fn "update" [pv "msg", pv "model"] (caseOf (v "msg") [(pcon "Spawned" [pv "pid"], tup2 (v "model") (ap (qv "Task" "perform") [.atexp (.paren (lams [pw] (ap (c "Checked") [v "pid"]))), .atexp (.paren (ap (qv "Process" "sleep") [.atexp (.scon (.intF 200))]))])), (pcon "Checked" [pv "pid"], letDefs [.pat pw (ap (qv "Debug" "log") [str "checked after 200 ms", .atexp .unit])] (tup2 (v "model") (ap (qv "Task" "perform") [.atexp (.paren (lams [pw] (c "Killed"))), .atexp (.paren (ap (qv "Process" "kill") [v "pid"]))]))), (P (pcA "Killed"), tup2 (v "model") (qv "Cmd" "none"))]),
    .fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", lams [pw] (qv "Sub" "none"))]]) ],
  checks := [
    chk .check "checked after 200 ms: ()" .data ] }

/-- The worker test of StandardA81SleepBeyond32BitsTest. -/
def w_elm_core_StandardA81SleepBeyond32BitsTest : Prog.WorkerTest := {
  prog := g_elm_core_StandardA81SleepBeyond32BitsTest,
  flagsType := .unit,
  flags := .null,
  host := .none,
  checks := [] }

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_core_StandardA81SleepBeyond32BitsTest 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_core_StandardA81SleepBeyond32BitsTest 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_core_StandardA81SleepBeyond32BitsTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_StandardA81SleepBeyond32BitsTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.