Skip to content

Commit

Permalink
Merge pull request #670 from nevalang/runtime_raceless_queue
Browse files Browse the repository at this point in the history
Race condition fix. Part 2 (Runtime)
  • Loading branch information
emil14 authored Jul 1, 2024
2 parents a544152 + 70c2039 commit a298081
Show file tree
Hide file tree
Showing 138 changed files with 2,209 additions and 2,233 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}",
"args": ["run", "examples/swork"]
"args": ["run", "-debug", "e2e/99_bottles_verbose/main"]
},
{
"name": "LSP",
Expand Down
8 changes: 4 additions & 4 deletions cmd/lsp/server/get_file_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ func (s *Server) GetFileView(glspCtx *glsp.Context, req GetFileViewRequest) (Get
func getExtraForFile(file src.File, scope src.Scope) (map[string]map[string]src.Interface, error) {
extra := map[string]map[string]src.Interface{}
for entityName, entity := range file.Entities {
if entity.Kind != src.FlowEntity {
if entity.Kind != src.ComponentEntity {
continue
}

nodesIfaces := map[string]src.Interface{}
for nodeName, node := range entity.Flow.Nodes {
for nodeName, node := range entity.Component.Nodes {
nodeEntity, _, err := scope.Entity(node.EntityRef)
if err != nil {
return nil, err
}

var iface src.Interface
if nodeEntity.Kind == src.FlowEntity {
iface = nodeEntity.Flow.Interface
if nodeEntity.Kind == src.ComponentEntity {
iface = nodeEntity.Component.Interface
} else if nodeEntity.Kind == src.InterfaceEntity {
iface = nodeEntity.Interface
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/99_bottles_verbose/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ flow PrintFirstLine(n int) (n int) {
match:else -> printf:args[0]
$firstLine1 -> printf:tpl

[println:sig, printf:args[0]] -> lock:sig
[println:sig, printf:sig] -> lock:sig

lock:data -> :n
}
Expand All @@ -69,6 +69,6 @@ flow PrintSecondLine(n int) (n int) {
match:else -> printf:args[0]
$secondLine1 -> printf:tpl

[println:sig, printf:args[0]] -> lock:sig
[println:sig, printf:sig] -> lock:sig
lock:data -> :n
}
4 changes: 2 additions & 2 deletions e2e/99_bottles_with_chain/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ flow PrintFirstLine(n int) (n int) {
($firstLine1 -> printf:tpl)
]

[println:sig, printf:args[0]] -> lock:sig
[println:sig, printf:sig] -> lock:sig
lock:data -> :n
}

Expand All @@ -60,6 +60,6 @@ flow PrintSecondLine(n int) (n int) {
($secondLine1 -> printf:tpl)
]

[println:sig, printf:args[0]] -> lock:sig
[println:sig, printf:sig] -> lock:sig
lock:data -> :n
}
2 changes: 1 addition & 1 deletion e2e/cli_new/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.23.0
neva: 0.25.0
6 changes: 3 additions & 3 deletions e2e/compare_ints_lt_equal/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
flow Main(start) (stop) {
nodes { Println, Lt<int>}
nodes { Println, Lt<int> }
:start -> [
(20 -> lt:compared),
(20 -> lt:actual)
]
lt:res -> println -> :stop
]
lt:res -> println -> :stop
}
11 changes: 5 additions & 6 deletions e2e/compare_strings/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
flow Main(start) (stop) {
nodes { Println, Gt<string>,If}
nodes { Println, Gt<string>, If }
:start -> [
('A' -> gt:compared),
('Z' -> gt:actual)
]
gt:res -> if

if:then -> ('Actual is greater' -> println -> :stop)
if:else -> ('Actual is lower' -> println -> :stop)
]
gt:res -> if
if:then -> ('Actual is greater' -> println -> :stop)
if:else -> ('Actual is lower' -> println -> :stop)
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flow Main(start) (stop) {
:start -> :stop
}
}
File renamed without changes.
3 changes: 1 addition & 2 deletions e2e/for_with_range_and_if/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ flow Main(start) (stop) {
flow Printer(data bool) (sig any) {
nodes { If, Println }
:data -> if
if:then -> ('true' -> println)
if:else -> ('false' -> println)
[if:then, if:else] -> println
println -> :sig
}
4 changes: 2 additions & 2 deletions e2e/logic_gate_and/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
flow Main(start) (stop) {
nodes { Println, And }
:start -> [
(true -> and:A),
(true -> and:B)
(true -> and:a),
(true -> and:b)
]
and -> println -> :stop
}
4 changes: 2 additions & 2 deletions e2e/logic_gate_or/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
flow Main(start) (stop) {
nodes { Println, Or }
:start -> [
(false -> or:A),
(false -> or:B)
(false -> or:a),
(false -> or:b)
]
or -> println -> :stop
}
22 changes: 22 additions & 0 deletions e2e/simple_fan_out/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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,
"<empty>\n<empty>\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
7 changes: 7 additions & 0 deletions e2e/simple_fan_out/main/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { time }

flow Main(start) (stop) {
nodes { p1 Println, p2 Println }
:start -> [p1, p2]
p1 -> (p2 -> :stop)
}
1 change: 1 addition & 0 deletions e2e/simple_fan_out/neva.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neva: 0.10.0
5 changes: 3 additions & 2 deletions examples/99_bottles/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ flow PrintFirstLine(n int) (n int) {
($firstLine1 -> printf:tpl)
]

[println, printf:args[0]] -> lock:sig
[println:sig, printf:sig] -> lock:sig
lock -> :n
}

Expand All @@ -55,6 +55,7 @@ flow PrintSecondLine(n int) (n int) {
($secondLine1 -> printf:tpl)
]

[println, printf:args[0]] -> lock:sig
[println:sig, printf:sig] -> lock:sig

lock:data -> :n
}
2 changes: 1 addition & 1 deletion examples/add_numbers/main.neva
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
flow Main(start) (stop) {
nodes {
add ReducePort<int> { Add<int> }
Println
add ReducePort<int> { Add<int> }
}
:start -> [
(1 -> add[0]),
Expand Down
32 changes: 11 additions & 21 deletions examples/fizzbuzz/main.neva
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
flow Main(start) (stop) {
nodes { Range, PrintLine, Match }

:start -> [
(1 -> range:from),
(101 -> range:to)
]
range.data -> printLine -> match:data
100 -> match:case[0] -> :stop
nodes { Range, Map<int, string>{FizzBuzz}, For{Println} }
:start -> [(1 -> range:from), (101 -> range:to)]
range -> map -> for -> :stop
}

flow PrintLine(data int) (data int) {
nodes { mod CaseMod, Println, Lock<int> }

:data -> [mod:data, lock:data]

15 -> mod:case[0] -> ('FizzBuzz' -> println)
3 -> mod:case[1] -> ('Fizz' -> println)
5 -> mod:case[2] -> ('Buzz' -> println)
mod:else -> println

println -> lock:sig
lock:data -> :data
}
flow FizzBuzz(data int) (res any) {
nodes { CaseMod }
:data -> caseMod:data
15 -> caseMod:case[0] -> ('FizzBuzz' -> :res)
3 -> caseMod:case[1] -> ('Fizz' -> :res)
5 -> caseMod:case[2] -> ('Buzz' -> :res)
caseMod:else -> :res
}
2 changes: 1 addition & 1 deletion examples/get_args/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { os, lists }

flow Main(start) (stop) {
nodes { os.Args, lists.For{Println}}
:start -> (args -> for -> :stop)
:start -> args -> for -> :stop
}
2 changes: 1 addition & 1 deletion examples/hello_world/main.neva
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flow Main(start) (stop) {
nodes { Println }
:start -> ('Hello, World!' -> println -> :stop)
}
}
10 changes: 6 additions & 4 deletions examples/stream_product/main.neva
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
flow Main(start) (stop) {
nodes {
r1 Range,
r2 Range,
Product<int, int>,
For<ProductRes<int, int>>{Println<ProductRes<int, int>>}
r1 Range
r2 Range
Product<int, int>
For<ProductResult<int, int>> {
Println<ProductResult<int, int>>
}
}
:start -> [
(0 -> [r1:from, r2:from]),
Expand Down
28 changes: 7 additions & 21 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,8 @@ func NewApp(
if err != nil {
return err
}
intr := interpreter.New(bldr, goc, debug)
if err := intr.Interpret(
context.Background(),
workdir,
dirFromArg,
); err != nil {
intr := interpreter.New(bldr, goc)
if err := intr.Interpret(context.Background(), dirFromArg, debug); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -148,25 +144,15 @@ func NewApp(
}
switch target {
case "go":
return goc.Compile(
workdir, dirFromArg, workdir,
)
return goc.Compile(dirFromArg, workdir, debug)
case "wasm":
return wasmc.Compile(
workdir, dirFromArg, workdir,
)
return wasmc.Compile(dirFromArg, workdir, debug)
case "json":
return jsonc.Compile(
workdir, dirFromArg, workdir,
)
return jsonc.Compile(dirFromArg, workdir, debug)
case "dot":
return dotc.Compile(
workdir, dirFromArg, workdir,
)
return dotc.Compile(dirFromArg, workdir, debug)
default:
return nativec.Compile(
workdir, dirFromArg, workdir,
)
return nativec.Compile(dirFromArg, workdir, debug)
}
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/compiler/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ func (a Analyzer) analyzeEntity(entity src.Entity, scope src.Scope) (src.Entity,
}.Wrap(err)
}
resolvedEntity.Interface = resolvedInterface
case src.FlowEntity:
analyzedFlow, err := a.analyzeFlow(entity.Flow, scope)
case src.ComponentEntity:
analyzedComponent, err := a.analyzeComponent(entity.Component, scope)
if err != nil {
return src.Entity{}, compiler.Error{
Location: &scope.Location,
Meta: &entity.Flow.Meta,
Meta: &entity.Component.Meta,
}.Wrap(err)
}
resolvedEntity.Flow = analyzedFlow
resolvedEntity.Component = analyzedComponent
default:
return src.Entity{}, &compiler.Error{
Err: fmt.Errorf("%w: %v", ErrUnknownEntityKind, entity.Kind),
Expand Down
Loading

0 comments on commit a298081

Please sign in to comment.