Skip to content

Move migration rules here #15

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

Merged
merged 41 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7083321
Setup skeleton for rewriting with scalafix.
olafurpg Jun 21, 2017
51edbb4
Add a few examples
julienrf Jun 26, 2017
29cf22b
Add Range, Array and String examples
julienrf Jun 27, 2017
3d46cfa
Depend on collections project in output.
olafurpg Jun 29, 2017
e2f2425
Almost complete with rewrite.
olafurpg Jul 15, 2017
e7d3944
Upgrade to scalafix 0.5.0-M3.
olafurpg Aug 10, 2017
6f1256e
Move replaceSymbol from config to rewrite
olafurpg Aug 10, 2017
e679c85
Use scalafix.syntax.normalized instead of custom rolled.
olafurpg Aug 10, 2017
632d1dc
WIP
olafurpg Aug 10, 2017
d4ea411
WIP
olafurpg Aug 10, 2017
791788d
WIP
olafurpg Aug 10, 2017
2466d82
WIP
olafurpg Aug 10, 2017
c0a5054
WIP
olafurpg Aug 10, 2017
5e31fb3
Upgrade to M4.
olafurpg Aug 15, 2017
6bf57f5
Add a few more examples
julienrf Aug 28, 2017
891df92
Add dep on parent project.
olafurpg Aug 28, 2017
55a4107
Improve documentation of the migration tool
julienrf Aug 29, 2017
9352c2c
Improve documentation of the migration tool and fix the input and out…
julienrf Aug 29, 2017
eb10070
Fix the output and tuned a few rules.
julienrf Aug 29, 2017
e2fa336
Unimport Predef conversions if used.
olafurpg Aug 29, 2017
3311594
Unimport both augmentString+wrapString if either appears.
olafurpg Aug 29, 2017
4b2d629
Prototype toX and to[X] conversions.
olafurpg Aug 29, 2017
ea68880
Fix compilation error in the output
julienrf Aug 30, 2017
c41b46e
Improve the to[X] rules
julienrf Aug 30, 2017
f059ccb
Fix scalafix build definition
julienrf Sep 12, 2017
8c9097f
Fix broken scalafix tests
marcelocenerine Nov 3, 2017
362d648
Upgrade Scalafix to 0.5.3
marcelocenerine Nov 4, 2017
ba42911
Scalafix rewrite for lazyZip
marcelocenerine Nov 7, 2017
3edd875
Remove rewrite rules that are not needed anymore
julienrf Dec 6, 2017
66c9265
Add failing test case (because of scalacenter/scalafix#478)
julienrf Dec 6, 2017
fce1608
Workaround for scalacenter/scalafix#478
julienrf Dec 6, 2017
68f9a70
Implement the rule for “import JavaConverters._”
julienrf Dec 6, 2017
e8de069
Migrate scala.Seq to strawman.collection.Seq
julienrf Dec 6, 2017
9b8a3ac
Revert "Migrate scala.Seq to strawman.collection.Seq"
julienrf Dec 6, 2017
589712c
Create two distinct scalafix rules targeting 2.12 and 2.13
julienrf Jan 19, 2018
ee1bdba
Add copyToBuffer rule
julienrf Jan 19, 2018
60fac10
Narrow the node on which the patch is performed
julienrf Mar 28, 2018
53f832b
Update the migration rule to use 2.13.0-M4-pre-20d3c21
julienrf Apr 18, 2018
8b59395
Move scalafix files into a scalafix subdirectory
julienrf Apr 19, 2018
6873b92
Add scalafix migration rule.
julienrf Apr 19, 2018
00cbc8f
Update README and CONTRIBUTING files with details related to the migr…
julienrf Apr 19, 2018
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
77 changes: 77 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Contributing

## Build

### Sbt Projects

- `scala-collection-compat` project (in the root directory): implementation of the compatibility library ;
- In directory `scalafix/` there is an independent build containing the implementation of the migration tool.

## Migration tool

Several levels of contribution are possible!

### Report a missing case

Create an issue tagged with the
[migration](https://github.com/scala/collection-strawman/labels/migration) label.
Embrace `diff`s to describe differences between the standard collections and
the strawman:

~~~ diff
- xs.toIterator
+ xs.iterator()
~~~

### Add a missing test case

Even better, instead of providing a diff, you can directly add it as a test case!

1. Fork this repository and create a separate branch;

2. Add a file in the `scalafix/input/src/main/scala/fix/` directory with code
that uses the standard collections:

~~~ scala
class toIteratorVsIterator(xs: Iterable[Int]) {
xs.toIterator
}
~~~

3. Add a corresponding file in the `scalafix/output/src/main/scala/fix/` directory
with the same code but using the strawman:

~~~ scala
import strawman.collection.Iterable

class toIteratorVsIterator(xs: Iterable[Int]) {
xs.iterator()
}
~~~

4. Check that your code example compiles
- run sbt from the `scalafix/` directory
and then run the following tasks `; input/compile ; output/compile`;

5. Commit your changes, push your branch to your fork and create a pull request.

Then maybe someone will take over and implement your use case… or maybe you will
(see next section)!

### Implement a missing case

Even better, complete the migration tool implementation to support the missing case!

After you have added the missing case (see previous section), run the following
sbt task (with sbt started from the `scalafix/` directory) to run the
migration tool on the input files and check whether the result matches the
expected output files:

~~~
> tests/test
~~~

Fix the implementation of the rule (in the
`rules/src/main/scala/fix/Scalacollectioncompat_v0.scala` file) until the
tests are green. You can find more help about the scalafix API in its
[documentation](https://scalacenter.github.io/scalafix/docs/rule-authors/setup).
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[![Build Status](https://travis-ci.org/scala/scala-collection-compat.svg?branch=master)](https://travis-ci.org/scala/scala-collection-compat)

Scala 2.13 Collection Compatibility Library
===========================================
Scala 2.13 Collection Compatibility Library And Migration Tool
==============================================================

## Compatibility Library

This library for Scala 2.12 provides limited compatibility with the new collection library in 2.13. We try to keep the
2.13 collections as backward compatible as possible but that is not always possible. For some of these cases this
Expand All @@ -24,3 +26,25 @@ This project can be cross-built on 2.13 (with new collections) and 2.12. The 2.1
empty `scala.collection.compat` package object that allows you to write `import scala.collection.compat._` in 2.13.
The 2.13 version has the compatibility extensions in this package. It also adds backported version of some new collection
types to other `scala.collection` subpackages.

## Migration Tool

A tool is being developed to automatically migrate code that uses the standard
collection to use the strawman.

To use it, add the [scalafix](https://scalacenter.github.io/scalafix/) sbt plugin
to your build, as explained in
[its documentation](https://scalacenter.github.io/scalafix/#Installation).

The migration tool is not exhaustive and we will continue to improve
it over time. If you encounter a use case that’s not supported, please
report it as described in the
[contributing documentation](CONTRIBUTING.md#migration-tool).

### Migrating a 2.12 code base to 2.13

Run the following sbt task on your project:

~~~
> scalafix github:scala/scala-collection-compat/v0
~~~
43 changes: 43 additions & 0 deletions scalafix/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def scalafixVersion = _root_.scalafix.Versions.version
inScope(Global)(
List(
scalaVersion := _root_.scalafix.Versions.scala212
)
)

lazy val root = project
.in(file("."))
.aggregate(
rules, input, output, tests
)

lazy val rules = project.settings(
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % scalafixVersion
)

lazy val input = project
.settings(
scalafixSourceroot := sourceDirectory.in(Compile).value
)

lazy val output = project
.settings(
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
scalaVersion := "2.13.0-M4-pre-20d3c21"
)

lazy val tests = project
.settings(
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
buildInfoPackage := "fix",
buildInfoKeys := Seq[BuildInfoKey](
"inputSourceroot" ->
sourceDirectory.in(input, Compile).value,
"outputSourceroot" ->
sourceDirectory.in(output, Compile).value,
"inputClassdirectory" ->
classDirectory.in(input, Compile).value
)
)
.dependsOn(input, rules)
.enablePlugins(BuildInfoPlugin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
rule = "scala:fix.Collectionstrawman_v0"
*/
package fix

object Collectionstrawman_v0_Stream {
val s = Stream(1, 2, 3)
s.append(List(4, 5, 6))
1 #:: 2 #:: 3 #:: Stream.Empty
val isEmpty: Stream[_] => Boolean = {
case Stream.Empty => true
case x #:: xs => false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
rule = "scala:fix.Collectionstrawman_v0"
*/
package fix

object Collectionstrawman_v0_Traversable {
def foo(xs: Traversable[(Int, String)], ys: List[Int]): Unit = {
xs.to[List]
xs.to[Set]
xs.toIterator
ys.iterator
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
rule = "scala:fix.Collectionstrawman_v0"
*/
package fix

import scala.language.postfixOps
object Collectionstrawman_v0_Tuple2Zipped {
def zipped(xs: List[Int], ys: List[Int]): Unit = {
(xs, ys).zipped
(xs,ys).zipped
((xs, ys) zipped)
(((xs) , (ys)).zipped)
(xs, // foo
ys).zipped
/* a */(/* b */ xs /* c */, /* d */ ys /* e */)/* f */./* g */zipped/* h */
(coll(1), coll(2)).zipped
(List(1, 2, 3), Stream.from(1)).zipped
}
def coll(x: Int): List[Int] = ???
}

object Collectionstrawman_v0_Tuple3Zipped {
def zipped(xs: List[Int], ys: List[Int], zs: List[Int]): Unit = {
(xs, ys, zs).zipped
(xs,ys,zs).zipped
((xs, ys, zs) zipped)
(((xs) , (ys) , (zs)).zipped)
(xs, // foo
ys, // bar
zs).zipped
/* a */(/* b */ xs /* c */, /* d */ ys /* e */, /* f */ zs /* g */)/* h */./* i */zipped/* j */
(coll(1), coll(2), coll(3)).zipped
(List(1, 2, 3), Set(1, 2, 3), Stream.from(1)).zipped
}
def coll(x: Int): List[Int] = ???
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
rule = "scala:fix.Collectionstrawman_v0"
*/
package fix

import scala.collection.mutable

class Collectionstrawman_v0_copyToBuffer(xs: List[Int], b: mutable.Buffer[Int]) {

xs.copyToBuffer(b)
(xs ++ xs).copyToBuffer(b)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fix

object Collectionstrawman_v0_Stream {
val s = LazyList(1, 2, 3)
s.lazyAppendAll(List(4, 5, 6))
1 #:: 2 #:: 3 #:: LazyList.Empty
val isEmpty: LazyList[_] => Boolean = {
case LazyList.Empty => true
case x #:: xs => false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fix

object Collectionstrawman_v0_Traversable {
def foo(xs: Iterable[(Int, String)], ys: List[Int]): Unit = {
xs.to(List)
xs.to(Set)
xs.iterator()
ys.iterator()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fix

import scala.language.postfixOps
object Collectionstrawman_v0_Tuple2Zipped {
def zipped(xs: List[Int], ys: List[Int]): Unit = {
xs.lazyZip(ys)
xs.lazyZip(ys)
(xs.lazyZip(ys) )
((xs).lazyZip((ys)))
xs.lazyZip(// foo
ys)
/* a *//* b */ xs /* c */.lazyZip(/* d */ ys /* e */)/* f *//* g *//* h */
coll(1).lazyZip(coll(2))
List(1, 2, 3).lazyZip(LazyList.from(1))
}
def coll(x: Int): List[Int] = ???
}

object Collectionstrawman_v0_Tuple3Zipped {
def zipped(xs: List[Int], ys: List[Int], zs: List[Int]): Unit = {
xs.lazyZip(ys).lazyZip(zs)
xs.lazyZip(ys).lazyZip(zs)
(xs.lazyZip(ys).lazyZip(zs) )
((xs).lazyZip((ys)).lazyZip((zs)))
xs.lazyZip(// foo
ys).lazyZip(// bar
zs)
/* a *//* b */ xs /* c */.lazyZip(/* d */ ys /* e */).lazyZip(/* f */ zs /* g */)/* h *//* i *//* j */
coll(1).lazyZip(coll(2)).lazyZip(coll(3))
List(1, 2, 3).lazyZip(Set(1, 2, 3)).lazyZip(LazyList.from(1))
}
def coll(x: Int): List[Int] = ???
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fix

import scala.collection.mutable

class Collectionstrawman_v0_copyToBuffer(xs: List[Int], b: mutable.Buffer[Int]) {

b ++= xs
b ++= xs ++ xs

}
1 change: 1 addition & 0 deletions scalafix/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
3 changes: 3 additions & 0 deletions scalafix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.7")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
Loading