Skip to content

Commit

Permalink
Merge pull request #751 from ScorexFoundation/develop
Browse files Browse the repository at this point in the history
Release v4.0.5
  • Loading branch information
aslesarenko authored Dec 1, 2021
2 parents 00ffd55 + 8262706 commit 44253ac
Show file tree
Hide file tree
Showing 93 changed files with 4,634 additions and 1,055 deletions.
64 changes: 8 additions & 56 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.language.postfixOps
import scala.util.Try
import scala.sys.process._

organization := "org.scorexfoundation"
Expand Down Expand Up @@ -55,17 +54,11 @@ 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 macroCompat = "org.typelevel" %% "macro-compat" % "1.1.1"
val paradise = "org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full
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 commonsIo = "commons-io" % "commons-io" % "2.5"

val specialVersion = "0.6.1"
val meta = "io.github.scalan" %% "meta" % specialVersion
val plugin = "io.github.scalan" %% "plugin" % specialVersion
val libraryconf = "io.github.scalan" %% "library-conf" % specialVersion
val commonsMath3 = "org.apache.commons" % "commons-math3" % "3.2"

val testingDependencies = Seq(
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
Expand Down Expand Up @@ -144,11 +137,7 @@ pgpSecretRing := file("ci/secring.asc")
pgpPassphrase := sys.env.get("PGP_PASSPHRASE").map(_.toArray)
usePgpKeyHex("C1FD62B4D44BDF702CDF2B726FF59DA944B150DD")

def libraryDefSettings = commonSettings ++ testSettings ++ Seq(
scalacOptions ++= Seq(
// s"-Xplugin:${file(".").absolutePath }/scalanizer/target/scala-2.12/scalanizer-assembly-core-opt-0d03a785-SNAPSHOT.jar"
)
)
def libraryDefSettings = commonSettings ++ testSettings

lazy val common = Project("common", file("common"))
.settings(commonSettings ++ testSettings,
Expand All @@ -160,9 +149,8 @@ lazy val common = Project("common", file("common"))

lazy val libraryapi = Project("library-api", file("library-api"))
.dependsOn(common % allConfigDependency)
.settings(libraryDefSettings :+ addCompilerPlugin(paradise),
libraryDependencies ++= Seq(
))
.settings(libraryDefSettings,
libraryDependencies ++= Seq())
.settings(publish / skip := true)

lazy val libraryimpl = Project("library-impl", file("library-impl"))
Expand All @@ -184,46 +172,11 @@ lazy val library = Project("library", file("library"))
libraryDependencies ++= Seq( debox ))
.settings(publish / skip := true)

lazy val sigmaconf = Project("sigma-conf", file("sigma-conf"))
.settings(commonSettings,
libraryDependencies ++= (
if(scalaBinaryVersion.value == "2.11")
Seq.empty
else
Seq(plugin, libraryconf)
),
skip in compile := scalaBinaryVersion.value == "2.11"
)
.settings(publish / skip := true)

lazy val scalanizer = Project("scalanizer", file("scalanizer"))
.dependsOn(sigmaconf, libraryapi, libraryimpl)
.settings(commonSettings,
libraryDependencies ++= (
if(scalaBinaryVersion.value == "2.11")
Seq.empty
else
Seq(meta, plugin)
),
skip in compile := scalaBinaryVersion.value == "2.11",
assemblyOption in assembly ~= { _.copy(includeScala = false, includeDependency = true) },
assemblyMergeStrategy in assembly := {
case PathList("scalan", xs @ _*) => MergeStrategy.first
case other => (assemblyMergeStrategy in assembly).value(other)
},
artifact in(Compile, assembly) := {
val art = (artifact in(Compile, assembly)).value
art.withClassifier(Some("assembly"))
},
addArtifact(artifact in(Compile, assembly), assembly)
)
.settings(publish / skip := true)

lazy val sigmaapi = Project("sigma-api", file("sigma-api"))
.dependsOn(common, libraryapi)
.settings(libraryDefSettings :+ addCompilerPlugin(paradise),
.settings(libraryDefSettings,
libraryDependencies ++= Seq(
macroCompat, scrypto, bouncycastleBcprov
scrypto, bouncycastleBcprov
))
.settings(publish / skip := true)

Expand Down Expand Up @@ -256,7 +209,7 @@ lazy val sigmastate = (project in file("sigmastate"))
.dependsOn(sigmaimpl % allConfigDependency, sigmalibrary % allConfigDependency)
.settings(libraryDefSettings)
.settings(libraryDependencies ++= Seq(
scorexUtil, kiama, fastparse,
scorexUtil, kiama, fastparse, commonsMath3,
if (scalaVersion.value == scala211) circeCore211 else circeCore,
if (scalaVersion.value == scala211) circeGeneric211 else circeGeneric,
if (scalaVersion.value == scala211) circeParser211 else circeParser
Expand All @@ -266,7 +219,7 @@ lazy val sigmastate = (project in file("sigmastate"))
lazy val sigma = (project in file("."))
.aggregate(
sigmastate, common, core, libraryapi, libraryimpl, library,
sigmaapi, sigmaimpl, sigmalibrary, sigmaconf, scalanizer)
sigmaapi, sigmaimpl, sigmalibrary)
.settings(libraryDefSettings, rootSettings)
.settings(publish / aggregate := false)
.settings(publishLocal / aggregate := false)
Expand Down Expand Up @@ -342,7 +295,6 @@ commands += Command.command("ergoItTest") { state =>
def runSpamTestTask(task: String, sigmastateVersion: String, log: Logger): Unit = {
val spamBranch = "master"
val envVars = Seq("SIGMASTATE_VERSION" -> sigmastateVersion,
"SPECIAL_VERSION" -> specialVersion,
// SSH_SPAM_REPO_KEY should be set (see Jenkins Credentials Binding Plugin)
"GIT_SSH_COMMAND" -> "ssh -i $SSH_SPAM_REPO_KEY")

Expand Down
159 changes: 159 additions & 0 deletions common/src/main/java/java7/compat/Math.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java7.compat;

/**
* Contains methods introduced since Java 1.8 which are not available in Java 1.7.
* Using this methods supports compatibility with Java 1.7 in non-JVM contexts like
* RoboVM.
* The implementations are copies from JDK 1.8 sources.
* <p>
* See
* <a href="https://github.com/ScorexFoundation/sigmastate-interpreter/issues/735">this issue</a>
*/
public final class Math {
/**
* Returns the sum of its arguments,
* throwing an exception if the result overflows an {@code int}.
*
* @param x the first value
* @param y the second value
* @return the result
* @throws ArithmeticException if the result overflows an int
* @since 1.8
*/
public static int addExact(int x, int y) {
int r = x + y;
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
if (((x ^ r) & (y ^ r)) < 0) {
throw new ArithmeticException("integer overflow");
}
return r;
}

/**
* Returns the sum of its arguments,
* throwing an exception if the result overflows a {@code long}.
*
* @param x the first value
* @param y the second value
* @return the result
* @throws ArithmeticException if the result overflows a long
* @since 1.8
*/
public static long addExact(long x, long y) {
long r = x + y;
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
if (((x ^ r) & (y ^ r)) < 0) {
throw new ArithmeticException("long overflow");
}
return r;
}

/**
* Returns the difference of the arguments,
* throwing an exception if the result overflows an {@code int}.
*
* @param x the first value
* @param y the second value to subtract from the first
* @return the result
* @throws ArithmeticException if the result overflows an int
* @since 1.8
*/
public static int subtractExact(int x, int y) {
int r = x - y;
// HD 2-12 Overflow iff the arguments have different signs and
// the sign of the result is different than the sign of x
if (((x ^ y) & (x ^ r)) < 0) {
throw new ArithmeticException("integer overflow");
}
return r;
}

/**
* Returns the difference of the arguments,
* throwing an exception if the result overflows a {@code long}.
*
* @param x the first value
* @param y the second value to subtract from the first
* @return the result
* @throws ArithmeticException if the result overflows a long
* @since 1.8
*/
public static long subtractExact(long x, long y) {
long r = x - y;
// HD 2-12 Overflow iff the arguments have different signs and
// the sign of the result is different than the sign of x
if (((x ^ y) & (x ^ r)) < 0) {
throw new ArithmeticException("long overflow");
}
return r;
}

/**
* Returns the product of the arguments,
* throwing an exception if the result overflows an {@code int}.
*
* @param x the first value
* @param y the second value
* @return the result
* @throws ArithmeticException if the result overflows an int
* @since 1.8
*/
public static int multiplyExact(int x, int y) {
long r = (long)x * (long)y;
if ((int)r != r) {
throw new ArithmeticException("integer overflow");
}
return (int)r;
}

/**
* Returns the product of the arguments,
* throwing an exception if the result overflows a {@code long}.
*
* @param x the first value
* @param y the second value
* @return the result
* @throws ArithmeticException if the result overflows a long
* @since 1.8
*/
public static long multiplyExact(long x, long y) {
long r = x * y;
long ax = java.lang.Math.abs(x);
long ay = java.lang.Math.abs(y);
if (((ax | ay) >>> 31 != 0)) {
// Some bits greater than 2^31 that might cause overflow
// Check the result using the divide operator
// and check for the special case of Long.MIN_VALUE * -1
if (((y != 0) && (r / y != x)) ||
(x == Long.MIN_VALUE && y == -1)) {
throw new ArithmeticException("long overflow");
}
}
return r;
}
}
9 changes: 9 additions & 0 deletions common/src/main/scala/scalan/AnyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,14 @@ class AVHashMap[K,V](val hashMap: HashMap[K,V]) extends AnyVal {
object AVHashMap {
/** Helper method to create a new map with the given capacity. */
def apply[K,V](initialCapacity: Int) = new AVHashMap[K,V](new HashMap[K,V](initialCapacity))

/** Helper method to create a new map from the sequence of K, V pairs. */
def fromSeq[K,V](items: Seq[(K, V)]): AVHashMap[K,V] = {
val map = new AVHashMap[K,V](new HashMap[K,V](items.length))
items.foreach { case (k, v) =>
map.put(k, v)
}
map
}
}

63 changes: 34 additions & 29 deletions common/src/main/scala/scalan/ExactIntegral.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,61 @@ package scalan

import scalan.util.Extensions._

import scala.math.Numeric.{ByteIsIntegral, LongIsIntegral, ShortIsIntegral, IntIsIntegral}

/** Integral operations with overflow checks.
* Raise exception when overflow is detected.
* Each instance of this typeclass overrides three methods `plus`, `minus`, `times`.
* All other methods are implemented by delegating to the corresponding Integral instance from
* standard Scala library.
/** Type-class which defines the operations on Integral types (Byte, Short, Int, Long, BigInt)
* with overflow checks.
*
* An exception is raised when an overflow is detected.
* Each concrete instance of this type-class overrides three methods `plus`, `minus`,
* `times`.
*
* By default all the methods are implemented by delegating to the corresponding Integral
* instance from the standard Scala library.
*
* This trait is used in core IR to avoid implicitly using standard scala implementations.
*/
trait ExactIntegral[T] extends Integral[T] {
val n: Integral[T]
override def quot(x: T, y: T): T = n.quot(x, y)
override def rem(x: T, y: T): T = n.rem(x, y)
override def negate(x: T): T = n.negate(x)
override def fromInt(x: Int): T = n.fromInt(x)
override def toInt(x: T): Int = n.toInt(x)
override def toLong(x: T): Long = n.toLong(x)
override def toFloat(x: T): Float = n.toFloat(x)
override def toDouble(x: T): Double = n.toDouble(x)
override def compare(x: T, y: T): Int = n.compare(x, y)
trait ExactIntegral[T] extends ExactNumeric[T] {
protected val n: scala.math.Integral[T]

/** Integer division operation `x / y`. */
def quot(x: T, y: T): T = n.quot(x, y)

/** Operation which returns remainder from dividing x by y.
* The exact rules are defined in the concrete instance of the type T.
* A default implementation delegates to Integral[T].rem method for the corresponding
* type T.
* The default implementation can be overridden for any concrete type T.
*/
def divisionRemainder(x: T, y: T): T = n.rem(x, y)
}

/** ExactNumeric instances for all types. */
/** ExactIntegral instances for all types. */
object ExactIntegral {

implicit object ByteIsExactIntegral extends ExactIntegral[Byte] {
val n = ByteIsIntegral
val n = scala.math.Numeric.ByteIsIntegral
override def plus(x: Byte, y: Byte): Byte = x.addExact(y)
override def minus(x: Byte, y: Byte): Byte = x.subtractExact(y)
override def times(x: Byte, y: Byte): Byte = x.multiplyExact(y)
}

implicit object ShortIsExactIntegral extends ExactIntegral[Short] {
val n = ShortIsIntegral
val n = scala.math.Numeric.ShortIsIntegral
override def plus(x: Short, y: Short): Short = x.addExact(y)
override def minus(x: Short, y: Short): Short = x.subtractExact(y)
override def times(x: Short, y: Short): Short = x.multiplyExact(y)
}

implicit object IntIsExactIntegral extends ExactIntegral[Int] {
val n = IntIsIntegral
override def plus(x: Int, y: Int): Int = Math.addExact(x, y)
override def minus(x: Int, y: Int): Int = Math.subtractExact(x, y)
override def times(x: Int, y: Int): Int = Math.multiplyExact(x, y)
val n = scala.math.Numeric.IntIsIntegral
override def plus(x: Int, y: Int): Int = java7.compat.Math.addExact(x, y)
override def minus(x: Int, y: Int): Int = java7.compat.Math.subtractExact(x, y)
override def times(x: Int, y: Int): Int = java7.compat.Math.multiplyExact(x, y)
}

implicit object LongIsExactIntegral extends ExactIntegral[Long] {
val n = LongIsIntegral
override def plus(x: Long, y: Long): Long = Math.addExact(x, y)
override def minus(x: Long, y: Long): Long = Math.subtractExact(x, y)
override def times(x: Long, y: Long): Long = Math.multiplyExact(x, y)
val n = scala.math.Numeric.LongIsIntegral
override def plus(x: Long, y: Long): Long = java7.compat.Math.addExact(x, y)
override def minus(x: Long, y: Long): Long = java7.compat.Math.subtractExact(x, y)
override def times(x: Long, y: Long): Long = java7.compat.Math.multiplyExact(x, y)
}
}
Loading

0 comments on commit 44253ac

Please sign in to comment.