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

feat(compiler): CRDT-maps implementation #1142

Merged
merged 91 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
7fbb552
WIP
DieMyst May 15, 2024
2aa40ff
use more MutableStreamType instead of StreamType, fix arrow inlining
DieMyst May 20, 2024
ec6cbf4
add `get` function inliner, WIP
DieMyst May 22, 2024
e7945f8
fix return type for `get`, add integration test
DieMyst May 22, 2024
1ca49ec
Merge remote-tracking branch 'origin/main' into stream-maps-implement…
DieMyst May 22, 2024
f3b1c07
fix type
DieMyst May 22, 2024
5d3f029
fix compilation
DieMyst May 22, 2024
fdde502
change `get` strategy
DieMyst May 22, 2024
8f571ef
use var for idx
DieMyst May 22, 2024
9c1e4d6
extend test
DieMyst May 23, 2024
e913982
fix compilation
DieMyst May 23, 2024
1c5d4c6
`getStream` func implementation and test
DieMyst May 23, 2024
90cae35
fix test
DieMyst May 23, 2024
331d199
fix test
DieMyst May 23, 2024
be1aa5e
keys implementation and test
DieMyst May 23, 2024
6b46780
fix test
DieMyst May 23, 2024
bca70e4
contains func implementation
DieMyst May 27, 2024
b728af5
fold over map and tests
DieMyst May 28, 2024
b6cc9a5
fix compilation
DieMyst May 28, 2024
fb2f1a8
change canon "#" to "#$"
DieMyst May 28, 2024
f00ea6e
are values not arrays?
DieMyst May 28, 2024
7ff3f57
fix compilation
DieMyst May 28, 2024
a2d8394
fix test value
DieMyst May 28, 2024
0273a5d
fix value test
DieMyst May 28, 2024
c3b2c01
refactoring
DieMyst May 28, 2024
e6ab134
keysStream implementation
DieMyst May 29, 2024
3bb8b79
Merge branch 'main' into stream-maps-implementation
DieMyst May 29, 2024
4c73704
fix unit tests
DieMyst May 29, 2024
9c5e241
refactoring
DieMyst May 29, 2024
4be3156
parsing stream map unit test
DieMyst May 29, 2024
2c2caa4
error on exporting function that returns or accepts stream map
DieMyst May 29, 2024
5b40397
add comments
DieMyst May 29, 2024
80e9f69
parseq test
DieMyst May 30, 2024
77f63c7
fix compilation
DieMyst May 30, 2024
ddf6f61
parseq for map test
DieMyst May 30, 2024
925bcfa
fix compilation
DieMyst May 30, 2024
6ccfe7b
fix compilation
DieMyst May 30, 2024
4c8eefe
Update integration-tests/src/__test__/examples.spec.ts
DieMyst May 30, 2024
ba9fa6e
fix PR
DieMyst May 30, 2024
dd3661b
for and parseq with tuples
DieMyst May 30, 2024
421452a
fix
DieMyst May 30, 2024
5436e9f
fix compilation
DieMyst May 30, 2024
17eafe2
fix
DieMyst May 30, 2024
0854adc
canon map before for
DieMyst May 30, 2024
e95ff0d
fix unit tests
DieMyst May 30, 2024
06ec9be
fix unit test
DieMyst May 30, 2024
3a9aec6
fix unit tests
DieMyst May 30, 2024
bf12d9b
fix
DieMyst May 30, 2024
6b1d105
println
DieMyst May 30, 2024
b1e0e96
println
DieMyst May 30, 2024
84f6b91
fix
DieMyst May 30, 2024
292ad58
let -> const
DieMyst May 31, 2024
a4195a4
PR fixes
DieMyst May 31, 2024
97ecb13
fix
DieMyst May 31, 2024
1e30e6f
fix test
DieMyst May 31, 2024
ea034dc
use canon stream instead of array
DieMyst May 31, 2024
5fa5e61
try to fix
DieMyst May 31, 2024
3313802
try to fix
DieMyst May 31, 2024
fc6dd43
use scalar in `keys` func
DieMyst May 31, 2024
ce63777
return to canonstreammap
DieMyst May 31, 2024
d5f1752
add comment
DieMyst May 31, 2024
21fc97c
Update types/src/main/scala/aqua/types/Type.scala
DieMyst Jun 3, 2024
d3cc038
Update types/src/main/scala/aqua/types/Type.scala
DieMyst Jun 3, 2024
28a4858
PR fixes
DieMyst Jun 3, 2024
3953bf0
PR fixes
DieMyst Jun 3, 2024
4eb1a60
Merge branch 'main' into stream-maps-implementation
DieMyst Jun 3, 2024
e314f06
Update model/inline/src/main/scala/aqua/model/inline/tag/ForTagInline…
DieMyst Jun 3, 2024
2f55f72
Update semantics/src/main/scala/aqua/semantics/expr/func/ForSem.scala
DieMyst Jun 3, 2024
7642198
Merge branch 'main' into stream-maps-implementation
DieMyst Jun 3, 2024
971fc15
fix compilation
DieMyst Jun 3, 2024
40dba48
PR fixes
DieMyst Jun 4, 2024
0cd02f1
try without flattens
DieMyst Jun 4, 2024
fbd2d49
fix compilation
DieMyst Jun 4, 2024
5f73ac6
revert flatten, add test
DieMyst Jun 4, 2024
a4f890f
fix compilation, flat indexes for IntoIndexModel
DieMyst Jun 4, 2024
ba26e35
fix test
DieMyst Jun 4, 2024
a4ae5f7
add comment
DieMyst Jun 4, 2024
111a2a0
semantic error on using `<-` with maps
DieMyst Jun 4, 2024
1c0992f
don't use braces
DieMyst Jun 5, 2024
05b9d73
fix parsing, unskip old test
DieMyst Jun 5, 2024
9088610
add capture tests for stream map, fix unit tests for parser
DieMyst Jun 5, 2024
100473a
restrictions test
DieMyst Jun 5, 2024
2fb193e
fix compilation
DieMyst Jun 5, 2024
701fe54
fix compilation
DieMyst Jun 5, 2024
3b5b392
check if map on the left when pushing tuple
DieMyst Jun 5, 2024
2ffeff8
test streams and maps in abilities
DieMyst Jun 5, 2024
aae9be0
fix ts compilation
DieMyst Jun 5, 2024
5eb29f1
skip test
DieMyst Jun 5, 2024
27b199b
fix tests
DieMyst Jun 5, 2024
ecff7d6
change to `intoField`
DieMyst Jun 5, 2024
0801091
refactoring
DieMyst Jun 6, 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
132 changes: 125 additions & 7 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
@@ -1,10 +1,128 @@
aqua Job declares *
aqua StreamMapTest declares *

use "declare"
export testGetFunc, testGetStreamFunc, testKeysFunc, testKeysStreamFunc
export testContainsFunc, testForFunc, testParSeqMap, testForTupleFunc

export timeout
import "builtin.aqua"

func timeout() -> AquaName.Worker:
w <- AquaName.getWorker()
a = w.host_id
<- w
func testGetFunc() -> []string, []string, []string, u32:
streamMap: %string
key = "key"
resEmpty = streamMap.get(key)
streamMap <<- key, "first value"
resFirst = streamMap.get(key)
streamMap <<- key, "second value"
resSecond = streamMap.get(key)
<- resEmpty, resFirst, resSecond, resSecond.length

func testGetStreamFunc() -> []string, string, string:
streamMap: %string
key = "key"
resEmptyStream = streamMap.getStream(key)
streamMap <<- key, "first value"
resFirstStream = streamMap.getStream(key)
streamMap <<- key, "second value"
resSecondStream = streamMap.getStream(key)
resFirst = resFirstStream[0]
resSecond = resSecondStream[1]
<- resEmptyStream, resFirst, resSecond

func testKeysFunc() -> []string, []string, []string:
streamMap: %string
resEmpty = streamMap.keys()
streamMap <<- "key one", ""
resFirst = streamMap.keys()
streamMap <<- "key two", ""
streamMap <<- "key one", ""
streamMap <<- "key one", "text"
resSecond = streamMap.keys()
<- resEmpty, resFirst, resSecond

func testKeysStreamFunc() -> []string, []string, []string:
streamMap: %string
resEmpty = streamMap.keysStream()
streamMap <<- "key one", ""
resFirst = streamMap.keysStream()
streamMap <<- "key one", "new"
streamMap <<- "key two", ""
resSecond = streamMap.keysStream()
<- resEmpty, resFirst, resSecond

func testContainsFunc() -> bool, bool, bool, bool, bool:
keys = ["key one", "key two"]
streamMap: %string
resFirst = streamMap.contains(keys[0])
streamMap <<- keys[0], ""
resSecond = streamMap.contains(keys[0])
resThird = streamMap.contains(keys[1])
streamMap <<- keys[0], "new"
streamMap <<- keys[1], ""
resFourth = streamMap.contains(keys[0])
resFifth = streamMap.contains(keys[1])
<- resFirst, resSecond, resThird, resFourth, resFifth

func testForFunc() -> []string, []string:
streamMap: %string
streamMap <<- "key one", "1"
streamMap <<- "key one", "2"

streamMap <<- "key two", "3"
streamMap <<- "key two", "4"
streamMap <<- "key two", "5"

streamMap <<- "key three", "6"

streamMap <<- "key four", "7"

streamKeys: *string
streamValues: *string

for kv <- streamMap:
streamKeys <<- kv.key
streamValues <<- kv.value
<- streamKeys, streamValues

func testParSeqMap(relay1: string, relay2: string, relay3: string) -> string:
relays = [relay1, relay2, relay3]
map: %u64
map2: %u64
parseq r <- relays on r:
map <<- "time", Peer.timestamp_ms()

for r <- relays par:
on r:
join map.get("time")[relays.length - 1]
map2 <<- "time", Peer.timestamp_ms()

join map2.get("time")[relays.length - 1]
<- "ok"

func testForTupleFunc() -> []string, []string, []string:
streamMap: %string
streamMap <<- "key one", "1"
streamMap <<- "key one", "2"

streamMap <<- "key two", "3"
streamMap <<- "key two", "4"
streamMap <<- "key two", "5"

streamMap <<- "key three", "6"

streamMap <<- "key four", "7"

streamFirst: *string
streamSecond: *string
streamThird: *string

for k, v <- streamMap:
streamFirst <<- k
streamSecond <<- v

for k, v <- streamMap:
streamFirst <<- v
streamSecond <<- k

for k, v <- streamMap:
streamThird <<- streamMap.get(k)!

<- streamFirst, streamSecond, streamThird
2 changes: 2 additions & 0 deletions aqua-src/builtin.aqua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
aqua Builtin declares *

-- Default public interface of Fluence nodes

alias Field : []string
Expand Down
5 changes: 3 additions & 2 deletions backend/air/src/main/scala/aqua/backend/air/AirGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package aqua.backend.air
import aqua.model.*
import aqua.raw.ops.Call
import aqua.res.*
import aqua.types.{ArrayType, CanonStreamType, StreamMapType, StreamType, Type}
import aqua.types.{ArrayType, CanonStreamMapType, CanonStreamType, StreamMapType, StreamType, Type}
import cats.Eval
import cats.data.Chain
import cats.free.Cofree
Expand All @@ -29,7 +29,8 @@ object AirGen extends Logging {
def varNameToString(name: String, `type`: Type): String =
(`type` match {
case _: StreamType => "$" + name
case _: CanonStreamType => "#" + name
case _: CanonStreamType => "#$" + name
case _: CanonStreamMapType => "#%" + name
case _: StreamMapType => "%" + name
case _ => name
}).replace('.', '_')
Expand Down
24 changes: 7 additions & 17 deletions integration-tests/aqua/examples/parseq.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@ export testParSeq

import "@fluencelabs/aqua-lib/builtin.aqua"

service NumOp("op"):
identity(n: u64) -> u64

data PeerRelay:
peer: string
relay: string

func testParSeq(peer1: string, peer2: string, peer3: string, relay1: string, relay2: string, relay3: string) -> string:
pr1 = PeerRelay(peer = peer1, relay = relay1)
pr2 = PeerRelay(peer = peer2, relay = relay2)
pr3 = PeerRelay(peer = peer3, relay = relay3)
peers = [pr1, pr2, pr3]
func testParSeq(relay1: string, relay2: string, relay3: string) -> string:
relays = [relay1, relay2, relay3]
stream: *u64
stream2: *u64
parseq p <- peers on p.peer via p.relay:
parseq r <- relays on r:
stream <- Peer.timestamp_ms()

for p <- peers par:
on p.peer via p.relay:
join stream[peers.length - 1]
for r <- relays par:
on r:
join stream[relays.length - 1]
stream2 <<- Peer.timestamp_ms()

join stream2[peers.length - 1]
join stream2[relays.length - 1]
<- "ok"
130 changes: 130 additions & 0 deletions integration-tests/aqua/examples/streamMap.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
aqua StreamMapTest declares *

export testGetFunc, testGetStreamFunc, testKeysFunc, testKeysStreamFunc
export testContainsFunc, testForFunc, testParSeqMap, testForTupleFunc

import "@fluencelabs/aqua-lib/builtin.aqua"

func testGetFunc() -> []string, []string, []string, u32:
streamMap: %string
key = "key"
resEmpty = streamMap.get(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: <- seems more canonical for function call

streamMap <<- key, "first value"
resFirst = streamMap.get(key)
streamMap <<- key, "second value"
resSecond = streamMap.get(key)
<- resEmpty, resFirst, resSecond, resSecond.length

func testGetStreamFunc() -> []string, string, string:
streamMap: %string
key = "key"
resEmptyStream = streamMap.getStream(key)
streamMap <<- key, "first value"
resFirstStream = streamMap.getStream(key)
streamMap <<- key, "second value"
resSecondStream = streamMap.getStream(key)
resFirst = resFirstStream[0]
resSecond = resSecondStream[1]
<- resEmptyStream, resFirst, resSecond

func testKeysFunc() -> []string, []string, []string:
streamMap: %string
resEmpty = streamMap.keys()
streamMap <<- "key one", ""
resFirst = streamMap.keys()
streamMap <<- "key two", ""
streamMap <<- "key one", ""
streamMap <<- "key one", "text"
resSecond = streamMap.keys()
<- resEmpty, resFirst, resSecond

func testKeysStreamFunc() -> []string, []string, []string:
streamMap: %string
resEmpty = streamMap.keysStream()
streamMap <<- "key one", ""
resFirst = streamMap.keysStream()
streamMap <<- "key one", "new"
streamMap <<- "key two", ""
resSecond = streamMap.keysStream()
join resFirst[0]
join resSecond[2]
<- resEmpty, resFirst, resSecond
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we join on result streams?


func testContainsFunc() -> bool, bool, bool, bool, bool:
keys = ["key one", "key two"]
streamMap: %string
resFirst = streamMap.contains(keys[0])
streamMap <<- keys[0], ""
resSecond = streamMap.contains(keys[0])
resThird = streamMap.contains(keys[1])
streamMap <<- keys[0], "new"
streamMap <<- keys[1], ""
resFourth = streamMap.contains(keys[0])
resFifth = streamMap.contains(keys[1])
<- resFirst, resSecond, resThird, resFourth, resFifth

func testForFunc() -> []string, []string:
streamMap: %string
streamMap <<- "key one", "1"
streamMap <<- "key one", "2"

streamMap <<- "key two", "3"
streamMap <<- "key two", "4"
streamMap <<- "key two", "5"

streamMap <<- "key three", "6"

streamMap <<- "key four", "7"

streamKeys: *string
streamValues: *string

for kv <- streamMap:
streamKeys <<- kv.key
streamValues <<- kv.value
<- streamKeys, streamValues

func testParSeqMap(relay1: string, relay2: string, relay3: string) -> string:
relays = [relay1, relay2, relay3]
map: %u64
map2: %u64
parseq r <- relays on r:
map <<- "time", Peer.timestamp_ms()

for r <- relays par:
on r:
join map.getStream("time")[relays.length - 1]
map2 <<- "time", Peer.timestamp_ms()

join map2.getStream("time")[relays.length - 1]
<- "ok"

func testForTupleFunc() -> []string, []string, []string:
streamMap: %string
streamMap <<- "key one", "1"
streamMap <<- "key one", "2"

streamMap <<- "key two", "3"
streamMap <<- "key two", "4"
streamMap <<- "key two", "5"

streamMap <<- "key three", "6"

streamMap <<- "key four", "7"

streamFirst: *string
streamSecond: *string
streamThird: *string

for k, v <- streamMap:
streamFirst <<- k
streamSecond <<- v

for k, v <- streamMap:
streamFirst <<- v
streamSecond <<- k

for k, v <- streamMap:
streamThird <<- streamMap.get(k)!

<- streamFirst, streamSecond, streamThird
41 changes: 41 additions & 0 deletions integration-tests/aqua/examples/streamMapAbilities.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
aqua StreamMapAbilities

export streamMapAbilityTest

ability Streams:
stream: *string
map: %string

ability Adds:
addToStream(s: string)
addToMap(k: string, v: string)

func addToStreamClosure(str: *string) -> string -> ():
cl = func (s: string):
str <<- s
<- cl

func addToMapClosure(str: %string) -> string, string -> ():
cl = func (k: string, v: string):
str <<- k, v
<- cl

func addTo{Streams}() -> Adds:
addStream = addToStreamClosure(Streams.stream)
addMap = addToMapClosure(Streams.map)
adds = Adds(addToStream = addStream, addToMap = addMap)
<- adds

func add{Adds}(s: string, k: string):
Adds.addToStream(s)
Adds.addToMap(k, k)

func streamMapAbilityTest() -> []string, []string:
stream: *string
map: %string
ab = Streams(stream = stream, map = map)
adds <- addTo{ab}()
add{adds}("one", "1")
add{adds}("two", "2")
add{adds}("three", "3")
<- stream, map.keys()
Loading
Loading