|
| 1 | +--- |
| 2 | +layout: home |
| 3 | +--- |
| 4 | + |
| 5 | +# Typelevel Scala |
| 6 | + |
| 7 | +## What is this repository? |
| 8 | + |
| 9 | +This [repository][tls] contains the [Typelevel][typelevel] [fork][fork] of the Scala compiler. |
| 10 | + |
| 11 | +Typelevel Scala is a conservative, collaborative and binary compatible fork of [Lightbend Scala][lbs]. The intention |
| 12 | +is for it to provide early access to bug fixes and enhancements of the Scala toolchain which are of particular |
| 13 | +interest to [projects][projects] which use the "Typelevel style" — extensive use of type classes, generic |
| 14 | +programming and exploitation of the distinctive features of Scala's type system such as higher-kinded, dependent and |
| 15 | +singleton types. |
| 16 | + |
| 17 | +## Relationship with Lightbend Scala |
| 18 | + |
| 19 | +Typelevel Scala releases will be made in lockstep with Lightbend Scala and will by default generate code which is |
| 20 | +binary compatible with code generated by Lightbend Scala. Code generated with Typelevel Scala can be freely linked |
| 21 | +against binary dependencies generated with Lightbend Scala and vice versa. This allows Typelevel Scala features and |
| 22 | +fixes to be used with minimal risk. |
| 23 | + |
| 24 | +The policy for inclusion of a fix or a feature in a Typelevel Scala release is as follows, |
| 25 | + |
| 26 | ++ It must be first submitted as a pull request to the corresponding version of Lightbend Scala. |
| 27 | ++ It must have a reasonable likelihood of being merged in a future Lightbend Scala release. |
| 28 | ++ It must offer a significant fix or feature for which there is no reasonable alternative or workaround. |
| 29 | ++ It must maintain binary compatibility with Lightbend Scala unless a binary change is the primary motivation for the |
| 30 | + addition. |
| 31 | + |
| 32 | +The aim of this policy is to keep Typelevel Scala as close as possible to Lightbend Scala whilst still providing |
| 33 | +significant benefits to people who are affected by the issues it addresses. The requirement that all changes exist as |
| 34 | +a pull request against Lightbend Scala _first_ and have a reasonable chance of being merged in a future Lightbend |
| 35 | +Scala release is intended to encourage collaboration and convergence between Typelevel and Lightbend Scala |
| 36 | +contributors. |
| 37 | + |
| 38 | +Apart from the first criterion there is room for interpretation — after all, what counts as "reasonable"? Where |
| 39 | +the letter of the policy is unclear we appeal to its spirit — we want access to these features and fixes in our |
| 40 | +projects _now_ and for that to be feasible it is essential that we maintain the greatest possible degree of binary |
| 41 | +interoperability with the rest of the Scala ecosystem. |
| 42 | + |
| 43 | +## Typelevel Scala releases |
| 44 | + |
| 45 | +Currently Typelevel Scala is available as a drop in replacement for Lightbend Scala 2.11.8. As soon as Lightbend Scala |
| 46 | +2.12.0-RC1 is published a corresponding release of Typelevel Scala will be published. |
| 47 | + |
| 48 | +### Typelevel Scala 2.11.8 |
| 49 | + |
| 50 | +The Typelevel Scala additions to Lightbend Scala 2.11.8 can be found on the branch |
| 51 | +[2.11.8-bin-typelevel][2.11.8-bin-typelevel] of this repository. |
| 52 | + |
| 53 | +Typelevel Scala 2.11.8 offers the following fixes and features over Lightbend Scala 2.11.8, |
| 54 | + |
| 55 | ++ Support for partial unification (ie. a fix for [SI-2712][SI-2712]) — merged in Lightbend Scala 2.12.0-RC1. |
| 56 | + |
| 57 | + An improvement to type inference for type constructors, enabled by the `-Ypartial-unification` scalac option. This |
| 58 | + has many benefits for libraries, such as Cats and Scalaz, which make extensive use of higher-kinded types. |
| 59 | + |
| 60 | + Full details on the [pull request][pr-2712]. |
| 61 | ++ Support for literal types (aka SIP-23) — proposed for Lightbend Scala 2.12.1. |
| 62 | + |
| 63 | + Implements [literal types][SIP-23]. Enabled by `-Yliteral-types`. |
| 64 | + |
| 65 | + Literals can now appear in type position, designating the corresponding singleton type. A `scala.ValueOf[T]` type |
| 66 | + class and corresponding `scala.Predef.valueOf[T]` operator has been added yielding the unique value of types with a |
| 67 | + single inhabitant. Support for `scala.Symbol` literal types has been added. |
| 68 | ++ A partial fix for SI-7046 — proposed for Lightbend Scala 2.12.1. |
| 69 | + |
| 70 | + The macro API call `knownDirectSubclasses` now yields the correct result in most cases and will report an error in |
| 71 | + cases where it is unable to yield the correct result. |
| 72 | + |
| 73 | + This is only a partial fix because subclasses defined in local scopes might be missed by `knownDirectSubclasses`. In |
| 74 | + mitigation it is very likely that a local subclass would represent an error in any scenario where |
| 75 | + `knownDirectSubclasses` might be used. An error will be reported in these cases. |
| 76 | + |
| 77 | + Full details on the [pull request][pr-7046]. |
| 78 | ++ A fix for SI-9760 — merged in Lightbend Scala 2.12.0-RC1. |
| 79 | + |
| 80 | + Higher kinded type arguments are now refined by GADT pattern matching. Details can be found on [the |
| 81 | + ticket][SI-9760]. |
| 82 | + |
| 83 | +## Should I use Typelevel Scala? In production? |
| 84 | + |
| 85 | +The baseline for Typelevel Scala is the corresponding version of Lightbend Scala. Every bugfix or feature addition to |
| 86 | +Typelevel Scala exists as a pull request against that Lightbend Scala version, so will have been passed by the full |
| 87 | +Scala toolchain test suite and, in most cases, will have been reviewed by the Lightbend Scala compiler team. |
| 88 | + |
| 89 | +If you are affected by one of the bugs which Typelevel Scala addresses then you will have to weigh the risks and costs |
| 90 | +of using a compiler with the bug (perhaps with workarounds using unnecessarily complex encodings, macros or compiler |
| 91 | +plugins), against the risks and costs of using an alternative Scala distribution which fixes that bug. Only you can |
| 92 | +make that call. The same considerations apply to the additional features that Typelevel Scala supports. |
| 93 | + |
| 94 | +More generally there are many reasons why you might want to use and contribute to Typelevel Scala, |
| 95 | + |
| 96 | ++ You want to evaluate or contribute to a feature or fix. |
| 97 | ++ You want to explore how new language features interact with existing libraries. |
| 98 | ++ You want to explore new library designs enabled by new language features. |
| 99 | ++ You want to propose new language features motiviated by your experiences with library design. |
| 100 | ++ You want to contribute a feature or fix to Lightbend/Typelevel Scala and want to evaluate its interactions with |
| 101 | + other pending features and fixes. |
| 102 | + |
| 103 | +Within the Typelevel family of projects we are particularly excited by the prospect of being able to coevolve |
| 104 | +libraries along with the language and believe that this is one of the best ways to keep the language fresh and |
| 105 | +relevant to practitioners. |
| 106 | + |
| 107 | +## How to use Typelevel Scala |
| 108 | + |
| 109 | +There are just two requirements for using Typelevel Scala in your existing projects, |
| 110 | + |
| 111 | ++ You must be using (or be able to switch to) a corresponding version of Lightbend Scala. Currently this is 2.11.8 |
| 112 | + with 2.12.0-RC1 expected as soon as it is released by Lightbend. |
| 113 | ++ You must be using (or be able to switch to) SBT 0.13.13-M1. Earlier versions of SBT don't have full support for |
| 114 | + using an alternative `scalaOrganization`. |
| 115 | + |
| 116 | +If you are using Lightbend Scala 2.11.8 and SBT 0.13.x the following steps will build your project with Typelevel |
| 117 | +Scala, |
| 118 | + |
| 119 | ++ Update your `project/build.properties` to require SBT 0.13.13-M1, |
| 120 | + |
| 121 | + ``` |
| 122 | + sbt.version=0.13.13-M1 |
| 123 | + ``` |
| 124 | + |
| 125 | ++ Add the following to your `build.sbt` immediately next to where you set `scalaVersion`, |
| 126 | + |
| 127 | + ``` |
| 128 | + scalaOrganization := "org.typelevel" |
| 129 | + ``` |
| 130 | + |
| 131 | + Alternatively, if you want to try Typelevel Scala without modifying your `build.sbt` you can instead create a file |
| 132 | + `local.sbt` at the root of your project with the following content, |
| 133 | + |
| 134 | + ``` |
| 135 | + scalaOrganization in ThisBuild := "org.typelevel" |
| 136 | + ``` |
| 137 | + |
| 138 | + This will be merged with your main build definitions and can be added to `.gitignore` or `.git/info/exclude` if so |
| 139 | + desired. |
| 140 | + |
| 141 | +Now your build should function as before but using the Typelevel Scala toolchain instead of the Lightbend one. You can |
| 142 | +verify this from the SBT prompt, |
| 143 | + |
| 144 | +``` |
| 145 | +> show scalaOrganization |
| 146 | +[info] org.typelevel |
| 147 | +> |
| 148 | +``` |
| 149 | + |
| 150 | +This will immediately provide you with the fixes for [SI-7046][SI-7046] and [SI-9760][SI-9760]. To additionally enable |
| 151 | +the the fix for [SI-2712] and the implementation of [SIP-23] you should add either or both of their enabling flags to |
| 152 | +`scalacOptions` (or `local.sbt` if that was the path you took earlier), |
| 153 | + |
| 154 | +``` |
| 155 | +scalacOptions += "-Ypartial-unification" // enable fix for SI-2712 |
| 156 | +scalacOptions += "-Yliteral-types" // enable SIP-23 implementation |
| 157 | +
|
| 158 | +``` |
| 159 | + |
| 160 | +Note that Typelevel Scala 2.11.8 replaces the [si2712fix compiler plugin][si2712fix-plugin] — if you are using |
| 161 | +it you should remove it from your build before switching to Typelevel Scala. |
| 162 | + |
| 163 | +Also note that the two compiler flags above should be used in preference to `-Xexperimental` at present — as |
| 164 | +well as enabling the above two features `-Xexperimental` also enables some other features which are not typically |
| 165 | +desirable. |
| 166 | + |
| 167 | +You now can verify that these features have been enabled from the SBT console, |
| 168 | + |
| 169 | +``` |
| 170 | +> console |
| 171 | +[info] Compiling 3 Scala sources to /home/miles/projects/value-wrapper/target/scala-2.11/classes... |
| 172 | +[info] Starting scala interpreter... |
| 173 | +[info] |
| 174 | +Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102). |
| 175 | +Type in expressions for evaluation. Or try :help. |
| 176 | +
|
| 177 | +scala> val foo: "foo" = "foo" // Use of literal type "foo" |
| 178 | +foo: "foo" = foo |
| 179 | +
|
| 180 | +scala> import scala.language.higherKinds |
| 181 | +import scala.language.higherKinds |
| 182 | +
|
| 183 | +scala> def foo[F[_], A](fa: F[A]): String = fa.toString |
| 184 | +foo: [F[_], A](fa: F[A])String |
| 185 | +
|
| 186 | +scala> foo((x: Int) => x*2) // Function1[Int, Int] unifies with F[_] |
| 187 | +res1: String = <function1> |
| 188 | +``` |
| 189 | + |
| 190 | +## Roadmap |
| 191 | + |
| 192 | +The following are high priority issues for Typelevel projects on which progress is likely to be made in 2016, |
| 193 | + |
| 194 | ++ Partial type application. |
| 195 | ++ Multiple implicit parameter blocks. |
| 196 | ++ Improved compile times for inductive implicits. |
| 197 | ++ Improved control over implicit prioritization. |
| 198 | ++ Improved error reporting for implicit resolution failures. |
| 199 | ++ GADT and singleton type bugfixes. |
| 200 | ++ Literal syntax for Byte and Short types. |
| 201 | ++ Support for alternative `scala.Predef`. |
| 202 | + |
| 203 | +In accordance with the policy for inclusion contributions on these issues will be made as pull requests against |
| 204 | +Lightbend Scala in the first instance. |
| 205 | + |
| 206 | +## How to contribute to Typelevel Scala |
| 207 | + |
| 208 | +Because of our policy of "pull request against Lightbend Scala first" the primary route to contributing to Typelevel |
| 209 | +Scala is by contributing to Lightbend Scala. The Lightbend Scala team have made huge advances in lowering the barrier |
| 210 | +to participation in compiler development recently, in large part due to a new SBT-based build, and [helpful |
| 211 | +documentation][lbs-readme] — the Scala distribution is now an SBT project which you can expect to work on in |
| 212 | +much the same way as any other github hosted FLOSS Scala project. [Miles Sabin][milessabin] has provided a write up |
| 213 | +(now slightly outdated) of the process [here][scalac-post]. |
| 214 | + |
| 215 | +Because a pull request against [scala/scala][lbs] is the first step, to contribute you will need to sign the [Scala |
| 216 | +CLA][scala-cla] and be willing to make your contributions under the [Scala License][scala-license]. Typelevel is |
| 217 | +strongly in favour of the currently Scala license/CLA (which requires contributors to grant a patent license but does |
| 218 | +not grant one in return) being replaced by the Apache 2.0 [license][apache-2.0-license] and [ICLA][apache-2.0-icla] |
| 219 | +(which both requires and grants a patent license) as soon as is feasible. If you would like to contribute but are |
| 220 | +unable to sign the CLA please raise this issue on the [Lightbend][lbs-gitter] and [Typelevel][tls-gitter] gitter |
| 221 | +channels. |
| 222 | + |
| 223 | +## Community |
| 224 | + |
| 225 | +Topics specific to Typelevel Scala are discussed on its [gitter channel][tls-gitter]. Scala compiler development is |
| 226 | +discussed on the [scala/contributors gitter channel][lbs-gitter]. |
| 227 | + |
| 228 | +People are expected to follow the [Typelevel Code of Conduct][coc] when discussing Typelevel Scala on the Github page, |
| 229 | +Gitter channel, or other venues. |
| 230 | + |
| 231 | +We hope that our community will be respectful, helpful, and kind. If you find yourself embroiled in a situation that |
| 232 | +becomes heated, or that fails to live up to our expectations, you should disengage and contact one of the [project |
| 233 | +maintainers](#maintainers) in private. We hope to avoid letting minor aggressions and misunderstandings escalate into |
| 234 | +larger problems. |
| 235 | + |
| 236 | +If you are being harassed, please contact one of [us](#maintainers) immediately so that we can support you. |
| 237 | + |
| 238 | +## Maintainers |
| 239 | + |
| 240 | +The current maintainers (people who can merge pull requests) are: |
| 241 | + |
| 242 | + + Erik Osheim ([@non](https://github.com/non)) |
| 243 | + + George Leontiev ([@folone](https://github.com/folone)) |
| 244 | + + Jon Pretty ([@propensive](https://github.com/propensive)) |
| 245 | + + Lars Hupel ([@larsrh](https://github.com/larsrh)) |
| 246 | + + Mike O'Connor ([@stew](https://github.com/stew)) |
| 247 | + + Miles Sabin ([@milessabin](https://github.com/milessabin)) |
| 248 | + + Tom Switzer ([@tixxit](https://github.com/tixxit)) |
| 249 | + |
| 250 | +[tls]: https://github.com/typelevel/scala |
| 251 | +[fork]: http://typelevel.org/blog/2014/09/02/typelevel-scala.html |
| 252 | +[lbs]: https://github.com/scala/scala |
| 253 | +[projects]: http://typelevel.org/projects/ |
| 254 | +[SI-2712]: https://issues.scala-lang.org/browse/SI-2712 |
| 255 | +[pr-2712]: https://github.com/scala/scala/pull/5102 |
| 256 | +[SI-7046]: https://issues.scala-lang.org/browse/SI-7046 |
| 257 | +[pr-7046]: https://github.com/scala/scala/pull/5284 |
| 258 | +[SI-9760]: https://issues.scala-lang.org/browse/SI-9760 |
| 259 | +[SIP-23]: https://github.com/scala/scala/pull/5310 |
| 260 | +[si2712fix-plugin]: https://github.com/milessabin/si2712fix-plugin |
| 261 | +[tls-gitter]: https://gitter.im/typelevel/scala |
| 262 | +[lbs-gitter]: https://gitter.im/scala/contributors |
| 263 | +[typelevel]: http://typelevel.org/ |
| 264 | +[coc]: http://typelevel.org/conduct.html |
| 265 | +[lbs-readme]: https://github.com/scala/scala/blob/2.12.x/README.md |
| 266 | +[scalac-post]: http://milessabin.com/blog/2016/05/13/scalac-hacking/ |
| 267 | +[milessabin]: https://github.com/milessabin |
| 268 | +[2.11.8-bin-typelevel]: https://github.com/typelevel/scala/commits/2.11.8-bin-typelevel |
| 269 | +[scala-cla]: http://www.lightbend.com/contribute/cla/scala |
| 270 | +[scala-license]: https://github.com/scala/scala/blob/2.12.x/doc/LICENSE.md |
| 271 | +[apache-2.0-license]: http://www.apache.org/licenses/LICENSE-2.0 |
| 272 | +[apache-2.0-icla]: https://www.apache.org/licenses/icla.txt |
0 commit comments