Skip to main content

The Scala on top

The Java core is fast but almost untyped: to it, every value is just an FBase, a primitive array under a few structural wrappers, with no notion of whether it holds Ints or Strings. All the typing arrives one layer up, in a sheet of Scala 3 so thin that most of it isn't there at runtime. Three features carry it: the opaque type, extension methods, and inline.

An opaque type gives FArray[A] its own identity at compile time while being a plain FBase at runtime; there is no wrapper object to allocate or escape-analyze. The whole API then hangs off it as extension methods (methods declared outside the type and resolved statically by the compiler, so each is an ordinary static call in the bytecode), and they come in two flavours. The next pages are organized around the difference between them:

loading source…

The structural ones (reverse, ++) just call the matching FBase method. Because an FArray already is its core, that's a direct call into the lazy O(1) node-builders from the Java core, with no specialization involved.

The elementwise ones are inline, and take their lambda inline too (inline def map[B](inline f: A => B)), so at each call site the body and your lambda splice in and forward to a generated per-kind …Impl. That forward is where primitives stay unboxed — How map stays unboxed follows it through.