nevalang/neva

Inconsistent output inside `For` with branching

emil14 opened this issue · 7 comments

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

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())
}

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
}

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

@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

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

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

Closed in favor of #644