mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
fix(compiler): Handle errors from result handling [fixes LNG-247] (#913)
Move args and return under try
This commit is contained in:
parent
a80033b81c
commit
f158074c4e
@ -159,10 +159,10 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers {
|
|||||||
val retVar = VarModel("ret", ScalarType.string)
|
val retVar = VarModel("ret", ScalarType.string)
|
||||||
|
|
||||||
val expected =
|
val expected =
|
||||||
SeqRes.wrap(
|
XorRes.wrap(
|
||||||
getDataSrv("-relay-", "-relay-", ScalarType.string),
|
SeqRes.wrap(
|
||||||
getDataSrv("peers", peers.name, peers.`type`),
|
getDataSrv("-relay-", "-relay-", ScalarType.string),
|
||||||
XorRes.wrap(
|
getDataSrv("peers", peers.name, peers.`type`),
|
||||||
RestrictionRes(results.name, resultsType).wrap(
|
RestrictionRes(results.name, resultsType).wrap(
|
||||||
SeqRes.wrap(
|
SeqRes.wrap(
|
||||||
ParRes.wrap(
|
ParRes.wrap(
|
||||||
@ -203,9 +203,9 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers {
|
|||||||
).leaf
|
).leaf
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
errorCall(transformCfg, 0, initPeer)
|
respCall(transformCfg, flatResult, initPeer)
|
||||||
),
|
),
|
||||||
respCall(transformCfg, flatResult, initPeer)
|
errorCall(transformCfg, 0, initPeer)
|
||||||
)
|
)
|
||||||
|
|
||||||
exec.body.equalsOrShowDiff(expected) shouldBe (true)
|
exec.body.equalsOrShowDiff(expected) shouldBe (true)
|
||||||
@ -276,8 +276,8 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers {
|
|||||||
val resCanonVM = VarModel("-res-fix-0", CanonStreamType(ScalarType.string))
|
val resCanonVM = VarModel("-res-fix-0", CanonStreamType(ScalarType.string))
|
||||||
val resFlatVM = VarModel("-res-flat-0", ArrayType(ScalarType.string))
|
val resFlatVM = VarModel("-res-flat-0", ArrayType(ScalarType.string))
|
||||||
|
|
||||||
val expected = SeqRes.wrap(
|
val expected = XorRes.wrap(
|
||||||
XorRes.wrap(
|
SeqRes.wrap(
|
||||||
RestrictionRes(resVM.name, resStreamType).wrap(
|
RestrictionRes(resVM.name, resStreamType).wrap(
|
||||||
SeqRes.wrap(
|
SeqRes.wrap(
|
||||||
// res <- foo()
|
// res <- foo()
|
||||||
@ -303,9 +303,9 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers {
|
|||||||
).leaf
|
).leaf
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
errorCall(transformCfg, 0, initPeer)
|
respCall(transformCfg, resFlatVM, initPeer)
|
||||||
),
|
),
|
||||||
respCall(transformCfg, resFlatVM, initPeer)
|
errorCall(transformCfg, 0, initPeer)
|
||||||
)
|
)
|
||||||
|
|
||||||
barfoo.body.equalsOrShowDiff(expected) should be(true)
|
barfoo.body.equalsOrShowDiff(expected) should be(true)
|
||||||
|
@ -9,7 +9,22 @@ import aqua.types.*
|
|||||||
import cats.syntax.show.*
|
import cats.syntax.show.*
|
||||||
import cats.syntax.option.*
|
import cats.syntax.option.*
|
||||||
|
|
||||||
// TODO: doc
|
/**
|
||||||
|
* Pre-transformer for top functions:
|
||||||
|
* - Get arguments
|
||||||
|
* - Get relay
|
||||||
|
* - Generate callbacks for function arguments
|
||||||
|
* - Handle result
|
||||||
|
* - Handle error
|
||||||
|
*
|
||||||
|
* @param argsProvider - provides arguments
|
||||||
|
* @param resultsHandler - handles results
|
||||||
|
* @param errorHandler - handles errors
|
||||||
|
* @param callback - generates callback for function argument
|
||||||
|
* @param relayVarName - name of the relay variable
|
||||||
|
* @param wrapCallableName - name of the generated wrapper function
|
||||||
|
* @param arrowCallbackPrefix - prefix for generated callbacks names
|
||||||
|
*/
|
||||||
case class FuncPreTransformer(
|
case class FuncPreTransformer(
|
||||||
argsProvider: ArgsProvider,
|
argsProvider: ArgsProvider,
|
||||||
resultsHandler: ResultsHandler,
|
resultsHandler: ResultsHandler,
|
||||||
@ -50,7 +65,7 @@ case class FuncPreTransformer(
|
|||||||
* removes function return
|
* removes function return
|
||||||
*
|
*
|
||||||
* @param func Function to transform
|
* @param func Function to transform
|
||||||
* @return
|
* @return Transformed function
|
||||||
*/
|
*/
|
||||||
def preTransform(func: FuncArrow): FuncArrow = {
|
def preTransform(func: FuncArrow): FuncArrow = {
|
||||||
val returnType = ProductType(func.ret.map(_.`type`).map {
|
val returnType = ProductType(func.ret.map(_.`type`).map {
|
||||||
@ -93,13 +108,13 @@ case class FuncPreTransformer(
|
|||||||
|
|
||||||
val call = CallArrowRawTag.func(func.funcName, funcCall).leaf
|
val call = CallArrowRawTag.func(func.funcName, funcCall).leaf
|
||||||
|
|
||||||
val body = SeqTag.wrap(
|
val body = TryTag.wrap(
|
||||||
provideArgs ++ List(
|
SeqTag.wrap(
|
||||||
TryTag.wrap(
|
provideArgs
|
||||||
call,
|
.appended(call)
|
||||||
handleError
|
.appendedAll(handleResults)
|
||||||
)
|
),
|
||||||
) ++ handleResults
|
handleError
|
||||||
)
|
)
|
||||||
|
|
||||||
FuncArrow(
|
FuncArrow(
|
||||||
|
@ -48,29 +48,28 @@ class TransformSpec extends AnyFlatSpec with Matchers {
|
|||||||
|
|
||||||
val procFC = fc.value.body
|
val procFC = fc.value.body
|
||||||
|
|
||||||
val expectedFC =
|
val expectedFC = XorRes.wrap(
|
||||||
SeqRes.wrap(
|
SeqRes.wrap(
|
||||||
dataCall(bc, "-relay-", initPeer),
|
dataCall(bc, "-relay-", initPeer),
|
||||||
XorRes.wrap(
|
XorRes.wrap(
|
||||||
XorRes.wrap(
|
SeqRes.wrap(
|
||||||
SeqRes.wrap(
|
through(relayV),
|
||||||
through(relayV),
|
through(otherRelay),
|
||||||
through(otherRelay),
|
callRes(1, otherPeer),
|
||||||
callRes(1, otherPeer),
|
through(otherRelay),
|
||||||
through(otherRelay),
|
through(relayV)
|
||||||
through(relayV)
|
|
||||||
),
|
|
||||||
SeqRes.wrap(
|
|
||||||
through(otherRelay),
|
|
||||||
through(relayV),
|
|
||||||
through(initPeer),
|
|
||||||
failErrorRes
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
errorCall(bc, 0, initPeer)
|
SeqRes.wrap(
|
||||||
|
through(otherRelay),
|
||||||
|
through(relayV),
|
||||||
|
through(initPeer),
|
||||||
|
failErrorRes
|
||||||
|
)
|
||||||
),
|
),
|
||||||
respCall(bc, ret, initPeer)
|
respCall(bc, ret, initPeer)
|
||||||
)
|
),
|
||||||
|
errorCall(bc, 0, initPeer)
|
||||||
|
)
|
||||||
|
|
||||||
procFC.equalsOrShowDiff(expectedFC) should be(true)
|
procFC.equalsOrShowDiff(expectedFC) should be(true)
|
||||||
|
|
||||||
@ -80,9 +79,21 @@ class TransformSpec extends AnyFlatSpec with Matchers {
|
|||||||
|
|
||||||
val ret = LiteralRaw.quote("return this")
|
val ret = LiteralRaw.quote("return this")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* func ret() -> string:
|
||||||
|
* srv0.fn0()
|
||||||
|
* on "other-peer":
|
||||||
|
* srv1.fn1()
|
||||||
|
* <- "return this"
|
||||||
|
*/
|
||||||
val func: FuncArrow = FuncArrow(
|
val func: FuncArrow = FuncArrow(
|
||||||
"ret",
|
"ret",
|
||||||
SeqTag.wrap(callOp(0).leaf, OnTag(otherPeer, Chain.empty).wrap(callOp(1).leaf)),
|
SeqTag.wrap(
|
||||||
|
callOp(0).leaf,
|
||||||
|
OnTag(otherPeer, Chain.empty).wrap(
|
||||||
|
callOp(1).leaf
|
||||||
|
)
|
||||||
|
),
|
||||||
stringArrow,
|
stringArrow,
|
||||||
ret :: Nil,
|
ret :: Nil,
|
||||||
Map.empty,
|
Map.empty,
|
||||||
@ -96,29 +107,26 @@ class TransformSpec extends AnyFlatSpec with Matchers {
|
|||||||
|
|
||||||
val procFC = fc.value.body
|
val procFC = fc.value.body
|
||||||
|
|
||||||
val expectedFC =
|
val expectedFC = XorRes.wrap(
|
||||||
SeqRes.wrap(
|
SeqRes.wrap(
|
||||||
dataCall(bc, "-relay-", initPeer),
|
dataCall(bc, "-relay-", initPeer),
|
||||||
|
callRes(0, initPeer),
|
||||||
XorRes.wrap(
|
XorRes.wrap(
|
||||||
SeqRes.wrap(
|
SeqRes.wrap(
|
||||||
callRes(0, initPeer),
|
through(relayV),
|
||||||
XorRes.wrap(
|
callRes(1, otherPeer),
|
||||||
SeqRes.wrap(
|
through(relayV)
|
||||||
through(relayV),
|
|
||||||
callRes(1, otherPeer),
|
|
||||||
through(relayV)
|
|
||||||
),
|
|
||||||
SeqRes.wrap(
|
|
||||||
through(relayV),
|
|
||||||
through(initPeer),
|
|
||||||
failErrorRes
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
errorCall(bc, 0, initPeer)
|
SeqRes.wrap(
|
||||||
|
through(relayV),
|
||||||
|
through(initPeer),
|
||||||
|
failErrorRes
|
||||||
|
)
|
||||||
),
|
),
|
||||||
respCall(bc, ret, initPeer)
|
respCall(bc, ret, initPeer)
|
||||||
)
|
),
|
||||||
|
errorCall(bc, 0, initPeer)
|
||||||
|
)
|
||||||
|
|
||||||
procFC.equalsOrShowDiff(expectedFC) should be(true)
|
procFC.equalsOrShowDiff(expectedFC) should be(true)
|
||||||
|
|
||||||
@ -126,13 +134,13 @@ class TransformSpec extends AnyFlatSpec with Matchers {
|
|||||||
|
|
||||||
"transform.forClient" should "link funcs correctly" in {
|
"transform.forClient" should "link funcs correctly" in {
|
||||||
/*
|
/*
|
||||||
func one() -> u64:
|
func f1() -> string:
|
||||||
variable <- Demo.get42()
|
v <- srv1.fn1()
|
||||||
<- variable
|
<- v
|
||||||
|
|
||||||
func two() -> u64:
|
func f2() -> string:
|
||||||
variable <- one()
|
v <- f1()
|
||||||
<- variable
|
<- v
|
||||||
*/
|
*/
|
||||||
|
|
||||||
val f1: FuncArrow =
|
val f1: FuncArrow =
|
||||||
@ -163,13 +171,13 @@ class TransformSpec extends AnyFlatSpec with Matchers {
|
|||||||
|
|
||||||
val procFC = Transform.funcRes(f2, bc).value.body
|
val procFC = Transform.funcRes(f2, bc).value.body
|
||||||
|
|
||||||
val expectedFC = SeqRes.wrap(
|
val expectedFC = XorRes.wrap(
|
||||||
dataCall(bc, "-relay-", initPeer),
|
SeqRes.wrap(
|
||||||
XorRes.wrap(
|
dataCall(bc, "-relay-", initPeer),
|
||||||
callRes(1, initPeer),
|
callRes(1, initPeer),
|
||||||
errorCall(bc, 0, initPeer)
|
respCall(bc, VarRaw("v", ScalarType.string), initPeer)
|
||||||
),
|
),
|
||||||
respCall(bc, VarRaw("v", ScalarType.string), initPeer)
|
errorCall(bc, 0, initPeer)
|
||||||
)
|
)
|
||||||
|
|
||||||
procFC.equalsOrShowDiff(expectedFC) should be(true)
|
procFC.equalsOrShowDiff(expectedFC) should be(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user