Skip to content

Commit

Permalink
Clean up and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Jun 9, 2023
1 parent dd08022 commit 01108d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/aqua-api/.js/src/main/scala/api/types/InputTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import aqua.api.AquaAPIConfig
import aqua.api.TargetType.*
import aqua.js.{FunctionDefJs, ServiceDefJs}
import aqua.model.transform.TransformConfig
import cats.data.Validated.{invalidNec, validNec, Invalid, Valid}
import cats.data.Validated.{invalidNec, validNec}
import cats.data.{Chain, NonEmptyChain, Validated, ValidatedNec}

import scala.scalajs.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ object CallArrowRawInliner extends RawInliner[CallArrowRaw] with Logging {
vars -> Inline(
ListMap.empty,
Chain.one(
// Leave meta information in tree after inlining
MetaModel
.CallArrowModel(fn.funcName)
.wrap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import cats.syntax.show.*
import cats.data.{Chain, NonEmptyList, NonEmptyMap}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import aqua.raw.value.ValueRaw
import aqua.raw.value.CallArrowRaw
import aqua.raw.arrow.FuncRaw
import aqua.raw.arrow.ArrowRaw
import aqua.raw.value.{CallArrowRaw, ValueRaw}
import aqua.raw.arrow.{ArrowRaw, FuncRaw}

class ArrowInlinerSpec extends AnyFlatSpec with Matchers {

Expand All @@ -37,7 +35,7 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {

model.equalsOrShowDiff(
CallServiceModel(
LiteralModel("\"dumb_srv_id\"", LiteralType.string),
LiteralModel.liftString("dumb_srv_id"),
"dumb",
CallModel(Nil, Nil)
).leaf
Expand Down Expand Up @@ -126,7 +124,7 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
CallModel.Export(canonModel.name, canonModel.`type`)
).leaf,
CallServiceModel(
LiteralModel("\"test-service\"", LiteralType.string),
LiteralModel.liftString("test-service"),
"some-call",
CallModel(canonModel :: Nil, Nil)
).leaf
Expand Down Expand Up @@ -221,7 +219,7 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
model.equalsOrShowDiff(
RestrictionModel(streamVar.name, true).wrap(
CallServiceModel(
LiteralModel("\"test-service\"", LiteralType.string),
LiteralModel.liftString("test-service"),
"some-call",
CallModel(streamModel :: Nil, Nil)
).leaf
Expand Down Expand Up @@ -306,15 +304,15 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
.CallArrowModel(innerName)
.wrap(
CallServiceModel(
LiteralModel("\"test-service\"", LiteralType.string),
LiteralModel.liftString("test-service"),
"get_records",
CallModel(Nil, CallModel.Export(recordsModel.name, recordsModel.`type`) :: Nil)
).leaf
),
SeqModel.wrap(
CanonicalizeModel(recordsModel, CallModel.Export(canonModel.name, canonType)).leaf,
CallServiceModel(
LiteralModel("\"callbackSrv\"", LiteralType.string),
LiteralModel.liftString("callbackSrv"),
"response",
CallModel(canonModel :: Nil, Nil)
).leaf
Expand Down Expand Up @@ -469,7 +467,7 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {

/**
* func inner() -> u16:
* res = 42
* res = 42
* <- res
*
* func outer() -> u16:
Expand Down Expand Up @@ -1051,7 +1049,7 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
model.equalsOrShowDiff(
SeqModel.wrap(
CallServiceModel(
LiteralModel("\"getSrv\"", LiteralType.string),
LiteralModel.liftString("getSrv"),
"getObj",
CallModel(Nil, CallModel.Export(objectVar.name, objectVar.`type`) :: Nil)
).leaf,
Expand All @@ -1061,7 +1059,7 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
SeqModel.wrap(
FlattenModel(ValueModel.fromRaw(objectVarLambda), flattenObject.name).leaf,
CallServiceModel(
LiteralModel("\"callbackSrv\"", LiteralType.string),
LiteralModel.liftString("callbackSrv"),
"response",
CallModel(ValueModel.fromRaw(flattenObject) :: Nil, Nil)
).leaf
Expand Down Expand Up @@ -1152,12 +1150,12 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
model.equalsOrShowDiff(
SeqModel.wrap(
CallServiceModel(
LiteralModel("\"getSrv\"", LiteralType.string),
LiteralModel.liftString("getSrv"),
"getArr",
CallModel(Nil, CallModel.Export(argArray.name, argArray.`type`) :: Nil)
).leaf,
CallServiceModel(
LiteralModel("\"getSrv\"", LiteralType.string),
LiteralModel.liftString("getSrv"),
"getIdx",
CallModel(Nil, CallModel.Export(idxVar.name, idxVar.`type`) :: Nil)
).leaf
Expand Down
9 changes: 9 additions & 0 deletions model/src/main/scala/aqua/model/OpModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ object OpModel extends TreeNodeCompanion[OpModel] {
}
}

/**
* Meta information embedded in a tree
*/
enum MetaModel extends OpModel {

/**
* Wraps subtree that was produced after inlining arrow
*
* @param name Name of arrow inlined
*/
case CallArrowModel(name: String)

override def wrap(children: Tree*): Tree =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import cats.data.Chain
import cats.free.Cofree
import cats.Eval

/**
* Base type for [[OpModel.Tree]] -> [[OpModel.Tree]] transformation
*/
trait OpTransform {

/**
* Transformation step
* (node, child results) => node result
*/
def folder: OpTransform.OpFolder

def apply(tree: OpModel.Tree): Eval[OpModel.Tree] =
Expand Down

0 comments on commit 01108d4

Please sign in to comment.