Pavel Voronin
Pavel Voronin

Reputation: 13983

What is Scala runtime, binary compatibility and how are Scala applications deployed?

These are three questions actually, but for me they are tightly connected.

Different Scala compilers produce different bytecode.

but this explains not much to me. Does it mean that the 'interface' of the bytecode is changed? Like changing the name of the field containing the instance of companion object, for example. If yes, then why is there no backward compatibility? Is not it possible to add metadata to the bytecode? Scala compiler could use it to change its behaviour/expectations and emit different bytecode for various versions.

Upvotes: 4

Views: 2252

Answers (2)

chengpohi
chengpohi

Reputation: 14217

Scala compile actually is translate Scala source to Java bytecode with including scala-library.

So when deploy Scala in a plain JVM, need to include scala-library.jar like other dependencies.

For binary compatibility it means if Scala 2.12.2 is binary compatible with Scala 2.12.1, and project is compiled with Scala 2.12.1, you don't need to recompile project with Scala 2.12.2, it can run directly with Scala 2.12.2 library. and also it means if project has a dependency compiled in Scala 2.12.1, it can be safely used in Scala 2.12.2.

Reference: http://docs.scala-lang.org/overviews/core/binary-compatibility-of-scala-releases.html

Upvotes: 1

JiriS
JiriS

Reputation: 7540

What is Scala runtime?

Yes, Scala runtime runs on top of JVM and all it needs is supporting scala-lang.jar library and "a plain" JVM of appropriate version. Scala code is compiled to JVM bytecode. You can see a bit more about what Scala compiler does here or you can check compilation phases.

And yes, when you want to run Scala code on JVM you should always provide scala-lang.jar, but JVM is not strictly necessary to run Scala code. There are projects like Scala native allowing you to run Scala code natively on your platform without JVM or Scala.js allowing you to run it on the top of JavaScript engine.

Where does that binary (in-)compatibility come from?

This (in-)compatibility comes from changes in ABI of (not only) Scala standard library (see ABI versioning). There is already a proposal to improve backward binary compatibility. See the details here

Upvotes: 5

Related Questions