8000 Fixes from scala/scala repository by julienrf · Pull Request #493 · scala/collection-strawman · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Fixes from scala/scala repository #493

Merged
merged 13 commits into from
Mar 12, 2018

Conversation

julienrf
Copy link
Contributor
@julienrf julienrf commented Mar 6, 2018

I went through the history of the collections on the scala/scala repo, for the last year, and backported all the things that were missing in the strawman.

Fixes #214.

@julienrf julienrf requested review from szeiger and lrytz March 6, 2018 17:39
@julienrf
Copy link
Contributor Author
julienrf commented Mar 6, 2018

I’m wondering what happened to scala/scala#5664, it seems to have been re 8000 verted (scala/scala@a11918d, scala/scala@76babbb and scala/scala@0365d58). Also, it seems that we have a similar PR (#354). What should we do about this stuff?

@lrytz
Copy link
Member
lrytz commented Mar 7, 2018

scala/scala#5664 was partially reverted because it was binary incompatible. We don't need to worry about that here.

@szeiger
Copy link
Contributor
szeiger commented Mar 7, 2018

#354 is the intended replacement for the parts in scala/scala#5664 that had to be reverted due to binary compatibility constraints.

* @return a $coll consisting only of the first `n` elements of this $coll,
* or else the whole $coll, if it has less than `n` elements.
* If `n` is negative, returns an empty $coll.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc comments for take and drop should be in IterableOnceOps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve put them here to override IterableOnce’s comments which give information about the fact that these operation consume the Iterator. This information is not relevant in Iterable.

But maybe we could organize the scaladoc differently…

Copy link
Contributor

Choose a reason for hiding this comment

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

The iterator comsumption stuff is contained in templates (or whatever you call those scaladoc variables). They should be defined as empty in Iterable and with the relevant text in Iterator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In ab2d3f3 I moved the documentation to IterableOnceOps but there is still an issue with the documentation of IterableOnceOps. I’ve opened #510 to keep track of it.

@@ -171,4 +171,8 @@ trait LinearSeqOps[+A, +CC[X] <: LinearSeq[X], +C <: LinearSeq[A]] extends Any w
}
last
}

override def tails: Iterator[C] =
Iterator.iterate(coll)(_.tail.asInstanceOf[C]).takeWhile(_.nonEmpty) ++ Iterator(newSpecificBuilder().result())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the cast necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the static return type of tail is LinearSeq[A], whereas we want a C.

Copy link
Contributor
@szeiger szeiger Mar 8, 2018

Choose a reason for hiding this comment

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

Hm, that's not nice. We lose the precise type on repeated applications of tail. this.type.tail results in C but C.tail is only LinearSeq[A].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having a more precise type would require a more complex upper bound on C.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem lies in the definition of LinearSeqOps. We need to make C recursive:

trait LinearSeqOps[+A, +CC[X] <: LinearSeq[X], +C <: LinearSeq[A] with LinearSeqOps[A, CC, C]] extends Any with SeqOps[A, CC, C]

And the same for immutable.LinearSeqOps and LazyListOps. With these changes the cast is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that’s what I was trying to say in my previous comment. The drawback is that it becomes harder to abstract over some LinearSeqOps. See how it is done for immutable.MapOps, which has similar bounds: https://github.com/scala/collection-strawman/blob/master/collections-contrib/src/main/scala/strawman/collection/decorators/HasImmutableMapOps.scala#L12-L17

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a problem for LinearSeqOps. The only changes I had to do downstream was to repeat the bounds in immutable.LinearSeqOps and LazyListOps. LinearSeqOps is just an implementation detail. You'd abstract over SeqOps, possibly restricted to subtypes of LinearSeq if you care about performance characteristics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allright, I’ve fixed that in a304aaf.

/** Splits a sequence into init :+ last.
* @return Some((init, last)) if sequence is non-empty. None otherwise.
/** Splits a sequence into init :+ tail.
* @return Some((init, tail)) if sequence is non-empty. None otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. :+ does split the sequence into (init, last).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, indeed…

@julienrf julienrf force-pushed the fixes-from-scala-scala branch from d049876 to 7a57af9 Compare March 7, 2018 15:49
@julienrf
Copy link
Contributor Author
julienrf commented Mar 8, 2018

#354 is the intended replacement for the parts in scala/scala#5664

OK, so that’s fine to not have it in this PR.

julienrf added 13 commits March 12, 2018 09:58
…y instance.

Fixes scala/bug#10399

Backport of 34d2f332d48adfd77c3060f948197326528b40d9 (by @joymufeng)
Backport of 58be110785aaef46333d59856c5f12cb575f4159 (by @Philippus)
Backport of 41133d93f78911bc60ce5e7ce7c9a242ce1b23a8 (by @id-ilych)
Backport of e29bff586f4c819e5b1f03ed8a497ac4a245f5fa (by @markus1189)
Backport of 55541745edcbb7b1d5a9830bad880cf5f543c0fe (by @markus1189)
Backport of 836297f305bd6901b60c7410bce1be25725b6ce3 (by Steve Robinson)
Backport of 7de41a40ecb0c5fbb8450823dc08218d93f4dc81 (by Håkon Hjelde Wold)
Backport of ea65e04beef05708f0d11377338605377c86d3b6 (by @ashawley)
Backport of 37dd50c0f1204354ec147b445652cd725126e063 (by @DanielMoss)
Backport of 5c7b14219b746812089c39876edaba9ee226a4bb (by @som-snytt).
Note that our implementation was already lazy enough, so I didn’t copy
the implementation of the referenced commit.
Backport of 0ee887573512ecd6411ac656ca03fc43696fa710 (by @martijnhoekstra)
@julienrf julienrf force-pushed the fixes-from-scala-scala branch from 7a57af9 to a304aaf Compare March 12, 2018 09:32
@szeiger szeiger merged commit 8a0f0a9 into scala:master Mar 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0