troops.ai: implicit class - the machinery behind the semantics - ny-scala october 2016

Post on 15-Apr-2017

157 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

we’re hiring!troops.ai/careers

Goal

Understand the Scala compiler by tracing the

compilation of a simple program and concentrating on a

single feature

Agenda

1. What is Implicit Conversion?

2. Result & RichResult

3. Compiler Data Structures & Phases

4. parser Phase

5. namer Phase

6. typer Phase

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.”

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.”

Result & RichResult

Result & RichResult

Data Structures

1. Compilation Unit

2. Context

3. Tree

4. Symbol

5. Type

6. Scope

Data Structures

1. Compilation Unit

2. Context

3. Tree

4. Symbol

5. Type

6. Scope

Data Structures

1. Compilation Unit

2. Context

3. Tree

4. Symbol

5. Type

6. Scope

Data Structures

1. Compilation Unit

2. Context

3. Tree

4. Symbol

5. Type

6. Scope

Data Structures

1. Compilation Unit

2. Context

3. Tree

4. Symbol

5. Type

6. Scope

Data Structures

1. Compilation Unit

2. Context

3. Tree

4. Symbol

5. Type

6. Scope

Compiler Phases

1. parser

2. namer

3. typer

Compiler Phases

1. parser

2. namer

3. typer

Compiler Phases

1. parser

2. namer

3. typer

parser Phase

parser Phase

...

namer Phase

namer Phase - enterImplicitWrapper

typer Phase

typer Phase

typer Phase - Select

typer Phase - Select

typer Phase - View

typer Phase - View

typer Phase - View

typer Phase - View

The End

Thanks

top related