Skip to content

Commit

Permalink
Merge pull request #815 from ScorexFoundation/v5.x-migrate-to-2.13
Browse files Browse the repository at this point in the history
[v5.x] Cross-compilation to 2.11, 2.12, 2.13
  • Loading branch information
aslesarenko authored Jan 26, 2023
2 parents dab64a3 + 1912384 commit dce7705
Show file tree
Hide file tree
Showing 99 changed files with 818 additions and 697 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.10, 2.11.12]
scala: [2.13.8, 2.12.10, 2.11.12]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand Down
41 changes: 37 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
# Contributing

## Building

Clone the repository and then run tests.
Clone the repository.

```shell
$ git clone git@github.com:ScorexFoundation/sigmastate-interpreter.git
$ cd sigmastate-interpreter
$ sbt test
```

Then you can compile the library with SBT and run tests.

```shell
$ sbt
sbt:sigma-state> compile
sbt:sigma-state> test
```

By default SBT uses Scala 2.12 for compilation and running tests. To compile for Scala 2.13 use the following commands:

```shell
$ sbt
sbt:sigma-state> ++2.13.8
sbt:sigma-state> compile
sbt:sigma-state> test
```

You can also run SBT commands for all Scala versions at once:

```shell
$ sbt
sbt:sigma-state> +compile
sbt:sigma-state> +test
```

To run specific test suite use the following command:

```shell
git clone git@github.com:ScorexFoundation/sigmastate-interpreter.git
cd sigmastate-interpreter
sbt test
sbt:sigma-state> testOnly <full test class name>
```

## Releasing
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@ libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "4.0.3"
| sigma-library | Implementation of graph IR nodes for Sigma types |
| sigmastate | Implementation ErgoTree, Interpreter and cost estimation |

## Contributing

We welcome contributions to this project! If you are interested in contributing, here are
a few ways to get started:

**Report bugs:** If you have found a bug please open an issue on the issue tracker.

**Fix bugs or implement features:** If you would like to fix a bug or implement a new
feature, please fork the repository and open a pull request with your changes. Please make
sure to include a clear description of the changes you have made and why you think they
should be included in the project.

**Improve documentation:** If you notice that the documentation could be improved, please
feel free to make changes and open a pull request.

**Review pull requests:** If you would like to help review pull requests, please take a
look at the open pull requests and leave comments on any that you would like to review.

Before you start working on a contribution, please make sure to read the [contributing
guidelines](CONTRIBUTING.md). These documents outline the expectations for contributions
to this project.

Thank you for your interest in contributing to this project! Your help is always appreciated!



Please submit a pull request or create an issue to add a new cryptographic primitives or better implementations.


## Acknowledgments

We thank JetBrains for [supporting](https://www.jetbrains.com/buy/opensource/) this project since 2021 by providing All Products Pack subscription.
Expand Down
32 changes: 18 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ organization := "org.scorexfoundation"

name := "sigma-state"

lazy val scala212 = "2.12.10"
lazy val scala213 = "2.13.8"
lazy val scala212 = "2.12.15"
lazy val scala211 = "2.11.12"

lazy val allConfigDependency = "compile->compile;test->test"

lazy val commonSettings = Seq(
organization := "org.scorexfoundation",
crossScalaVersions := Seq(scala212, scala211),
crossScalaVersions := Seq(scala213, scala212, scala211),
scalaVersion := scala212,
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Ywarn-unused:_,imports", "-Ywarn-unused:imports")
case Some((2, 12)) => Seq("-Ywarn-unused:_,imports", "-Ywarn-unused:imports")
case Some((2, 11)) => Seq()
case _ => sys.error("Unsupported scala version")
Expand Down Expand Up @@ -61,20 +63,22 @@ dynverSeparator in ThisBuild := "-"
val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.64"
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.1.10"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.8"
val debox = "org.spire-math" %% "debox" % "0.8.0"
val kiama = "org.bitbucket.inkytonik.kiama" %% "kiama" % "2.1.0"
val fastparse = "com.lihaoyi" %% "fastparse" % "1.0.0"
val debox = "org.scorexfoundation" %% "debox" % "0.9.0"
val spireMacros = "org.typelevel" %% "spire-macros" % "0.17.0-M1" // The last version published for Scala 2.11-2.13
val kiama = "org.bitbucket.inkytonik.kiama" %% "kiama" % "2.5.0"
val fastparse = "com.lihaoyi" %% "fastparse" % "2.3.3"
val commonsIo = "commons-io" % "commons-io" % "2.5"
val commonsMath3 = "org.apache.commons" % "commons-math3" % "3.2"
val scalaCompat = "org.scala-lang.modules" %% "scala-collection-compat" % "2.7.0"

val testingDependencies = Seq(
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"org.scalactic" %% "scalactic" % "3.0.+" % "test",
"org.scalacheck" %% "scalacheck" % "1.14.+" % "test",
"com.lihaoyi" %% "pprint" % "0.5.4" % "test", // the last version with Scala 2.11 support
"com.storm-enroute" %% "scalameter" % "0.8.2" % Test,
"junit" % "junit" % "4.12" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test"
"org.scalatest" %% "scalatest" % "3.0.9" % Test,
"org.scalactic" %% "scalactic" % "3.0.9" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.3" % Test,
"com.lihaoyi" %% "pprint" % "0.6.3" % Test,
"com.storm-enroute" %% "scalameter" % "0.19" % Test,
"junit" % "junit" % "4.12" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test
)

lazy val testSettings = Seq(
Expand All @@ -90,7 +94,7 @@ libraryDependencies ++= Seq(
scrypto,
scorexUtil,
"org.bouncycastle" % "bcprov-jdk15on" % "1.+",
kiama, fastparse, debox
kiama, fastparse, debox, spireMacros, scalaCompat
) ++ testingDependencies

lazy val circeCore211 = "io.circe" %% "circe-core" % "0.10.0"
Expand Down Expand Up @@ -140,7 +144,7 @@ lazy val common = Project("common", file("common"))
.settings(commonSettings ++ testSettings,
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
debox, commonsIo
debox, commonsIo, scalaCompat
))
.settings(publish / skip := true)

Expand Down
2 changes: 2 additions & 0 deletions common/src/main/scala/scalan/package.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

import scala.language.experimental.macros
import scala.reflect.ClassTag

package object scalan {
Expand Down
46 changes: 23 additions & 23 deletions common/src/main/scala/scalan/util/CollectionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import java.util.function.BiConsumer

import scala.collection.{Seq, mutable, GenIterable}
import scala.collection.mutable.{HashMap, ArrayBuffer}
import scala.collection.generic.CanBuildFrom
import scala.reflect.ClassTag
import scala.collection.compat._

object CollectionUtil {

Expand Down Expand Up @@ -83,7 +83,7 @@ object CollectionUtil {
}

/** Perform relational inner join of two sequences using the given key projections. */
def joinSeqs[O, I, K](outer: GenIterable[O], inner: GenIterable[I])(outKey: O=>K, inKey: I=>K): GenIterable[(O,I)] = {
def joinSeqs[O, I, K](outer: Iterable[O], inner: Iterable[I])(outKey: O=>K, inKey: I=>K): Iterable[(O,I)] = {
val kvs = createMultiMap(inner.map(i => (inKey(i), i)))
val res = outer.flatMap(o => {
val ko = outKey(o)
Expand Down Expand Up @@ -222,8 +222,8 @@ object CollectionUtil {
res
}

def filterCast[B:ClassTag](implicit cbf: CanBuildFrom[Source[A], B, Source[B]]): Source[B] = {
val b = cbf()
def filterCast[B:ClassTag](implicit cbf: BuildFrom[Source[A], B, Source[B]]): Source[B] = {
val b = cbf.newBuilder(xs)
for (x <- xs) {
x match {
case y: B =>
Expand All @@ -234,7 +234,7 @@ object CollectionUtil {
b.result()
}

def cast[B:ClassTag](implicit cbf: CanBuildFrom[Source[A], B, Source[B]]): Source[B] = {
def cast[B:ClassTag](implicit cbf: BuildFrom[Source[A], B, Source[B]]): Source[B] = {
for (x <- xs) {
assert(x match { case _: B => true case _ => false}, s"Value $x doesn't conform to type ${reflect.classTag[B]}")
}
Expand All @@ -252,8 +252,8 @@ object CollectionUtil {
return None
}

def filterMap[B](f: A => Option[B])(implicit cbf: CanBuildFrom[Source[A], B, Source[B]]): Source[B] = {
val b = cbf()
def filterMap[B](f: A => Option[B])(implicit cbf: BuildFrom[Source[A], B, Source[B]]): Source[B] = {
val b = cbf.newBuilder(xs)
for (x <- xs) {
f(x) match {
case Some(y) =>
Expand All @@ -265,11 +265,11 @@ object CollectionUtil {
}

def mapUnzip[B1, B2](f: A => (B1,B2))
(implicit cbf1: CanBuildFrom[Source[A], B1, Source[B1]],
cbf2: CanBuildFrom[Source[A], B2, Source[B2]]): (Source[B1], Source[B2]) =
(implicit cbf1: BuildFrom[Source[A], B1, Source[B1]],
cbf2: BuildFrom[Source[A], B2, Source[B2]]): (Source[B1], Source[B2]) =
{
val b1 = cbf1()
val b2 = cbf2()
val b1 = cbf1.newBuilder(xs)
val b2 = cbf2.newBuilder(xs)
for (x <- xs) {
val (y1, y2) = f(x)
b1 += y1; b2 += y2
Expand All @@ -278,23 +278,23 @@ object CollectionUtil {
}

def mapUnzip[B1, B2, B3](f: A => (B1,B2,B3))
(implicit cbf1: CanBuildFrom[Source[A], B1, Source[B1]],
cbf2: CanBuildFrom[Source[A], B2, Source[B2]],
cbf3: CanBuildFrom[Source[A], B3, Source[B3]]): (Source[B1], Source[B2], Source[B3]) =
(implicit cbf1: BuildFrom[Source[A], B1, Source[B1]],
cbf2: BuildFrom[Source[A], B2, Source[B2]],
cbf3: BuildFrom[Source[A], B3, Source[B3]]): (Source[B1], Source[B2], Source[B3]) =
{
val b1 = cbf1()
val b2 = cbf2()
val b3 = cbf3()
val b1 = cbf1.newBuilder(xs)
val b2 = cbf2.newBuilder(xs)
val b3 = cbf3.newBuilder(xs)
for (x <- xs) {
val (y1, y2, y3) = f(x)
b1 += y1; b2 += y2; b3 += y3
}
(b1.result(), b2.result(), b3.result())
}

def distinctBy[K](key: A => K)(implicit cbf: CanBuildFrom[Source[A], A, Source[A]]): Source[A] = {
def distinctBy[K](key: A => K)(implicit cbf: BuildFrom[Source[A], A, Source[A]]): Source[A] = {
val keys = mutable.Set[K]()
val b = cbf()
val b = cbf.newBuilder(xs)
for (x <- xs) {
val k = key(x)
if (!keys.contains(k)) {
Expand All @@ -308,22 +308,22 @@ object CollectionUtil {
/** Apply m for each element of this collection, group by key and reduce each group using r.
* @returns one item for each group in a new collection of (K,V) pairs. */
def mapReduce[K, V](map: A => (K, V))(reduce: (V, V) => V)
(implicit cbf: CanBuildFrom[Source[A], (K,V), Source[(K,V)]]): Source[(K, V)] = {
(implicit cbf: BuildFrom[Source[A], (K,V), Source[(K,V)]]): Source[(K, V)] = {
val result = scala.collection.mutable.LinkedHashMap.empty[K, V]
xs.foldLeft(result)((r, x) => {
val (key, value) = map(x)
result.update(key, if (result.contains(key)) reduce(result(key), value) else value)
result
})
val b = cbf()
val b = cbf.newBuilder(xs)
for (kv <- result) b += kv
b.result()
}

def mergeWith[K]
(ys: Source[A], key: A => K, merge: (A,A) => A)
(implicit cbf: CanBuildFrom[Source[A], A, Source[A]]): Source[A] = {
val b = cbf()
(implicit cbf: BuildFrom[Source[A], A, Source[A]]): Source[A] = {
val b = cbf.newBuilder(xs)
for (v <- (xs ++ ys).mapReduce(x => (key(x), x))(merge))
b += v._2
b.result()
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/scalan/util/GraphUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scalan.util

import scalan.DFunc
import debox.{Set => DSet, Buffer => DBuffer}
import spire.syntax.all.cfor
import debox.cfor
import scala.reflect.ClassTag

object GraphUtil {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/scalan/util/ProcessUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ProcessUtil {
)
(builder ! logger) match {
case 0 =>
ProcessOutput(stdOutBuffer, stdErrBuffer, interleavedBuffer)
ProcessOutput(stdOutBuffer.toSeq, stdErrBuffer.toSeq, interleavedBuffer.toSeq)
case exitCode =>
val envPrefix = extraEnv.map {
case (name, value) => s"$name=${escapeCommandLineArg(value)} "
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/scalan/util/StringUtil.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scalan.util

import spire.syntax.all.cfor
import debox.cfor

object StringUtil {
final def quote(x: Any) = "\"" + x + "\""
Expand Down
4 changes: 2 additions & 2 deletions common/src/test/scala/sigmastate/VersionTesting.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sigmastate

import spire.syntax.all.cfor
import debox.cfor

import scala.util.DynamicVariable

Expand All @@ -10,7 +10,7 @@ trait VersionTesting {
* In the branch for v6.0 the new version 3 should be added so that the tests run for both.
*/
protected val activatedVersions: Seq[Byte] =
(0 to VersionContext.MaxSupportedScriptVersion).map(_.toByte).toArray
(0 to VersionContext.MaxSupportedScriptVersion).map(_.toByte).toArray[Byte]

private[sigmastate] val _currActivatedVersion = new DynamicVariable[Byte](2) // v5.x by default

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/scala/scalan/Base.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package scalan
import java.lang.reflect.{Constructor => Constr}
import java.util.Arrays
import scalan.OverloadHack.Overloaded1

import scala.language.implicitConversions
import scala.annotation.implicitNotFound
import scala.annotation.unchecked.uncheckedVariance
import scalan.compilation.GraphVizConfig
import scalan.util.StringUtil
import debox.{Buffer => DBuffer}
import spire.syntax.all.cfor
import debox.{cfor, Buffer => DBuffer}

import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable

/**
Expand Down Expand Up @@ -467,7 +469,7 @@ abstract class Base { scalan: Scalan =>
* and leave non-Ref items unchanged. */
final def apply(xs: Seq[Any])(implicit o: Overloaded1): Seq[Any] = {
val len = xs.length
if (len == 0) mutable.WrappedArray.empty
if (len == 0) ArraySeq.empty
else {
val res = new Array[Any](len)
cfor(0)(_ < len, _ + 1) { i =>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalan/MethodCalls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.reflect.ClassTag
import scalan.compilation.{GraphVizConfig, GraphVizExport}
import scalan.util.ScalaNameUtil
import debox.{Buffer => DBuffer}
import spire.syntax.all.cfor
import debox.cfor

trait MethodCalls extends Base with GraphVizExport { self: Scalan =>

Expand Down
Loading

0 comments on commit dce7705

Please sign in to comment.