Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit d61ab50

Browse files
authored
Add slides about the Scala 3 migration course (#129)
1 parent 2f5f4fe commit d61ab50

14 files changed

+241
-0
lines changed

slides/99-scala3-migration-course.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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+
## &#173;
5+
## &#173;
6+
## &#173;
7+
## Scala 3 migration course
8+
9+
---
10+
11+
## Course overview
12+
## &#173;
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+
### &#173;
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+
## &#173;
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+
## &#173;
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+
## &#173;
54+
### => Ecosystem jump between 2.12 and 2.13
55+
56+
---
57+
58+
## Compatibility between Scala 2.13 and Scala 3
59+
## &#173;
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+
## &#173;
67+
68+
### => Backward and forward compatibility between Scala 2.13 and Scala 3
69+
70+
---
71+
72+
## For 3 use 2.13
73+
## &#173;
74+
75+
![](images/compatibility-3-to-213.svg)
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+
## &#173;
90+
91+
![](images/compatibility-213-to-3.svg)
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+
## &#173;
107+
108+
![](images/compatibility-sandwich.svg)
109+
110+
---
111+
112+
## The diamond pattern
113+
## &#173;
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+
## &#173;
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+
## &#173;
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+
## &#173;
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+
![](images/incompat-syntax.png)
161+
162+
---
163+
164+
## Dropped features
165+
166+
![](images/incompat-dropped-features.png)
167+
---
168+
169+
## Contextual abstractions (Implicits)
170+
171+
![](images/incompat-context-abstractions.png)
172+
173+
---
174+
175+
## Other changed features
176+
177+
![](images/incompat-changed-features.png)
178+
179+
---
180+
181+
## Type checker and type inference
182+
183+
![](images/incompat-types.png)
184+
185+
---
186+
187+
## sbt-scala3-migrate
188+
189+
- It's an sbt plugin
190+
191+
![](images/sbt-scala3-migrate-install.png)
192+
193+
- It can assist you during the migration to Scala 3 of your build
194+
195+
![](images/sbt-scala3-migrate-welcome.png)
196+
197+
---
198+
199+
## Scala 3 migration course
200+
201+
![](images/scalacenter-scala3-migration-course.png)
202+
203+
---
204+
205+
## Scala 3 migration course
206+
## &#173;
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+
```
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
50.1 KB
Loading
Lines changed: 3 additions & 0 deletions
Loading
110 KB
Loading
97.1 KB
Loading
120 KB
Loading

slides/images/incompat-syntax.png

118 KB
Loading

slides/images/incompat-types.png

120 KB
Loading
37.6 KB
Loading
216 KB
Loading
Loading

0 commit comments

Comments
 (0)