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

Remove all uses of toIterable in code compiled with Scala 2.13.x. #4561

Merged
merged 1 commit into from Sep 29, 2021

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Sep 29, 2021

It will be deprecated in Scala 2.13.7.

See scala/scala#9774 (not yet reviewed at the time of this writing)

After these changes, the only remaining uses of .toIterable are in code that is 2.11- or 2.12-specific:

$ git grep -w toIterable
library/src/main/scala-old-collections/scala/scalajs/js/WrappedMap.scala:    underlying.asInstanceOf[js.Map.Raw[K, V]].keys().toIterator.toIterable
scalalib/overrides-2.11/scala/collection/immutable/Range.scala:  override def toIterable = this
scalalib/overrides-2.12/scala/collection/immutable/Range.scala:  override def toIterable = this

@sjrd sjrd requested a review from gzm0 September 29, 2021 12:02
@@ -37,7 +37,7 @@ object JUnitTestPlatformImpl {
}

def writeLines(lines: List[String], file: String): Unit =
Files.write(Paths.get(file), lines.toIterable.asJava, UTF_8)
Files.write(Paths.get(file), (lines: Iterable[String]).asJava, UTF_8)

Choose a reason for hiding this comment

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

out of curiosity, why does this need to be converted specifically to the less specific JavaCollectionWrappers.IterableWrapper rather than JavaCollectionWrappers.SeqWrapper?

Copy link
Member Author

Choose a reason for hiding this comment

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

SeqWrapper seems to be index-based:
https://github.com/scala/scala/blob/207c01b8efa96b9ba556bedcffc13458be2eafbd/src/library/scala/collection/convert/JavaCollectionWrappers.scala#L81
which is not good for a linear collection like List. Explicitly ascribing to Iterable makes it 100% sure that it is going to use a linear implementation.

Choose a reason for hiding this comment

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

that actually stopped working in 2.13, as toIterable on subtypes of Iterable[_] was changed to return this.type

@sjrd sjrd merged commit 0d04e61 into scala-js:master Sep 29, 2021
@sjrd sjrd deleted the no-toiterable branch September 29, 2021 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants