CoreIssue1110PortDeclarationOrderTest
Checks, in A Standard Definition of Elm?:rule p-updaterule p-outrule p-in-acceptrule e-msg-port
Translated into Lean for the mechanisation of the book: see its Lean translation.
Issue: elm/core#1110
A subscription returned together with a port command is active in time to receive that command's synchronous reply. <https://github.com/elm/core/issues/1110> On `Start`, `update` returns `echoOut "hello"` and a model for which `zsubscriptions` returns `echoIn Got`. The test's host answers each `echoOut` value synchronously on `echoIn`, so `Got "hello"` should arrive. In Elm 0.19.1 the outcome depends on declaration order: with the subscriptions function named so that it sorts after `update`, the command is dispatched before the new subscription is in place and the reply is dropped.
Results
elm-0.19.1
failran in 83 msMissing pattern: got: "hello" --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
elm-0.19.2
failran in 99 msMissing pattern: got: "hello" --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
elm-0.19.3
failran in 87 msMissing pattern: got: "hello" --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
lamdera-1.5.0
failran in 74 msMissing pattern: got: "hello" --- output ---
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/CoreIssue1110PortDeclarationOrderTest] in its title.
Source
The -- CHECK: lines give the expected output.
port module CoreIssue1110PortDeclarationOrderTest exposing (main)
{-| A subscription returned together with a port command is active in time to receive that command's synchronous reply.
<https://github.com/elm/core/issues/1110>
On `Start`, `update` returns `echoOut "hello"` and a model for which `zsubscriptions` returns
`echoIn Got`. The test's host answers each `echoOut` value synchronously on `echoIn`, so `Got
"hello"` should arrive. In Elm 0.19.1 the outcome depends on declaration order: with the
subscriptions function named so that it sorts after `update`, the command is dispatched before the
new subscription is in place and the reply is dropped.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, p-update, p-out, p-in-accept, e-msg-port
-- CHECK: got: "hello"
import Process
import Task
port echoOut : String -> Cmd msg
port echoIn : (String -> msg) -> Sub msg
type Msg
= Start
| Got String
init : () -> ( Bool, Cmd Msg )
init _ =
( False, Task.perform (always Start) (Process.sleep 10) )
update : Msg -> Bool -> ( Bool, Cmd Msg )
update msg listening =
case msg of
Start ->
( True, echoOut "hello" )
Got s ->
let
_ =
Debug.log "got" s
in
( listening, Cmd.none )
zsubscriptions : Bool -> Sub Msg
zsubscriptions listening =
if listening then
echoIn Got
else
Sub.none
main : Program () Bool Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = zsubscriptions
}
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_CoreIssue1110PortDeclarationOrderTest, 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 the test runner's echo host, which sends every value delivered on echoOut back on echoIn, in order. 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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
got | "hello" | "hello" | t_elm_core_CoreIssue1110PortDeclarationOrderTest |
/-- tests/elm-core/src/CoreIssue1110PortDeclarationOrderTest.elm -/
def g_elm_core_CoreIssue1110PortDeclarationOrderTest : Program := {
name := "CoreIssue1110PortDeclarationOrderTest", source := "tests/elm-core/src",
exposing := (.items [.var "main"]), imports := [⟨"Process", "Process", none⟩, ⟨"Task", "Task", none⟩],
types := [("Msg", [("Start", 0), ("Got", 1)])],
aliases := [],
ports := [("echoOut", .out, .string), ("echoIn", .inn, .string)],
defs := [
.fn "init" [pw] (tup2 (c "False") (ap (qv "Task" "perform") [.atexp (.paren (ap (v "always") [c "Start"])), .atexp (.paren (ap (qv "Process" "sleep") [.atexp (.scon (.intF 10))]))])),
.fn "update" [pv "msg", pv "listening"] (caseOf (v "msg") [(P (pcA "Start"), tup2 (c "True") (ap (v "echoOut") [str "hello"])), (pcon "Got" [pv "s"], letDefs [.pat pw (ap (qv "Debug" "log") [str "got", v "s"])] (tup2 (v "listening") (qv "Cmd" "none")))]),
.fn "zsubscriptions" [pv "listening"] (ifte (v "listening") (ap (v "echoIn") [c "Got"]) (qv "Sub" "none")),
.fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", v "zsubscriptions")]]) ],
checks := [
chk .check "got: \"hello\"" .string ] }
/-- The worker test of CoreIssue1110PortDeclarationOrderTest. -/
def w_elm_core_CoreIssue1110PortDeclarationOrderTest : Prog.WorkerTest := {
prog := g_elm_core_CoreIssue1110PortDeclarationOrderTest,
flagsType := .unit,
flags := .null,
host := .echo "echoOut" "echoIn",
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_CoreIssue1110PortDeclarationOrderTest 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_CoreIssue1110PortDeclarationOrderTest 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_CoreIssue1110PortDeclarationOrderTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_CoreIssue1110PortDeclarationOrderTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.