SlideShare une entreprise Scribd logo
1  sur  56
Télécharger pour lire hors ligne
From DOT to Dotty
Martin Odersky
ScalaX, London, 8 December 2016
DOT: Foundations
dotty: Prototype
… for future Scala
Why Do Foundations Matter?
• They help ensure properties such as type soundness.
• They serve as a feedback loop for language design.
• They help detect hidden connections between language
features.
Why Not Pick Existing
Foundations?
• Because they would lead to variants of existing
languages.
• Foundations are formative!
Our Aim
We are looking for a minimal theory that can model
1. type parameterization,
2. modules,
3. objects and classes.
minimal: We do not deal with inheritance here.
Our Aim
We are looking for a minimal theory that can model
1. type parameterization,
2. modules,
3. objects and classes.
There were several attempts before, including νObj,
which was proposed as a basis for Scala (ECOOP 2003).
But none of them felt completely canonical or minimal.
Related: 1ML, which can model (1) and (2) by mapping to
System F.
Dependent Types
• We will model modules as objects with type members.
• This requires a notion of dependent type - the type
referred to by a type member depends on the owning
value.
• In Scala we restrict dependencies to paths.
• In the calculus presented here we restrict it further to
variables.
Variable x
Path p = x | p.a
Dependent Types in Code
We can model heterogeneous maps like this:
Dependent Types in Code
Dependent Types in Code
Foundations: DOT
The DOT calculus is intended to be a minimal foundation of
Scala.
Its type structure is a blueprint for the types used internally
in the compiler.
DOT Terms
• Translated to Scala notation, the language covered by
DOT is:
Value v = (x: T) => t Function
new { x: T => d } Object
Definition d = def a = t Method definition
type A = T Type
Term t = v Value
x Variable
t1(t2) Application
t.a Selection
{ val x = t1; t2 } Local definition.
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } Recursion
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } Recursion
Should Scala have these?
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } Recursion
Will replace the
T1 with T2
syntax
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } RecursionScala has only refinements
T { d1 … dn}
with this as self reference.
DOT Syntax in Greek
Note: terms are in ANF form.
This simplifies some things, but is not essential.
Type Assignment
Definition Type Assignment
Subtyping
Expressiveness
Simple as the model is, it is actually quite expressive.
Directly representable:
▶ type parameters
▶ variance
▶ nominal typing
▶ generative modules
▶ self types
▶ ADTs and simple classes
Requires smallish extension:
▶ Classes with inheritance
Meta Theory
Simple as the model is, the soundness proof of DOT was
surprisingly hard.
▶ Attempts were made since about 2008.
▶ Previous publications (FOOL 12, OOPSLA 14) report
about (some) advances and (lots of) difficulties.
▶ Essential challenge: Subtyping theories are
programmer-definable.
Programmer-Definable Theorems
In Scala and DOT, the subtyping relation is given in part by
user-definable definitions:
type T >: S <: U { T: S .. U }
This makes T a supertype of S and a subtype of U. By
transitivity, S <: U.
So the type definition above proves a subtype relationship
which was potentially not provable before.
Bad Bounds
What if the bounds are non-sensical?
Example:
type T >: Any <: Nothing
By the same argument as before, this implies that
Any <: Nothing
Once we have that, again by transitivity we get S <: T for
arbitrary S and T.
That is, the subtyping relations collapses to a single point!
This means that most proof techniques for soundness fail.
Dealing with it
Observation: To prove preservation, we need to reason at
the top-level only about environments that arise from an
actual computation
Such environments correspond to run-time stores which
binds variables to values.
And values have guaranteed good bounds because all type
members in definitions are aliases.
By an elaborate argument one can make use of this
observation to show soundness.
For Details
Consequences for Language Design
• So far: Some soundness issues were known, but it was
not clear how to fix them.
• Can one impose restrictions to guarantee good
bounds?
• Has been tried for a while but was not complete.
• The meta theory taught us a principle to ensure
soundness:
Every prefix p of a type selection p.A must be a
computed value.
Things To Avoid
trait BadBounds { type A >: Any <: Nothing }
lazy val x: BadBounds = ???
BadBounds # A
val x: BadBounds = null
Need to drastically restrict types we
can write in a lazy val:
Only concrete types with good bounds
are allowed.Need to drastically restrict types we
can write in a projection:
Only concrete types with good bounds
are allowed.
Things To Avoid
trait BadBounds { type A >: Any <: Nothing }
lazy val x: BadBounds = ???
BadBounds # A
val x: BadBounds = null
Need to track null in the type system
(straightforward)
Need to track initialization status
(hard)
dotty
dotty is the working name for our new Scala compiler.
• Builds on DOT in its internal data structures.
• Generics get expressed as type members.
• Supports the next iteration(s) of the Scala
programming language.
A Whirlwind Tour Of Dotty
Constructs
Dropped Features
DelayedInit
Macros
Existential Types
Procedure Syntax
Early Initializers
General Type
Projection
def run() { ... }
Will be rewritten automatically to
def run(): Unit = { ... }
class Foo
extends DelayedInit
class C extends {
val x = e
} with D
Use trait parameters
instead
T # X
- Was shown to be unsound
for general types T.
- Projection C#X from class
types C still available.
(the reflection
based kind)
def m(...) =
macro impl(...)
C[U] forSome { type U }
Wildcards C[_]still supported.
Implemented New Features
Multiversal Equality
Intersection Types
Union types
Trait parameters
Function arity
adaptation
pairs.map((x, y) => x + y)
instead of
pairs.map {
case (x, y) => x + y
}
T & U
- replaces T with U
- is commutative
T | U
avoids huge lubs
@static methods and fields
non-blocking lazy vals
trait T(x: Int) { ... }
object O {
@static val x = ...
@static def f() = ...
}
lazy val x = ... // thread-local
@volatile
lazy val x - ... // thread-safe,
// avoids dead-locks
type-safe ==, !=
And Further Down the
Road ?
Implicit Function Types
scala.meta
scrap all 22’s
effects
Implicit Function Types
What Are Implicit Function Types?
and what is “Contextual Abstraction”?
“Abstraction”
The ability to name a concept
and use just the name afterward
“Contextual”
The context comprises all the inputs that let a program do
its work, including:
• configuration data
• capabilities
• dependency injection
• type class instances
Implicit Parameters
• Technique of choice to pass inputs to program parts that
need them.
• Advantage over normal parameters:
No boilerplate code to pass them along the edges of a
call graph.
• But we still need to declare them as parameters
everywhere they are passed!
Example: Transaction Handling
Example (2)
Example (3)
Example Run
Can We Do Better?
• Problem: Boilerplate code for declaring implicit
parameters
• Repeating this 3x does not look so terrible.
• But in the dotty compiler there are 2641(!) occurrences of
• We’d like to get rid of them.
Towards A Solution
Let’s massage the definition of f1 a bit:
f1’s right hand side is now an implicit function value.
What is its type?
So far: Transaction => Int
From now on: implicit Transaction => Int
or, desugared: ImplicitFunction1[Transaction, Int]
Inside ImplicitFunction1
ImplicitFunction1 can be thought of being defined as
follows:
Analogously for all other arities.
Two Rules for Typing
1. Implicit functions get implicit arguments just like implicit
methods. Given:
f expands to f(a)
2. Implicit functions get created on demand. If the
expected type of b is implicit A => B, then
b expands to implicit _: A => b
Revised Example:
But where does current come from?
Revised Example (2)
Summary
• Implicit function types are a neat way to abstract over
contexts.
• It’s a very powerful feature, because it allows one to
inject implicit values in a scope simply by defining type.
• This opens up a lot of possibilities.
• I expect it will fundamentally affect the kind of Scala code
in the future.
When Can I Expect This?
Scala 2.12
Scala 2.13
Scala 3.0
TASTY,
middle end?
stdlib
collections
dotty MVP
dotty 0.x releases
2016
backend, classpath handling
Scala 2.14
2017
2018
This is open source work, depends on community’s contributions.
à Roadmap is tentative, no promises:
“MVP” = minimal
viable
prototype
Contributors
Theory (DOT): Nada Amin, Tiark Rompf, Sandro Stucki, Samuel
Grütter. based on previous work by Adriaan Moors, Donna Malayeri,
Geoffrey Washburn, and others.
Implementation (dotty): Many contributors, including
Dmitry Petrashko Nicolas Stucki
Guillaume Martres Sebastien Douraene
Felix Mulder Ondrej Lhotak
Liu Fengyun Vera Salvisberg
Close collaboration with scalac team
Adriaan Moors Seth Tisue
Jason Zaugg Stefan Zeiger
Lukas Rytz
Find out more on scala-lang.org/blog
Thank You

Contenu connexe

Tendances

Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mindSander Mak (@Sander_Mak)
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaTomer Gabel
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IAjit Nayak
 
Programming in Scala - Lecture One
Programming in Scala - Lecture OneProgramming in Scala - Lecture One
Programming in Scala - Lecture OneAngelo Corsaro
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 

Tendances (11)

Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
 
Scala basic
Scala basicScala basic
Scala basic
 
Devoxx
DevoxxDevoxx
Devoxx
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Programming in Scala - Lecture One
Programming in Scala - Lecture OneProgramming in Scala - Lecture One
Programming in Scala - Lecture One
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 

Similaire à From DOT to Dotty

Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Alexander Podkhalyuzin
 
Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)Alexander Podkhalyuzin
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowLightbend
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharpDaniele Pozzobon
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#Alfonso Garcia-Caro
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NETBlackRabbitCoder
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and conceptsNicola Bonelli
 
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxStatic abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxMarco Parenzan
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scaladatamantra
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are DatabasesMartin Odersky
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 

Similaire à From DOT to Dotty (20)

Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)
 
Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To Know
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and concepts
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Generics
GenericsGenerics
Generics
 
scala.ppt
scala.pptscala.ppt
scala.ppt
 
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxStatic abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scala
 
Scala
ScalaScala
Scala
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Generics
GenericsGenerics
Generics
 
Opps concept
Opps conceptOpps concept
Opps concept
 
PL Lecture 03 - Types
PL Lecture 03 - TypesPL Lecture 03 - Types
PL Lecture 03 - Types
 

Plus de Martin Odersky

Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and EffectsMartin Odersky
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of ScalaMartin Odersky
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleMartin Odersky
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange openingMartin Odersky
 

Plus de Martin Odersky (8)

scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Flatmap
FlatmapFlatmap
Flatmap
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
 

Dernier

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Dernier (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

From DOT to Dotty

  • 1. From DOT to Dotty Martin Odersky ScalaX, London, 8 December 2016
  • 3. Why Do Foundations Matter? • They help ensure properties such as type soundness. • They serve as a feedback loop for language design. • They help detect hidden connections between language features.
  • 4. Why Not Pick Existing Foundations? • Because they would lead to variants of existing languages. • Foundations are formative!
  • 5. Our Aim We are looking for a minimal theory that can model 1. type parameterization, 2. modules, 3. objects and classes. minimal: We do not deal with inheritance here.
  • 6. Our Aim We are looking for a minimal theory that can model 1. type parameterization, 2. modules, 3. objects and classes. There were several attempts before, including νObj, which was proposed as a basis for Scala (ECOOP 2003). But none of them felt completely canonical or minimal. Related: 1ML, which can model (1) and (2) by mapping to System F.
  • 7. Dependent Types • We will model modules as objects with type members. • This requires a notion of dependent type - the type referred to by a type member depends on the owning value. • In Scala we restrict dependencies to paths. • In the calculus presented here we restrict it further to variables. Variable x Path p = x | p.a
  • 8. Dependent Types in Code We can model heterogeneous maps like this:
  • 11. Foundations: DOT The DOT calculus is intended to be a minimal foundation of Scala. Its type structure is a blueprint for the types used internally in the compiler.
  • 12. DOT Terms • Translated to Scala notation, the language covered by DOT is: Value v = (x: T) => t Function new { x: T => d } Object Definition d = def a = t Method definition type A = T Type Term t = v Value x Variable t1(t2) Application t.a Selection { val x = t1; t2 } Local definition.
  • 13. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } Recursion
  • 14. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } Recursion Should Scala have these?
  • 15. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } Recursion Will replace the T1 with T2 syntax
  • 16. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } RecursionScala has only refinements T { d1 … dn} with this as self reference.
  • 17. DOT Syntax in Greek Note: terms are in ANF form. This simplifies some things, but is not essential.
  • 21. Expressiveness Simple as the model is, it is actually quite expressive. Directly representable: ▶ type parameters ▶ variance ▶ nominal typing ▶ generative modules ▶ self types ▶ ADTs and simple classes Requires smallish extension: ▶ Classes with inheritance
  • 22. Meta Theory Simple as the model is, the soundness proof of DOT was surprisingly hard. ▶ Attempts were made since about 2008. ▶ Previous publications (FOOL 12, OOPSLA 14) report about (some) advances and (lots of) difficulties. ▶ Essential challenge: Subtyping theories are programmer-definable.
  • 23. Programmer-Definable Theorems In Scala and DOT, the subtyping relation is given in part by user-definable definitions: type T >: S <: U { T: S .. U } This makes T a supertype of S and a subtype of U. By transitivity, S <: U. So the type definition above proves a subtype relationship which was potentially not provable before.
  • 24. Bad Bounds What if the bounds are non-sensical? Example: type T >: Any <: Nothing By the same argument as before, this implies that Any <: Nothing Once we have that, again by transitivity we get S <: T for arbitrary S and T. That is, the subtyping relations collapses to a single point! This means that most proof techniques for soundness fail.
  • 25. Dealing with it Observation: To prove preservation, we need to reason at the top-level only about environments that arise from an actual computation Such environments correspond to run-time stores which binds variables to values. And values have guaranteed good bounds because all type members in definitions are aliases. By an elaborate argument one can make use of this observation to show soundness.
  • 27. Consequences for Language Design • So far: Some soundness issues were known, but it was not clear how to fix them. • Can one impose restrictions to guarantee good bounds? • Has been tried for a while but was not complete. • The meta theory taught us a principle to ensure soundness: Every prefix p of a type selection p.A must be a computed value.
  • 28. Things To Avoid trait BadBounds { type A >: Any <: Nothing } lazy val x: BadBounds = ??? BadBounds # A val x: BadBounds = null Need to drastically restrict types we can write in a lazy val: Only concrete types with good bounds are allowed.Need to drastically restrict types we can write in a projection: Only concrete types with good bounds are allowed.
  • 29.
  • 30.
  • 31. Things To Avoid trait BadBounds { type A >: Any <: Nothing } lazy val x: BadBounds = ??? BadBounds # A val x: BadBounds = null Need to track null in the type system (straightforward) Need to track initialization status (hard)
  • 32. dotty dotty is the working name for our new Scala compiler. • Builds on DOT in its internal data structures. • Generics get expressed as type members. • Supports the next iteration(s) of the Scala programming language.
  • 33. A Whirlwind Tour Of Dotty Constructs
  • 34. Dropped Features DelayedInit Macros Existential Types Procedure Syntax Early Initializers General Type Projection def run() { ... } Will be rewritten automatically to def run(): Unit = { ... } class Foo extends DelayedInit class C extends { val x = e } with D Use trait parameters instead T # X - Was shown to be unsound for general types T. - Projection C#X from class types C still available. (the reflection based kind) def m(...) = macro impl(...) C[U] forSome { type U } Wildcards C[_]still supported.
  • 35. Implemented New Features Multiversal Equality Intersection Types Union types Trait parameters Function arity adaptation pairs.map((x, y) => x + y) instead of pairs.map { case (x, y) => x + y } T & U - replaces T with U - is commutative T | U avoids huge lubs @static methods and fields non-blocking lazy vals trait T(x: Int) { ... } object O { @static val x = ... @static def f() = ... } lazy val x = ... // thread-local @volatile lazy val x - ... // thread-safe, // avoids dead-locks type-safe ==, !=
  • 36. And Further Down the Road ? Implicit Function Types scala.meta scrap all 22’s effects
  • 38. What Are Implicit Function Types? and what is “Contextual Abstraction”?
  • 39. “Abstraction” The ability to name a concept and use just the name afterward
  • 40. “Contextual” The context comprises all the inputs that let a program do its work, including: • configuration data • capabilities • dependency injection • type class instances
  • 41. Implicit Parameters • Technique of choice to pass inputs to program parts that need them. • Advantage over normal parameters: No boilerplate code to pass them along the edges of a call graph. • But we still need to declare them as parameters everywhere they are passed!
  • 46. Can We Do Better? • Problem: Boilerplate code for declaring implicit parameters • Repeating this 3x does not look so terrible. • But in the dotty compiler there are 2641(!) occurrences of • We’d like to get rid of them.
  • 47. Towards A Solution Let’s massage the definition of f1 a bit: f1’s right hand side is now an implicit function value. What is its type? So far: Transaction => Int From now on: implicit Transaction => Int or, desugared: ImplicitFunction1[Transaction, Int]
  • 48. Inside ImplicitFunction1 ImplicitFunction1 can be thought of being defined as follows: Analogously for all other arities.
  • 49. Two Rules for Typing 1. Implicit functions get implicit arguments just like implicit methods. Given: f expands to f(a) 2. Implicit functions get created on demand. If the expected type of b is implicit A => B, then b expands to implicit _: A => b
  • 50. Revised Example: But where does current come from?
  • 52. Summary • Implicit function types are a neat way to abstract over contexts. • It’s a very powerful feature, because it allows one to inject implicit values in a scope simply by defining type. • This opens up a lot of possibilities. • I expect it will fundamentally affect the kind of Scala code in the future.
  • 53. When Can I Expect This? Scala 2.12 Scala 2.13 Scala 3.0 TASTY, middle end? stdlib collections dotty MVP dotty 0.x releases 2016 backend, classpath handling Scala 2.14 2017 2018 This is open source work, depends on community’s contributions. à Roadmap is tentative, no promises: “MVP” = minimal viable prototype
  • 54. Contributors Theory (DOT): Nada Amin, Tiark Rompf, Sandro Stucki, Samuel Grütter. based on previous work by Adriaan Moors, Donna Malayeri, Geoffrey Washburn, and others. Implementation (dotty): Many contributors, including Dmitry Petrashko Nicolas Stucki Guillaume Martres Sebastien Douraene Felix Mulder Ondrej Lhotak Liu Fengyun Vera Salvisberg Close collaboration with scalac team Adriaan Moors Seth Tisue Jason Zaugg Stefan Zeiger Lukas Rytz
  • 55. Find out more on scala-lang.org/blog