mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 14:40:17 +00:00
gates for on-via
in seq, optimize gates with literals
This commit is contained in:
parent
1e2e35ee88
commit
4104fe78c5
@ -1,18 +1,41 @@
|
|||||||
package aqua.api
|
package aqua.api
|
||||||
import cats.effect.{IO, IOApp}
|
|
||||||
|
import aqua.api.TargetType.{JavaScriptType, TypeScriptType}
|
||||||
import aqua.backend.js.JavaScriptBackend
|
import aqua.backend.js.JavaScriptBackend
|
||||||
import aqua.backend.ts.TypeScriptBackend
|
import aqua.backend.ts.TypeScriptBackend
|
||||||
import aqua.api.TargetType.JavaScriptType
|
import aqua.compiler.AquaCompiled
|
||||||
|
import aqua.files.FileModuleId
|
||||||
|
import cats.data.Chain
|
||||||
|
import cats.effect.{IO, IOApp}
|
||||||
|
import fs2.io.file.{Files, Path}
|
||||||
|
import cats.data.Validated.{Valid, Invalid}
|
||||||
|
import fs2.{Stream, text}
|
||||||
|
|
||||||
object Test extends IOApp.Simple {
|
object Test extends IOApp.Simple {
|
||||||
|
|
||||||
override def run: IO[Unit] = {
|
override def run: IO[Unit] = {
|
||||||
val input =
|
APICompilation
|
||||||
"""func getNumber(number: u32) -> u32:
|
.compilePath(
|
||||||
| <- number
|
"./aqua-src/antithesis.aqua",
|
||||||
|""".stripMargin
|
"./aqua" :: Nil,
|
||||||
APICompilation.compileString(input, Nil, AquaAPIConfig(targetType = JavaScriptType), JavaScriptBackend()).map {
|
AquaAPIConfig(targetType = TypeScriptType),
|
||||||
res =>
|
TypeScriptBackend(false, "IFluenceClient$$")
|
||||||
println(res)
|
)
|
||||||
}
|
.flatMap {
|
||||||
|
case Valid(res: Chain[AquaCompiled[FileModuleId]]) =>
|
||||||
|
val content = res.get(0).get.compiled.head.content
|
||||||
|
|
||||||
|
val targetPath = Path("./target/antithesis.ts")
|
||||||
|
Stream.emit(content)
|
||||||
|
.through(text.utf8.encode)
|
||||||
|
.through(Files[IO].writeAll(targetPath))
|
||||||
|
.attempt
|
||||||
|
|
||||||
|
.compile
|
||||||
|
.last.map(_ => println(s"File: ${targetPath.absolute.normalize}"))
|
||||||
|
case Invalid(e) =>
|
||||||
|
IO.pure(println(e))
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
build.sbt
52
build.sbt
@ -38,56 +38,6 @@ val commons = Seq(
|
|||||||
|
|
||||||
commons
|
commons
|
||||||
|
|
||||||
lazy val cli = crossProject(JSPlatform, JVMPlatform)
|
|
||||||
.withoutSuffixFor(JVMPlatform)
|
|
||||||
.crossType(CrossType.Pure)
|
|
||||||
.in(file("cli/cli"))
|
|
||||||
.enablePlugins(GraalVMNativeImagePlugin)
|
|
||||||
.settings(commons)
|
|
||||||
.settings(
|
|
||||||
Compile / mainClass := Some("aqua.AquaCli"),
|
|
||||||
graalVMNativeImageOptions ++= Seq(
|
|
||||||
"--no-fallback",
|
|
||||||
"--diagnostics-mode",
|
|
||||||
"--initialize-at-build-time",
|
|
||||||
"--initialize-at-run-time=scala.util.Random$",
|
|
||||||
"-H:-DeleteLocalSymbols",
|
|
||||||
"-H:+PreserveFramePointer",
|
|
||||||
"-H:+ReportExceptionStackTraces",
|
|
||||||
"-H:+DashboardHeap",
|
|
||||||
"-H:+DashboardCode",
|
|
||||||
"-H:+DashboardPointsTo",
|
|
||||||
"-H:+DashboardAll"
|
|
||||||
) ++ sys.env
|
|
||||||
.get("COMPILE_STATIC")
|
|
||||||
.filter(_.trim.toLowerCase() == "true")
|
|
||||||
.map(_ => Seq("--static"))
|
|
||||||
.getOrElse(Seq.empty),
|
|
||||||
libraryDependencies ++= Seq(
|
|
||||||
"com.monovore" %%% "decline" % declineV,
|
|
||||||
"com.monovore" %%% "decline-effect" % declineV
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.dependsOn(compiler, `backend-air`, `backend-ts`, io, definitions, logging, constants, `aqua-run`)
|
|
||||||
|
|
||||||
lazy val cliJS = cli.js
|
|
||||||
.settings(
|
|
||||||
Compile / fastOptJS / artifactPath := baseDirectory.value / "../../cli-npm" / "aqua.js",
|
|
||||||
Compile / fullOptJS / artifactPath := baseDirectory.value / "../../cli-npm" / "aqua.js",
|
|
||||||
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)),
|
|
||||||
scalaJSUseMainModuleInitializer := true
|
|
||||||
)
|
|
||||||
.dependsOn(`js-exports`, `js-imports`)
|
|
||||||
|
|
||||||
lazy val cliJVM = cli.jvm
|
|
||||||
.settings(
|
|
||||||
Compile / run / mainClass := Some("aqua.AquaCli"),
|
|
||||||
assembly / mainClass := Some("aqua.AquaCli"),
|
|
||||||
assembly / assemblyJarName := "aqua-" + version.value + ".jar",
|
|
||||||
libraryDependencies ++= Seq(
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
lazy val `aqua-run` = crossProject(JSPlatform, JVMPlatform)
|
lazy val `aqua-run` = crossProject(JSPlatform, JVMPlatform)
|
||||||
.withoutSuffixFor(JVMPlatform)
|
.withoutSuffixFor(JVMPlatform)
|
||||||
.crossType(CrossType.Pure)
|
.crossType(CrossType.Pure)
|
||||||
@ -149,7 +99,7 @@ lazy val `aqua-api` = crossProject(JSPlatform, JVMPlatform)
|
|||||||
.crossType(CrossType.Pure)
|
.crossType(CrossType.Pure)
|
||||||
.in(file("api/api"))
|
.in(file("api/api"))
|
||||||
.settings(commons)
|
.settings(commons)
|
||||||
.dependsOn(`aqua-run`, `backend-api`)
|
.dependsOn(`aqua-run`, `backend-api`, io)
|
||||||
|
|
||||||
lazy val `aqua-apiJS` = `aqua-api`.js
|
lazy val `aqua-apiJS` = `aqua-api`.js
|
||||||
.settings(
|
.settings(
|
||||||
|
@ -80,6 +80,13 @@ private[inline] object Inline {
|
|||||||
case _ => ParModel.wrap(ops).some
|
case _ => ParModel.wrap(ops).some
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def seqDesugarPrefix(ops: List[OpModel.Tree]): Option[OpModel.Tree] =
|
||||||
|
ops match {
|
||||||
|
case Nil => none
|
||||||
|
case x :: Nil => x.some
|
||||||
|
case _ => SeqModel.wrap(ops).some
|
||||||
|
}
|
||||||
|
|
||||||
def parDesugarPrefixOpt(ops: Option[OpModel.Tree]*): Option[OpModel.Tree] =
|
def parDesugarPrefixOpt(ops: Option[OpModel.Tree]*): Option[OpModel.Tree] =
|
||||||
parDesugarPrefix(ops.toList.flatten)
|
parDesugarPrefix(ops.toList.flatten)
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,24 @@
|
|||||||
package aqua.model.inline
|
package aqua.model.inline
|
||||||
|
|
||||||
import aqua.model.inline.state.{Arrows, Exports, Mangler}
|
|
||||||
import aqua.model.*
|
import aqua.model.*
|
||||||
|
import aqua.model.inline.Inline.{parDesugarPrefixOpt, seqDesugarPrefix}
|
||||||
import aqua.model.inline.RawValueInliner.collectionToModel
|
import aqua.model.inline.RawValueInliner.collectionToModel
|
||||||
import aqua.model.inline.raw.CallArrowRawInliner
|
import aqua.model.inline.raw.CallArrowRawInliner
|
||||||
import aqua.raw.value.ApplyBinaryOpRaw.Op as BinOp
|
import aqua.model.inline.state.{Arrows, Exports, Mangler}
|
||||||
import aqua.raw.ops.*
|
import aqua.raw.ops.*
|
||||||
import aqua.raw.value.*
|
import aqua.raw.value.*
|
||||||
import aqua.types.{BoxType, CanonStreamType, DataType, StreamType}
|
import aqua.raw.value.ApplyBinaryOpRaw.Op as BinOp
|
||||||
import aqua.model.inline.Inline.parDesugarPrefixOpt
|
import aqua.types.{BoxType, CanonStreamType, StreamType}
|
||||||
|
import cats.data.{Chain, State, StateT}
|
||||||
import cats.syntax.traverse.*
|
import cats.instances.list.*
|
||||||
import cats.syntax.applicative.*
|
import cats.syntax.applicative.*
|
||||||
import cats.syntax.flatMap.*
|
|
||||||
import cats.syntax.apply.*
|
import cats.syntax.apply.*
|
||||||
|
import cats.syntax.bifunctor.*
|
||||||
|
import cats.syntax.flatMap.*
|
||||||
import cats.syntax.functor.*
|
import cats.syntax.functor.*
|
||||||
import cats.syntax.option.*
|
import cats.syntax.option.*
|
||||||
import cats.instances.list.*
|
import cats.syntax.traverse.*
|
||||||
import cats.data.{Chain, State, StateT}
|
import scribe.Logging
|
||||||
import cats.syntax.show.*
|
|
||||||
import cats.syntax.bifunctor.*
|
|
||||||
import scribe.{log, Logging}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [[TagInliner]] prepares a [[RawTag]] for futher processing by converting [[ValueRaw]]s into [[ValueModel]]s.
|
* [[TagInliner]] prepares a [[RawTag]] for futher processing by converting [[ValueRaw]]s into [[ValueModel]]s.
|
||||||
@ -33,8 +31,7 @@ import scribe.{log, Logging}
|
|||||||
*/
|
*/
|
||||||
object TagInliner extends Logging {
|
object TagInliner extends Logging {
|
||||||
|
|
||||||
import RawValueInliner.{callToModel, valueListToModel, valueToModel}
|
import RawValueInliner.{valueListToModel, valueToModel}
|
||||||
|
|
||||||
import aqua.model.inline.Inline.parDesugarPrefix
|
import aqua.model.inline.Inline.parDesugarPrefix
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,7 +201,7 @@ object TagInliner extends Logging {
|
|||||||
)
|
)
|
||||||
} yield TagInlined.Mapping(
|
} yield TagInlined.Mapping(
|
||||||
toModel = toModel,
|
toModel = toModel,
|
||||||
prefix = parDesugarPrefix(viaF.prependedAll(pif))
|
prefix = seqDesugarPrefix(viaF.prependedAll(pif))
|
||||||
)
|
)
|
||||||
|
|
||||||
case IfTag(valueRaw) =>
|
case IfTag(valueRaw) =>
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
package aqua.model.inline.raw
|
package aqua.model.inline.raw
|
||||||
|
|
||||||
import aqua.model.*
|
import aqua.model.{EmptyModel, *}
|
||||||
import aqua.model.inline.Inline
|
import aqua.model.inline.Inline
|
||||||
import aqua.model.inline.state.{Arrows, Exports, Mangler}
|
import aqua.model.inline.state.{Arrows, Exports, Mangler}
|
||||||
import aqua.raw.value.{ApplyGateRaw, LiteralRaw, VarRaw}
|
import aqua.raw.value.{ApplyGateRaw, LiteralRaw, VarRaw}
|
||||||
import aqua.model.inline.RawValueInliner.unfold
|
import aqua.model.inline.RawValueInliner.unfold
|
||||||
import aqua.types.{ArrayType, CanonStreamType, ScalarType, StreamType}
|
import aqua.types.{ArrayType, CanonStreamType, ScalarType, StreamType}
|
||||||
|
|
||||||
import cats.data.State
|
import cats.data.State
|
||||||
import cats.data.Chain
|
import cats.data.Chain
|
||||||
import cats.syntax.monoid.*
|
import cats.syntax.monoid.*
|
||||||
import cats.syntax.option.*
|
import cats.syntax.option.*
|
||||||
import scribe.Logging
|
import scribe.Logging
|
||||||
|
|
||||||
|
import scala.util.Try
|
||||||
|
|
||||||
object ApplyGateRawInliner extends RawInliner[ApplyGateRaw] with Logging {
|
object ApplyGateRawInliner extends RawInliner[ApplyGateRaw] with Logging {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,10 +62,10 @@ object ApplyGateRawInliner extends RawInliner[ApplyGateRaw] with Logging {
|
|||||||
val resultCanon =
|
val resultCanon =
|
||||||
VarModel(canonName, CanonStreamType(streamType.element))
|
VarModel(canonName, CanonStreamType(streamType.element))
|
||||||
|
|
||||||
val incrVar = VarModel(idxIncrName, ScalarType.u32)
|
val (incrVar, incrOp) = increment(idxModel, idxIncrName)
|
||||||
|
|
||||||
RestrictionModel(varSTest.name, streamType).wrap(
|
RestrictionModel(varSTest.name, streamType).wrap(
|
||||||
increment(idxModel, incrVar),
|
incrOp,
|
||||||
ForModel(iter.name, VarModel(streamName, streamType), ForModel.Mode.Never.some).wrap(
|
ForModel(iter.name, VarModel(streamName, streamType), ForModel.Mode.Never.some).wrap(
|
||||||
PushToStreamModel(
|
PushToStreamModel(
|
||||||
iter,
|
iter,
|
||||||
@ -132,13 +133,30 @@ object ApplyGateRawInliner extends RawInliner[ApplyGateRaw] with Logging {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def increment(v: ValueModel, result: VarModel) =
|
private def increment(v: ValueModel, name: String): (ValueModel, OpModel.Tree) = {
|
||||||
CallServiceModel(
|
val incrVar = VarModel(name, ScalarType.u32)
|
||||||
LiteralModel("\"math\"", ScalarType.string),
|
val incrValue = v match {
|
||||||
"add",
|
case LiteralModel(value, _) =>
|
||||||
CallModel(
|
Try(value.toInt + 1).toOption.map(LiteralModel.number).getOrElse(incrVar)
|
||||||
v :: LiteralModel.fromRaw(LiteralRaw.number(1)) :: Nil,
|
case _ =>
|
||||||
CallModel.Export(result.name, result.`type`) :: Nil
|
incrVar
|
||||||
)
|
}
|
||||||
).leaf
|
incrValue match {
|
||||||
|
case _: LiteralModel =>
|
||||||
|
(incrValue, EmptyModel.leaf)
|
||||||
|
case _ =>
|
||||||
|
(
|
||||||
|
incrVar,
|
||||||
|
CallServiceModel(
|
||||||
|
LiteralModel("\"math\"", ScalarType.string),
|
||||||
|
"add",
|
||||||
|
CallModel(
|
||||||
|
incrVar :: LiteralModel.fromRaw(LiteralRaw.number(1)) :: Nil,
|
||||||
|
CallModel.Export(incrVar.name, incrVar.`type`) :: Nil
|
||||||
|
)
|
||||||
|
).leaf
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import cats.syntax.option.*
|
|||||||
|
|
||||||
object ResBuilder {
|
object ResBuilder {
|
||||||
|
|
||||||
def join(stream: VarModel, onIdx: ValueModel, peer: ValueModel) = {
|
def join(stream: VarModel, onIdxV: ValueModel, peer: ValueModel) = {
|
||||||
val testVM = VarModel(stream.name + "_test", stream.`type`)
|
val testVM = VarModel(stream.name + "_test", stream.`type`)
|
||||||
val testStreamType = stream.`type`.asInstanceOf[StreamType] // Unsafe
|
val testStreamType = stream.`type`.asInstanceOf[StreamType] // Unsafe
|
||||||
val iter = VarModel(stream.name + "_fold_var", ScalarType.string)
|
val iter = VarModel(stream.name + "_fold_var", ScalarType.string)
|
||||||
@ -18,30 +18,37 @@ object ResBuilder {
|
|||||||
val arrayRes = VarModel(stream.name + "_gate", ArrayType(ScalarType.string))
|
val arrayRes = VarModel(stream.name + "_gate", ArrayType(ScalarType.string))
|
||||||
val idx = VarModel(stream.name + "_incr", ScalarType.u32)
|
val idx = VarModel(stream.name + "_incr", ScalarType.u32)
|
||||||
|
|
||||||
|
val (onIdx, idxTree) = onIdxV match {
|
||||||
|
case LiteralModel(v, t) =>
|
||||||
|
(Some(LiteralModel.number(v.toInt + 1)), Nil)
|
||||||
|
case _ =>
|
||||||
|
(None, CallServiceRes(
|
||||||
|
LiteralModel("\"math\"", ScalarType.string),
|
||||||
|
"add",
|
||||||
|
CallRes(
|
||||||
|
onIdxV :: LiteralModel.fromRaw(LiteralRaw.number(1)) :: Nil,
|
||||||
|
Some(CallModel.Export(idx.name, idx.`type`))
|
||||||
|
),
|
||||||
|
peer
|
||||||
|
).leaf :: Nil)
|
||||||
|
}
|
||||||
|
|
||||||
RestrictionRes(testVM.name, testStreamType).wrap(
|
RestrictionRes(testVM.name, testStreamType).wrap(
|
||||||
CallServiceRes(
|
idxTree :::
|
||||||
LiteralModel("\"math\"", ScalarType.string),
|
|
||||||
"add",
|
|
||||||
CallRes(
|
|
||||||
onIdx :: LiteralModel.fromRaw(LiteralRaw.number(1)) :: Nil,
|
|
||||||
Some(CallModel.Export(idx.name, idx.`type`))
|
|
||||||
),
|
|
||||||
peer
|
|
||||||
).leaf,
|
|
||||||
FoldRes(iter.name, stream, ForModel.Mode.Never.some).wrap(
|
FoldRes(iter.name, stream, ForModel.Mode.Never.some).wrap(
|
||||||
ApRes(iter, CallModel.Export(testVM.name, testVM.`type`)).leaf,
|
ApRes(iter, CallModel.Export(testVM.name, testVM.`type`)).leaf,
|
||||||
CanonRes(testVM, peer, CallModel.Export(canon.name, canon.`type`)).leaf,
|
CanonRes(testVM, peer, CallModel.Export(canon.name, canon.`type`)).leaf,
|
||||||
XorRes.wrap(
|
XorRes.wrap(
|
||||||
MatchMismatchRes(
|
MatchMismatchRes(
|
||||||
canon.copy(properties = Chain.one(FunctorModel("length", ScalarType.u32))),
|
canon.copy(properties = Chain.one(FunctorModel("length", ScalarType.u32))),
|
||||||
idx,
|
onIdx.getOrElse(idx),
|
||||||
true
|
true
|
||||||
).leaf,
|
).leaf,
|
||||||
NextRes(iter.name).leaf
|
NextRes(iter.name).leaf
|
||||||
)
|
)
|
||||||
),
|
) ::
|
||||||
CanonRes(testVM, peer, CallModel.Export(canonRes.name, canonRes.`type`)).leaf,
|
CanonRes(testVM, peer, CallModel.Export(canonRes.name, canonRes.`type`)).leaf ::
|
||||||
ApRes(canonRes, CallModel.Export(arrayRes.name, arrayRes.`type`)).leaf
|
ApRes(canonRes, CallModel.Export(arrayRes.name, arrayRes.`type`)).leaf :: Nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user