Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props drilling, anonymous Interfaces, working filter, meta everywhere, etc #799

Merged
merged 28 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
20e64dc
refactor(sourcecode): node.Deps -> node.DIArgs
emil14 Dec 6, 2024
58bdfa0
fix(compiler:irgen): deps drill (passing handlers through components)
emil14 Dec 6, 2024
e7408b3
feat(std): anonymous single ports in interfaces; re-implemented filte…
emil14 Dec 6, 2024
9ae995c
feat(examples/e2e): return filter test; add explicit any to ports; pr…
emil14 Dec 6, 2024
49a03e9
fix(builder): refs to core.Meta
emil14 Dec 6, 2024
4fc2901
fix(runtime:funcs:fmt): sig -> res
emil14 Dec 6, 2024
c927c16
refactor(compiler): meta and error
emil14 Dec 6, 2024
8296745
refactor(compiler): meta, location and mod-ref, to core, update scope…
emil14 Dec 6, 2024
47555a0
refactor(irgen): get rid of compiler error
emil14 Dec 6, 2024
f60f372
fix(desugarer): upd after refactorign with core
emil14 Dec 6, 2024
2c4b42c
feat(parser): fill meta for each entity at each parsing step
emil14 Dec 6, 2024
0d1d1f9
feat(analyzer:error_handling): fill location from entity instead of s…
emil14 Dec 6, 2024
90b669d
fix(di): bump
emil14 Dec 7, 2024
d68c90f
fix(examples,e2e:interfaces): anonymous single-ports
emil14 Dec 7, 2024
b9773ee
feat(deps): nevalang/x to 0016
emil14 Dec 7, 2024
8aa1e8e
refactor(compiler): move graphReduction to IR package, move its call …
emil14 Dec 7, 2024
6383565
wip(irgen): di drilling
emil14 Dec 8, 2024
ffb7907
feat(lsp): fix bug when module found up to workspace and we see its p…
emil14 Dec 10, 2024
dcc469d
fix(cli): trim tailing / when `neva run` or `neva build` are executed
emil14 Dec 10, 2024
b40fa5b
fix(compiler): add missing path to fe result
emil14 Dec 10, 2024
2a6e792
refactor(std): port names
emil14 Dec 11, 2024
0f1be19
fix(compiler): add missing changes for port names refactoring
emil14 Dec 11, 2024
fc70d7c
wip(compiler): adding meta everywhere; feat(desugarer): reset counter…
emil14 Dec 13, 2024
bc697cf
fix(desugarer): do not reset counters, because that lead to overwriti…
emil14 Dec 15, 2024
3df29ae
fix(std:builtin): filter/split - unpack data before sending to predic…
emil14 Dec 15, 2024
adad78f
fix(desugarer): unit tests
emil14 Dec 15, 2024
330a5d2
feat(version): bump to 029 everywhere
emil14 Dec 15, 2024
ec41d5a
fix(examples,e2e): fix compile and runtime errors (analyzer doesn't c…
emil14 Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ vendor
tmp
tmp.md
todo.md
docker-compose.yml
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/e2e",
"args": ["run", "--trace", "tutorial/src"]
"cwd": "${workspaceFolder}/e2e/filter_list",
"args": ["run", "--trace", "main"]
},
{
"name": "DEBUG CODEGEN",
Expand Down
27 changes: 27 additions & 0 deletions benchmarks/simplest_message_passing/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test

import (
"os"
"os/exec"
"testing"

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

func BenchmarkMessagePassing(b *testing.B) {
err := os.Chdir("..")
require.NoError(b, err)

wd, err := os.Getwd()
require.NoError(b, err)
defer os.Chdir(wd)

b.ResetTimer()

for i := 0; i < b.N; i++ {
cmd := exec.Command("neva", "run", "message_passing")
_, err := cmd.CombinedOutput()
require.NoError(b, err)
require.Equal(b, 0, cmd.ProcessState.ExitCode())
}
}
5 changes: 5 additions & 0 deletions benchmarks/simplest_message_passing/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def Main(start any) (stop any) {
wait Wait
---
:start -> 1..1000 -> wait -> :stop
}
36 changes: 32 additions & 4 deletions cmd/lsp/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package indexer

emil14 marked this conversation as resolved.
Show resolved Hide resolved
import (
"context"
"path/filepath"
"strings"

"github.com/nevalang/neva/internal/builder"
"github.com/nevalang/neva/internal/compiler"
Expand All @@ -15,12 +17,38 @@ type Indexer struct {
analyzer analyzer.Analyzer
}

func (i Indexer) FullIndex(ctx context.Context, path string) (src.Build, *compiler.Error) {
feResult, err := i.fe.Process(ctx, path)
func (i Indexer) FullScan(
ctx context.Context,
workspacePath string,
) (src.Build, bool, *compiler.Error) {
feResult, err := i.fe.Process(ctx, workspacePath)
if err != nil {
return src.Build{}, err
return src.Build{}, false, err
}
return i.analyzer.AnalyzeBuild(feResult.ParsedBuild)

// if nevalang module is found, but it's not part of the workspace
if isParentPath(workspacePath, feResult.Path) {
return src.Build{}, false, nil
}

aBuild, err := i.analyzer.AnalyzeBuild(feResult.ParsedBuild)
if err != nil {
return src.Build{}, false, err
}

return aBuild, true, nil
}

func isParentPath(parent, child string) bool {
parent = filepath.Clean(parent)
child = filepath.Clean(child)

rel, err := filepath.Rel(parent, child)
if err != nil {
return false
}

return !strings.HasPrefix(rel, "..")
}

func New(
Expand Down
1 change: 1 addition & 0 deletions cmd/lsp/server/general_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

func (s *Server) Initialize(glspCtx *glsp.Context, params *protocol.InitializeParams) (any, error) {
s.workspacePath = *params.RootPath

return protocol.InitializeResult{
Capabilities: s.handler.CreateServerCapabilities(),
ServerInfo: &protocol.InitializeResultServerInfo{
Expand Down
21 changes: 15 additions & 6 deletions cmd/lsp/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,29 @@ type Server struct {
index *src.Build

problemsMutex *sync.Mutex
problemFiles map[string]struct{}
problemFiles map[string]struct{} // we only need to store file urls but not their problems

activeFile string
activeFileMutex *sync.Mutex
}

// indexAndNotifyProblems does full scan of the workspace
// and sends diagnostics if there are any problems
func (s *Server) indexAndNotifyProblems(notify glsp.NotifyFunc) error {
build, err := s.indexer.FullIndex(context.Background(), s.workspacePath)
build, found, proplems := s.indexer.FullScan(
context.Background(),
s.workspacePath,
)

if !found {
return nil
}

s.indexMutex.Lock()
s.index = &build
s.indexMutex.Unlock()

if err == nil {
if proplems == nil {
// clear problems
s.problemsMutex.Lock()
for uri := range s.problemFiles {
Expand All @@ -60,13 +69,13 @@ func (s *Server) indexAndNotifyProblems(notify glsp.NotifyFunc) error {

// remember problem and send diagnostic
s.problemsMutex.Lock()
uri := filepath.Join(s.workspacePath, err.Location.String())
uri := filepath.Join(s.workspacePath, proplems.Meta.Location.String())
s.problemFiles[uri] = struct{}{}
notify(
protocol.ServerTextDocumentPublishDiagnostics,
s.createDiagnostics(*err, uri),
s.createDiagnostics(*proplems, uri),
)
s.logger.Info("diagnostic sent:", "err", err)
s.logger.Info("diagnostic sent:", "err", proplems)
s.problemsMutex.Unlock()

return nil
Expand Down
2 changes: 1 addition & 1 deletion docs/book/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def Main(start any) (stop any) {
:start -> lock:sig
greeting:msg -> lock:data
lock:data -> println:data
println:sig -> :stop
println:res -> :stop
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/book/program_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ neva: 0.28.2
deps:
github.com/nevalang/x:
path: github.com/nevalang/x
version: 0.0.14
version: 0.0.16
```

The `deps` field is a map where each dependency has an alias. When adding dependencies via CLI (e.g., `neva get github.com/nevalang/x`), the package manager automatically inserts a key-value pair. Third-party dependencies must have a valid git-clone path and a fixed semver version. The package manager uses git to download the repo and looks for the corresponding git-tag. The alias typically defaults to the module's path, but custom aliases allow multiple versions of the same module:
Expand All @@ -55,7 +55,7 @@ neva: 0.28.2
deps:
github.com/nevalang/x@0-0-12:
path: github.com/nevalang/x
version: 0.0.14
version: 0.0.16
github.com/nevalang/x@0-0-11:
path: github.com/nevalang/x
version: 0.0.11
Expand All @@ -71,7 +71,7 @@ Module references uniquely identify modules in a build, used by the compiler to

```yaml
path: github.com/nevalang/x
version: 0.0.14
version: 0.0.16
```

### Entry Module
Expand Down Expand Up @@ -312,7 +312,7 @@ Third-party imports are imports of packages located in third-party modules - mod
deps:
github.com/nevalang/x:
path: github.com/nevalang/x
version: 0.0.14
version: 0.0.16
```

Then when you `import { github.com/nevalang/x }` compiler will know exactly path and version of the module you are referring to.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ When chaining nodes, we actually reference their ports implicitly. The chain cou
```neva
:start -> 'World' -> greet:data
greet:res -> println:data
println:sig -> :stop
println:res -> :stop
```

Both versions are equivalent, but the chained syntax is preferred for readability.
Expand Down
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_naive/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def Main(start any) (stop any) {
scanner2:res -> parser2:data
parser2:res -> add:right
add:res -> println:data
println:sig -> :stop
println:res -> :stop
[parser1:err, parser2:err] -> panic
}
6 changes: 3 additions & 3 deletions e2e/add_nums_from_stdin_with_default_any/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ def Main(start any) (stop any) {
---
:start -> aux:sig
[aux:res, aux:err] -> println:data
println:sig -> :stop
println:res -> :stop
}

def Aux(sig) (res int, err error) {
def Aux(sig any) (res int, err error) {
reader1 IntReader
reader2 IntReader
add Add<int>
Expand All @@ -23,7 +23,7 @@ def Aux(sig) (res int, err error) {
def IntReader(sig any) (num int, err error) {
fmt.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
:sig -> scanln:res
scanln:res -> parseNum:data
parseNum:res -> :num
parseNum:err -> :err
Expand Down
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_with_err_handling/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def Main(start any) (stop any) {
parser1:res -> [add:left, scanner2:sig]
scanner2:res -> parser2:data
parser2:res -> add:right
println:sig -> :stop
println:res -> :stop
[parser1:err, parser2:err, add:res] -> println:data
}
6 changes: 3 additions & 3 deletions e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ def Main(start any) (stop any) {
---
:start -> aux:sig
[aux:res, aux:err] -> println:data
println:sig -> :stop
println:res -> :stop
}

def Aux(sig) (res int, err error) {
def Aux(sig any) (res int, err error) {
reader1 IntReader
reader2 IntReader
add Add<int>
Expand All @@ -23,7 +23,7 @@ def Aux(sig) (res int, err error) {
def IntReader(sig any) (num int, err error) {
fmt.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
:sig -> scanln:res
scanln:res -> parseNum:data
parseNum:res -> :num
parseNum:err -> :err
Expand Down
4 changes: 2 additions & 2 deletions e2e/add_nums_from_stdin_with_sub_components/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def Main(start any) (stop any) {
---
:start -> aux:sig
[aux:res, aux:err] -> println:data
println:sig -> :stop
println:res -> :stop
}

def Aux(sig any) (res int, err error) {
Expand All @@ -23,7 +23,7 @@ def Aux(sig any) (res int, err error) {
def IntReader(sig any) (num int, err error) {
fmt.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
:sig -> scanln:res
scanln:res -> parseNum:data
parseNum:res -> :num
parseNum:err -> :err
Expand Down
2 changes: 1 addition & 1 deletion e2e/add_nums_verbose/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def Main(start any) (stop any) {
2 -> adder:right
]
adder:res -> println:data
println:sig -> :stop
println:res -> :stop
}
2 changes: 1 addition & 1 deletion e2e/comments/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def Main(start any) (stop any) {
---
// comment inside def 2
:start -> println:data
println:sig -> :stop
println:res -> :stop
// comment inside def 3
}
// top-level comment 2
2 changes: 1 addition & 1 deletion e2e/const_refs_verbose/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def Main(start any) (stop any) {
fmt.Println
---
:start -> $numsStruct -> println:data
println:sig -> :stop
println:res -> :stop
}
2 changes: 1 addition & 1 deletion e2e/duplicate_receiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test(t *testing.T) {
require.Contains(
t,
string(out),
"main/main.neva:7:1: port 'println:sig' is used twice\n",
"main/main.neva:7:1: port 'println:res' is used twice\n",
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
Expand Down
2 changes: 1 addition & 1 deletion e2e/duplicate_sender/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ def Main(start any) (stop any) {
---
:start -> println
:start -> panic
println:sig -> :stop
println:res -> :stop
}
4 changes: 2 additions & 2 deletions e2e/echo_verbose/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def Main(start any) (stop any) {
fmt.Scanln
fmt.Println<string>
---
:start -> scanln:sig
:start -> scanln:res
scanln:res -> println:data
println:sig -> :stop
println:res -> :stop
}
4 changes: 2 additions & 2 deletions e2e/enums_verbose/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type Day enum {
Sunday
}

def DayPrinter(day Day) (sig) {
def DayPrinter(day Day) (sig any) {
fmt.Println
---
:day -> println:data
println:sig -> :sig
println:res -> :sig
}
2 changes: 1 addition & 1 deletion e2e/hello_world_verbose/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def Main(start any) (stop any) {
:start -> lock:sig
greeting:msg -> lock:data
lock:data -> println:data
println:sig -> :stop
println:res -> :stop
}
2 changes: 1 addition & 1 deletion e2e/hello_world_with_const_sender/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def Main(start any) (stop any) {
:start -> lock:sig
$greeting -> lock:data
lock:data -> println:data
println:sig -> :stop
println:res -> :stop
}
2 changes: 1 addition & 1 deletion e2e/hello_world_with_implicit_any/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ def Main(start any) (stop any) {
fmt.Println<any>
---
:start -> 'Hello, World!' -> println:data
println:sig -> :stop
println:res -> :stop
}
2 changes: 1 addition & 1 deletion e2e/hello_world_with_literal_sender/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ def Main(start any) (stop any) {
println fmt.Println<string>
---
:start -> 'Hello, World!' -> println:data
println:sig -> :stop
println:res -> :stop
}
2 changes: 1 addition & 1 deletion e2e/hello_world_with_then_connection/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ def Main(start any) (stop any) {
println fmt.Println<string>
---
:start -> $greeting -> println:data
println:sig -> :stop
println:res -> :stop
}
Loading
Loading