SlideShare a Scribd company logo
1 of 14
Download to read offline
Managing Binary Compatibility in Scala

                Mirco Dotta

                    Typesafe


                June 3, 2011




            Mirco Dotta   Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion


Outline



   Introduction
       Example
       Scala vs. Java


   Sources of Incompatibility
      Type Inferencer
      Trait


   Conclusion




                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Example Scala vs. Java


Example

   Assume Analyzer is part of a library we produce. We decide that
   its API has to evolve as follows:
class Analyzer { // old version                            class Analyzer { // new version
  def analyze(issues: HashMap[ , ]) {...}                    def analyze(issues: Map[ , ]) {...}
}                                                          }

   Further, assume the next expression was compiled against the old
   library
   new Analyzer().analyze(new HashMap[Any,Any]())

   Would the compiled code work if run against the new library?

   The answer lies in the bytecode...


                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Example Scala vs. Java


 Example: Bytecode
      Let’s take look at the generated bytecode for the two versions:
class Analyzer { // old version                 class Analyzer { // new version
 analyze(Lscala/collection/immutable/HashMap);V analyze(Lscala/collection/immutable/Map);V
}}                                              }}

      The expression compiled against the old library would look like:
  ...
  invokevirtual #9;// #9 == Analyzer.analyze:(Lscala/collection/immutable/HashMap;)V

      ⇒ The method’s name has been statically resolved at
      compile-time.

      Running it against the new library would result in the JVM
      throwing a NoSuchMethodException.

      ⇒ The evolution of class Analyzer breaks compatibility with
      pre-existing binaries.
                                            Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Example Scala vs. Java


Is Binary Compatibility a Scala issue?


   The short answer is No. The discussed example can be easily
   ported in Java.

   Scala shares with Java many sources of binary incompatibility.

   But Scala offers many language features not available in Java:
          Type Inferencer
          First-class functions
          Multiple inheritance via mixin composition (i.e., traits)
   . . . Just to cite a few.

   ⇒ Scala code has new “unique” sources of binary incompatibility.



                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion      Type Inferencer Trait


Type Inferencer: Member Signature
     Does the following evolution break binary compatibility?
  class TextAnalyzer { // old version                     class TextAnalyzer { // new version
    def analyze(text: String) = {                           def analyze(text: String) = {
       val issues = Map[String,Any]()                          val issues = new HashMap[String,Any]()
       // ...                                                  // ...
       issues                                                  issues
  }}                                                      }}


     Question
     What is the inferred return type of analyze?

     Let’s compare the two methods’ signature.
class TextAnalyzer { // old version                         class TextAnalyzer { // new version
  public scala.collection.immutable.Map                       public scala.collection.immutable.HashMap
     analyze(java.lang.String);                                  analyze(java.lang.String);
}                                                           }


                                           Mirco Dotta       Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Type Inferencer Trait


Type Inferencer: Member Signature (2)

   Question
   Can we prevent the method’s signature change?
   That’s easy! The method’s return type has to be explicitly
   declared:
   class TextAnalyzer { // bytecode compatible new version
     def analyze(text: String): Map[String,Any] = {
        val issues = new HashMap()
        // ...
        issues
   }}


   Take Home Message
   Always declare the member’s type. If you don’t, you may
   inadvertently change the member’s signature.

                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Type Inferencer Trait


Trait Compilation

   Traits are a powerful language construct that enables
   multiple-inheritance on top of a runtime – the JVM – that does
   not natively support it.

   Understanding how traits are compiled is crucial if you need to
   ensure release-to-release binary compatibility.

   So, how does the Scala compiler generate the bytecode of a trait?

   There are two key elements:
          A trait is compiled into an interface plus an abstract class
          containing only static methods.
          “Forwarder” methods are injected in classes inheriting traits.

                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion     Type Inferencer Trait


Trait Compilation Explained
    An example will help visualize how traits get compiled:
    // declared in a library
    trait TypeAnalyzer {
      def analyze(prog: Program) {...}
    }


    // client code
    class TypingPhase extends TypeAnalyzer

    The following is the (pseudo-)bytecode generated by scalac:

interface TypeAnalyzer {                                 class TypingPhase implements TraitAnalyzer {
  void analyze(prog: Program);                             // forwarder method injected by scalac
}                                                          void analyze(prog: Program) {
abstract class TypeAnalyzer$class {                           // delegates to implementation
  static void analyze($this: TypeAnalyzer,                    TypeAnalyzer$class.analyze(this,prog)
                     prog: Program) {                      }
     // the trait’s method impl code                     }
  }
}
                                          Mirco Dotta      Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion    Type Inferencer Trait


Trait: Adding a concrete method
     Question
     Can we add a member in a trait without breaking compatibility
     with pre-existing binaries?

trait TypeAnalyzer { // new version                   // compiled against the old version
  def analyze(prog: Program) {...}                    class TypingPhase implements TraitAnalyzer {
  def analyze(clazz: ClassInfo) {...}                   // forwarder method injected by scalac
}                                                       void analyze(prog: Program) {
                                                           // delegates to implementation
                                                           TypeAnalyzer$class.analyze(this,prog)
//TypeAnalyzer trait compiled                           }
interface TypeAnalyzer {                                // missing concrete implementation!
  void analyze(prog: Program);                          ??analyze(clazz: ClassInfo)??
  void analyze(clazz: ClassInfo);                     }
}
abstract class TypeAnalyzer$class {
  static void analyze($this: TypeAnalyzer,            Take Home Message
        prog: Program{...}
  static void analyze($this: TypeAnalyzer,            Adding a concrete method in a trait
        clazz: ClassInfo) {...}                       breaks binary compatibility.
}
                                           Mirco Dotta     Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Conclusion Future Work Scala Migration Manager


Conclusion


          Ensuring release-to-release binary compatibility of Scala
          libraries is possible.
          Though, sometimes it can be difficult to tell if a change in the
          API of a class/trait will break pre-existing binaries.
          In the discussed examples we have seen that:
                  Type inferencer may be at the root of changes in the signature
                  of a method.
                  Traits are a sensible source of binary incompatibilities.


   It really looks like library’s maintainers’ life ain’t that easy...



                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Conclusion Future Work Scala Migration Manager


Introducing the Scala Migration Manager (MiMa)

   Today we release the Scala Migration Manager! (beta)
          It’s free!!
          It will tell you, library maintainers, if your next release is
          binary compatible with the current one.
          It will tell you, libraries users, if two releases of a library are
          binary compatible.
   MiMa can collect and report all sources of “syntactic” binary
   incompatibilities between two releases of a same library.
          “Syntactic” means NO LinkageError (e.g.,
          NoSuchMethodException) will ever be thrown at runtime.

   Now it’s time for a demo!

                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion   Conclusion Future Work Scala Migration Manager


Future Work


  Reporting binary incompatibilities is only half of the story. We are
  already working on a “companion” tool that will help you migrate
  binary incompatibilities.

  For the reporting there are many ideas spinning around. Your
  feedback will help us decide what brings you immediate value

  One that I believe is useful:
          Maven/Sbt integration.




                                         Mirco Dotta    Managing Binary Compatibility in Scala
Introduction Sources of Incompatibility Conclusion       Conclusion Future Work Scala Migration Manager


Scala Migration Manager

   Visit http://typesafe.com/technology/migration-manager
          More information about the Migration Manager
          Download it and try it out, it’s free!

   We want to hear back from you.
          Success stories
          Request new features
          Report bugs
   Want to know more, make sure to get in touch!
                        Mirco Dotta, email: mirco.dotta@typesafe.com, twitter: @mircodotta




                                         Mirco Dotta        Managing Binary Compatibility in Scala

More Related Content

What's hot

Core Java Certification
Core Java CertificationCore Java Certification
Core Java CertificationVskills
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiNico Ludwig
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Kernel Training
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8 Bansilal Haudakari
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedyearninginjava
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzJAX London
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz SAurabh PRajapati
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Javahendersk
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsAnton Keks
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...Coen De Roover
 

What's hot (20)

Core Java Certification
Core Java CertificationCore Java Certification
Core Java Certification
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Annotations
AnnotationsAnnotations
Annotations
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
 
Java training
Java trainingJava training
Java training
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, Assertions
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
 

Viewers also liked

Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...mircodotta
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Futuremircodotta
 
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...Lightbend
 
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...Lightbend
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)mircodotta
 
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)mircodotta
 
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...Lightbend
 
Akka streams scala italy2015
Akka streams scala italy2015Akka streams scala italy2015
Akka streams scala italy2015mircodotta
 
Lightbend Fast Data Platform
Lightbend Fast Data PlatformLightbend Fast Data Platform
Lightbend Fast Data PlatformLightbend
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lightbend
 
Journey to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big DataJourney to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big DataLightbend
 
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...Lightbend
 

Viewers also liked (13)

Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Future
 
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
 
Akka streams
Akka streamsAkka streams
Akka streams
 
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)
 
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
 
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
 
Akka streams scala italy2015
Akka streams scala italy2015Akka streams scala italy2015
Akka streams scala italy2015
 
Lightbend Fast Data Platform
Lightbend Fast Data PlatformLightbend Fast Data Platform
Lightbend Fast Data Platform
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
 
Journey to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big DataJourney to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big Data
 
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
 

Similar to Managing Binary Compatibility in Scala

Discover Tasty Query: The library for Scala program analysis
Discover Tasty Query: The library for Scala program analysisDiscover Tasty Query: The library for Scala program analysis
Discover Tasty Query: The library for Scala program analysisJames Thompson
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Codemotion
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 dcubeio
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene BurmakoVasil Remeniuk
 
Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»e-Legion
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slidesunny khan
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMarakana Inc.
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaDerek Chen-Becker
 
Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...
Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...
Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...ICSM 2011
 
Scala overview
Scala overviewScala overview
Scala overviewSteve Min
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 

Similar to Managing Binary Compatibility in Scala (20)

Discover Tasty Query: The library for Scala program analysis
Discover Tasty Query: The library for Scala program analysisDiscover Tasty Query: The library for Scala program analysis
Discover Tasty Query: The library for Scala program analysis
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene Burmako
 
Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...
Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...
Postdoc symposium - A Logic Meta-Programming Foundation for Example-Driven Pa...
 
JVM
JVMJVM
JVM
 
Unit 1 notes.pdf
Unit 1 notes.pdfUnit 1 notes.pdf
Unit 1 notes.pdf
 
Scala overview
Scala overviewScala overview
Scala overview
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

Managing Binary Compatibility in Scala

  • 1. Managing Binary Compatibility in Scala Mirco Dotta Typesafe June 3, 2011 Mirco Dotta Managing Binary Compatibility in Scala
  • 2. Introduction Sources of Incompatibility Conclusion Outline Introduction Example Scala vs. Java Sources of Incompatibility Type Inferencer Trait Conclusion Mirco Dotta Managing Binary Compatibility in Scala
  • 3. Introduction Sources of Incompatibility Conclusion Example Scala vs. Java Example Assume Analyzer is part of a library we produce. We decide that its API has to evolve as follows: class Analyzer { // old version class Analyzer { // new version def analyze(issues: HashMap[ , ]) {...} def analyze(issues: Map[ , ]) {...} } } Further, assume the next expression was compiled against the old library new Analyzer().analyze(new HashMap[Any,Any]()) Would the compiled code work if run against the new library? The answer lies in the bytecode... Mirco Dotta Managing Binary Compatibility in Scala
  • 4. Introduction Sources of Incompatibility Conclusion Example Scala vs. Java Example: Bytecode Let’s take look at the generated bytecode for the two versions: class Analyzer { // old version class Analyzer { // new version analyze(Lscala/collection/immutable/HashMap);V analyze(Lscala/collection/immutable/Map);V }} }} The expression compiled against the old library would look like: ... invokevirtual #9;// #9 == Analyzer.analyze:(Lscala/collection/immutable/HashMap;)V ⇒ The method’s name has been statically resolved at compile-time. Running it against the new library would result in the JVM throwing a NoSuchMethodException. ⇒ The evolution of class Analyzer breaks compatibility with pre-existing binaries. Mirco Dotta Managing Binary Compatibility in Scala
  • 5. Introduction Sources of Incompatibility Conclusion Example Scala vs. Java Is Binary Compatibility a Scala issue? The short answer is No. The discussed example can be easily ported in Java. Scala shares with Java many sources of binary incompatibility. But Scala offers many language features not available in Java: Type Inferencer First-class functions Multiple inheritance via mixin composition (i.e., traits) . . . Just to cite a few. ⇒ Scala code has new “unique” sources of binary incompatibility. Mirco Dotta Managing Binary Compatibility in Scala
  • 6. Introduction Sources of Incompatibility Conclusion Type Inferencer Trait Type Inferencer: Member Signature Does the following evolution break binary compatibility? class TextAnalyzer { // old version class TextAnalyzer { // new version def analyze(text: String) = { def analyze(text: String) = { val issues = Map[String,Any]() val issues = new HashMap[String,Any]() // ... // ... issues issues }} }} Question What is the inferred return type of analyze? Let’s compare the two methods’ signature. class TextAnalyzer { // old version class TextAnalyzer { // new version public scala.collection.immutable.Map public scala.collection.immutable.HashMap analyze(java.lang.String); analyze(java.lang.String); } } Mirco Dotta Managing Binary Compatibility in Scala
  • 7. Introduction Sources of Incompatibility Conclusion Type Inferencer Trait Type Inferencer: Member Signature (2) Question Can we prevent the method’s signature change? That’s easy! The method’s return type has to be explicitly declared: class TextAnalyzer { // bytecode compatible new version def analyze(text: String): Map[String,Any] = { val issues = new HashMap() // ... issues }} Take Home Message Always declare the member’s type. If you don’t, you may inadvertently change the member’s signature. Mirco Dotta Managing Binary Compatibility in Scala
  • 8. Introduction Sources of Incompatibility Conclusion Type Inferencer Trait Trait Compilation Traits are a powerful language construct that enables multiple-inheritance on top of a runtime – the JVM – that does not natively support it. Understanding how traits are compiled is crucial if you need to ensure release-to-release binary compatibility. So, how does the Scala compiler generate the bytecode of a trait? There are two key elements: A trait is compiled into an interface plus an abstract class containing only static methods. “Forwarder” methods are injected in classes inheriting traits. Mirco Dotta Managing Binary Compatibility in Scala
  • 9. Introduction Sources of Incompatibility Conclusion Type Inferencer Trait Trait Compilation Explained An example will help visualize how traits get compiled: // declared in a library trait TypeAnalyzer { def analyze(prog: Program) {...} } // client code class TypingPhase extends TypeAnalyzer The following is the (pseudo-)bytecode generated by scalac: interface TypeAnalyzer { class TypingPhase implements TraitAnalyzer { void analyze(prog: Program); // forwarder method injected by scalac } void analyze(prog: Program) { abstract class TypeAnalyzer$class { // delegates to implementation static void analyze($this: TypeAnalyzer, TypeAnalyzer$class.analyze(this,prog) prog: Program) { } // the trait’s method impl code } } } Mirco Dotta Managing Binary Compatibility in Scala
  • 10. Introduction Sources of Incompatibility Conclusion Type Inferencer Trait Trait: Adding a concrete method Question Can we add a member in a trait without breaking compatibility with pre-existing binaries? trait TypeAnalyzer { // new version // compiled against the old version def analyze(prog: Program) {...} class TypingPhase implements TraitAnalyzer { def analyze(clazz: ClassInfo) {...} // forwarder method injected by scalac } void analyze(prog: Program) { // delegates to implementation TypeAnalyzer$class.analyze(this,prog) //TypeAnalyzer trait compiled } interface TypeAnalyzer { // missing concrete implementation! void analyze(prog: Program); ??analyze(clazz: ClassInfo)?? void analyze(clazz: ClassInfo); } } abstract class TypeAnalyzer$class { static void analyze($this: TypeAnalyzer, Take Home Message prog: Program{...} static void analyze($this: TypeAnalyzer, Adding a concrete method in a trait clazz: ClassInfo) {...} breaks binary compatibility. } Mirco Dotta Managing Binary Compatibility in Scala
  • 11. Introduction Sources of Incompatibility Conclusion Conclusion Future Work Scala Migration Manager Conclusion Ensuring release-to-release binary compatibility of Scala libraries is possible. Though, sometimes it can be difficult to tell if a change in the API of a class/trait will break pre-existing binaries. In the discussed examples we have seen that: Type inferencer may be at the root of changes in the signature of a method. Traits are a sensible source of binary incompatibilities. It really looks like library’s maintainers’ life ain’t that easy... Mirco Dotta Managing Binary Compatibility in Scala
  • 12. Introduction Sources of Incompatibility Conclusion Conclusion Future Work Scala Migration Manager Introducing the Scala Migration Manager (MiMa) Today we release the Scala Migration Manager! (beta) It’s free!! It will tell you, library maintainers, if your next release is binary compatible with the current one. It will tell you, libraries users, if two releases of a library are binary compatible. MiMa can collect and report all sources of “syntactic” binary incompatibilities between two releases of a same library. “Syntactic” means NO LinkageError (e.g., NoSuchMethodException) will ever be thrown at runtime. Now it’s time for a demo! Mirco Dotta Managing Binary Compatibility in Scala
  • 13. Introduction Sources of Incompatibility Conclusion Conclusion Future Work Scala Migration Manager Future Work Reporting binary incompatibilities is only half of the story. We are already working on a “companion” tool that will help you migrate binary incompatibilities. For the reporting there are many ideas spinning around. Your feedback will help us decide what brings you immediate value One that I believe is useful: Maven/Sbt integration. Mirco Dotta Managing Binary Compatibility in Scala
  • 14. Introduction Sources of Incompatibility Conclusion Conclusion Future Work Scala Migration Manager Scala Migration Manager Visit http://typesafe.com/technology/migration-manager More information about the Migration Manager Download it and try it out, it’s free! We want to hear back from you. Success stories Request new features Report bugs Want to know more, make sure to get in touch! Mirco Dotta, email: mirco.dotta@typesafe.com, twitter: @mircodotta Mirco Dotta Managing Binary Compatibility in Scala