Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla...
Transcript of Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla...
![Page 1: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/1.jpg)
Project Valhalla: The Good, the Bad and the Ugly
18th of March 2015ScalaDays SF
San Francisco, CA
![Page 2: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/2.jpg)
Vlad URECHEPhD student in the Scala Team @ EPFL
Working on program transformations in the Scala programming language, focusing on data representation.Contributions to specialization, backend and Scaladoc.
@
@VladUreche
@VladUreche
![Page 3: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/3.jpg)
Vlad URECHEPhD student in the Scala Team @ EPFL
Working on program transformations in the Scala programming language, focusing on data representation.Contributions to specialization, backend and Scaladoc.
@
@VladUreche
@VladUreche
Miniboxing is an alternativeto the specialization trans-formation in scalac:
● Guides the programmerinto maximizing performance
● Moderate increase in bytecode size
● Good performance
See scala-miniboxing.org.
![Page 4: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/4.jpg)
Vlad URECHEPhD student in the Scala Team @ EPFL
Working on program transformations in the Scala programming language, focusing on data representation.Contributions to specialization, backend and Scaladoc.
@
@VladUreche
@VladUreche
Late Data Layout is the underlying technique used for:
● Programmer-driventransformations
● Miniboxing● Multi-param value classes● Compiler support for
multi-stage programming
See scala-ldl.org.
![Page 5: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/5.jpg)
Project Valhalla: The Good, the Bad and the Ugly
![Page 6: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/6.jpg)
Project ValhallaProject Valhalla
● Oracle project – started in 2014
– goal: support for● specialization and ● value classes
– in the Java Virtual Machine
– effort lead by Brian Goetz and John Rose● No hard promises
– but it might make it into JDK 10
![Page 7: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/7.jpg)
Project Valhalla: The Good, the Bad and the Ugly
![Page 8: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/8.jpg)
Project Valhalla: The Good, the Bad and the Ugly
● Generics Specialization● Very good performance● Predictable results
● Support for value classes● Even for multiple
parameters
![Page 9: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/9.jpg)
Project Valhalla: The Good, the Bad and the Ugly
● Incompatible with the Scala type system● Variance● Existential quantification
![Page 10: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/10.jpg)
Project Valhalla: The Good, the Bad and the Ugly
● We can support the Scalatype system to some extent● But some patterns are no
longer compatible
![Page 11: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/11.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 12: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/12.jpg)
CompilersCompilers
![Page 13: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/13.jpg)
CompilersCompilers
Source code(language 1)
compiler
C, C++, Java, Scala, C#, Haskell, Clojure, ...
![Page 14: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/14.jpg)
CompilersCompilers
Source code(language 1)
Source code(language 2)
compiler
C, C++, Java, Scala, C#, Haskell, Clojure, ...
x86/ARM assemblyLLVM bitcodeCuda codeJVM bytecode.NET bytecode...
![Page 15: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/15.jpg)
CompilersCompilers
Source code(language 1)
Source code(language 2)
compiler
C, C++, Java, Scala, C#, Haskell, Clojure, ...
x86/ARM assemblyLLVM bitcodeCuda codeJVM bytecode.NET bytecode...
Why so much fuss ?
![Page 16: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/16.jpg)
CompilersCompilers
Abstraction Imple-mentation
compiler
![Page 17: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/17.jpg)
CompilersCompilers
Abstraction Imple-mentation
compiler
Variable
![Page 18: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/18.jpg)
CompilersCompilers
Abstraction Imple-mentation
compiler
Variable Stack slot orProcessor register orHeap location
![Page 19: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/19.jpg)
CompilersCompilers
Abstraction Imple-mentation
compiler
Variable Stack slot orProcessor register orHeap location
… Implementation details
![Page 20: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/20.jpg)
Scala compilerScala compiler
Scala Abstractions
![Page 21: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/21.jpg)
Scala compilerScala compiler
Scala Abstractions
scalac JVM Bytecode
![Page 22: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/22.jpg)
Scala compilerScala compiler
Scala Abstractions
scalac
Types
JVM Bytecode
![Page 23: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/23.jpg)
Scala compilerScala compiler
Scala Abstractions
scalac
Types ClassesInterfaces
JVM Bytecode
![Page 24: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/24.jpg)
Scala compilerScala compiler
trait T1trait T2val t: T1 with T2 = new T1 with T2
![Page 25: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/25.jpg)
Scala compilerScala compiler
trait T1trait T2val t: T1 with T2 = new T1 with T2
…class $anon extends T1 with T2 { … }val t: T1 = new $anon
equivalentsource forthe JVMbytecodeoutput by
scalac
![Page 26: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/26.jpg)
Scala compilerScala compiler
trait T1trait T2val t: T1 with T2 = new T1 with T2
…class $anon extends T1 with T2 { … }val t: T1 = new $anon
![Page 27: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/27.jpg)
Scala compilerScala compiler
trait T1trait T2val t: T1 with T2 = new T1 with T2
…class $anon extends T1 with T2 { … }val t: T1 = new $anon
instantiation class
![Page 28: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/28.jpg)
Scala compilerScala compiler
trait T1trait T2val t: T1 with T2 = new T1 with T2
…class $anon extends T1 with T2 { … }val t: T1 = new $anon
referenceclass/interface
instantiation class
![Page 29: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/29.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
![Page 30: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/30.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new $anon
new T1 { ... }
new T1 with ...
● For any new instantiation in the source code, there must exist a bytecode class that is instantiated
![Page 31: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/31.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new $anon
t: T1
t: T1 with ...: T1
new T1 { ... }
new T1 with ...
● For any new instantiation in the source code, there must exist a bytecode class that is instantiated
● For any value of a type in the source code, there must exist a class or interface that allows calling its methods
![Page 32: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/32.jpg)
Scala compilerScala compiler
Scala Abstractions
scalac
Types ClassesInterfaces
JVM Bytecode
![Page 33: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/33.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 34: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/34.jpg)
Valhalla ProposalValhalla Proposal
● Presentation is based on an documented proposal– Submitted for review to the
● scala-internals and ● valhalla-dev mailing lists
● Proposal document: go.epfl.ch/valhalla– Not yet a pre-SIP, it's too early
![Page 35: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/35.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 36: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/36.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
Erasure
![Page 37: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/37.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
![Page 38: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/38.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
![Page 39: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/39.jpg)
Generic Type ParamsGeneric Type Params
def foo[T](t: T) = new C[T](t)
def foo(t: Object): … = new …(t)
![Page 40: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/40.jpg)
Generic Type ParamsGeneric Type Params
def foo[T](t: T) = new C[T](t)
def foo(t: Object): … = new …(t)
The decision mustbe made staticallyat compile-time.
![Page 41: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/41.jpg)
Generic Type ParamsGeneric Type Params
def foo[T](t: T) = new C[T](t)
def foo(t: Object): C = new C(t)
![Page 42: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/42.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
![Page 43: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/43.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
![Page 44: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/44.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
c: C[_]
![Page 45: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/45.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance
Code size
Abstraction
Instantiation
Applicability
Type-baseddecisions
![Page 46: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/46.jpg)
Erasure>PerformanceErasure>Performance
class C[+T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
![Page 47: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/47.jpg)
Erasure>PerformanceErasure>Performance
class C[+T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
class C(t: Object)val c1: C = new C(???)val c2: C = new C(???)
![Page 48: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/48.jpg)
class C(t: Object)val c1: C = new C(???)val c2: C = new C(???)
Erasure>PerformanceErasure>Performance
class C[+T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
Need to box values → overhead
![Page 49: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/49.jpg)
Erasure>PerformanceErasure>Performance
class C[+T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
class C(t: Object)val c1: C = new C(Integer.valueOf(3))val c2: C = new C(Double.valueOf(3.0))
![Page 50: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/50.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size
Abstraction
Instantiation
Applicability
Type-baseddecisions
![Page 51: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/51.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
c: C[_]
![Page 52: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/52.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
c: C[_]
![Page 53: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/53.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
c: C[_]
This is the bytecode part.
![Page 54: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/54.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C
Erasure
: C
![Page 55: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/55.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction
Instantiation
Applicability
Type-baseddecisions
![Page 56: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/56.jpg)
Erasure>AbstractionErasure>Abstraction
class C[+T](t: T)val c1: C[_] = new C(3)val c2: C[Any] = new C(3.0)
![Page 57: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/57.jpg)
Erasure>AbstractionErasure>Abstraction
class C[+T](t: T)val c1: C[_] = new C(3)val c2: C[Any] = new C(3.0)
class C(t: Object)val c1: C = new C(Integer.valueOf(3))val c2: C = new C(Double.valueOf(3.0))
![Page 58: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/58.jpg)
Erasure>AbstractionErasure>Abstraction
class C[+T](t: T)val c1: C[_] = new C(3)val c2: C[Any] = new C(3.0)
class C(t: Object)val c1: C = new C(Integer.valueOf(3))val c2: C = new C(Double.valueOf(3.0))
Both variance and existentials can be
translated easily whenusing erasure.
![Page 59: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/59.jpg)
Erasure>AbstractionErasure>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
![Page 60: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/60.jpg)
Erasure>AbstractionErasure>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1) = ...def identity: Function1 = ...foo(identity)
![Page 61: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/61.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation
Applicability
Type-baseddecisions
![Page 62: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/62.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation
Applicability
Type-baseddecisions
● skipped in the presentation● fully described in the proposal
go.epfl.ch/valhalla
![Page 63: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/63.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation
Applicability
Type-baseddecisions
![Page 64: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/64.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation
Applicability
Type-baseddecisions
Is it always possible toinstantiate the type desired.e.g. not for Array[T], which needs a ClassTag in scope forthe instantiation
![Page 65: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/65.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability
Type-baseddecisions
Is it always possible toinstantiate the type desired.e.g. not for Array[T], which needs a ClassTag in scope forthe instantiation
![Page 66: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/66.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability
Type-baseddecisions
Is it always possible toinstantiate the type desired.e.g. not for Array[T], which needs a ClassTag in scope forthe instantiation
Depending on the approachto implementing generics, classes can be optimized for:● primitive types● value classes● both
![Page 67: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/67.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
Is it always possible toinstantiate the type desired.e.g. not for Array[T], which needs a ClassTag in scope forthe instantiation
Depending on the approachto implementing generics, classes can be optimized for:● primitive types● value classes● both
![Page 68: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/68.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
Is it always possible toinstantiate the type desired.e.g. not for Array[T], which needs a ClassTag in scope forthe instantiation
Depending on the approachto implementing generics, classes can be optimized for:● primitive types● value classes● both
Can code behave differentlybased on the type argumentsused to instantiate it?
![Page 69: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/69.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
worst
Is it always possible toinstantiate the type desired.e.g. not for Array[T], which needs a ClassTag in scope forthe instantiation
Depending on the approachto implementing generics, classes can be optimized for:● primitive types● value classes● both
Can code behave differentlybased on the type argumentsused to instantiate it?
![Page 70: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/70.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
worst
![Page 71: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/71.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst
Code size best
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
worst
Can we fix this?Enter Project Valhalla.
![Page 72: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/72.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 73: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/73.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
c: C[_]
![Page 74: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/74.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
new C
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Erasure
: C
Forces boxed arguments.
c: C[_]
![Page 75: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/75.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla c: C[_]
![Page 76: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/76.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C : C
c: C[_]
![Page 77: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/77.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=int}
new C : C
: C_{T=int}
c: C[_]
![Page 78: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/78.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
c: C[_]
![Page 79: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/79.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
![Page 80: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/80.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
![Page 81: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/81.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
???
???
![Page 82: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/82.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
???
???
Java forbids the equivalentof C[T] and C[_]
![Page 83: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/83.jpg)
Valhalla>PerformanceValhalla>Performance
class C[any +T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
![Page 84: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/84.jpg)
class C(t: Object)class C_{T=int}(t: int)class C_{T=double}(t: double)
Valhalla>PerformanceValhalla>Performance
class C[any +T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
![Page 85: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/85.jpg)
class C(t: Object)class C_{T=int}(t: int)class C_{T=double}(t: double)val c1: C = new C_{T=int}(3)val c2: C = new C_{T=double}(3.0)
Valhalla>PerformanceValhalla>Performance
class C[any +T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
![Page 86: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/86.jpg)
class C(t: Object)class C_{T=int}(t: int)class C_{T=double}(t: double)val c1: C = new C_{T=int}(3)val c2: C = new C_{T=double}(3.0)
Valhalla>PerformanceValhalla>Performance
class C[any +T](t: T)val c1: C[Int] = new C(3)val c2: C[Double] = new C(3.0)
Unboxed values
![Page 87: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/87.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best
Code size best
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
worst
![Page 88: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/88.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
???
???
![Page 89: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/89.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
instantiated atloading-timefrom thebytecode template
bytecode for the erased version + metadata necessary to instantiate the class for value types
![Page 90: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/90.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best
Code size best good
Abstraction best
Instantiation best
Applicability worst
Type-baseddecisions
worst
![Page 91: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/91.jpg)
Valhalla>AbstractionValhalla>Abstraction
class C[any +T](t: T)val c: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
![Page 92: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/92.jpg)
Valhalla>AbstractionValhalla>Abstraction
class C[any +T](t: T)val c: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
![Page 93: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/93.jpg)
Valhalla>AbstractionValhalla>Abstraction
class C[any +T](t: T)val c: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
// C_{T=double}
![Page 94: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/94.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
???
???
![Page 95: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/95.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
Valhalla
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C : C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
???
???
Different classes, nothingin common among them
![Page 96: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/96.jpg)
Valhalla>AbstractionValhalla>Abstraction
class C[any +T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
// C_{T=double}
![Page 97: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/97.jpg)
Valhalla>AbstractionValhalla>Abstraction
class C[any +T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
// C_{T=double}
// Object :(
![Page 98: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/98.jpg)
Valhalla>AbstractionValhalla>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
![Page 99: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/99.jpg)
Valhalla>AbstractionValhalla>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1_{T1=int,R=int}) = ...def identity: Function1 = ...foo(identity[Int])
![Page 100: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/100.jpg)
Valhalla>AbstractionValhalla>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1_{T1=int,R=int}) = ...def identity: Function1 = ...foo(identity[Int])
Mismatch, the erasedFunction1 and the
instantiated templateFunction1_{T1=...} are
incompatible
![Page 101: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/101.jpg)
Valhalla>AbstractionValhalla>Abstraction
● What does it mean to you?– We lost definition-site variance (class C[+T])
– We lost existential quantification over values (C[_])
– Specialization is all-or-nothing● .NET experience not all code is worth specializing→
![Page 102: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/102.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best
Code size best good
Abstraction best worst
Instantiation best
Applicability worst
Type-baseddecisions
worst
![Page 103: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/103.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best
Code size best good
Abstraction best worst
Instantiation best worst
Applicability worst best
Type-baseddecisions
worst best
![Page 104: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/104.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best
Code size best good
Abstraction best worst
Instantiation best worst
Applicability worst best
Type-baseddecisions
worst best
No go for ScalaMiniboxing addresses that
![Page 105: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/105.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 106: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/106.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
c: C[_]
![Page 107: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/107.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
new C_L
new C_J
new C_D
c: C[_]
![Page 108: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/108.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
![Page 109: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/109.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
c: C[_]
Common interface shared by all miniboxed classes
new C_L
new C_J
new C_D
![Page 110: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/110.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best
Code size best good
Abstraction best worst
Instantiation best worst
Applicability worst best
Type-baseddecisions
worst best
![Page 111: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/111.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance
![Page 112: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/112.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
![Page 113: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/113.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
![Page 114: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/114.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
For T = Int
![Page 115: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/115.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
For T = Int
![Page 116: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/116.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
For T = Int
![Page 117: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/117.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
The object version of Cacts as type C[Int]
→ suboptimal
For T = Int
![Page 118: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/118.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
![Page 119: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/119.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible, but we lose all abstraction→
![Page 120: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/120.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible, but we lose all abstraction→– Specialization →
![Page 121: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/121.jpg)
Miniboxing>PerformanceMiniboxing>Performance
scala> class C[@specialized T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> new C(3)res0: C[Int] = C$mcI$sp@33b1594e // specialized version
scala> newC(3)res1: C[Int] = C@7de0a5c6 // generic version
specialization
![Page 122: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/122.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible, but we lose all abstraction→– Specialization slowdown, no warning→
![Page 123: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/123.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible, but we lose all abstraction→– Specialization slowdown, no warning→– Miniboxing →
![Page 124: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/124.jpg)
Miniboxing>PerformanceMiniboxing>Performanceminiboxing
scala> class C[@miniboxed T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)<console>:8: warning: The following code could benefit from miniboxing specialization if the type parameter T of method newC would be marked as "@miniboxed T" (it would be used to instantiate miniboxed type parameter T of class C) def newC[T](t: T) = new C(t) ^newC: [T](t: T)C[T]
scala> new C(3)res0: C[Int] = C_J@5b649d6f // specialized version
scala> newC(3)<console>:10: warning: The method newC would benefit from miniboxing type parameter T, since it is instantiated by a primitive type. newC(3) ^res1: C[Int] = C_L@38013f5a // generic version
![Page 125: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/125.jpg)
Miniboxing>PerformanceMiniboxing>Performanceminiboxing
scala> class C[@miniboxed T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)<console>:8: warning: The following code could benefit from miniboxing specialization if the type parameter T of method newC would be marked as "@miniboxed T" (it would be used to instantiate miniboxed type parameter T of class C) def newC[T](t: T) = new C(t) ^newC: [T](t: T)C[T]
scala> new C(3)res0: C[Int] = C_J@5b649d6f // specialized version
scala> newC(3)<console>:10: warning: The method newC would benefit from miniboxing type parameter T, since it is instantiated by a primitive type. newC(3) ^res1: C[Int] = C_L@38013f5a // generic version
What it's trying to say:Hey, you're about to shoot
yourself in the foot! Watch out!
![Page 126: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/126.jpg)
Miniboxing>PerformanceMiniboxing>Performanceminiboxing
scala> class C[@miniboxed T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)<console>:8: warning: The following code could benefit from miniboxing specialization if the type parameter T of method newC would be marked as "@miniboxed T" (it would be used to instantiate miniboxed type parameter T of class C) def newC[T](t: T) = new C(t) ^newC: [T](t: T)C[T]
scala> new C(3)res0: C[Int] = C_J@5b649d6f // specialized version
scala> newC(3)<console>:10: warning: The method newC would benefit from miniboxing type parameter T, since it is instantiated by a primitive type. newC(3) ^res1: C[Int] = C_L@38013f5a // generic version
What it's trying to say:Hey, you're about to shoot
yourself in the foot! Watch out!
What it's trying to say:Should I call a doctor?
![Page 127: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/127.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible, but we lose all abstraction→– Specialization slowdown, no warning→– Miniboxing warns, but still slows down→
Heed the warnings!
![Page 128: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/128.jpg)
Miniboxing>PerformanceMiniboxing>Performance
● Examples– “Clash of the Lambdas” Scala benchmarks (vs Java8)
● improved by 2.5-14x over generic (arxiv.org)
– “Optimistic Re-Specialization” (Tom Switzer)● improved by 10x over generic (io.pellucid.com)
– Many other benchmarks● on the website scala-miniboxing.org
![Page 129: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/129.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good
Code size best good
Abstraction best worst
Instantiation best worst
Applicability worst best
Type-baseddecisions
worst best
![Page 130: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/130.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]
: C
: C
: C
new C_L
new C_J
new C_D
c: C[_]
![Page 131: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/131.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
: C
: C
: C
new C_L
new C_J
new C_D
bytecode
![Page 132: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/132.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good
Code size best good worst
Abstraction best worst
Instantiation best worst
Applicability worst best
Type-baseddecisions
worst best
![Page 133: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/133.jpg)
Miniboxing>AbstractionMiniboxing>Abstraction
class C[@miniboxed T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// bytecode: C_J
// bytecode: C_D
![Page 134: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/134.jpg)
Miniboxing>AbstractionMiniboxing>Abstraction
class C[@miniboxed T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// bytecode: C_J
// bytecode: C_D
// bytecode: C
![Page 135: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/135.jpg)
Miniboxing>AbstractionMiniboxing>Abstraction
class C[@miniboxed T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// bytecode: C_J
// bytecode: C_D
// bytecode: C
![Page 136: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/136.jpg)
Miniboxing>AbstractionMiniboxing>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
![Page 137: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/137.jpg)
Miniboxing>AbstractionMiniboxing>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1) = ...def identity: Function1 = ...foo(identity)
![Page 138: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/138.jpg)
Miniboxing>AbstractionMiniboxing>Abstraction
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1) = ...def identity: Function1 = ...foo(identity)
![Page 139: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/139.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good
Code size best good worst
Abstraction best worst good
Instantiation best worst
Applicability worst best
Type-baseddecisions
worst best
![Page 140: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/140.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good
Code size best good worst
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 141: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/141.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good
Code size best good worst
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
Either solution has adrawback. What about
combining them?
![Page 142: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/142.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 143: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/143.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
???
???Valhalla
![Page 144: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/144.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
Generic
???
???Ragnarök
![Page 145: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/145.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
Generic
???
???Ragnarök
![Page 146: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/146.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
C_interface
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
GenericRagnarök
![Page 147: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/147.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
C_interface
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
GenericRagnarök
![Page 148: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/148.jpg)
RagnarökRagnarök
● Instantiated templates are specialized– But contain a compatibility layer
● Generic interface abstracts over the compat. layer– At the cost of losing optimality
– Some limitations still apply
![Page 149: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/149.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good
Code size best good worst
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 150: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/150.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good best
Code size best good worst
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 151: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/151.jpg)
RagnarökRagnarök>Performance>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible→– Specialization no warning, slowdown→– Miniboxing warns, but still slows down→
![Page 152: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/152.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
C_interface
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
GenericRagnarök
![Page 153: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/153.jpg)
RagnarökRagnarök>Performance>Performance
● Good baseline performance● But there are slowdowns
– Object version used for primitive types
– Valhalla impossible, but we lose all abstraction→– Specialization slowdown, no warning→– Miniboxing warns, but still slows down→– Ragnarok → like miniboxing
![Page 154: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/154.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good best
Code size best good worst
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 155: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/155.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good good
Code size best good worst
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 156: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/156.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
Specialized
Generic
load-time
bytecode
C_interface
: C_{T=int}
: C_{T=float}
: C_{T=double}
: C
Ragnarök
![Page 157: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/157.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good good
Code size best good worst good
Abstraction best worst good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 158: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/158.jpg)
Ragnarök>AbstractionRagnarök>Abstraction
class C[T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
// C_{T=double}
![Page 159: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/159.jpg)
Ragnarök>AbstractionRagnarök>Abstraction
class C[T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
// C_{T=double}
// C_interface
![Page 160: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/160.jpg)
Ragnarök>AbstractionRagnarök>Abstraction
class C[T](t: T)val c1: C[_] = if (…) new C[Int](3) else new C[Double](3.0)
// C_{T=int}
// C_{T=double}
// C_interface
![Page 161: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/161.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good good
Code size best good worst good
Abstraction best worst good good
Instantiation best worst good
Applicability worst best good
Type-baseddecisions
worst best good
![Page 162: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/162.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good good
Code size best good worst good
Abstraction best worst good good
Instantiation best worst good good
Applicability worst best good good
Type-baseddecisions
worst best good good
![Page 163: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/163.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good good
Code size best good worst good
Abstraction best worst good
Instantiation best worst good good
Applicability worst best good good
Type-baseddecisions
worst best good good
goodish
![Page 164: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/164.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 165: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/165.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
Ragnarok
![Page 166: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/166.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
Ragnarok
![Page 167: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/167.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> val c1: C[Int] = new C(3)c1: C[Int] = C_{T=int}@33b1594e
Ragnarok
![Page 168: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/168.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> val c1: C[Int] = new C(3)c1: C[Int] = C_{T=int}@33b1594e
scala> val c2: C[Int] = newC(3)
Ragnarok
![Page 169: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/169.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> val c1: C[Int] = new C(3)c1: C[Int] = C_{T=int}@33b1594e
scala> val c2: C[Int] = newC(3)<console>:10: error: Type mismatch:found: C[Int] (generic)expected: C[Int] (specialized)
val c1: C[Int] = new C(3) ^
Ragnarok
![Page 170: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/170.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
C_interface
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
GenericRagnarök
![Page 171: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/171.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T]
new C[String]
new C[Int]
new C[Float]
new C[Double]
c: C[T]
c: C[String]
c: C[Int]
c: C[Float]
c: C[Double]new C_{T=double}
new C_{T=float}
new C_{T=int}
new C
C_interface
: C_{T=int}
: C_{T=float}
: C_{T=double}
c: C[_]
: C
Specialized
GenericRagnarök
Instantiate in genericcontext with T = Int
![Page 172: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/172.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T] c: C[T]
c: C[Int]
new C
C_interface
: C_{T=int}
: C
Specialized
GenericRagnarök
Instantiate in genericcontext with T = Int
![Page 173: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/173.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T] c: C[T]
c: C[Int]
new C
C_interface
: C_{T=int}
: C
Specialized
GenericRagnarök
Instantiate in genericcontext with T = Int
![Page 174: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/174.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T] c: C[T]
c: C[Int]
new C
C_interface
: C_{T=int}
: C
Specialized
GenericRagnarök
Instantiate in genericcontext with T = Int
C_{T=int} is a strongerpromise than C_interface
![Page 175: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/175.jpg)
GenericGeneric
ImplementationImplementationGenericGeneric
ReferenceReference
new C[T] c: C[T]
c: C[Int]
new C
C_interface
: C_{T=int}
: C
Specialized
GenericRagnarök
Instantiate in genericcontext with T = Int
C_{T=int} is a strongerpromise than C_interface
At bytecode level:C_{T_int} is a subtype of C_interface
C_interface is not a subtype of C_{T=int}
![Page 176: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/176.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> val c1: C[Int] = new C(3)c1: C[Int] = C_{T=int}@33b1594e
scala> val c2: C[Int] = newC(3)<console>:10: error: Type mismatch:found: C[Int] (generic)expected: C[Int] (specialized)
val c1: C[Int] = new C(3) ^
Ragnarok
![Page 177: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/177.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> val c1: C[Int] = new C(3)c1: C[Int] = C_{T=int}@33b1594e
scala> val c2: C[Int] = newC(3)<console>:10: error: Type mismatch:found: C[Int] (generic) // C_interfaceexpected: C[Int] (specialized) // C_{T=int}
val c1: C[Int] = new C(3) ^
Ragnarok
![Page 178: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/178.jpg)
Ragnarök>LimitationsRagnarök>Limitations
scala> class C[any T](t: T)defined class C
scala> def newC[T](t: T) = new C(t)newC: [T](t: T)C[T]
scala> val c1: C[Int] = new C(3)c1: C[Int] = C_{T=int}@33b1594e
scala> val c2: C[Int] = newC(3)<console>:10: error: Type mismatch:found: C[Int] (generic) // C_interfaceexpected: C[Int] (specialized) // C_{T=int}
val c1: C[Int] = new C(3) ^
Ragnarok
At bytecode level:C_{T_int} is a subtype of C_interface
C_interface is not a subtype of C_{T=int}
![Page 179: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/179.jpg)
Motivation
Generics
Conclusion
Compatibility
Limitations
Erasure
Valhalla
Miniboxing
![Page 180: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/180.jpg)
ConclusionConclusion
● Ragnarök Proposal: go.epfl.ch/valhalla● Valhalla
– Load-time instantiation support● Miniboxing
– Compatibility scheme
– Warnings ● Still in progress
– Abstractions (addressing the limitations)
![Page 182: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/182.jpg)
PropertiesProperties
Erasure Valhalla Miniboxing Ragnarök
Performance worst best good good
Code size best good worst good
Abstraction best worst good
Instantiation best worst good good
Applicability worst best good good
Type-baseddecisions
worst best good good
goodish
![Page 183: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/183.jpg)
Ragnarök>LimitationsRagnarök>Limitations
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
![Page 184: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/184.jpg)
RagnarökRagnarök>Limitations>Limitations
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1_{T1=int,R=int}) = ...def identity: Function1_interface = ...foo(identity)
![Page 185: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/185.jpg)
RagnarökRagnarök>Limitations>Limitations
def foo(t: Int => Int) = ...def identity[T]: T=> T = ...foo(identity[Int])
def foo(t: Function1_{T1=int,R=int}) = ...def identity: Function1_interface = ...foo(identity)
Mismatch: expected: Function1_{T1=int,R=int} found: Function1_interface
![Page 186: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/186.jpg)
RagnarökRagnarök>Limitations>Limitations
scala> def foo(f: Int => Int) = f(3)foo: (t: Int => Int)Int
scala> def identity[T]: T=>T = (x: T) => xidentity: [T]=> T => T
scala> foo(identity[Int])<console>:10: error: The result of method identity is a generic Function1[T, T], which is instantiated for T=Int. However, this is not compatible with the specialized Function1[Int, Int]. A fix would be to mark the type parameter T of method identity as “any T”:
foo(identity[Int]) ^
![Page 187: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/187.jpg)
RagnarökRagnarök>Limitations>Limitations
def foo(t: Int => Int) = ...def identity[any T]: T => T = ...foo(identity[Int])
![Page 188: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/188.jpg)
RagnarökRagnarök>Limitations>Limitations
def foo(t: Int => Int) = ...def identity[any T]: T => T = ...foo(identity[Int])
![Page 189: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/189.jpg)
RagnarökRagnarök>Limitations>Limitations
def foo(t: Any => Nothing) = …// works with and without “any”:def identity[T]: T=> T = ...foo(identity[Int])
![Page 190: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/190.jpg)
RagnarökRagnarök>Limitations>Limitations
def foo(t: Any => Nothing) = …// works with and without “any”:def identity[T]: T=> T = ...foo(identity[Int])
![Page 191: Project Valhalla - Lightbenddownloads.typesafe.com/website/...Project_Valhalla.pdfProject Valhalla Oracle project – started in 2014 – goal: support for specialization and value](https://reader036.fdocuments.us/reader036/viewer/2022062913/5e4116a1248bf914d56ffb44/html5/thumbnails/191.jpg)
RagnarökRagnarök>Limitations>Limitations
scala> def foo(f: Int => Int) = f(3)foo: (t: Int => Int)Int
scala> def identity[T]: T=>T = (x: T) => xidentity: [T]=> T => T
scala> foo(identity[Int])<console>:10: error: The result of method identity is a generic Function1[T, T], which is instantiated for T=Int. However, this is not compatible with the specialized Function1[Int, Int]. A fix would be to mark the type parameter T of method identity as “any T”:
foo(identity[Int]) ^
Mock-up of a possibleerror message