implementing
play

Implementing Method Type Specialisation In Dotty T Outline What - PowerPoint PPT Presentation

Author Alexandre Sikiaridis Masters Student - EPFL Supervised by Dmitry Petrashko Martin Odersky Method Type Specialisation in Dotty Implementing Method Type Specialisation In Dotty T Outline What is specialisation? Method


  1. Author Alexandre Sikiaridis Masters Student - EPFL Supervised by Dmitry Petrashko Martin Odersky Method Type Specialisation in Dotty Implementing Method Type Specialisation In Dotty T

  2. Outline • What is specialisation? • Method Specialisation - Implementation in Dotty • Future Developments Method Type Specialisation in Dotty 1/15

  3. What is Specialisation? • Scala compiles parametric polymorphism away through boxing • This impacts runtime performance negatively Method Type Specialisation in Dotty 2/15

  4. What is Specialisation? • Scala compiles parametric polymorphism away through boxing • This impacts runtime performance negatively Method Type Specialisation in Dotty 2/15

  5. What is Specialisation? Method Type Specialisation in Dotty 2/15 Compiled with scalac

  6. What is Specialisation? • Specialisation is an optimisation option • It avoids boxing by generating ’’ specialised ’’ copies of methods and classes Method Type Specialisation in Dotty 3/15

  7. What is Specialisation? • Specialisation is an optimisation option • It avoids boxing by generating ’’ specialised ’’ copies of methods and classes Method Type Specialisation in Dotty @specialised(Int) 3/15

  8. What is Specialisation? Method Type Specialisation in Dotty 3/15 Compiled with scalac

  9. What is Specialisation? • Beware! Specialisation may result in significant code-size increase • Creates 10 copies per type parameter (9 primitive types) – so 1’000 clones of methods like Function3 • “The greatest shortcoming of the human race is our inability to Method Type Specialisation in Dotty understand the exponential function .” ~ Albert A. Bartlett 4/15

  10. What is Specialisation? • Beware! Specialisation may result in significant code-size increase • Creates 10 copies per type parameter (9 primitive types) – so 1’000 clones of methods like Function3 • “The greatest shortcoming of the human race is our inability to Method Type Specialisation in Dotty understand the exponential function .” ~ Albert A. Bartlett 4/15

  11. Implementation in Dotty Method Type 5/15 Specialisation in Dotty

  12. Implementation in Dotty • Can be divided into four steps • Annotations retrieval Method Type Specialisation in Dotty • Symbols generation • Trees translation • Method calls dispatching 6/15

  13. Implementation in Dotty • Can be divided into four steps • Annotations retrieval PreSpecializer Method Type Specialisation in Dotty • Symbols generation DenotTransformer • Trees translation TypeSpecializer • Method calls dispatching 6/15

  14. Annotations Retrieval • Specialisation is done on- demand • Either user-provided, requested by an earlier phase Method Type (e.g. Linker) or triggered with Specialisation in Dotty ‘’ -Yspecialize:all ’’ 7/15

  15. Annotations Retrieval • Specialisation is done on- demand • Either user-provided, requested by an earlier phase Method Type (e.g. Linker) or triggered with Specialisation in Dotty ‘’ -Yspecialize:all ’’ • @specialized annotations trigger the optimisation • Parameters to the annotation can be Types or Specializable Groups 7/15

  16. Annotations Retrieval • Specialisation is done on- demand • Either user-provided, requested by an earlier phase Method Type (e.g. Linker) or triggered with Specialisation in Dotty ‘’ -Yspecialize:all ’’ • @specialized annotations trigger the optimisation • Parameters to the annotation can be Types or Specializable Groups • Those have to be retrieved 7/15 upfront

  17. Annotations Retrieval • Specialisation types are passed along to TypeSpecializer with the concerned method’s symbol, through a PhaseCache Method Type Specialisation in Dotty • Requests are later stored by TypeSpecializer in a map from symbol to types list 8/15

  18. Symbols Generation • TypeSpecializer triggers the generation of specialised symbols when appropriate • Produces the combinatations of primitive types indicated by PreSpecializer Method Type Specialisation in Dotty • Calls DenotTransformer for concrete generation of Symbols 9/15

  19. Symbols Generation • Dotty performs caching for subtypes • It holds ’’ Frozen ’’ Flags to ensure transformations are transferred to subtypes • Symbols must be generated during transformation of the Method Type Specialisation in Dotty denotation of the owner • They can then be entered in their owner’s scope • Method declarations outside of classes can be specialised without those precautions 10/15

  20. Trees Translation • TypeSpecializer goes through all DefDef ’s • If it finds one that has been requested for Method Type Specialisation in Dotty specialisation: • It creates a PolyDefDef remembering TypeBounds • It instantiates a TreeTypeMap handling recursive translation of the 11/15 RHS

  21. Incomplete Type Information (Refers to issue #592 | www.github.com/lampepfl/dotty/issues/592) • In some cases, relying on type inference fails and creates TypeMismatch errors Method Type Specialisation in Dotty • From A<:B and B<:Int , typechecker does not infer A<:Int • Returning Foo[A] does not fit the expected Foo[Int] • Elected solution: type casts 12/15

  22. Incomplete Type Information 12/15 Method Type Specialisation in Dotty

  23. Method Calls Dispatching • Method calls are compared to generated specialised variants • If several variants are available, best fitting one is determined by comparing argument types at call site and those of the Method Type specialised variant Specialisation in Dotty • If not all types fit, method call remains generic 13/15

  24. Future Developments • Partial Specialisation Method Type Specialisation in Dotty • ’’ What if I only want to specialise T ?’’ • A prototype exists, but needs some debugging still • Class Specialisation 14/15 • More testing

  25. A ’’ Special ’’ Thank You Method Type Specialisation in Dotty I. Dragos Type Specialization in Scala 2.8 [http://www.scala-lang.org/old/sites/default/files/sids/dragos/Thu,%202010-05- 15/15 06,%2017:56/sid-spec.pdf]

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend