sdk icon indicating copy to clipboard operation
sdk copied to clipboard

☂️ Development modular AOT compiler targeting iOS/arm64

Open alexmarkov opened this issue 2 months ago • 0 comments

It becomes increasingly difficult to use JIT for development on iOS (https://github.com/flutter/flutter/issues/163984, https://github.com/flutter/flutter/issues/175962). Eventually we would like to step away from using JIT and replace it with a new AOT compiler along with bytecode interpreter for debugging and hot reload.

This is an umbrella issue for implementation of a new modular AOT compiler for development on iOS (for Flutter debug mode).

Approximate plan to bring up the new compiler:

  • First run:

    • [x] Implement essential parts of CFG IR (types, constants, functions, subset of instructions).
    • [x] Partially implement translation of AST to CFG IR.
    • [x] Implement SSA computation and a few optimization passes.
    • [ ] Implement arm64 assembler.
    • [ ] Sketch register allocation and code generation.
    • [ ] Implement module snapshot writer in the compiler and module snapshot reader in the VM.
    • [ ] Implement Mach-O image writer.
  • [x] Milestone 1. Run "hello, world" (on mac/arm64).
  • Feature completeness and correctness track:

    • [ ] Implement closures and captured variables (depends on https://github.com/dart-lang/sdk/issues/61572).
    • [ ] Implement late variables and fields.
    • [ ] Implement async/async*/sync* functions.
    • [ ] Implement super invocations.
    • [ ] Implement list, set and map literals.
    • [ ] Implement records.
    • [ ] Implement dart:ffi.
    • [ ] Implement deferred libraries.
    • [ ] Implement all recognized methods for correctness.
    • [ ] Implement all necessary stubs in the new compiler.
  • [ ] Milestone 2. 90% of language tests are passing (on mac/arm64).
  • [ ] Milestone 3. All core libraries are fully compiled with the new compiler.
  • [ ] Milestone 4. 95+% of all tests are passing (on mac/arm64).
  • Performance track:

    • [ ] Compare performance against JIT and production AOT on Golem micro-benchmarks.
    • [ ] Implement all recognized methods for performance.
    • [ ] Implement devirtualization and inlining.
    • [ ] Implement LICM.
    • [ ] Implement DCE.
    • [ ] Revise calling conventions (requires compiling all core libraries with the new compiler).
    • [ ] Profile compiler and fix low-hanging fruits to improve compilation speed.
    • [ ] (Optional) implement load/store forwarding.
    • [ ] (Optional) implement allocation sinking.
    • [ ] (Optional) implement write barrier elimination.
  • Integration with bytecode interpreter:

    • [ ] Suport deoptimization from native code to bytecode.
      • [ ] Generate deoptimization info in the new compiler.
      • [ ] Implement switching from native code to bytecode in the VM in case of debugging or hot reload.
      • [ ] Add stress testing mode to deoptimize random functions to bytecode.
  • Integration with Flutter:

    • [ ] Integrate new compiler into front-end server.
    • [ ] Support modular compilation and new compiler in Flutter tools.
    • [ ] Support multiple app dynamic libraries in the Flutter engine on iOS.
  • [ ] Milestone 5. Flutter apps can run on iOS without JIT, with debugging and hot reload.

alexmarkov avatar Oct 01 '25 17:10 alexmarkov