Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/series/3.x' into topic/ref-access
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Jun 16, 2022
2 parents 288317d + 57899cb commit 3e40f68
Show file tree
Hide file tree
Showing 75 changed files with 2,031 additions and 508 deletions.
87 changes: 59 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
branches: [series/3.*]
push:
branches: [series/3.*]
tags: [v*]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -23,25 +24,19 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
scala: [3.0.2, 2.12.15, 2.13.8]
java:
- temurin@8
- temurin@11
- temurin@17
- graal_21.3.0@11
java: [temurin@8, temurin@11, temurin@17, graalvm@11]
ci: [ciJVM, ciJS, ciFirefox, ciChrome]
exclude:
- scala: 3.0.2
java: temurin@11
- scala: 3.0.2
java: temurin@17
- scala: 3.0.2
java: graal_21.3.0@11
java: graalvm@11
- scala: 2.12.15
java: temurin@11
- scala: 2.12.15
java: temurin@17
- scala: 2.12.15
java: graal_21.3.0@11
java: graalvm@11
- os: windows-latest
scala: 3.0.2
- os: macos-latest
Expand All @@ -63,7 +58,7 @@ jobs:
- ci: ciJS
java: temurin@17
- ci: ciJS
java: graal_21.3.0@11
java: graalvm@11
- os: windows-latest
ci: ciJS
- os: macos-latest
Expand All @@ -73,7 +68,7 @@ jobs:
- ci: ciFirefox
java: temurin@17
- ci: ciFirefox
java: graal_21.3.0@11
java: graalvm@11
- os: windows-latest
ci: ciFirefox
- os: macos-latest
Expand All @@ -83,13 +78,13 @@ jobs:
- ci: ciChrome
java: temurin@17
- ci: ciChrome
java: graal_21.3.0@11
java: graalvm@11
- os: windows-latest
ci: ciChrome
- os: macos-latest
ci: ciChrome
- os: windows-latest
java: graal_21.3.0@11
java: graalvm@11
runs-on: ${{ matrix.os }}
steps:
- name: Ignore line ending differences in git
Expand All @@ -98,37 +93,73 @@ jobs:
run: git config --global core.autocrlf false

- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@8)
id: download-java-temurin-8
if: matrix.java == 'temurin@8'
uses: typelevel/download-java@v1
with:
distribution: temurin
java-version: 8

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v2
with:
distribution: temurin
distribution: jdkfile
java-version: 8
jdkFile: ${{ steps.download-java-temurin-8.outputs.jdkFile }}

- name: Download Java (temurin@11)
id: download-java-temurin-11
if: matrix.java == 'temurin@11'
uses: typelevel/download-java@v1
with:
distribution: temurin
java-version: 11

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
distribution: temurin
distribution: jdkfile
java-version: 11
jdkFile: ${{ steps.download-java-temurin-11.outputs.jdkFile }}

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v1
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v2
with:
distribution: temurin
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Download Java (graalvm@11)
id: download-java-graalvm-11
if: matrix.java == 'graalvm@11'
uses: typelevel/download-java@v1
with:
distribution: graalvm
java-version: 11

- name: Setup GraalVM (graal_21.3.0@11)
if: matrix.java == 'graal_21.3.0@11'
uses: DeLaGuardo/setup-graalvm@5.0
- name: Setup Java (graalvm@11)
if: matrix.java == 'graalvm@11'
uses: actions/setup-java@v2
with:
graalvm: 21.3.0
java: java11
distribution: jdkfile
java-version: 11
jdkFile: ${{ steps.download-java-graalvm-11.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v2
Expand All @@ -142,11 +173,11 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Setup NodeJS v14 LTS
- name: Setup NodeJS v16 LTS
if: matrix.ci == 'ciJS'
uses: actions/setup-node@v2.4.0
with:
node-version: 14
node-version: 16

- name: Install jsdom and source-map-support
if: matrix.ci == 'ciJS'
Expand All @@ -155,19 +186,19 @@ jobs:

- name: Check that workflows are up to date
shell: bash
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
run: sbt '++${{ matrix.scala }}' 'project /' githubWorkflowCheck

- name: Check that scalafix has been run
if: matrix.scala != '3.0.2'
shell: bash
run: sbt ++${{ matrix.scala }} 'root/scalafixAll --check'
run: sbt '++${{ matrix.scala }}' 'root/scalafixAll --check'

- shell: bash
run: sbt ++${{ matrix.scala }} '${{ matrix.ci }}'
run: sbt '++${{ matrix.scala }}' '${{ matrix.ci }}'

- if: (matrix.scala == '2.13.8' || matrix.scala == '3.0.2') && matrix.ci == 'ciJVM'
shell: bash
run: sbt ++${{ matrix.scala }} docs/mdoc
run: sbt '++${{ matrix.scala }}' docs/mdoc

- name: Test Example JVM App Within Sbt
if: matrix.ci == 'ciJVM' && matrix.os == 'ubuntu-latest'
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.4.3
version = 3.5.8

runner.dialect = Scala213Source3
fileOverride {
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

## Getting Started

- Wired: **3.3.8**
- Tired: **2.5.4**
- Wired: **3.3.12**
- Tired: **2.5.5** (end of life)

```scala
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.3.8"
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.3.12"
```

The above represents the core, stable dependency which brings in the entirety of Cats Effect. This is *most likely* what you want. All current Cats Effect releases are published for Scala 2.12, 2.13, 3.0, and Scala.js 1.7.
Expand All @@ -30,22 +30,22 @@ Depending on your use-case, you may want to consider one of the several other mo

```scala
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect-kernel" % "3.3.8",
"org.typelevel" %% "cats-effect-laws" % "3.3.8" % Test)
"org.typelevel" %% "cats-effect-kernel" % "3.3.12",
"org.typelevel" %% "cats-effect-laws" % "3.3.12" % Test)
```

If you're a middleware framework (like [Fs2](https://fs2.io/)), you probably want to depend on **std**, which gives you access to `Queue`, `Semaphore`, and much more without introducing a hard-dependency on `IO` outside of your tests:

```scala
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect-std" % "3.3.8",
"org.typelevel" %% "cats-effect" % "3.3.8" % Test)
"org.typelevel" %% "cats-effect-std" % "3.3.12",
"org.typelevel" %% "cats-effect" % "3.3.12" % Test)
```

You may also find some utility in the **testkit** and **kernel-testkit** projects, which contain `TestContext`, generators for `IO`, and a few other things:

```scala
libraryDependencies += "org.typelevel" %% "cats-effect-testkit" % "3.3.8" % Test
libraryDependencies += "org.typelevel" %% "cats-effect-testkit" % "3.3.12" % Test
```

Cats Effect provides backward binary compatibility within the 2.x and 3.x version lines, and both forward and backward compatibility within any major/minor line. This is analogous to the versioning scheme used by Cats itself, as well as other major projects such as Scala.js. Thus, any project depending upon Cats Effect 2.2.1 can be used with libraries compiled against Cats Effect 2.0.0 or 2.2.3, but *not* with libraries compiled against 2.3.0 or higher.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class AsyncBenchmark {
@Benchmark
def start() = {
def loop(i: Int): IO[Int] =
if (i < size)(IO(i + 1)).start.flatMap(_.joinWithNever).flatMap(loop)
if (i < size) IO(i + 1).start.flatMap(_.joinWithNever).flatMap(loop)
else
IO.pure(i)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class DispatcherBenchmark {
}
}))

Dispatcher[IO]
Dispatcher
.parallel[IO](await = false)
.use { disp =>
List
.range(0, size)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2020-2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cats.effect.benchmarks

import cats.effect.IO
import cats.effect.std.Random
import cats.effect.unsafe.implicits.global

import org.openjdk.jmh.annotations._

import java.util.concurrent.TimeUnit

/**
* To do comparative benchmarks between versions:
*
* benchmarks/run-benchmark RandomBenchmark
*
* This will generate results in `benchmarks/results`.
*
* Or to run the benchmark from within sbt:
*
* jmh:run -i 10 -wi 10 -f 2 -t 1 cats.effect.benchmarks.RandomBenchmark
*
* Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". Please note that
* benchmarks should be usually executed at least in 10 iterations (as a rule of thumb), but
* more is better.
*/
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
class RandomBenchmark {

@Param(Array("10000", "100000", "1000000"))
var size: Int = _

var list: List[Int] = _
var vector: Vector[Int] = _
var map: Map[String, Int] = _

@Setup
def setup(): Unit = {
list = (1 to size).toList
vector = (1 to size).toVector
map = (1 to size).map(x => (x.toString, x)).toMap
}

val random: Random[IO] = Random.scalaUtilRandom[IO].unsafeRunSync()

@Benchmark
def elementOfList(): Int = {
random.elementOf(list).unsafeRunSync()
}

@Benchmark
def elementOfVector(): Int = {
random.elementOf(vector).unsafeRunSync()
}

@Benchmark
def elementOfMap(): (String, Int) = {
random.elementOf(map).unsafeRunSync()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class WorkStealingBenchmark {
IO {
val size = math.max(100, math.min(n, 2000))
val array = new Array[AnyRef](size)
for (i <- (0 until size)) {
for (i <- 0 until size) {
array(i) = new AnyRef()
}
array
Expand Down Expand Up @@ -176,7 +176,7 @@ class WorkStealingBenchmark {
(Scheduler.fromScheduledExecutor(executor), () => executor.shutdown())
}

val compute = new WorkStealingThreadPool(256, "io-compute", 60.seconds)
val compute = new WorkStealingThreadPool(256, "io-compute", 60.seconds, _.printStackTrace())

val cancelationCheckThreshold =
System.getProperty("cats.effect.cancelation.check.threshold", "512").toInt
Expand Down
Loading

0 comments on commit 3e40f68

Please sign in to comment.