Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixed #1411 - updated Chunk to use scala.collection.Seq #1413

Merged
merged 9 commits into from
Feb 11, 2019

Conversation

mpilquist
Copy link
Member

Initial pass at fixing #1411. One issue that remains is that varargs on 2.13 passes an ArraySeq now, not a WrappedArray, so I'm unsure if the optimization in Chunk.seq is accomplishing anything. I think I looked in to this once before but will do so again.

@@ -534,16 +535,16 @@ object Chunk {
override def map[O2](f: O => O2): Chunk[O2] = indexedSeq(s.map(f))
}

/** Creates a chunk backed by a `Seq`. */
def seq[O](s: Seq[O]): Chunk[O] = s match {
/** Creates a chunk backed by a mutable `Seq`. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A collection.Seq an be either mutable or immutable, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It is a parent of both collection.immutable.Seq and collection.mutable.Seq.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not binary compatible on 2.13.0-M5, right? Is the strategy to wait until the next 2.13.0, or to say that's not subject to binary compatibility, being a standard library milestone? I'm content either way.

👍 to the spirit of the change. collection.Seq is not my favorite type, but we'll see it a lot until Scala 2.12 falls into disuse.

case a: collection.mutable.WrappedArray[O] =>
array(a.array.asInstanceOf[Array[O]])
case v: Vector[O] => vector(v)
case ix: IndexedSeq[O] => indexedSeq(ix)
case _ =>
if (s.isEmpty) empty
else if (s.tail.isEmpty) singleton(s.head)
else buffer(collection.mutable.Buffer(s: _*))
else buffer(collection.mutable.Buffer((s.toSeq): _*))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a match for Buffer to go through buffer without s.toSeq be worthwhile? I doubt this gets passed Buffers often, but it's what jawn-fs2 always sends. I may end up special casing it there, even after this fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea.

The s.toSeq here is weird -- I think that will no longer be necessary as of 2.13.0-RC1. I'll add a comment to double check that.

@mpilquist
Copy link
Member Author

This is not binary compatible on 2.13.0-M5, right? Is the strategy to wait until the next 2.13.0, or to say that's not subject to binary compatibility, being a standard library milestone? I'm content either way.

I was thinking of saying no binary compatibility on 2.13 milestones.

👍 to the spirit of the change. collection.Seq is not my favorite type, but we'll see it a lot until Scala 2.12 falls into disuse.

Same :)

@mpilquist
Copy link
Member Author

Okay this one should be ready for re-review & merge.

@@ -249,6 +249,13 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
.settings(
name := "fs2-core",
sourceDirectories in (Compile, scalafmt) += baseDirectory.value / "../shared/src/main/scala",
unmanagedSourceDirectories in Compile += {
val dir = CrossVersion.partialVersion(scalaVersion.value) match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't sbt support this just by naming the source directory scala-2.13- (or something like that)? I'm looking at cats: https://github.com/typelevel/cats/tree/master/core/src/main

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind then :D

Copy link
Contributor

@lJoublanc lJoublanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So playing around with IndexedSeq I've noticed that it has the same change from 2.12 -> 2.13 i.e. becomes immutable. I'm wondering whether you need to apply the same import collection.IndexedSeq to make this work with both types. Specifically, is there a way to check that inside Chunk.seq (now Chunk.iterable) mutable IndexedSeqs are matching correctly?

@@ -1,6 +1,7 @@
package fs2

import scala.collection.immutable.{Queue => SQueue}
import scala.collection.{Seq => GSeq}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that this problem also extends to IndexedSeq. Is it necessary to give it the same treatment?

// cast is safe b/c the array constructor will check for primitive vs boxed arrays
array(arr.asInstanceOf[Array[O]])
case v: Vector[O] => vector(v)
case ix: IndexedSeq[O] => indexedSeq(ix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suspect this is only picking up immutable IndexedSeqs, as explained above.

@mpilquist
Copy link
Member Author

So playing around with IndexedSeq I've noticed that it has the same change from 2.12 -> 2.13 i.e. becomes immutable. I'm wondering whether you need to apply the same import collection.IndexedSeq to make this work with both types. Specifically, is there a way to check that inside Chunk.seq (now Chunk.iterable) mutable IndexedSeqs are matching correctly?

Thanks, fixed

@mpilquist mpilquist merged commit d402869 into typelevel:series/1.0 Feb 11, 2019
@mpilquist mpilquist added this to the 1.0.4 milestone Mar 1, 2019
@mpilquist mpilquist deleted the bugfix/1411 branch February 18, 2020 12:57
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants