|
| 1 | +<!-- .slide: data-background-color="#781010" data-background-image="images/bg-reveal.ps.png" --> |
| 2 | + |
| 3 | +[//]: # (The following is a hack to move the slide H2 section down) |
| 4 | +## ­ |
| 5 | +## ­ |
| 6 | +## ­ |
| 7 | +## Scala 3 migration course |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Course overview |
| 12 | +## ­ |
| 13 | + |
| 14 | +* In this course we will: |
| 15 | + * Start from an existing sbt build (Scala 2.13) |
| 16 | + * Use sbt-scala3-migrate to migrate the build to Scala 3 |
| 17 | +### ­ |
| 18 | +* The objective is to learn the four steps of migrating a project: |
| 19 | + * Updating the dependencies |
| 20 | + * Updating the compiler options |
| 21 | + * Patching the syntax of the code |
| 22 | + * Fixing the type inference errors |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Dotty/Scala 3 |
| 29 | +## ­ |
| 30 | + |
| 31 | +* Dotty: New research project started in 2012 by Martin Odersky's lab at EPFL |
| 32 | +* Dotty announced to become Scala 3 (April 2018) |
| 33 | +* 3.0.0 released on May 13, 2021 |
| 34 | +* [3.3.0](https://github.com/lampepfl/dotty/releases/tag/3.3.0) relased on May 30th, 2023. First LTS (Long Term Support) release. |
| 35 | +* IDE support |
| 36 | + * [Visual Studio Code](https://code.visualstudio.com) with [Metals](https://scalameta.org/metals/) |
| 37 | + * integrated support in Metals including Scala Worksheet support! |
| 38 | + * [IntelliJ](https://www.jetbrains.com/idea/) |
| 39 | + * Scala 3 support with the [Scala Plugin](https://lp.jetbrains.com/intellij-scala/) |
| 40 | +* There's the [Scala 3 Migration Guide](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html)! |
| 41 | + |
| 42 | +--- |
| 43 | +## Compatibility in Scala 2 |
| 44 | +## ­ |
| 45 | + |
| 46 | +- Before Scala 2.10: no compatibility between any two versions |
| 47 | + - Different standard library |
| 48 | + - Different binary interface |
| 49 | +- Since Scala 2.10: strict binary compatibility in minor versions |
| 50 | + - 2.13.11 is compatible with 2.13.8 |
| 51 | + - 2.13.11 is not compatible with 2.12.19 |
| 52 | + |
| 53 | +## ­ |
| 54 | +### => Ecosystem jump between 2.12 and 2.13 |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +## Compatibility between Scala 2.13 and Scala 3 |
| 59 | +## ­ |
| 60 | + |
| 61 | +* Scala 3 uses the Scala 2.13 standard library |
| 62 | +* Scala 3 produces Scala 2.13 compatible binaries (class files, sjsir, ...) |
| 63 | +* Scala 3 can read Scala 2.13 signatures (Pickle format) |
| 64 | +* Scala 2.13 can read Scala 3 signatures (TASTy) using -Ytasty-reader |
| 65 | + |
| 66 | +## ­ |
| 67 | + |
| 68 | +### => Backward and forward compatibility between Scala 2.13 and Scala 3 |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## For 3 use 2.13 |
| 73 | +## ­ |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +``` |
| 78 | +lazy val foo = project.in(file("foo")) |
| 79 | + .settings( |
| 80 | + scalaVersion := "3.0.0", |
| 81 | + libraryDependencies += |
| 82 | + ("org.bar" %% "bar" % "1.0.0").cross(CrossVersion.for3Use2_13) |
| 83 | + ) |
| 84 | +``` |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## For 2.13 use 3 (TASTy reader) |
| 89 | +## ­ |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +``` |
| 94 | +lazy val foo = project.in(ile("foo")) |
| 95 | + .settings( |
| 96 | + scalaVersion := "2.13.6", |
| 97 | + scalacOptions += "-Ytasty-reader", |
| 98 | + libraryDependencies += |
| 99 | + ("org.bar" %% "bar" % "1.0.0").cross(CrossVersion.for2_13Use3) |
| 100 | + ) |
| 101 | +``` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## The sandwich pattern |
| 106 | +## ­ |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## The diamond pattern |
| 113 | +## ­ |
| 114 | + |
| 115 | +<img src="images/compatibility-diamond.png" width="500"/> |
| 116 | + |
| 117 | +``` |
| 118 | +[error] Modules were resolved with conflicting cross-version suffixes in main: |
| 119 | +[error] org.typelevel:cats _3, _2.13 |
| 120 | +``` |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Metaprogramming |
| 125 | +## ­ |
| 126 | + |
| 127 | +- Scala 2.13 macros are experimental |
| 128 | +- Scala 3 macros are based on new foundations. |
| 129 | +They are simpler and more stable. |
| 130 | +- Scala 2.13 and Scala 3 macros are incompatible |
| 131 | +- The community started migrating the macro libraries to Scala 3. |
| 132 | +See [Table of macro libraries.](https://scalacenter.github.io/scala-3-migration-guide/docs/macros/macro-libraries.html) |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## Compiler plugins |
| 137 | +## ­ |
| 138 | + |
| 139 | +- The Scala 3 compiler is completely new |
| 140 | +- Scala 2.13 plugins cannot be used in Scala 3 |
| 141 | +- Scala 3 plugins are more constrained |
| 142 | +- Some important plugins were integrated in the compiler, and can be activated with an option: |
| 143 | + - `-Ykind-projector` |
| 144 | + - `-scalajs` |
| 145 | + - `-semanticdb` |
| 146 | + |
| 147 | +--- |
| 148 | +## Compiler Options (`scalacOptions`) |
| 149 | +## ­ |
| 150 | + |
| 151 | +- Most options are available |
| 152 | +- Some are renamed |
| 153 | +- Some are dropped |
| 154 | +- Some of the most used Scala 2 options are ported to Scala 3. For example, we ported `-Wunused` to Scala 3.3.0. |
| 155 | +- See [table of compiler options](https://docs.scala-lang.org/scala3/guides/migration/options-lookup.html). |
| 156 | + |
| 157 | +--- |
| 158 | +## Syntactic changes |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## Dropped features |
| 165 | + |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +## Contextual abstractions (Implicits) |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## Other changed features |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## Type checker and type inference |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +--- |
| 186 | + |
| 187 | +## sbt-scala3-migrate |
| 188 | + |
| 189 | +- It's an sbt plugin |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | +- It can assist you during the migration to Scala 3 of your build |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## Scala 3 migration course |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | +--- |
| 204 | + |
| 205 | +## Scala 3 migration course |
| 206 | +## ­ |
| 207 | + |
| 208 | +``` |
| 209 | +$ cmtc install -f -s scalacenter/scala3-migration-course |
| 210 | +Downloading studentified course from 'https://github.com/scalacenter/scala3-migration-course/releases/download/0.1.0/scala3-migrate-course-student.zip' to courses directory |
| 211 | +
|
| 212 | +Project scalacenter/scala3-migration-course (0.1.0) successfully installed to: |
| 213 | + /home/user/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course |
| 214 | +
|
| 215 | +Current course set to '/home/user/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course' |
| 216 | +
|
| 217 | +Exercises in repository: |
| 218 | + 1. * exercise_000_initial_state |
| 219 | + 2. exercise_001_install_sbt_scala3_migrate |
| 220 | + 3. exercise_002_migrate_dependencies |
| 221 | + 4. exercise_003_migrate_scalac_options |
| 222 | + 5. exercise_004_migrate_syntax |
| 223 | + 6. exercise_005_migrate_types |
| 224 | + 7. exercise_006_update_scala_version |
| 225 | +``` |
0 commit comments