Native-specific overrides for Scala standard library components, providing VM memory management and enhanced Enumeration implementation
npx @tessl/cli install tessl/maven-org-scala-native--scalalib-native0-5-2-13@0.5.0Native-specific implementations that replace or enhance standard Scala library components for the Scala Native runtime. This module provides platform-optimized versions of select Scala standard library components, improving performance and compatibility with native compilation.
libraryDependencies += "org.scala-native" %%% "scalalib" % "0.5.8"The scalalib overrides are automatically used when the corresponding standard library classes are imported:
// Enumeration override is used automatically
import scala.Enumeration
// VM memory management utilities (package-private)
import scala.collection.immutable.VM// Enumeration works identically to standard Scala but with native optimizations
object Color extends Enumeration {
type Color = Value
val Red, Green, Blue = Value
}
val color = Color.Red
val allColors = Color.values
// VM memory management (used internally by collections)
import scala.collection.immutable.VM
VM.releaseFence() // Atomic memory fence operationThe scalalib module provides only two key override components:
This focused approach ensures that critical standard library components have native-specific optimizations while maintaining full API compatibility with standard Scala implementations.
Package-private atomic memory fence operations for internal use by immutable collections, providing thread-safe memory synchronization in the native runtime environment.
package scala.collection.immutable
/* private[immutable] */ object VM {
def releaseFence(): Unit
}Complete native-optimized implementation of Scala enumerations with improved performance, better memory management, and Scala.js compatibility.
abstract class Enumeration(initial: Int) extends Serializable {
def this(): Enumeration
def values: ValueSet
def apply(x: Int): Value
def withName(s: String): Value
def maxId: Int
protected def Value: Value
protected def Value(i: Int): Value
protected def Value(name: String): Value
protected def Value(i: Int, name: String): Value
}
abstract class Enumeration#Value extends Ordered[Value] with Serializable {
def id: Int
def compare(that: Value): Int
def +(v: Value): ValueSet
}
class Enumeration#ValueSet extends immutable.SortedSet[Value] with Serializable {
def contains(v: Value): Boolean
def +(value: Value): ValueSet
def -(value: Value): ValueSet
def iterator: Iterator[Value]
def toBitMask: Array[Long]
}// ValueSet factory
object Enumeration#ValueSet {
val empty: ValueSet
def apply(elems: Value*): ValueSet
def fromBitMask(elems: Array[Long]): ValueSet
def newBuilder: mutable.Builder[Value, ValueSet]
}
// Internal Val implementation
protected class Enumeration#Val(i: Int, name: String) extends Value with Serializable {
def this(i: Int): Val
def this(name: String): Val
def this(): Val
def id: Int
}
// Value ordering
object Enumeration#ValueOrdering extends Ordering[Value] {
def compare(x: Value, y: Value): Int
}