Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
f6cad50
Add Roslyn-format EnC CustomDebugInformation codec and portable PDB m…
NatElkins Jul 1, 2026
0d02145
Use ProcessStartInfo.Arguments for net472 compatibility
NatElkins Jul 1, 2026
66a1412
Make the EnC CDI test module public for xunit v3 discovery
NatElkins Jul 2, 2026
c8639f3
Extract stable synthesized-name replay layer
NatElkins Jul 2, 2026
d6319c1
Add ECMA-335 EnC metadata delta writer
NatElkins Jul 1, 2026
b0a487f
Add typed-tree diff slice for hot reload
NatElkins Jul 2, 2026
d505ab9
Fix generated-name scope test in stable names slice
NatElkins Jul 8, 2026
7aaacc5
Fix EnC CDI cross-validation test process launch on Desktop and bare …
NatElkins Jul 3, 2026
c78b2f6
Remove extra EOF blank line in delta metadata tests
NatElkins Jul 8, 2026
2facaf2
Merge branch 'refresh/20260717/hotreload-typedtree-diff' into refresh…
NatElkins Jul 17, 2026
cd1339b
Merge branch 'refresh/20260717/hotreload-stable-names' into refresh/2…
NatElkins Jul 17, 2026
ba5bce9
Merge branch 'refresh/20260717/enc-metadata-delta-writer' into refres…
NatElkins Jul 17, 2026
c23986b
Add hot reload baseline reader state
NatElkins Jul 3, 2026
ac6a1ba
Extract hot reload delta emitter
NatElkins Jul 3, 2026
11e8fa0
Fix synthesized-name snapshot assertions to use the array equality ov…
NatElkins Jul 3, 2026
b228654
Align the signature-change diff test with the evolved differ classifi…
NatElkins Jul 3, 2026
3e1678d
Validate hot reload baseline metadata inputs
NatElkins Jul 17, 2026
5fdf705
Enforce cumulative metadata delta invariants
NatElkins Jul 17, 2026
c584660
Validate hot reload generated names before classification
NatElkins Jul 17, 2026
9a9211e
Validate hot reload baseline metadata inputs
NatElkins Jul 17, 2026
be6df7b
Preserve reviewed lower-slice invariants in delta emitter
NatElkins Jul 17, 2026
8932904
Unify delta emission on the shared metadata writer
NatElkins Jul 17, 2026
d40f0bc
Fail closed on unresolved accessor metadata
NatElkins Jul 17, 2026
11b50cc
Extract hot reload session slice
NatElkins Jul 3, 2026
36ef5ba
Fix CI compile breaks and extraction debris in the session slice tests
NatElkins Jul 3, 2026
330761c
Fix net472 and CI-image portability breaks in session slice tests
NatElkins Jul 3, 2026
a886637
Drop the netcore-only Contains overload from delta builder tests
NatElkins Jul 3, 2026
9bb2547
Gate the Roslyn baseline comparison tests to .NET Core
NatElkins Jul 3, 2026
6420b62
Normalize fixture line endings before update-source splicing
NatElkins Jul 3, 2026
c67ec56
Update ilxgen name-path architecture guard
NatElkins Jul 8, 2026
a4b8616
Remove duplicate delta metadata test copies
NatElkins Jul 8, 2026
4a1efa4
Remove duplicate compiler global reset member
NatElkins Jul 8, 2026
7216294
Remove duplicate compiler global reset signature
NatElkins Jul 8, 2026
2b461a8
Repair session slice after metadata writer consolidation
NatElkins Jul 17, 2026
9bf2891
Make hot reload session updates transactional
NatElkins Jul 17, 2026
1f7fa5d
Extract the flag-gated in-process compile perf slice
NatElkins Jul 3, 2026
8554882
Apply post-main hot reload perf cleanup
NatElkins Jul 7, 2026
eb1e86d
Remove trailing EOF whitespace in hot reload tests
NatElkins Jul 8, 2026
9c2d4b6
Fix synthesized type alias reuse in in-process hot reload
NatElkins Jul 10, 2026
464ee2a
Preserve hot reload slice invariants in in-process compilation
NatElkins Jul 17, 2026
8ea9e6b
Harden in-process hot reload compilation
NatElkins Jul 17, 2026
63db0b3
Verify overlapping hot reload emits serialize
NatElkins Jul 17, 2026
00f11e6
Minimize in-process compiler surface drift
NatElkins Jul 17, 2026
9112dab
Report hot reload update capabilities
NatElkins Jul 17, 2026
21dbd06
Report hot reload update capabilities
NatElkins Jul 17, 2026
b26df0f
Expose required hot reload capabilities
NatElkins Jul 17, 2026
408de0c
Report hot reload update capabilities
NatElkins Jul 17, 2026
5fa9d32
Expose required hot reload capabilities
NatElkins Jul 17, 2026
490f458
Document F# hot reload rude-edit diagnostics
NatElkins Jul 17, 2026
412edf5
Document F# hot reload rude-edit diagnostics
NatElkins Jul 17, 2026
16b0de1
Format delta metadata writer sources
NatElkins Jul 17, 2026
a402010
Format delta metadata writer sources
NatElkins Jul 17, 2026
c7aed88
Format delta metadata writer sources
NatElkins Jul 17, 2026
24f4879
Format hot reload compiler sources
NatElkins Jul 17, 2026
34950ea
Format hot reload compiler sources
NatElkins Jul 17, 2026
733a531
Format hot reload compiler sources
NatElkins Jul 17, 2026
1248503
Format hot reload emitter sources
NatElkins Jul 17, 2026
254b36c
Format hot reload session sources
NatElkins Jul 17, 2026
7e8cf28
Format in-process hot reload sources
NatElkins Jul 17, 2026
4768d1b
Retry CI after Linux runner memory exhaustion
NatElkins Jul 18, 2026
bdb1d28
Add typed-tree diff slice for hot reload
NatElkins Jul 2, 2026
1a5c97e
Make typed-tree diff classification fail closed
NatElkins Jul 17, 2026
f7dd5dd
Format hot reload compiler sources
NatElkins Jul 17, 2026
c2d4c86
Add ECMA-335 EnC metadata delta writer
NatElkins Jul 1, 2026
83696d2
Remove extra EOF blank line in delta metadata tests
NatElkins Jul 8, 2026
6cc71de
Enforce cumulative metadata delta invariants
NatElkins Jul 17, 2026
7e2770f
Format delta metadata writer sources
NatElkins Jul 17, 2026
078961d
Retry CI after regression job timeout
NatElkins Jul 18, 2026
33fceef
Share delta user string encoding and trace configuration
NatElkins Jul 22, 2026
0e55c15
Harden hot reload session capture and file handling
NatElkins Jul 22, 2026
ad6c411
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 22, 2026
e981e30
Handle metadata-only methods in PDB ambiguity checks
NatElkins Jul 22, 2026
1f7a82b
Share delta user string encoding and trace configuration
NatElkins Jul 22, 2026
06378d5
Make synthesized name snapshots deterministic
NatElkins Jul 22, 2026
6129dda
Harden typed-tree diff classification
NatElkins Jul 22, 2026
9b7afdc
Preserve threaded optimizer state in incremental emit cache
NatElkins Jul 22, 2026
2913faf
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 22, 2026
5f85d70
Handle metadata-only methods in PDB ambiguity checks
NatElkins Jul 22, 2026
1463648
Share delta user string encoding and trace configuration
NatElkins Jul 22, 2026
b05b479
Make synthesized name snapshots deterministic
NatElkins Jul 22, 2026
1366c65
Harden hot reload session capture and file handling
NatElkins Jul 22, 2026
4ad2364
Harden baseline metadata parsing
NatElkins Jul 22, 2026
88c0c62
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 22, 2026
9dad496
Handle metadata-only methods in PDB ambiguity checks
NatElkins Jul 22, 2026
e7531a7
Make synthesized name snapshots deterministic
NatElkins Jul 22, 2026
eaaf64e
Harden typed-tree diff classification
NatElkins Jul 22, 2026
2491370
Harden baseline metadata parsing
NatElkins Jul 22, 2026
03b7852
Harden typed-tree diff classification
NatElkins Jul 22, 2026
73e2687
Harden baseline metadata parsing
NatElkins Jul 22, 2026
ac42fbf
Harden delta metadata identity and cleanup
NatElkins Jul 22, 2026
2aefa5f
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 22, 2026
17f464f
Handle metadata-only methods in PDB ambiguity checks
NatElkins Jul 22, 2026
25eca5c
Share delta user string encoding and trace configuration
NatElkins Jul 22, 2026
98aeadb
Make synthesized name snapshots deterministic
NatElkins Jul 22, 2026
e84c143
Harden typed-tree diff classification
NatElkins Jul 22, 2026
2a827b0
Harden baseline metadata parsing
NatElkins Jul 22, 2026
01d19b1
Harden delta metadata identity and cleanup
NatElkins Jul 22, 2026
6365078
Harden delta metadata identity and cleanup
NatElkins Jul 22, 2026
118edc8
Ignore transient provider scopes in body identity
NatElkins Jul 22, 2026
eb661b3
Ignore transient provider scopes in body identity
NatElkins Jul 22, 2026
20f67d8
Ignore transient provider scopes in body identity
NatElkins Jul 22, 2026
54eba2f
Preserve recorded synthesized alias replay
NatElkins Jul 22, 2026
e3e089d
Bound decision-tree identity traversal
NatElkins Jul 23, 2026
7ffe458
Bound baseline string heap reads
NatElkins Jul 23, 2026
42d29eb
Bound decision-tree identity traversal
NatElkins Jul 23, 2026
0b44ec4
Fail closed on closure-name recapture mismatch
NatElkins Jul 23, 2026
7b00822
Bound baseline string heap reads
NatElkins Jul 23, 2026
ec0f30b
Bound decision-tree identity traversal
NatElkins Jul 23, 2026
f2d7c1e
Bound baseline string heap reads
NatElkins Jul 23, 2026
f2e3b13
Fail closed on closure-name recapture mismatch
NatElkins Jul 23, 2026
bee5347
Bound decision-tree identity traversal
NatElkins Jul 23, 2026
76c874c
Bound baseline string heap reads
NatElkins Jul 23, 2026
a052db3
Format bounded string heap reader
NatElkins Jul 23, 2026
474bbef
Format bounded string heap reader
NatElkins Jul 23, 2026
9f6a761
Make closure recapture test deterministic
NatElkins Jul 23, 2026
68d281d
Make closure recapture test deterministic
NatElkins Jul 23, 2026
e5d6392
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 23, 2026
54cd67d
Merge branch 'main' into enc-metadata-delta-writer
T-Gro Jul 24, 2026
62df5dc
Merge branch 'main' into hotreload-typedtree-diff
T-Gro Jul 24, 2026
8d28083
Merge remote-tracking branch 'origin/main' into refresh/20260717/enc-…
NatElkins Jul 24, 2026
b492d58
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 24, 2026
ead308d
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 24, 2026
7622b7e
Merge remote-tracking branch 'origin/main' into refresh/20260717/hotr…
NatElkins Jul 24, 2026
c83b6ab
Complete hot reload merge integration
NatElkins Jul 24, 2026
6c7a61b
Fix compiled baseline metadata table parsing
NatElkins Jul 24, 2026
4386ab1
Update delta metadata test writer options
NatElkins Jul 24, 2026
e0a38af
Complete baseline reader merge integration
NatElkins Jul 24, 2026
e1d6a50
Merge branch 'refresh/20260717/enc-metadata-delta-writer' into refres…
NatElkins Jul 24, 2026
3ce3b14
Merge branch 'refresh/20260717/hotreload-typedtree-diff' into refresh…
NatElkins Jul 24, 2026
b994397
Merge branch 'refresh/20260717/hotreload-baseline-reader' into refres…
NatElkins Jul 24, 2026
cf0202c
Merge branch 'refresh/20260717/hotreload-delta-emitter' into refresh/…
NatElkins Jul 24, 2026
469a3b2
Complete session merge integration
NatElkins Jul 24, 2026
5b12365
Deduplicate merged compiler source entries
NatElkins Jul 24, 2026
4c0bba2
Merge branch 'refresh/20260717/hotreload-delta-emitter' into refresh/…
NatElkins Jul 24, 2026
c4005a9
Merge branch 'refresh/20260717/hotreload-session' into refresh/202607…
NatElkins Jul 24, 2026
000171d
Remove obsolete baseline reader copy
NatElkins Jul 24, 2026
e9b19d1
Merge branch 'refresh/20260717/hotreload-delta-emitter' into refresh/…
NatElkins Jul 24, 2026
cdbf303
Merge branch 'refresh/20260717/hotreload-session' into refresh/202607…
NatElkins Jul 24, 2026
a34afbc
Renumber hot reload driver diagnostics
NatElkins Jul 24, 2026
30b5e44
Merge branch 'refresh/20260717/hotreload-session' into refresh/202607…
NatElkins Jul 24, 2026
0ad1dce
Place baseline reader release note in current FCS notes
NatElkins Jul 24, 2026
47e92ee
Merge refreshed baseline reader release note
NatElkins Jul 24, 2026
5bdb691
Deduplicate composite release notes
NatElkins Jul 24, 2026
88053ca
Merge refreshed delta emitter release notes
NatElkins Jul 24, 2026
1511b10
Give session slice a single current release note
NatElkins Jul 24, 2026
5e4a084
Merge refreshed session release notes
NatElkins Jul 24, 2026
efd961e
Give in-process slice a single current release note
NatElkins Jul 24, 2026
238ebb6
Keep hot reload diagnostics sorted
NatElkins Jul 24, 2026
12a64db
Merge sorted hot reload diagnostics
NatElkins Jul 24, 2026
06e0ad8
Merge current main
NatElkins Jul 24, 2026
e56776f
Merge current main
NatElkins Jul 24, 2026
6218916
Merge current main
NatElkins Jul 24, 2026
2ec1bd2
Merge refreshed enc-metadata-delta-writer
NatElkins Jul 24, 2026
5f359e8
Merge refreshed hotreload-typedtree-diff
NatElkins Jul 24, 2026
b2642b8
Merge refreshed hotreload-baseline-reader
NatElkins Jul 24, 2026
ea8c3d3
Merge refreshed delta emitter
NatElkins Jul 24, 2026
d2b2966
Merge refreshed hot reload session
NatElkins Jul 24, 2026
f9be8ba
Merge remote-tracking branch 'origin/main' into merge/20260806/hotrel…
NatElkins Aug 6, 2026
c156e15
Merge remote-tracking branch 'origin/main' into merge/20260806/hotrel…
NatElkins Aug 6, 2026
169c41c
Merge branch 'merge/20260806/hotreload-baseline-reader' into merge/20…
NatElkins Aug 6, 2026
ea862ec
Merge branch 'merge/20260806/hotreload-typedtree-diff' into merge/202…
NatElkins Aug 6, 2026
ed3decb
Remove duplicated delta metadata compile entries after main merge
NatElkins Aug 6, 2026
aad5b56
Drop null match on Path.ChangeExtension result for new nullness rules
NatElkins Aug 6, 2026
b78ffd6
Use Async.RunSynchronouslyImmediate after test helper removal
NatElkins Aug 6, 2026
d04bd1a
Merge branch 'merge/20260806/hotreload-typedtree-diff' into merge/202…
NatElkins Aug 6, 2026
a259542
Merge branch 'merge/20260806/hotreload-delta-emitter' into merge/2026…
NatElkins Aug 6, 2026
2b16c6c
Use Async.RunSynchronouslyImmediate after test helper removal
NatElkins Aug 6, 2026
f222ff4
Drop null handling on Path.ChangeExtension results for new nullness r…
NatElkins Aug 6, 2026
bef7ea6
Merge branch 'merge/20260806/hotreload-session' into merge/20260806/h…
NatElkins Aug 6, 2026
3554fbc
Drop null handling on Path results in demo session for new nullness r…
NatElkins Aug 6, 2026
9daea03
Opt demo sample out of central package management
NatElkins Aug 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions FSharp.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<BuildType Solution="Proto|*" Project="Release" />
</Project>
</Folder>
<Folder Name="/Tests/HotReloadDemo/">
<Project Path="tests/projects/HotReloadDemo/HotReloadDemoApp/HotReloadDemoApp.fsproj">
<BuildType Solution="Proto|*" Project="Debug" />
</Project>
</Folder>
<Folder Name="/Tests/FSharp.Compiler.Service.Tests support/">
<Project Path="tests/service/data/CSharp_Analysis/CSharp_Analysis.csproj">
<BuildType Solution="Proto|*" Project="Debug" />
Expand Down
27 changes: 27 additions & 0 deletions docs/hot-reload-rude-edits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# F# hot reload rude-edit diagnostics

F# hot reload reports an `FSHRDL` diagnostic when an edit cannot be applied safely to the running process. The application is rebuilt and restarted instead of applying a delta that could leave it in an invalid state.

The diagnostic message identifies the affected declaration and the reason for the restart. These codes are owned by the F# compiler and are separate from Roslyn's `ENC` diagnostic namespace.

| Code | Meaning | What to do |
| --- | --- | --- |
| `FSHRDL001` | A member signature changed. | Undo the signature change to apply in place, or allow the rebuild and restart. |
| `FSHRDL002` | An `inline` annotation changed. | Allow the rebuild and restart. |
| `FSHRDL003` | A type representation or layout changed. | Allow the rebuild and restart. |
| `FSHRDL004` | A declaration was added in a shape the runtime cannot add. | Allow the rebuild and restart. |
| `FSHRDL005` | A declaration was removed. | Allow the rebuild and restart. |
| `FSHRDL006` | A virtual, abstract, or override member was added. | Allow the rebuild and restart. |
| `FSHRDL007` | A constructor was added. | Allow the rebuild and restart. |
| `FSHRDL008` | A user-defined operator was added. | Allow the rebuild and restart. |
| `FSHRDL009` | An explicit interface implementation was added. | Allow the rebuild and restart. |
| `FSHRDL010` | A member was added to an interface. | Allow the rebuild and restart. |
| `FSHRDL011` | A field was added in a shape the runtime cannot add. | Allow the rebuild and restart. |
| `FSHRDL012` | A lambda's lowered shape changed incompatibly. | Allow the rebuild and restart. |
| `FSHRDL013` | A state machine's resumable or hoisted layout changed incompatibly. | Keep the existing resume-point and captured-value layout, or allow the rebuild and restart. |
| `FSHRDL014` | A query expression's lowered shape changed incompatibly. | Allow the rebuild and restart. |
| `FSHRDL015` | A synthesized compiler declaration changed incompatibly. | Allow the rebuild and restart. |
| `FSHRDL016` | The runtime did not advertise a capability required by the edit. | Update the runtime if a newer version supports the capability, or allow the rebuild and restart. |
| `FSHRDL099` | The edit is unsupported for another fail-closed reason. | Follow the detailed message and allow the rebuild and restart. |

These diagnostics are intentionally fail closed. If the compiler cannot prove that an edit is safe, it requests a restart and leaves the running application unchanged.
5 changes: 5 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@

### Added

* Add an internal typed-tree diff utility for future F# hot reload edit classification. It is not called by normal compilation. ([PR #20025](https://github.com/dotnet/fsharp/pull/20025))
* Added internal synthesized-name replay infrastructure for compiler-generated names, preserving normal compilation output while enabling future hot reload name stability work.
* Added an experimental, internal, flag-gated in-process compile path for hot reload sessions. `FSHARP_HOTRELOAD_INPROCESS_COMPILE` refreshes the output assembly and PDB from the latest checked project before delta emission, while `FSHARP_HOTRELOAD_INCREMENTAL_EMIT` enables a nested per-file optimized-tree cache. ([PR #20031](https://github.com/dotnet/fsharp/pull/20031))
* Added internal F# hot reload delta emitter and symbol matcher infrastructure with direct emitter test coverage. ([PR #20027](https://github.com/dotnet/fsharp/pull/20027))
* Added `FSharpMemberOrFunctionOrValue.IsPropertyAccessor` convenience property that returns true for compiler-generated property accessors (`get_X` / `set_X`). ([Issue #18157](https://github.com/dotnet/fsharp/issues/18157), [PR #19883](https://github.com/dotnet/fsharp/pull/19883))
* Added warning FS3884 when a function or delegate value is used as an interpolated string argument. ([PR #19289](https://github.com/dotnet/fsharp/pull/19289))
* Symbols: add ObsoleteDiagnosticInfo ([PR #19359](https://github.com/dotnet/fsharp/pull/19359))
Expand All @@ -150,6 +153,8 @@
* Add internal `ResetCompilerGeneratedNameState` to `CompilerGlobalState` name generators so warm-checker re-compilation can produce fresh-process-identical generated names. ([PR #20017](https://github.com/dotnet/fsharp/pull/20017))
* Add internal ECMA-335 Edit-and-Continue metadata delta writer to AbstractIL. ([PR #20019](https://github.com/dotnet/fsharp/pull/20019))
* Add Roslyn-format EnC CustomDebugInformation codec and portable PDB method CDI emission support to AbstractIL. ([PR #20018](https://github.com/dotnet/fsharp/pull/20018))
* Add an experimental `FSharpChecker` hot reload session API with per-project baselines, capability-gated delta emission, and `Commit`/`Discard` transaction semantics. Off by default behind `--test:HotReloadDeltas`. ([Issue #11636](https://github.com/dotnet/fsharp/issues/11636), [PR #20030](https://github.com/dotnet/fsharp/pull/20030))
* Add internal hot reload baseline reading for recorded EnC state and synthesized-name snapshot PDB data. ([PR #20026](https://github.com/dotnet/fsharp/pull/20026))
* Support for the `<include>` XML documentation tag: at compile time, documentation is copied from an external XML file selected by an XPath query and emitted into the generated documentation file. `<inheritdoc>` remains unsupported. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19186](https://github.com/dotnet/fsharp/pull/19186))
* Expand `<inheritdoc/>` at tooling time. In IDE tooltips, completion, and signature help, documentation is inherited from base classes, interfaces, overridden members, and constructors (matched by parameter signature). The FCS Symbols API (`FSharpSymbol.XmlDoc`) additionally resolves explicit `cref` targets, but does not expand constructor inheritance. The compiler emits the tag verbatim into generated XML documentation files, matching C#; `<include>` is not implemented. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19188](https://github.com/dotnet/fsharp/pull/19188))

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/AbstractIL/DeltaIndexSizing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ module internal FSharp.Compiler.AbstractIL.DeltaIndexSizing

open FSharp.Compiler.AbstractIL.BinaryConstants
open FSharp.Compiler.AbstractIL.ILDeltaHandles
open FSharp.Compiler.AbstractIL.ILMetadataHeaps
open FSharp.Compiler.AbstractIL.DeltaMetadataEncoding

type MetadataHeapSizes = FSharp.Compiler.AbstractIL.ILBinaryWriter.MetadataHeapSizes

/// Holds computed "bigness" flags for all coded index types.
/// When true, the index requires 4 bytes; when false, 2 bytes suffice.
type CodedIndexSizes =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/AbstractIL/DeltaMetadataSerializer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open System
open System.Collections.Generic
open System.IO
open System.Text
open FSharp.Compiler.AbstractIL.ILMetadataHeaps
open FSharp.Compiler.AbstractIL.ILBinaryWriter
open FSharp.Compiler.AbstractIL.BinaryConstants
open FSharp.Compiler.AbstractIL.ILDeltaHandles
open FSharp.Compiler.AbstractIL.DeltaMetadataTables
Expand Down
169 changes: 168 additions & 1 deletion src/Compiler/AbstractIL/EncMethodDebugInformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ open System.IO
open System.Reflection.Metadata
open System.Reflection.Metadata.Ecma335
open System.Runtime.InteropServices
open System.Text
open Microsoft.FSharp.NativeInterop

open FSharp.Compiler.AbstractIL.ILPdbWriter

/// Portable-PDB CustomDebugInformation kind GUIDs for the EnC blobs, copied verbatim
/// from roslyn/src/Dependencies/CodeAnalysis.Debugging/PortableCustomDebugInfoKinds.cs.
[<RequireQualifiedAccess>]
Expand All @@ -47,6 +50,10 @@ module PortableCustomDebugInfoKinds =
/// EnC State Machine State Map CDI kind.
let encStateMachineStateMap = Guid("8B78CD68-2EDE-420B-980B-E15884B8AAA3")

/// F#-owned hot reload synthesized-name snapshot CDI kind. The blob records
/// FSharpSynthesizedTypeMaps.Snapshot bucket arrays in allocation-slot order.
let fsharpSynthesizedNameSnapshot = Guid("49DDB47E-9C74-46EC-8626-0350676571EB")

/// Closure ordinal of a lambda that is lowered to a static (non-capturing) method.
/// Mirrors Roslyn's LambdaDebugInfo.StaticClosureOrdinal.
[<Literal>]
Expand Down Expand Up @@ -167,7 +174,7 @@ let private MaxOccurrenceKey = 0x1FFFFFFD
/// 16-bit segments, least-significant segment = the innermost ordinal; an enclosing
/// ordinal p is stored as (p + 1) shifted left 16 so that depth-1 keys (< 0x10000) and
/// depth-2 keys (>= 0x10000) never collide. Fails closed (None) past the limits: chains
/// deeper than 2, ordinals > 0xFFFF, or keys exceeding the compressed-integer budget
/// deeper than 2, ordinals > 0xFFFF, or keys exceeding the compressed-integer budget,
/// callers must then treat the chain as unmappable, never truncate.
let tryEncodeOccurrenceKey (ordinalChain: int list) : int option =
match ordinalChain with
Expand Down Expand Up @@ -209,6 +216,134 @@ let private invalidData (blobName: string) (offset: int) =
// nullness model, so guard with box (FS3261-safe) rather than dropping the check.
let private isEmpty (blob: byte[]) = isNull (box blob) || blob.Length = 0

// ---------------------------------------------------------------------------
// F# hot reload module CDI: synthesized-name allocation snapshot
// Format:
// compressed(version = 1), compressed(bucket count),
// then buckets sorted by key for deterministic PDB bytes:
// string key, compressed(name count), string name in allocation-slot order.
// Strings are compressed(byte length) followed by UTF-8 bytes.
// ---------------------------------------------------------------------------

[<Literal>]
let private SynthesizedNameSnapshotBlobVersion = 1

let private writeUtf8String (builder: BlobBuilder) (value: string) =
if isNull (box value) then
invalidArg (nameof value) "snapshot strings must be non-null"

let bytes = Encoding.UTF8.GetBytes value
builder.WriteCompressedInteger bytes.Length
builder.WriteBytes bytes

let private readUtf8String (blobName: string) (reader: byref<BlobReader>) =
let length = reader.ReadCompressedInteger()

if length < 0 || length > reader.RemainingBytes then
invalidData blobName reader.Offset

let bytes = reader.ReadBytes length
Encoding.UTF8.GetString(bytes, 0, bytes.Length)

let private materializeSynthesizedNameSnapshot (snapshot: seq<struct (string * string[])>) =
snapshot
|> Seq.map (fun struct (key, names) ->
if isNull (box key) then
invalidArg (nameof snapshot) "snapshot keys must be non-null"

if isNull (box names) then
invalidArg (nameof snapshot) $"snapshot bucket '{key}' must be non-null"

key, Array.copy names)
|> Seq.sortBy fst
|> Seq.toArray

/// Serializes an allocation-ordered synthesized-name snapshot into the F#-owned module
/// CDI blob. An empty snapshot returns an empty blob so no CDI row needs to be emitted.
let serializeSynthesizedNameSnapshot (snapshot: seq<struct (string * string[])>) : byte[] =
let buckets = materializeSynthesizedNameSnapshot snapshot

if buckets.Length = 0 then
Array.empty
else
let builder = BlobBuilder()
builder.WriteCompressedInteger SynthesizedNameSnapshotBlobVersion
builder.WriteCompressedInteger buckets.Length

for key, names in buckets do
writeUtf8String builder key
builder.WriteCompressedInteger names.Length

for name in names do
writeUtf8String builder name

builder.ToArray()

/// Deserializes the F#-owned synthesized-name snapshot CDI blob. Bucket order in the
/// blob is deterministic only; each bucket array is returned exactly in recorded slot order.
let deserializeSynthesizedNameSnapshot (blob: byte[]) : Map<string, string[]> =
if isEmpty blob then
Map.empty
else
let handle = GCHandle.Alloc(blob, GCHandleType.Pinned)

try
let mutable reader =
BlobReader(NativePtr.ofNativeInt<byte> (handle.AddrOfPinnedObject()), blob.Length)

try
let version = reader.ReadCompressedInteger()

if version <> SynthesizedNameSnapshotBlobVersion then
invalidData "synthesized name snapshot" reader.Offset

let bucketCount = reader.ReadCompressedInteger()

if bucketCount <= 0 || bucketCount > reader.RemainingBytes / 2 then
invalidData "synthesized name snapshot" reader.Offset

let buckets = ResizeArray<string * string[]>()

for _ in 1..bucketCount do
let key = readUtf8String "synthesized name snapshot" &reader
let nameCount = reader.ReadCompressedInteger()

// Every serialized name consumes at least one byte for its UTF-8
// length, so this check bounds allocation before Array.zeroCreate.
if nameCount < 0 || nameCount > reader.RemainingBytes then
invalidData "synthesized name snapshot" reader.Offset

let names = Array.zeroCreate nameCount

for i in 0 .. nameCount - 1 do
names[i] <- readUtf8String "synthesized name snapshot" &reader

buckets.Add(key, names)

if reader.RemainingBytes <> 0 then
invalidData "synthesized name snapshot" reader.Offset

buckets |> Seq.map id |> Map.ofSeq
with :? BadImageFormatException ->
invalidData "synthesized name snapshot" reader.Offset
finally
handle.Free()

/// Creates the module-level CustomDebugInformation row for the allocation-ordered
/// synthesized-name snapshot. Empty snapshots emit no row.
let computeSynthesizedNameSnapshotCustomDebugInfoRows (snapshot: seq<struct (string * string[])>) : PdbModuleCustomDebugInfo list =
let blob = serializeSynthesizedNameSnapshot snapshot

if blob.Length = 0 then
[]
else
[
{
KindGuid = PortableCustomDebugInfoKinds.fsharpSynthesizedNameSnapshot
Blob = blob
}
]

// ---------------------------------------------------------------------------
// EnC Local Slot Map
// Format (EditAndContinueMethodDebugInformation.cs, SerializeLocalSlots lines 145-191,
Expand Down Expand Up @@ -555,3 +690,35 @@ let readEncMethodDebugInfoFromPortablePdb (pdbBytes: byte[]) : Map<int, EncMetho
// Not a portable PDB image (or a corrupted one): callers still get an empty
// map instead of a crash.
Map.empty

/// Reads the F#-owned allocation-ordered synthesized-name snapshot from a portable PDB.
/// None means either the record is absent or invalid; callers must fall back to IL
/// reconstruction rather than trusting a partial layout.
let readSynthesizedNameSnapshotFromPortablePdb (pdbBytes: byte[]) : Map<string, string[]> option =
if isEmpty pdbBytes then
None
else
try
use provider =
MetadataReaderProvider.FromPortablePdbImage(ImmutableArray.CreateRange pdbBytes)

let reader = provider.GetMetadataReader()

let blobs =
[
for cdiHandle in reader.CustomDebugInformation do
let cdi = reader.GetCustomDebugInformation cdiHandle

if cdi.Parent.Kind = HandleKind.ModuleDefinition then
let kind = reader.GetGuid cdi.Kind

if kind = PortableCustomDebugInfoKinds.fsharpSynthesizedNameSnapshot then
reader.GetBlobBytes cdi.Value
]

match blobs with
| [ blob ] -> Some(deserializeSynthesizedNameSnapshot blob)
| _ -> None
with
| :? BadImageFormatException
| :? InvalidDataException -> None
21 changes: 21 additions & 0 deletions src/Compiler/AbstractIL/EncMethodDebugInformation.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ module PortableCustomDebugInfoKinds =
/// EnC State Machine State Map CDI kind.
val encStateMachineStateMap: System.Guid

/// F#-owned hot reload synthesized-name snapshot CDI kind.
val fsharpSynthesizedNameSnapshot: System.Guid

/// Closure ordinal of a lambda that is lowered to a static (non-capturing) method.
/// Mirrors Roslyn's LambdaDebugInfo.StaticClosureOrdinal.
[<Literal>]
Expand Down Expand Up @@ -135,6 +138,19 @@ val tryEncodeOccurrenceKey: ordinalChain: int list -> int option
/// root-first ordinal chain.
val decodeOccurrenceKey: key: int -> int list

/// Serializes an allocation-ordered synthesized-name snapshot into the F#-owned module
/// CDI blob. An empty snapshot returns an empty blob so no CDI row needs to be emitted.
val serializeSynthesizedNameSnapshot: snapshot: seq<struct (string * string[])> -> byte[]

/// Deserializes the F#-owned synthesized-name snapshot CDI blob. Bucket order in the
/// blob is deterministic only; each bucket array is returned exactly in recorded slot order.
val deserializeSynthesizedNameSnapshot: blob: byte[] -> Map<string, string[]>

/// Creates the module-level CustomDebugInformation row for the allocation-ordered
/// synthesized-name snapshot. Empty snapshots emit no row.
val computeSynthesizedNameSnapshotCustomDebugInfoRows:
snapshot: seq<struct (string * string[])> -> FSharp.Compiler.AbstractIL.ILPdbWriter.PdbModuleCustomDebugInfo list

/// Serializes the EnC Local Slot Map blob for 'info', byte-for-byte as Roslyn's
/// SerializeLocalSlots. Returns the empty array when there are no slots (no CDI row
/// should be emitted then).
Expand Down Expand Up @@ -176,3 +192,8 @@ val deserialize:
/// Fail safe: a null/empty or non-PDB image yields the empty map, and a method whose
/// blobs do not decode is omitted rather than guessed.
val readEncMethodDebugInfoFromPortablePdb: pdbBytes: byte[] -> Map<int, EncMethodDebugInformation>

/// Reads the F#-owned allocation-ordered synthesized-name snapshot from a portable PDB.
/// None means either the record is absent or invalid; callers must fall back to IL
/// reconstruction rather than trusting a partial layout.
val readSynthesizedNameSnapshotFromPortablePdb: pdbBytes: byte[] -> Map<string, string[]> option
2 changes: 1 addition & 1 deletion src/Compiler/AbstractIL/FSharpDeltaMetadataWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module internal FSharp.Compiler.AbstractIL.FSharpDeltaMetadataWriter
open System
open System.Collections.Generic
open Microsoft.FSharp.Collections
open FSharp.Compiler.AbstractIL.ILMetadataHeaps
open FSharp.Compiler.AbstractIL.ILBinaryWriter
open FSharp.Compiler.AbstractIL.BinaryConstants
open FSharp.Compiler.AbstractIL.ILDeltaHandles
open FSharp.Compiler.AbstractIL.IlxDeltaStreams
Expand Down
Loading
Loading