Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016
-
Upload
troops-engineering -
Category
Software
-
view
157 -
download
1
Transcript of Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016
![Page 1: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/1.jpg)
![Page 2: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/2.jpg)
![Page 4: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/4.jpg)
Goal
Understand the Scala compiler by tracing the
compilation of a simple program and concentrating on a
single feature
![Page 5: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/5.jpg)
Agenda
1. What is Implicit Conversion?
2. Result & RichResult
3. Compiler Data Structures & Phases
4. parser Phase
5. namer Phase
6. typer Phase
![Page 6: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/6.jpg)
Implicit Conversion
1. Scala Language Specification 7.3
2. Scala Improvement Process 13
“In a selection e.m with e of type T, if the selector m does not denote an accessible member of T … a view v is searched which is applicable to e and whose result contains a member named m.”
“An implicit class is desugared into a class and implicit method pairing, where the implicit method mimics the constructor of the class.”
![Page 7: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/7.jpg)
Implicit Conversion
1. Scala Language Specification 7.3
2. Scala Improvement Process 13
“In a selection e.m with e of type T, if the selector m does not denote an accessible member of T … a view v is searched which is applicable to e and whose result contains a member named m.”
“An implicit class is desugared into a class and implicit method pairing, where the implicit method mimics the constructor of the class.”
![Page 8: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/8.jpg)
Result & RichResult
![Page 9: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/9.jpg)
Result & RichResult
![Page 10: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/10.jpg)
Data Structures
1. Compilation Unit
2. Context
3. Tree
4. Symbol
5. Type
6. Scope
![Page 11: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/11.jpg)
Data Structures
1. Compilation Unit
2. Context
3. Tree
4. Symbol
5. Type
6. Scope
![Page 12: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/12.jpg)
Data Structures
1. Compilation Unit
2. Context
3. Tree
4. Symbol
5. Type
6. Scope
![Page 13: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/13.jpg)
Data Structures
1. Compilation Unit
2. Context
3. Tree
4. Symbol
5. Type
6. Scope
![Page 14: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/14.jpg)
Data Structures
1. Compilation Unit
2. Context
3. Tree
4. Symbol
5. Type
6. Scope
![Page 15: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/15.jpg)
Data Structures
1. Compilation Unit
2. Context
3. Tree
4. Symbol
5. Type
6. Scope
![Page 16: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/16.jpg)
Compiler Phases
1. parser
2. namer
3. typer
![Page 17: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/17.jpg)
Compiler Phases
1. parser
2. namer
3. typer
![Page 18: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/18.jpg)
Compiler Phases
1. parser
2. namer
3. typer
![Page 19: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/19.jpg)
parser Phase
![Page 20: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/20.jpg)
parser Phase
...
![Page 21: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/21.jpg)
namer Phase
![Page 22: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/22.jpg)
namer Phase - enterImplicitWrapper
![Page 23: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/23.jpg)
typer Phase
![Page 24: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/24.jpg)
typer Phase
![Page 25: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/25.jpg)
typer Phase - Select
![Page 26: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/26.jpg)
typer Phase - Select
![Page 27: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/27.jpg)
typer Phase - View
![Page 28: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/28.jpg)
typer Phase - View
![Page 29: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/29.jpg)
typer Phase - View
![Page 30: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/30.jpg)
typer Phase - View
![Page 31: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/31.jpg)
The End
![Page 32: Troops.ai: Implicit Class - The Machinery Behind the Semantics - ny-scala October 2016](https://reader031.fdocuments.us/reader031/viewer/2022030316/587453241a28abd53e8b724d/html5/thumbnails/32.jpg)
Thanks