nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

Inconsistent output inside `For` with branching #635

Closed emil14 closed 1 month ago

emil14 commented 1 month ago

Output isn't consistent

component Main(start) (stop) {
    nodes { For{Printer}, Range }
    :start -> [(1 -> range:from), (11 -> range:to)]
    range -> for -> :stop
}

component Printer(data int) (sig any) {
    nodes { Even, PrintTwice, If }
    :data -> even -> if
    if:then -> ('is even' -> printTwice)
    if:else -> ('is odd' -> printTwice)
    printTwice -> :sig
}

component Even(data int) (res bool) {
    nodes { Mod }
    :data -> mod:data
    2 -> mod:case[0] -> (true -> :res)
    mod:else -> (false -> :res)
}

component PrintTwice(data string) (sig any) {
    nodes { p1 Println, p2 Println }
    :data -> p1 -> p2 -> :sig
}

Related to #575

emil14 commented 1 month ago

Here's e2e

package test

import (
    "os/exec"
    "testing"

    "github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
    cmd := exec.Command("neva", "run", "main")

    out, err := cmd.CombinedOutput()
    require.NoError(t, err)

    require.Equal(
        t,
        `is odd
is odd
is even
is even
is odd
is odd
is even
is even
is odd
is odd
is even
is even
is odd
is odd
is even
is even
is odd
is odd
is even
is even
`,
        string(out),
    )

    require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
Catya3 commented 1 month ago

printSlow version will also trigger the bug

component PrintSlow(data string) (sig any) {
    nodes { p1 Println, time.Sleep }
    200000000 -> sleep:dur // 200 ms
    :data -> p1 -> sleep:data -> :sig
}
Catya3 commented 1 month ago

Just to be pedantic, #575 is about early termination whereas this one is about items printed out of order. Is that a correct interpretation?

emil14 commented 1 month ago

@Catya3 yeah, don't sure if they are related

unpredictable termination was because of branching, basically data-race

this one also looks like some kind of race

Catya3 commented 1 month ago

It looks like For actually fixes the unpredictable termination and now we have items executed out of order. Not sure what causes it

emil14 commented 1 month ago

Yeah I think the same. I just wanna keep 575 opened until we fix this one, just to be sure

emil14 commented 1 month ago

Closed in favor of #644