Dart Kernel is a small high-level intermediate language for Dart programs. It serves as a compact binary object-file format supporting separate compilation and linking, and provides infrastructure for whole-program analysis and transformations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dart-lang/sdk/llms.txt
Use this file to discover all available pages before exploring further.
What is Kernel?
Kernel is an intermediate representation (IR) that sits between Dart source code and the various execution backends (VM, dart2js, dart2native). It provides:- Compact binary format - Efficient serialization for fast loading and reduced file sizes
- Separate compilation - Support for incremental compilation and linking
- Analysis infrastructure - Foundation for whole-program optimizations
- Transformation support - Enable compiler passes and code transformations
Binary Format Structure
The kernel binary format uses the magic number0x90ABCDEF and includes:
ComponentFile Structure
Encoding Types
The binary format uses several efficient encoding schemes: Variable-length integers (UInt):UInt7- 7-bit unsigned integer (0-127)UInt14- 14-bit unsigned integer with tag bitUInt30- 30-bit unsigned integer with tag bitsUInt32- 32-bit big-endian unsigned integer
- Strings are encoded as WTF-8 (a variant of UTF-8)
- String table maps indices to end offsets in payload array
- Efficient deduplication through string indexing
Component Structure
A Kernel component is the top-level container that bundles libraries:Key Features
Canonical Names: Unique identifiers for all declarations across the component. Enable fast reference resolution and linking. Source Mapping: Maps file URIs to source code and line-start tables for accurate error reporting and debugging. Metadata Repositories: Extensible mechanism for backends to attach custom metadata to AST nodes.Libraries and Declarations
Each library in a component contains:File Offsets and Source Locations
Kernel maintains source location information:- Precise error reporting
- IDE navigation and debugging
- Source-level transformations
Component Index
The component index provides semi-random access to component sections:Usage in the Dart SDK
Kernel is used throughout the Dart toolchain: Frontend (CFE): Compiles Dart source to kernel format- Performs parsing, type checking, and inference
- Generates
.dillfiles (kernel binary)
- Skips parsing and type checking
- Faster startup compared to source compilation
- Benefits from shared frontend
- Consistent semantics across platforms
- Enables whole-program optimizations
- Platform-specific code generation
Working with Kernel
To read kernel files in Dart:Format Versioning
The current format version is129. Version changes when:
- AST node structure changes
- Encoding schemes are modified
- New features are added
Related Topics
- Kernel AST Structure - Detailed AST node types
- Kernel Transformations - Transformation infrastructure
- Type System - Kernel type representation
- Operational Semantics - Execution model
References
- Binary Format Specification
- pkg/kernel - Kernel package source