Skip to content

Standard library ​

Mini has no JDK and no stdlib JAR. The standard library is Kotlin source in stdlib/ (ported from the Kotlin standard library, Apache-2.0, see stdlib/NOTICE) and is compiled together with every program.

How it is compiled ​

minic build a.kt sends your files plus all of stdlib/ through the K2 frontend in one run, with -no-stdlib -no-jdk -Xallow-kotlin-package. Consequently every stdlib function, including inline ones like map and filter, has an IR body that the backend can translate. Before translation a reachability pass drops everything the program cannot reach, so the generated C stays small: println("x") is about 66 lines of C, a StringBuilder program about 220. Each build pays about 3 seconds to analyse roughly 5700 lines of stdlib; caching that is a planned optimization.

Reachability keeps every dispatch-capable member of a reached class (open, override, abstract, interface members); final, non-overriding methods are kept only if they are called.

Layout ​

DirectoryContents
kotlin/builtins (Any, Int, String, Array, ... declared without bodies, recognized by the compiler), Throwable and the exceptions, Preconditions (require, check, error, TODO), Standard (let, run, apply, also, with, takeIf, repeat), Pair/Triple, Lazy, Comparator, Result
kotlin/collections/the collection interfaces, ArrayList, HashMap, LinkedHashMap, HashSet, LinkedHashSet, ArrayDeque, builders (listOf, mapOf, buildList...), map/filter/fold/sortedBy/groupBy/zip/windowed...
kotlin/text/String functions, StringBuilder, Char, number parsing and formatting
kotlin/ranges, math, comparisonsIntRange/LongRange/CharRange and progressions, coerceIn, abs, maxOf, compareBy
mini/memory/the memory API: allocators, annotations, free, move, spawn (see the memory guide)
mini/io/file read and write helpers used by the self-hosted compiler
mini/internal/the native interface (CSymbol, Intrinsics)
java/lang/Thread.kta placeholder so that mini.memory.spawn has something to refer to

Native primitives ​

Everything native goes through one annotation, mini.internal.CSymbol("mk_name"), on an external declaration. A call becomes an ordinary C call mk_name(receiver, args...). Arguments are borrowed, reference results are owned (+1). Every symbol is listed in runtime/include/minirt.h, and a test checks that header, Kotlin declaration and the JVM test implementation agree. Strings, StringBuilder and arrays are opaque runtime handles, so the stdlib code needs no compiler knowledge about them.

Tests ​

  • stdlib-test/ holds unit tests that run on the JVM twice: against Mini's stdlib sources (with the package renamed) and against the real kotlin-stdlib, so the expected values are real Kotlin behavior.
  • compiler/testdata/stdlib_*.kt are built and run natively and compared with output generated by the JVM.

Known deviations from Kotlin ​

  • StringBuilder is not a CharSequence/Appendable; isEmpty, indices and friends are declared on String.
  • Character classification and case conversion cover ASCII and Latin-1 only. Regex, "..".format(..), Sequence, Random, Duration and the array functions are available; coroutine-based sequence { } and the static String.format(..) form are not (see docs/stdlib.md, section 10).
  • HashMap and HashSet replicate java.util.HashMap iteration order (no tree bins).
  • Read-only lists, sets and maps are the mutable implementations behind the interface, as on Kotlin/Native.
  • Everything is single-threaded: lazy is unsynchronized.
  • Throwable has no stack trace API. Throwable.toString() uses kotlin. instead of java.lang. package names.
  • Hash maps keep before/after links, which are reference cycles, so they leak under plain reference counting.

Released under the Apache License 2.0.