Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build warnings #2769

Merged
merged 10 commits into from
Dec 25, 2021
6 changes: 6 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ project.excludeFilters = [
"scalafix/*"
]

fileOverride {
"glob:**/scala-3/**" {
runner.dialect = scala3
}
}

docstrings.wrap = "no"

maxColumn = 100
Expand Down
4 changes: 2 additions & 2 deletions benchmark/src/main/scala/fs2/benchmark/ChannelBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChannelBenchmark {
var lists: List[List[Unit]] = _

@Setup
def setup() {
def setup() = {
list = List.fill(size)(())
val subList = List.fill(size / 8)(())
lists = List.fill(8)(subList)
Expand Down Expand Up @@ -70,7 +70,7 @@ class ChannelBenchmark {
.bounded[IO, Unit](size / 8)
.flatMap { channel =>
val action = sendAll(list, channel.send(()).start.void)
action *> channel.stream.take(size).through(blackHole).compile.drain
action *> channel.stream.take(size.toLong).through(blackHole).compile.drain
}
.unsafeRunSync()

Expand Down
18 changes: 5 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ ThisBuild / developers ++= List(

ThisBuild / fatalWarningsInCI := false

ThisBuild / Test / javaOptions ++= Seq(
"-Dscala.concurrent.context.minThreads=8",
"-Dscala.concurrent.context.numThreads=8",
"-Dscala.concurrent.context.maxThreads=8"
)
ThisBuild / Test / run / javaOptions ++= Seq("-Xms64m", "-Xmx64m")
ThisBuild / Test / parallelExecution := false

ThisBuild / initialCommands := s"""
Expand Down Expand Up @@ -169,7 +163,8 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[MissingClassProblem](
"fs2.io.net.SocketCompanionPlatform$IntCallbackHandler"
),
ProblemFilters.exclude[MissingClassProblem]("fs2.Chunk$BufferChunk")
ProblemFilters.exclude[MissingClassProblem]("fs2.Chunk$BufferChunk"),
ProblemFilters.exclude[DirectMissingMethodProblem]("fs2.Chunk.makeArrayBuilder")
)

lazy val root = project
Expand Down Expand Up @@ -235,16 +230,13 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
)
},
Compile / doc / scalacOptions ++= (if (scalaVersion.value.startsWith("2.")) Seq("-nowarn")
else Nil),
Compile / scalafmt / unmanagedSources := (Compile / scalafmt / unmanagedSources).value
.filterNot(_.toString.endsWith("NotGiven.scala")),
Test / scalafmt / unmanagedSources := (Test / scalafmt / unmanagedSources).value
.filterNot(_.toString.endsWith("NotGiven.scala"))
else Nil)
)

lazy val coreJVM = core.jvm
.settings(
Test / fork := true
Test / fork := true,
doctestIgnoreRegex := Some(".*NotGiven.scala")
)

lazy val coreJS = core.js
Expand Down
5 changes: 1 addition & 4 deletions core/shared/src/main/scala-2.12/fs2/ChunkPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package fs2

import scala.collection.mutable.{ArrayBuilder, WrappedArray}
import scala.collection.mutable.WrappedArray
import scala.reflect.ClassTag

private[fs2] trait ChunkPlatform[+O] { self: Chunk[O] => }
Expand All @@ -34,9 +34,6 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type =>
case _ => None
}

private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] =
ArrayBuilder.make()(ct)

/** Creates a chunk backed by a `WrappedArray`
*/
def wrappedArray[O](wrappedArray: WrappedArray[O]): Chunk[O] = {
Expand Down
6 changes: 5 additions & 1 deletion core/shared/src/main/scala-2.12/fs2/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
package fs2

import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.Builder
import scala.collection.mutable.{ArrayBuilder, Builder}
import scala.reflect.ClassTag

package object internal {
private[fs2] type Factory[-A, +C] = CanBuildFrom[Nothing, A, C]

private[fs2] implicit class FactoryOps[-A, +C](private val factory: Factory[A, C]) {
def newBuilder: Builder[A, C] = factory()
}

private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] =
ArrayBuilder.make()(ct)
}
4 changes: 0 additions & 4 deletions core/shared/src/main/scala-2.13/fs2/ChunkPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package fs2

import scala.collection.immutable.ArraySeq
import scala.collection.immutable
import scala.collection.mutable.ArrayBuilder
import scala.reflect.ClassTag

private[fs2] trait ChunkPlatform[+O] { self: Chunk[O] =>
Expand Down Expand Up @@ -54,9 +53,6 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type =>
case _ => None
}

private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] =
ArrayBuilder.make(ct)

/** Creates a chunk backed by an immutable `ArraySeq`.
*/
def arraySeq[O](arraySeq: immutable.ArraySeq[O]): Chunk[O] = {
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala-2.13/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

package fs2

import scala.reflect.ClassTag
import scala.collection.mutable.ArrayBuilder

package object internal {
private[fs2] type Factory[-A, +C] = scala.collection.Factory[A, C]

private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] =
ArrayBuilder.make(ct)
}
7 changes: 1 addition & 6 deletions core/shared/src/main/scala-3/fs2/ChunkPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package fs2

import scala.collection.immutable.ArraySeq
import scala.collection.immutable
import scala.collection.mutable.ArrayBuilder
import scala.reflect.ClassTag

private[fs2] trait ChunkPlatform[+O] { self: Chunk[O] =>
Expand Down Expand Up @@ -63,9 +62,6 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type =>
case _ => None
}

private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] =
ArrayBuilder.make(ct)

/** Creates a chunk backed by an immutable `ArraySeq`.
*/
def arraySeq[O](arraySeq: immutable.ArraySeq[O]): Chunk[O] = {
Expand All @@ -92,8 +88,7 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type =>
def apply(i: Int) = values(offset + i)

def copyToArray[O2 >: O](xs: Array[O2], start: Int): Unit =
if (xs.getClass eq ct.wrap.runtimeClass)
System.arraycopy(values, offset, xs, start, length)
if (xs.getClass eq ct.wrap.runtimeClass) System.arraycopy(values, offset, xs, start, length)
else {
values.iterator.slice(offset, offset + length).copyToArray(xs, start)
()
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala-3/fs2/compat/NotGiven.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
package fs2.compat

type NotGiven[+A] = scala.util.NotGiven[A]
val NotGiven = scala.util.NotGiven
val NotGiven = scala.util.NotGiven
6 changes: 6 additions & 0 deletions core/shared/src/main/scala-3/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

package fs2

import scala.reflect.ClassTag
import scala.collection.mutable.ArrayBuilder

package object internal {
private[fs2] type Factory[-A, +C] = scala.collection.Factory[A, C]

private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] =
ArrayBuilder.make(ct)
}
12 changes: 7 additions & 5 deletions core/shared/src/main/scala/fs2/Chunk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import cats.{Alternative, Applicative, Eq, Eval, Monad, Monoid, Traverse, Traver
import cats.data.{Chain, NonEmptyList}
import cats.syntax.all._

import fs2.internal._

/** Immutable, strict, finite sequence of values that supports efficient index-based random access of elements,
* is memory efficient for all sizes, and avoids unnecessary copying.
*
Expand Down Expand Up @@ -80,7 +82,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu

/** More efficient version of `filter(pf.isDefinedAt).map(pf)`. */
def collect[O2](pf: PartialFunction[O, O2]): Chunk[O2] = {
val b = Chunk.makeArrayBuilder[Any]
val b = makeArrayBuilder[Any]
b.sizeHint(size)
foreach(o => if (pf.isDefinedAt(o)) b += pf(o))
Chunk.array(b.result()).asInstanceOf[Chunk[O2]]
Expand Down Expand Up @@ -112,7 +114,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu

/** Returns a chunk that has only the elements that satisfy the supplied predicate. */
def filter(p: O => Boolean): Chunk[O] = {
val b = Chunk.makeArrayBuilder(thisClassTag)
val b = makeArrayBuilder(thisClassTag)
b.sizeHint(size)
foreach(e => if (p(e)) b += e)
Chunk.array(b.result()).asInstanceOf[Chunk[O]]
Expand Down Expand Up @@ -209,7 +211,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu

/** Maps the supplied function over each element and returns a chunk of just the defined results. */
def mapFilter[O2](f: O => Option[O2]): Chunk[O2] = {
val b = Chunk.makeArrayBuilder[Any]
val b = makeArrayBuilder[Any]
b.sizeHint(size)
foreach { o =>
val o2 = f(o)
Expand Down Expand Up @@ -333,7 +335,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu
*/
def toIndexedChunk: Chunk[O] = this match {
case _: Chunk.Queue[_] =>
val b = Chunk.makeArrayBuilder[Any]
val b = makeArrayBuilder[Any]
b.sizeHint(size)
foreach(o => b += o)
Chunk.array(b.result()).asInstanceOf[Chunk[O]]
Expand Down Expand Up @@ -612,7 +614,7 @@ object Chunk
else {
val head = itr.next()
if (itr.hasNext) {
val bldr = Chunk.makeArrayBuilder[Any]
val bldr = makeArrayBuilder[Any]
bldr += head
bldr ++= itr
array(bldr.result()).asInstanceOf[Chunk[O]]
Expand Down
14 changes: 7 additions & 7 deletions core/shared/src/main/scala/fs2/Pull.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ object Pull extends PullLowPriority {
* The `F` type must be explicitly provided (e.g., via `raiseError[IO]`
* or `raiseError[Fallible]`).
*/
@nowarn("cat=unused-params")
@nowarn // ("cat=unused-params") - unsupported category on scala 3
def raiseError[F[_]: RaiseThrowable](err: Throwable): Pull[F, INothing, INothing] = Fail(err)

/** Creates a pull that evaluates the supplied effect `fr`, emits no
Expand Down Expand Up @@ -649,7 +649,7 @@ object Pull extends PullLowPriority {
): Pull[F, O, Unit] =
view match {
case IdContP => fmoc
case bv: Bind[F, O, Unit, Unit] =>
case bv: Bind[F, O, Unit, Unit] @unchecked =>
fmoc match {
case r: Terminal[Unit] =>
try bv(r)
Expand Down Expand Up @@ -696,7 +696,7 @@ object Pull extends PullLowPriority {
* Each operation also generates an output of type `R` that is used
* as control information for the rest of the interpretation or compilation.
*/
private abstract class Action[+F[_], +O, +R] extends Pull[F, O, R] with ViewL[F, O]
private sealed abstract class Action[+F[_], +O, +R] extends Pull[F, O, R] with ViewL[F, O]

/* An action that emits a non-empty chunk of outputs. */
private final case class Output[+O](values: Chunk[O]) extends Action[Pure, O, Unit]
Expand Down Expand Up @@ -1165,8 +1165,8 @@ object Pull extends PullLowPriority {
}
}

viewL(stream) match {
case tst: Translate[h, G, _] @nowarn => // y = Unit
(viewL(stream): @unchecked) match { // unchecked b/c scala 3 erroneously reports exhaustiveness warning
case tst: Translate[h, G, _] @unchecked => // y = Unit
val translateRunner: Run[h, X, F[End]] = new TranslateRunner(tst.fk, getCont[Unit, G, X])
val composed: h ~> F = translation.compose[h](tst.fk)
go[h, X, End](scope, extendedTopLevelScope, composed, translateRunner, tst.stream)
Expand All @@ -1181,14 +1181,14 @@ object Pull extends PullLowPriority {
val fmrunr = new FlatMapR(getCont[Unit, G, X], fmout.fun)
F.unit >> go(scope, extendedTopLevelScope, translation, fmrunr, fmout.stream)

case u: Uncons[G, y] @nowarn =>
case u: Uncons[G, y] @unchecked =>
val v = getCont[Option[(Chunk[y], Pull[G, y, Unit])], G, X]
// a Uncons is run on the same scope, without shifting.
val runr = new BuildR[G, y, End]
F.unit >> go(scope, extendedTopLevelScope, translation, runr, u.stream).attempt
.flatMap(_.fold(goErr(_, v), _.apply(new UnconsRunR(v))))

case s: StepLeg[G, y] @nowarn =>
case s: StepLeg[G, y] @unchecked =>
val v = getCont[Option[Stream.StepLeg[G, y]], G, X]
val runr = new BuildR[G, y, End]
scope
Expand Down
22 changes: 10 additions & 12 deletions core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import scala.concurrent.TimeoutException
import scala.concurrent.duration._
import cats.{Eval => _, _}
import cats.data.Ior
import cats.effect.{Concurrent, IO, SyncIO}
import cats.effect.{Concurrent, SyncIO}
import cats.effect.kernel._
import cats.effect.kernel.implicits._
import cats.effect.std.{Console, Queue, QueueSink, QueueSource, Semaphore}
Expand All @@ -36,8 +36,6 @@ import fs2.compat._
import fs2.concurrent._
import fs2.internal._

import scala.collection.mutable.ArrayBuffer

/** A stream producing output of type `O` and which may evaluate `F` effects.
*
* - '''Purely functional''' a value of type `Stream[F, O]` _describes_ an effectful computation.
Expand Down Expand Up @@ -1183,7 +1181,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
* res0: List[Int] = List(1, 2, 2, 3, 3, 3)
* }}}
*/
@nowarn("cat=unused-params")
@nowarn // ("cat=unused-params") - unsupported category on scala 3
def flatMap[F2[x] >: F[x], O2](
f: O => Stream[F2, O2]
)(implicit ev: NotGiven[O <:< Nothing]): Stream[F2, O2] =
Expand Down Expand Up @@ -2361,7 +2359,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
): Stream[F2, O2] =
this.asInstanceOf[Stream[F, Either[Throwable, O2]]].chunks.flatMap { c =>
val size = c.size
val builder = Chunk.makeArrayBuilder[Any]
val builder = makeArrayBuilder[Any]
builder.sizeHint(size)
var i = 0
var exOpt: Option[Throwable] = None
Expand Down Expand Up @@ -2507,14 +2505,14 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
if (prev.isEmpty) Pull.done
else Pull.output1(prev.take(size))
case Some((hd, tl)) =>
val buffer = ArrayBuffer.empty[Chunk[O]]
val builder = makeArrayBuilder[Chunk[O]]
var current = prev ++ hd
while (current.size >= step) {
val (nHeads, nTails) = current.splitAt(step)
buffer += nHeads.take(size)
builder += nHeads.take(size)
current = nTails
}
Pull.output(Chunk.buffer(buffer)) >> stepNotSmallerThanSize(tl, current)
Pull.output(Chunk.array(builder.result())) >> stepNotSmallerThanSize(tl, current)
}

def stepSmallerThanSize(
Expand All @@ -2528,18 +2526,18 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
if (prev.isEmpty) Pull.done
else Pull.output1((window ++ prev).take(size))
case Some((hd, tl)) =>
val buffer = ArrayBuffer.empty[Chunk[O]]
val builder = makeArrayBuilder[Chunk[O]]
var w = window
var current = prev ++ hd
while (current.size >= step) {
val (head, tail) = current.splitAt(step)
val wind = w ++ head
buffer += wind
builder += wind
w = wind.drop(step)
current = tail
}

Pull.output(Chunk.buffer(buffer)) >> stepSmallerThanSize(tl, w, current)
Pull.output(Chunk.array(builder.result())) >> stepSmallerThanSize(tl, w, current)
}

val resultPull =
Expand Down Expand Up @@ -3371,7 +3369,7 @@ object Stream extends StreamLowPriority {
* All elements that are available, up to the specified limit,
* are dequeued and emitted as a single chunk.
*/
@nowarn("cat=unused-params")
@nowarn // ("cat=unused-params") - unsupported category on scala 3
def fromQueueNoneTerminated[F[_]: Functor, A](
queue: QueueSource[F, Option[A]],
limit: Int = Int.MaxValue
Expand Down
Loading