Skip to content

Hot reload#1

Open
NatElkins wants to merge 437 commits intomasterfrom
hot-reload
Open

Hot reload#1
NatElkins wants to merge 437 commits intomasterfrom
hot-reload

Conversation

@NatElkins
Copy link
Owner

@NatElkins NatElkins commented Nov 26, 2025

F# Hot Reload (Edit-and-Continue) Implementation

This PR introduces hot reload infrastructure for F# on top of .NET's MetadataUpdater.ApplyUpdate pipeline, with Roslyn-parity-oriented metadata behavior and multi-generation delta chaining.

Status Snapshot (2026-02-07)

  • PR: NatElkins/fsharp#1
  • Branch head: hot-reload@c454aeb
  • Scope has evolved significantly since the original PR text; this description reflects the current state.

Verified in this branch

  • ./.dotnet/dotnet build FSharp.sln -c Debug -v minimal
  • ./.dotnet/dotnet test tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj -c Debug --no-build --filter FullyQualifiedName~HotReload -v minimal ✅ (258 passed)
  • ./.dotnet/dotnet test tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj -c Debug --no-build --filter FullyQualifiedName~HotReload -v minimal ✅ (101 passed)

What This PR Adds

  • Hot reload session lifecycle in FSharpChecker:
    • StartHotReloadSession
    • EmitHotReloadDelta
    • EndHotReloadSession
    • HotReloadSessionActive
    • HotReloadCapabilities
  • Typed-tree diff + rude-edit classification pipeline for deciding delta vs rebuild.
  • Baseline capture (FSharpEmitBaseline) and generation chaining (EncId/EncBaseId) across multiple edits.
  • Delta emitters for metadata/IL/PDB with EncLog/EncMap tracking.
  • Runtime integration path exercised by component tests and demo tooling.
  • In-repo demo app (tests/projects/HotReloadDemo/HotReloadDemoApp) and smoke script (tests/scripts/hot-reload-demo-smoke.sh).

Recent Architecture/Parity Direction (late 2025)

  • Significant SRM boundary reduction/refactoring in hot reload paths:
    • byte-based baseline metadata readers
    • unified handle/index abstractions (BinaryConstants/delta token helpers)
    • PDB parity tests and shared reader/writer utilities
  • Roslyn parity fixes for StandAloneSig row handling and metadata sizing/encoding behaviors.
  • Method additions enabled with Roslyn-parity restrictions (c454aeb).

Supported vs Unsupported (Current)

Supported

  • Method-body edits with metadata/IL/PDB delta emission.
  • Multi-generation sessions.
  • Runtime apply scenarios validated by component tests (when runtime prerequisites are set).
  • Limited method additions under emitter restrictions (no incompatible type-layout changes).

Still rejected / rebuild required

  • Structural edits that change type layout/signature semantics beyond supported boundaries.
  • Edits that introduce unsupported metadata/token mapping cases (reported as UnsupportedEdit/rude edits).

Runtime Apply Capability Model

  • Capability flag is intentionally conservative:
    • RuntimeApply is only advertised when the runtime supports it and FSHARP_HOTRELOAD_ENABLE_RUNTIME_APPLY=1 is set.
  • Demo smoke supports both modes:
    • default: emit + validate deltas without runtime apply
    • opt-in: runtime apply path via HOTRELOAD_SMOKE_RUNTIME_APPLY=1

Remaining Follow-ups (Not Claimed Done Here)

  • Broaden structural edit coverage (especially synthesized/complex scenarios) while preserving Roslyn parity.
  • Improve telemetry/diagnostics surfacing for hosts.
  • Wire official dotnet watch integration path.
  • Continue tightening mdv + runtime parity checks as the final acceptance bar.

Key Files

  • Service/session API: src/Compiler/Service/service.fs, src/Compiler/HotReload/EditAndContinueLanguageService.fs
  • Delta emission: src/Compiler/CodeGen/IlxDeltaEmitter.fs, src/Compiler/CodeGen/FSharpDeltaMetadataWriter.fs, src/Compiler/CodeGen/DeltaMetadataSerializer.fs
  • Baseline/capabilities: src/Compiler/CodeGen/HotReloadBaseline.fs, src/Compiler/HotReload/HotReloadCapabilities.fs
  • Tests:
    • tests/FSharp.Compiler.Service.Tests/HotReload/*
    • tests/FSharp.Compiler.ComponentTests/HotReload/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants