Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into v5.0.9-RC
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.sbt
#	common/shared/src/main/scala/scalan/util/ReflectionUtil.scala
#	graph-ir/src/main/scala/scalan/TypeDescs.scala
  • Loading branch information
aslesarenko committed Jun 8, 2023
2 parents 18d9e4c + 50ce9da commit 8170ff7
Show file tree
Hide file tree
Showing 171 changed files with 3,373 additions and 1,456 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,55 @@ jobs:
env:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

buildJs:
name: JS - Test and publish a snapshot
env:
HAS_SECRETS: ${{ secrets.SONATYPE_PASSWORD != '' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.10]
java: [adopt@1.8]
node-version: [16.x]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup NPM
uses: pnpm/action-setup@v2
with:
version: 7.21.0
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- run: pnpm install --prefix sigma-js

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Runs tests and collect coverage
run: sbt -jvm-opts ci/ci.jvmopts ++${{ matrix.scala }} commonJS/test corelibJS/test interpreterJS/test

- name: Publish a snapshot ${{ github.ref }}
if: env.HAS_SECRETS == 'true'
run: sbt ++${{ matrix.scala }} sdkJS/publish
env:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
76 changes: 75 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,78 @@
# Contributing

## Building

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
sbt:sigma-state> testOnly <full test class name>
```

## Releasing

### Setup GPG key

Follow [instructions](https://central.sonatype.org/publish/requirements/gpg/) to set up GPG key.
You will need:
- create a GPG key pair;
- publish your public key to a public key server;

### Check Sonatype credentials
Try to login to Nexus Repository Manager with your credentials [here](https://oss.sonatype.org/#welcome)

### Using Sonatype with SBT

Follow [instructions](https://www.scala-sbt.org/release/docs/Using-Sonatype.html) to set up Sonatype with SBT.
You will also need:
- [how to publish a release](https://docs.scala-lang.org/overviews/contributors/index.html#publish-a-release)
- [sbt-sonatype plugin](https://github.com/xerial/sbt-sonatype)
- [sbt-dynver plugin](https://github.com/sbt/sbt-dynver)

### Publishing release
This can be done manually or automatically by Github Actions.

#### Manual publishing
To publish release to Sonatype, use the following:
```
$sbt
sbt:sigma-state> +publishSigned
sbt:sigma-state> sonatypeBundleRelease
```

#### Automatic publishing
To publish release version to Sonatype, do the following:
- make a tag with version number `vX.Y.Z` (used by `sbt-dynver` to set `version` in `build.sbt`);
- make a tag with version number `vX.Y.Z` (used by `sbt-dynver` to set `version` key);
- use the new tag to make a Github release, which triggers [`release.yml`](.github/workflows/release.yml) workflow and publishes release version to Sonatype;
62 changes: 49 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,59 @@ This library is
on Maven repository and can be added to the SBT configuration of Scala project.

```scala
libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "4.0.3"
libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "5.0.6"
```

## Repository Organization

| sub-module | description |
|---|-----|
| common | Used in all other submodules and contain basic utility classes |
| core | Implementation of graph-based intermediate representation of ErgoTree, which is used in cost estimation and interpretation |
| docs | Collection of documents |
| library | Implementation of graph IR nodes for Coll, Size and other types |
| library-api | Declarations of interfaces |
| library-impl | Implementation of interfaces |
| sigma-api | Declarations of runtime interfaces which are used in ErgoTree interpreter |
| sigma-impl | Implementation of sigma-api interfaces |
| sigma-library | Implementation of graph IR nodes for Sigma types |
| sigmastate | Implementation ErgoTree, Interpreter and cost estimation |
| sub-module | description |
|-------------|-------------------------------------------------------------------------------------------|
| common | Used in all other submodules and contain basic utility classes |
| core-lib | Contains core classes such as Coll, BigInt used by interpreter |
| docs | Collection of documents |
| graph-ir | Implementation of graph-based intermediate representation of ErgoTree, which is used in by ErgoScript compiler |
| interpreter | Implementation of ErgoTree Interpreter |
| sc | Implementation of ErgoScript compiler |

## 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.

<img src="https://www.yourkit.com/images/yklogo.png"/>

We thank YourKit for support of open source projects with its full-featured Java Profiler.
YourKit, LLC is the creator of <a href="https://www.yourkit.com/java/profiler/">YourKit Java Profiler</a>
and <a href="https://www.yourkit.com/.net/profiler/">YourKit .NET Profiler</a>,
innovative and intelligent tools for profiling Java and .NET applications.

## References

Expand Down
42 changes: 30 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ lazy val allConfigDependency = "compile->compile;test->test"

lazy val commonSettings = Seq(
organization := "org.scorexfoundation",
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Ywarn-unused:_,imports", "-Ywarn-unused:imports", "-release", "8")
case Some((2, 12)) => Seq("-Ywarn-unused:_,imports", "-Ywarn-unused:imports", "-release", "8")
case Some((2, 11)) => Seq()
case _ => sys.error("Unsupported scala version")
}
},
javacOptions ++= javacReleaseOption,
resolvers += Resolver.sonatypeRepo("public"),
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),
homepage := Some(url("https://github.com/ScorexFoundation/sigmastate-interpreter")),
Expand Down Expand Up @@ -47,28 +56,36 @@ lazy val commonSettings = Seq(

lazy val crossScalaSettings = Seq(
crossScalaVersions := Seq(scala213, scala212, scala211),
scalaVersion := scala212
scalaVersion := scala213
)
lazy val crossScalaSettingsJS = Seq(
crossScalaVersions := Seq(scala213, scala212),
scalaVersion := scala212
scalaVersion := scala213
)

// prefix version with "-SNAPSHOT" for builds without a git tag
def javacReleaseOption = {
if (System.getProperty("java.version").startsWith("1."))
// java <9 "--release" is not supported
Seq()
else
Seq("--release", "8")
}

// suffix version with "-SNAPSHOT" for builds without a git tag
dynverSonatypeSnapshots in ThisBuild := true
// use "-" instead of default "+"
dynverSeparator in ThisBuild := "-"

val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.66"

val scrypto = "org.scorexfoundation" %% "scrypto" % "2.3.0"
def scryptoDependency = {
libraryDependencies +=
"org.scorexfoundation" %%% "scrypto" % "2.3.0"
}
val scryptoDependency =
libraryDependencies += "org.scorexfoundation" %%% "scrypto" % "2.3.0"

val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.2.0"
val scorexUtilDependency =
libraryDependencies += "org.scorexfoundation" %%% "scorex-util" % "0.2.0"

val debox = "org.scorexfoundation" %% "debox" % "0.10.0"
val spireMacros = "org.typelevel" %% "spire-macros" % "0.17.0-M1"

Expand Down Expand Up @@ -185,15 +202,14 @@ lazy val corelib = crossProject(JVMPlatform, JSPlatform)
commonDependenies2,
testingDependencies2,
crossScalaSettings,
scryptoDependency,
publish / skip := true
)
.jvmSettings(
crossScalaSettings,
scryptoDependency
crossScalaSettings
)
.jsSettings(
crossScalaSettingsJS,
scryptoDependency,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0"
),
Expand Down Expand Up @@ -222,8 +238,7 @@ lazy val interpreter = crossProject(JVMPlatform, JSPlatform)
.jsSettings(
crossScalaSettingsJS,
libraryDependencies ++= Seq (
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0").cross(CrossVersion.for3Use2_13)
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0"
),
useYarn := true
)
Expand All @@ -234,6 +249,9 @@ lazy val interpreterJS = interpreter.js
// how to setup ScalablyTyped https://youtu.be/hWUAVrNj65c?t=1397
externalNpm := {println(s"baseDirectory: ${baseDirectory.value}"); file(s"${baseDirectory.value}/../../sigma-js") },
stIgnore ++= List("bouncycastle-js"),
scalaJSLinkerConfig ~= { conf =>
conf.withSourceMap(false)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion
)
Expand Down
50 changes: 50 additions & 0 deletions common/js/src/main/scala/scalan/reflection/Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package scalan.reflection

import scala.collection.mutable

/** JS Platform dependent implementation of reflection methods. */
object Platform {
/** Returns an RClass instance for the given class.
*
* @param clazz The class for which to retrieve an RClass instance.
* @tparam T The type of the class.
* @return An RClass instance for the given class.
* @throws java.lang.RuntimeException if RClass metadata for the given class cannot be
* found.
*/
def resolveClass[T](clazz: Class[T]): RClass[T] = {
val res = CommonReflection.classes.get(clazz) match {
case Some(c) =>
assert(c.clazz == clazz)
c
case _ =>
sys.error(s"Cannot find RClass data for $clazz")
// Uncomment the following line to collect missing reflection data and generate Scala code for it
// memoize(classes)(clazz, new JRClass[T](clazz))
}
res.asInstanceOf[RClass[T]]
}

/** A cache that stores key-value pairs using HashMap.
* This class is thread-safe using the synchronized access to the underlying HashMap
* instance.
*
* @tparam K the type of keys used in the cache
* @tparam V the type of values stored in the cache
*/
class Cache[K, V] {
private val map = mutable.HashMap.empty[K, V]

/** Retrieves the value associated with the given key from the cache or
* computes and stores the value if the key is not present in the cache.
* This method is thread-safe using the synchronized block.
*
* @param key the key to look up or store in the cache
* @param value a by-name parameter that computes the value to be stored if the key is not present
* @return the value associated with the key, either retrieved or computed
*/
def getOrElseUpdate(key: K, value: => V): V = synchronized {
map.getOrElseUpdate(key, value)
}
}
}
Loading

0 comments on commit 8170ff7

Please sign in to comment.