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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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


def readLines(file: String): List[String] =
Files.readAllLines(Paths.get(file), UTF_8).asScala.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class EntryPointAnalyzerBackend(linkerConfig: StandardConfig,
implicit ec: ExecutionContext): Future[Report] = {

val modules = moduleSet.modules.flatMap(_.externalDependencies).toSet
Files.write(entryPointOutputFile, modules.toIterable.asJava,
Files.write(entryPointOutputFile, (modules: Iterable[String]).asJava,
StandardCharsets.UTF_8)

standard.emit(moduleSet, output, logger)
Expand Down
4 changes: 2 additions & 2 deletions scalalib/overrides-2.13/scala/Enumeration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ abstract class Enumeration (initial: Int) extends Serializable {
override protected def fromSpecific(coll: IterableOnce[Value]) = ValueSet.fromSpecific(coll)
override protected def newSpecificBuilder = ValueSet.newBuilder

def map(f: Value => Value): ValueSet = fromSpecific(new View.Map(toIterable, f))
def flatMap(f: Value => IterableOnce[Value]): ValueSet = fromSpecific(new View.FlatMap(toIterable, f))
def map(f: Value => Value): ValueSet = fromSpecific(new View.Map(this, f))
def flatMap(f: Value => IterableOnce[Value]): ValueSet = fromSpecific(new View.FlatMap(this, f))

// necessary for disambiguation:
override def map[B](f: Value => B)(implicit @implicitNotFound(ValueSet.ordMsg) ev: Ordering[B]): immutable.SortedSet[B] =
Expand Down