Skip to content

Commit

Permalink
Merge pull request #363 from ScorexFoundation/v2.0
Browse files Browse the repository at this point in the history
v2.0
  • Loading branch information
catena2w authored Mar 14, 2019
2 parents 07bf22d + c97d366 commit 2b4b07a
Show file tree
Hide file tree
Showing 302 changed files with 28,470 additions and 6,901 deletions.
21 changes: 10 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
sigma.pdf
sigma.toc
sigma.aux
sigma.log
sigma.out
sigma.bbl
sigma.blg
sigma.fls
sigma.synctex.gz
sigma.fdb_latexmk
*.pdf
*.toc
*.aux
*.log
*.out
*.bbl
*.blg
*.fls
*.fdb_latexmk

*.log
test-out/

flamegraphs/
# sbt specific
.cache
.lib/
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ before_cache:
# These directories are cached to S3 at the end of the build
cache:
directories:
- $HOME/.ivy2/cache

- $HOME/.ivy2/cache
- $HOME/.sbt
language: scala

jdk:
Expand Down
144 changes: 113 additions & 31 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ lazy val commonSettings = Seq(
<name>Alexander Chepurnoy</name>
<url>http://chepurnoy.org/</url>
</developer>
</developers>
<developer>
<id>aslesarenko</id>
<name>Alexander Slesarenko</name>
<url>https://github.com/aslesarenko/</url>
</developer>
</developers>,
publishMavenStyle := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) { Some("snapshots" at nexus + "content/repositories/snapshots") }
else { Some("releases" at nexus + "service/local/staging/deploy/maven2") }
}

)

enablePlugins(GitVersioning)
Expand Down Expand Up @@ -57,14 +69,24 @@ version in ThisBuild := {
}
}

val specialVersion = "master-6eca3f22-SNAPSHOT"
val specialCommon = "io.github.scalan" %% "common" % specialVersion
val specialCore = "io.github.scalan" %% "core" % specialVersion
git.gitUncommittedChanges in ThisBuild := true

val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.60"
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.1.6"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.3"
val macroCompat = "org.typelevel" %% "macro-compat" % "1.1.1"
val paradise = "org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full

val specialVersion = "master-5ffd1bf8-SNAPSHOT"
val specialCommon = "io.github.scalan" %% "common" % specialVersion
val specialCore = "io.github.scalan" %% "core" % specialVersion
val specialLibrary = "io.github.scalan" %% "library" % specialVersion

val specialSigmaVersion = "master-354d6254-SNAPSHOT"
val sigmaImpl = "io.github.scalan" %% "sigma-impl" % specialSigmaVersion
val sigmaLibrary = "io.github.scalan" %% "sigma-library" % specialSigmaVersion
val meta = "io.github.scalan" %% "meta" % specialVersion
val plugin = "io.github.scalan" %% "plugin" % specialVersion
val libraryapi = "io.github.scalan" %% "library-api" % specialVersion
val libraryimpl = "io.github.scalan" %% "library-impl" % specialVersion
val libraryconf = "io.github.scalan" %% "library-conf" % specialVersion

val testingDependencies = Seq(
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
Expand All @@ -75,19 +97,24 @@ val testingDependencies = Seq(
specialCommon, (specialCommon % Test).classifier("tests"),
specialCore, (specialCore % Test).classifier("tests"),
specialLibrary, (specialLibrary % Test).classifier("tests"),
sigmaImpl, (sigmaImpl % Test).classifier("tests"),
sigmaLibrary, (sigmaLibrary % Test).classifier("tests"),
)

lazy val testSettings = Seq(
libraryDependencies ++= testingDependencies,
parallelExecution in Test := false,
baseDirectory in Test := file("."),
publishArtifact in Test := true,
publishArtifact in(Test, packageSrc) := true,
publishArtifact in(Test, packageDoc) := false,
test in assembly := {})

libraryDependencies ++= Seq(
"org.scorexfoundation" %% "scrypto" % "2.1.4",
"org.scorexfoundation" %% "scorex-util" % "0.1.1",
scrypto,
scorexUtil,
"org.bouncycastle" % "bcprov-jdk15on" % "1.+",
"com.typesafe.akka" %% "akka-actor" % "2.4.+",
"org.bitbucket.inkytonik.kiama" %% "kiama" % "2.1.0",
"com.lihaoyi" %% "fastparse" % "1.0.0",
sigmaImpl,
sigmaLibrary,
) ++ testingDependencies


Expand All @@ -96,18 +123,9 @@ scalacOptions ++= Seq("-feature", "-deprecation")
//uncomment lines below if the Scala compiler hangs to see where it happens
//scalacOptions in Compile ++= Seq("-Xprompt", "-Ydebug", "-verbose" )


publishMavenStyle := true

parallelExecution in Test := false
publishArtifact in Test := false

publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) { Some("snapshots" at nexus + "content/repositories/snapshots") }
else { Some("releases" at nexus + "service/local/staging/deploy/maven2") }
}

pomIncludeRepository := { _ => false }

credentials += Credentials(Path.userHome / ".sbt" / ".sigma-sonatype-credentials")
Expand All @@ -117,10 +135,64 @@ credentials ++= (for {
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq

lazy val sigma = (project in file(".")).settings(commonSettings: _*)
def libraryDefSettings = commonSettings ++ testSettings ++ Seq(
scalacOptions ++= Seq(
// s"-Xplugin:${file(".").absolutePath }/scalanizer/target/scala-2.12/scalanizer-assembly-better-costing-2a66ed5c-SNAPSHOT.jar"
)
)

lazy val sigmaconf = Project("sigma-conf", file("sigma-conf"))
.settings(commonSettings,
libraryDependencies ++= Seq(
plugin, libraryconf
))

lazy val scalanizer = Project("scalanizer", file("scalanizer"))
.dependsOn(sigmaconf)
.settings(commonSettings,
libraryDependencies ++= Seq(meta, plugin, libraryapi, libraryimpl),
// publishArtifact in(Compile, packageBin) := false,
assemblyOption in assembly ~= { _.copy(includeScala = false, includeDependency = true) },
artifact in(Compile, assembly) := {
val art = (artifact in(Compile, assembly)).value
art.withClassifier(Some("assembly"))
},
addArtifact(artifact in(Compile, assembly), assembly)
)

lazy val sigmaapi = Project("sigma-api", file("sigma-api"))
.settings(libraryDefSettings :+ addCompilerPlugin(paradise),
libraryDependencies ++= Seq(
specialCommon, meta, libraryapi, macroCompat, scrypto, bouncycastleBcprov
))

lazy val sigmaimpl = Project("sigma-impl", file("sigma-impl"))
.dependsOn(sigmaapi % allConfigDependency)
.settings(libraryDefSettings,
libraryDependencies ++= Seq(
libraryapi, libraryimpl, scrypto, bouncycastleBcprov
))

lazy val sigmalibrary = Project("sigma-library", file("sigma-library"))
.dependsOn(sigmaimpl % allConfigDependency)
.settings(libraryDefSettings,
libraryDependencies ++= Seq(
specialCommon, (specialCommon % Test).classifier("tests"),
specialCore, (specialCore % Test).classifier("tests"),
libraryapi, (libraryapi % Test).classifier("tests"),
libraryimpl, (libraryimpl % Test).classifier("tests"),
specialLibrary, (specialLibrary % Test).classifier("tests"),
scrypto,
bouncycastleBcprov
))

lazy val sigma = (project in file("."))
.aggregate(sigmaapi, sigmaimpl, sigmalibrary, sigmaconf, scalanizer)
.dependsOn(sigmaimpl % allConfigDependency, sigmalibrary % allConfigDependency)
.settings(commonSettings: _*)

def runErgoTask(task: String, sigmastateVersion: String, log: Logger): Unit = {
val ergoBranch = "master"
val ergoBranch = "v2.0"
log.info(s"Testing current build in Ergo (branch $ergoBranch):")
val cwd = new File("").absolutePath
val ergoPath = new File(cwd + "/ergo-tests/")
Expand All @@ -138,24 +210,34 @@ def runErgoTask(task: String, sigmastateVersion: String, log: Logger): Unit = {

log.info(s"Running Ergo tests in $ergoPath with Sigmastate version $sigmastateVersion")
val res = Process(Seq("sbt", task), ergoPath, "SIGMASTATE_VERSION" -> sigmastateVersion) !

if (res != 0) sys.error(s"Ergo $task failed!")
}

lazy val ergoUnitTest = TaskKey[Unit]("ergoUnitTest", "run ergo unit tests with current version")
ergoUnitTest := {
lazy val ergoUnitTestTask = TaskKey[Unit]("ergoUnitTestTask", "run ergo unit tests with current version")
ergoUnitTestTask := {
val log = streams.value.log
val sigmastateVersion = version.value
runErgoTask("test", sigmastateVersion, log)
}

ergoUnitTest := ergoUnitTest.dependsOn(publishLocal).value
commands += Command.command("ergoUnitTest") { state =>
"clean" ::
"publishLocal" ::
"ergoUnitTestTask" ::
state
}

lazy val ergoItTest = TaskKey[Unit]("ergoItTest", "run ergo it:test with current version")
ergoItTest := {
lazy val ergoItTestTask = TaskKey[Unit]("ergoItTestTask", "run ergo it:test with current version")
ergoItTestTask := {
val log = streams.value.log
val sigmastateVersion = version.value
runErgoTask("it:test", sigmastateVersion, log)
}

ergoItTest := ergoItTest.dependsOn(publishLocal).value
commands += Command.command("ergoItTest") { state =>
"clean" ::
"publishLocal" ::
"ergoItTestTask" ::
state
}
28 changes: 14 additions & 14 deletions docs/Costing.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ represent cost and size (costing information, costing properties).
Note, that `cost` and `dataSize` are independent parameters because some _costed_ values may have
very small `dataSize`, but at the same time very high `cost`, e.g. result of contract may be `true`
boolean value whose `dataSize` is 1 byte, but its `cost` is the cost of executing the whole contract.
The opposite is also possible. For example a context variable of `Col[Byte]` type have `cost` equal 0,
The opposite is also possible. For example a context variable of `Coll[Byte]` type have `cost` equal 0,
but may have very big `dataSize`.

From this perspective Costed Graph `graphC` is a data flow graph between costed values.
Expand Down Expand Up @@ -210,23 +210,23 @@ CCostedPair(
CCostedPrim(true, costOf("Const:() => Boolean"), sizeOf[Boolean])))
```

##### Costed Values of Col Type
##### Costed Values of Coll Type

If `Item` is a type of array element, then costed value of type `Col[Item]` is
represented by the following specializations of `Costed[Col[Item]]` type
If `Item` is a type of array element, then costed value of type `Coll[Item]` is
represented by the following specializations of `Costed[Coll[Item]]` type
```scala
class CCostedCol[Item](
class CCostedColl[Item](
val values: Coll[Item], val costs: Coll[Int],
val sizes: Coll[Long], val valuesCost: Int) extends CostedCol[Item] {
val sizes: Coll[Long], val valuesCost: Int) extends CostedColl[Item] {
def value: Coll[Item] = values
def cost: Int = valuesCost + costs.sum
def dataSize: Long = sizes.sum
def mapCosted[Res](f: Costed[Item] => Costed[Res]): CostedCol[Res] = rewritableMethod
def mapCosted[Res](f: Costed[Item] => Costed[Res]): CostedColl[Res] = rewritableMethod
def foldCosted[B](zero: Costed[B], op: Costed[(B, Item)] => Costed[B]): Costed[B] = rewritableMethod
}
```
For constant, context variables and registers values of `Col` type the costing information
of `CCostedCol` is computed from actual data.
For constant, context variables and registers values of `Coll` type the costing information
of `CCostedColl` is computed from actual data.

Note methods `mapCosted` and `foldCosted`, these methods represent costed version of original
collection methods. Note the methods are defined as rewritable, meaning their implementation
Expand Down Expand Up @@ -309,7 +309,7 @@ explicit by using `eval` helper and also employ other idioms of staged evaluatio
```scala
case MapCollection(input, id, mapper) =>
val eIn = stypeToElem(input.tpe.elemType) // translate sigma type to Special type descriptor
val xs = asRep[CostedCol[Any]](eval(input)) // recursively build subgraph for input argument
val xs = asRep[CostedColl[Any]](eval(input)) // recursively build subgraph for input argument
implicit val eAny = xs.elem.asInstanceOf[CostedElem[Coll[Any],_]].eVal.eA
assert(eIn == eAny, s"Types should be equal: but $eIn != $eAny")
val mapperC = fun { x: Rep[Costed[Any]] => // x argument is already costed
Expand Down Expand Up @@ -409,13 +409,13 @@ of the specific cases into reusable modules.
to hook into graph building process and perform on the fly substitution of
specific sub-graphs with equivalent but different sub-graphs.
The following rule uses auto-generated extractor `mapCosted` which recognizes invocations of method
`CostedCol.mapCosted` (Remember, this method was used in costing rule for `MapCollection` tree node).
`CostedColl.mapCosted` (Remember, this method was used in costing rule for `MapCollection` tree node).

```scala
override def rewriteDef[T](d: Def[T]): Rep[_] = {
val CCM = CostedColMethods
val CCM = CostedCollMethods
d match {
case CCM.mapCosted(xs: RCostedCol[a], _f: RCostedFunc[_, b]) =>
case CCM.mapCosted(xs: RCostedColl[a], _f: RCostedFunc[_, b]) =>
val f = asRep[Costed[a] => Costed[b]](_f)
val (calcF, costF, sizeF) = splitCostedFunc[a, b](f)
val vals = xs.values.map(calcF)
Expand All @@ -436,7 +436,7 @@ override def rewriteDef[T](d: Def[T]): Rep[_] = {
colBuilder.replicate(xs.sizes.length, typeSize(tpeB))
} else
xs.sizes.map(sizeF)
RCCostedCol(vals, costs, sizes, xs.valuesCost)
RCCostedColl(vals, costs, sizes, xs.valuesCost)
case _ => super.rewriteDef(d)
}
}
Expand Down
Loading

0 comments on commit 2b4b07a

Please sign in to comment.