SlideShare a Scribd company logo
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 (20)

PDF
Core Java Certification
Vskills
 
PDF
Core Java Tutorial
eMexo Technologies
 
PDF
Review of c_sharp2_features_part_ii
Nico Ludwig
 
PPTX
Core Java introduction | Basics | free course
Kernel Training
 
PPT
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
PDF
Java Presentation For Syntax
PravinYalameli
 
PPT
Java Basics
Brandon Black
 
PDF
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 
PPTX
Functional Programming In Jdk8
Bansilal Haudakari
 
PPT
Annotations
Knoldus Inc.
 
PDF
Java Faqs useful for freshers and experienced
yearninginjava
 
PPTX
Inheritance in Java
Ganesh kumar reddy
 
PPT
Java tutorial PPT
Intelligo Technologies
 
PDF
Lambda: A Peek Under The Hood - Brian Goetz
JAX London
 
PPTX
Java history, versions, types of errors and exception, quiz
SAurabh PRajapati
 
ODP
Method Handles in Java
hendersk
 
PPTX
Java training
Ducat Education
 
PPT
Unit 5 Java
arnold 7490
 
PDF
Java Course 5: Enums, Generics, Assertions
Anton Keks
 
PDF
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
Coen De Roover
 
Core Java Certification
Vskills
 
Core Java Tutorial
eMexo Technologies
 
Review of c_sharp2_features_part_ii
Nico Ludwig
 
Core Java introduction | Basics | free course
Kernel Training
 
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
Java Presentation For Syntax
PravinYalameli
 
Java Basics
Brandon Black
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 
Functional Programming In Jdk8
Bansilal Haudakari
 
Annotations
Knoldus Inc.
 
Java Faqs useful for freshers and experienced
yearninginjava
 
Inheritance in Java
Ganesh kumar reddy
 
Java tutorial PPT
Intelligo Technologies
 
Lambda: A Peek Under The Hood - Brian Goetz
JAX London
 
Java history, versions, types of errors and exception, quiz
SAurabh PRajapati
 
Method Handles in Java
hendersk
 
Java training
Ducat Education
 
Unit 5 Java
arnold 7490
 
Java Course 5: Enums, Generics, Assertions
Anton Keks
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
Coen De Roover
 

Viewers also liked (13)

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

Similar to Managing Binary Compatibility in Scala (Scala Days 2011) (20)

PDF
Getting Started With Scala
Meetu Maltiar
 
PDF
Getting Started With Scala
Xebia IT Architects
 
ODP
Introducing scala
Meetu Maltiar
 
PDF
Scala Bootcamp 1
Knoldus Inc.
 
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
PDF
An Introduction to Scala for Java Developers
Miles Sabin
 
PDF
Software Engineering Thailand: Programming with Scala
Brian Topping
 
PDF
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
PDF
Scalax
Martin Odersky
 
PDF
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
PDF
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
PDF
Real World Java Compatibility
Tim Ellison
 
PDF
Real World Java Compatibility (Tim Ellison)
Chris Bailey
 
PDF
Power of functions in a typed world
Debasish Ghosh
 
PPTX
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
PDF
The Scala Programming Language
league
 
PDF
Yes scala can!
amirmoulavi
 
PDF
Changes and Bugs: Mining and Predicting Development Activities
Thomas Zimmermann
 
PDF
Meet scala
Wojciech Pituła
 
PDF
scalaliftoff2009.pdf
Hiroshi Ono
 
Getting Started With Scala
Meetu Maltiar
 
Getting Started With Scala
Xebia IT Architects
 
Introducing scala
Meetu Maltiar
 
Scala Bootcamp 1
Knoldus Inc.
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
Miles Sabin
 
Software Engineering Thailand: Programming with Scala
Brian Topping
 
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
Real World Java Compatibility
Tim Ellison
 
Real World Java Compatibility (Tim Ellison)
Chris Bailey
 
Power of functions in a typed world
Debasish Ghosh
 
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
The Scala Programming Language
league
 
Yes scala can!
amirmoulavi
 
Changes and Bugs: Mining and Predicting Development Activities
Thomas Zimmermann
 
Meet scala
Wojciech Pituła
 
scalaliftoff2009.pdf
Hiroshi Ono
 
Ad

Recently uploaded (20)

PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 

Managing Binary Compatibility in Scala (Scala Days 2011)

  • 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: [email protected], twitter: @mircodotta Mirco Dotta Managing Binary Compatibility in Scala