Skip to content

Commit 920a0d5

Browse files
[main] Source code updates from dotnet/fsharp (#7609)
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
1 parent 88604a2 commit 920a0d5

11 files changed

Lines changed: 112 additions & 161 deletions

File tree

‎src/fsharp/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Fixed
22

3+
* Stop leaking a `System.Diagnostics.Metrics.MeterListener` per `Cache` in DEBUG builds. Each cache created a `CacheMetrics.CacheMetricsListener` (which starts a `MeterListener` registered in the process-global metrics registry) and never disposed it, so listeners accumulated for the lifetime of the process. Because every cache hit/miss/add published to all registered listeners, the per-operation cost grew linearly with the number of leaked listeners, so repeated checks (and Debug FCS test runs) slowed down over time. The per-cache `CacheMetricsListener` and the per-instance `cacheId` tag are removed; `DebugDisplay` and tests now read the existing name-aggregated stats populated by the single `ListenToAll` listener, so no per-cache listener is created and no per-operation cost is added. ([PR #19995](https://github.com/dotnet/fsharp/pull/19995))
34
* Fix state machine lowering dropping the side-effectful receiver of an unused unit-typed member access (e.g. inside `task { (effectful()).UnitProp }`). ([Issue #13099](https://github.com/dotnet/fsharp/issues/13099), [PR #19885](https://github.com/dotnet/fsharp/pull/19885))
45
* `--deterministic` Release builds now produce byte-identical `FSharp.Compiler.Service.dll` under `--parallelcompilation+` and `--parallelcompilation-`, so it is restored to the determinism gate (now also checked sequential-vs-parallel). Code generation runs the same deferred per-file drain in both modes, with type/member/field emit-order keys and generated names derived from the file being emitted rather than thread-scheduling order. ([Issue #19928](https://github.com/dotnet/fsharp/issues/19928), [PR #19929](https://github.com/dotnet/fsharp/pull/19929))
56
* Fix `[<CompiledName>]` silently producing duplicate IL entries (FS0192/FS2014) when applied to a multi-value let-binding (e.g. `let a, b = 1, 2`); now emits FS0755 at type-check time. ([Issue #6131](https://github.com/dotnet/fsharp/issues/6131), [PR #19924](https://github.com/dotnet/fsharp/pull/19924))

‎src/fsharp/eng/Version.Details.props‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ This file should be imported by eng/Versions.props
88
<!-- dotnet-arcade dependencies -->
99
<MicrosoftDotNetArcadeSdkPackageVersion>10.0.0-beta.26324.4</MicrosoftDotNetArcadeSdkPackageVersion>
1010
<!-- dotnet-msbuild dependencies -->
11-
<MicrosoftBuildPackageVersion>18.10.0-preview-26353-05</MicrosoftBuildPackageVersion>
12-
<MicrosoftBuildFrameworkPackageVersion>18.10.0-preview-26353-05</MicrosoftBuildFrameworkPackageVersion>
13-
<MicrosoftBuildTasksCorePackageVersion>18.10.0-preview-26353-05</MicrosoftBuildTasksCorePackageVersion>
14-
<MicrosoftBuildUtilitiesCorePackageVersion>18.10.0-preview-26353-05</MicrosoftBuildUtilitiesCorePackageVersion>
11+
<MicrosoftBuildPackageVersion>18.10.0-preview-26357-08</MicrosoftBuildPackageVersion>
12+
<MicrosoftBuildFrameworkPackageVersion>18.10.0-preview-26357-08</MicrosoftBuildFrameworkPackageVersion>
13+
<MicrosoftBuildTasksCorePackageVersion>18.10.0-preview-26357-08</MicrosoftBuildTasksCorePackageVersion>
14+
<MicrosoftBuildUtilitiesCorePackageVersion>18.10.0-preview-26357-08</MicrosoftBuildUtilitiesCorePackageVersion>
1515
<!-- dotnet-optimization dependencies -->
1616
<optimizationlinuxarm64MIBCRuntimePackageVersion>1.0.0-prerelease.26318.1</optimizationlinuxarm64MIBCRuntimePackageVersion>
1717
<optimizationlinuxx64MIBCRuntimePackageVersion>1.0.0-prerelease.26318.1</optimizationlinuxx64MIBCRuntimePackageVersion>
1818
<optimizationwindows_ntarm64MIBCRuntimePackageVersion>1.0.0-prerelease.26318.1</optimizationwindows_ntarm64MIBCRuntimePackageVersion>
1919
<optimizationwindows_ntx64MIBCRuntimePackageVersion>1.0.0-prerelease.26318.1</optimizationwindows_ntx64MIBCRuntimePackageVersion>
2020
<optimizationwindows_ntx86MIBCRuntimePackageVersion>1.0.0-prerelease.26318.1</optimizationwindows_ntx86MIBCRuntimePackageVersion>
2121
<!-- dotnet-roslyn dependencies -->
22-
<MicrosoftCodeAnalysisPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisPackageVersion>
23-
<MicrosoftCodeAnalysisCompilersPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisCompilersPackageVersion>
24-
<MicrosoftCodeAnalysisCSharpPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisCSharpPackageVersion>
25-
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
26-
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
27-
<MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>
28-
<MicrosoftCodeAnalysisFeaturesPackageVersion>5.10.0-1.26356.6</MicrosoftCodeAnalysisFeaturesPackageVersion>
29-
<MicrosoftVisualStudioLanguageServicesPackageVersion>5.10.0-1.26356.6</MicrosoftVisualStudioLanguageServicesPackageVersion>
22+
<MicrosoftCodeAnalysisPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisPackageVersion>
23+
<MicrosoftCodeAnalysisCompilersPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisCompilersPackageVersion>
24+
<MicrosoftCodeAnalysisCSharpPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisCSharpPackageVersion>
25+
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
26+
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
27+
<MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>
28+
<MicrosoftCodeAnalysisFeaturesPackageVersion>5.10.0-1.26357.6</MicrosoftCodeAnalysisFeaturesPackageVersion>
29+
<MicrosoftVisualStudioLanguageServicesPackageVersion>5.10.0-1.26357.6</MicrosoftVisualStudioLanguageServicesPackageVersion>
3030
<!-- dotnet-runtime dependencies -->
3131
<SystemCollectionsImmutablePackageVersion>10.0.2</SystemCollectionsImmutablePackageVersion>
3232
<SystemCompositionPackageVersion>10.0.2</SystemCompositionPackageVersion>

‎src/fsharp/eng/Version.Details.xml‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,53 @@
22
<Dependencies>
33
<Source Uri="https://github.com/dotnet/dotnet" Mapping="fsharp" Sha="1358fe9202089df7bdb79282a191c9dbbb773a06" BarId="320196" />
44
<ProductDependencies>
5-
<Dependency Name="Microsoft.Build" Version="18.10.0-preview-26353-05">
5+
<Dependency Name="Microsoft.Build" Version="18.10.0-preview-26357-08">
66
<Uri>https://github.com/dotnet/msbuild</Uri>
7-
<Sha>e2c0a316c8fb5b2d991eb71bdd78bc4a8e279bf8</Sha>
7+
<Sha>746aeb090c9e2bcedc398751370da862014ebf7a</Sha>
88
</Dependency>
9-
<Dependency Name="Microsoft.Build.Framework" Version="18.10.0-preview-26353-05">
9+
<Dependency Name="Microsoft.Build.Framework" Version="18.10.0-preview-26357-08">
1010
<Uri>https://github.com/dotnet/msbuild</Uri>
11-
<Sha>e2c0a316c8fb5b2d991eb71bdd78bc4a8e279bf8</Sha>
11+
<Sha>746aeb090c9e2bcedc398751370da862014ebf7a</Sha>
1212
</Dependency>
13-
<Dependency Name="Microsoft.Build.Tasks.Core" Version="18.10.0-preview-26353-05">
13+
<Dependency Name="Microsoft.Build.Tasks.Core" Version="18.10.0-preview-26357-08">
1414
<Uri>https://github.com/dotnet/msbuild</Uri>
15-
<Sha>e2c0a316c8fb5b2d991eb71bdd78bc4a8e279bf8</Sha>
15+
<Sha>746aeb090c9e2bcedc398751370da862014ebf7a</Sha>
1616
</Dependency>
17-
<Dependency Name="Microsoft.Build.Utilities.Core" Version="18.10.0-preview-26353-05">
17+
<Dependency Name="Microsoft.Build.Utilities.Core" Version="18.10.0-preview-26357-08">
1818
<Uri>https://github.com/dotnet/msbuild</Uri>
19-
<Sha>e2c0a316c8fb5b2d991eb71bdd78bc4a8e279bf8</Sha>
19+
<Sha>746aeb090c9e2bcedc398751370da862014ebf7a</Sha>
2020
</Dependency>
21-
<Dependency Name="Microsoft.CodeAnalysis" Version="5.10.0-1.26356.6">
21+
<Dependency Name="Microsoft.CodeAnalysis" Version="5.10.0-1.26357.6">
2222
<Uri>https://github.com/dotnet/roslyn</Uri>
23-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
23+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
2424
</Dependency>
25-
<Dependency Name="Microsoft.CodeAnalysis.Features" Version="5.10.0-1.26356.6">
25+
<Dependency Name="Microsoft.CodeAnalysis.Features" Version="5.10.0-1.26357.6">
2626
<Uri>https://github.com/dotnet/roslyn</Uri>
27-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
27+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
2828
</Dependency>
29-
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="5.10.0-1.26356.6">
29+
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="5.10.0-1.26357.6">
3030
<Uri>https://github.com/dotnet/roslyn</Uri>
31-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
31+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
3232
</Dependency>
33-
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="5.10.0-1.26356.6">
33+
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="5.10.0-1.26357.6">
3434
<Uri>https://github.com/dotnet/roslyn</Uri>
35-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
35+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
3636
</Dependency>
37-
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.FSharp" Version="5.10.0-1.26356.6">
37+
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.FSharp" Version="5.10.0-1.26357.6">
3838
<Uri>https://github.com/dotnet/roslyn</Uri>
39-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
39+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
4040
</Dependency>
41-
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="5.10.0-1.26356.6">
41+
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="5.10.0-1.26357.6">
4242
<Uri>https://github.com/dotnet/roslyn</Uri>
43-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
43+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
4444
</Dependency>
45-
<Dependency Name="Microsoft.CodeAnalysis.Compilers" Version="5.10.0-1.26356.6">
45+
<Dependency Name="Microsoft.CodeAnalysis.Compilers" Version="5.10.0-1.26357.6">
4646
<Uri>https://github.com/dotnet/roslyn</Uri>
47-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
47+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
4848
</Dependency>
49-
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="5.10.0-1.26356.6">
49+
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="5.10.0-1.26357.6">
5050
<Uri>https://github.com/dotnet/roslyn</Uri>
51-
<Sha>ed7c2f0b8555529c2abd079945dbc918f0e009df</Sha>
51+
<Sha>97ee762dcf4f7135ff591ebf24b6f1dab3fe0632</Sha>
5252
</Dependency>
5353
<!-- Necessary for source-build. This allows the live version of the package to be used by source-build. -->
5454
<Dependency Name="System.Collections.Immutable" Version="10.0.2">

‎src/fsharp/src/Compiler/Service/service.fs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,6 @@ type FSharpChecker
623623

624624
static member Instance = globalInstance.Force()
625625

626-
static member internal CreateOverloadCacheMetricsListener() =
627-
new CacheMetrics.CacheMetricsListener("overloadResolutionCache")
628-
629626
member internal _.FrameworkImportsCache = backgroundCompiler.FrameworkImportsCache
630627

631628
/// Tokenize a single line, returning token information and a tokenization state represented by an integer

‎src/fsharp/src/Compiler/Service/service.fsi‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,6 @@ type public FSharpChecker =
506506
[<Obsolete("Please create an instance of FSharpChecker using FSharpChecker.Create")>]
507507
static member Instance: FSharpChecker
508508

509-
/// Creates a listener for overload resolution cache metrics, aggregating across all compilations.
510-
static member internal CreateOverloadCacheMetricsListener: unit -> CacheMetrics.CacheMetricsListener
511-
512509
member internal FrameworkImportsCache: FrameworkImportsCache
513510
member internal ReferenceResolver: LegacyReferenceResolver
514511

‎src/fsharp/src/Compiler/Utilities/Caches.fs‎

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ module CacheMetrics =
2222
let creations = Meter.CreateCounter<int64>("creations", "count")
2323
let disposals = Meter.CreateCounter<int64>("disposals", "count")
2424

25-
let mutable private nextCacheId = 0
26-
2725
let mkTags (name: string) =
28-
let cacheId = Interlocked.Increment &nextCacheId
2926
// Avoid TagList(ReadOnlySpan<...>) to support net472 runtime
27+
// Only the cache name is tagged: a per-instance id would be published on every measurement,
28+
// inflating the tag payload sent to any connected exporter for no in-process benefit.
3029
let mutable tags = TagList()
3130
tags.Add("name", box name)
32-
tags.Add("cacheId", box cacheId)
3331
tags
3432

3533
let Add (tags: inref<TagList>) = adds.Add(1L, &tags)
@@ -78,6 +76,10 @@ module CacheMetrics =
7876
let getStatsByName name =
7977
statsByName.GetOrAdd(name, fun _ -> Stats())
8078

79+
let getTotalsByName name = (getStatsByName name).GetTotals()
80+
81+
let getRatioByName name = (getStatsByName name).Ratio
82+
8183
let ListenToAll () =
8284
let listener = new MeterListener()
8385

@@ -123,50 +125,6 @@ module CacheMetrics =
123125
Console.WriteLine(StatsToString())
124126
}
125127

126-
[<Sealed>]
127-
type CacheMetricsListener(cacheTags: TagList, ?nameOnlyFilter: string) =
128-
129-
let stats = Stats()
130-
let listener = new MeterListener()
131-
132-
do
133-
for instrument in allCounters do
134-
listener.EnableMeasurementEvents instrument
135-
136-
listener.SetMeasurementEventCallback(fun instrument v tags _ ->
137-
let shouldIncrement =
138-
match nameOnlyFilter with
139-
| Some filterName ->
140-
match tags[0].Value with
141-
| :? string as name when name = filterName -> true
142-
| _ -> false
143-
| None -> tags[0] = cacheTags[0] && tags[1] = cacheTags[1]
144-
145-
if shouldIncrement then
146-
stats.Incr instrument.Name v)
147-
148-
listener.Start()
149-
150-
/// Creates a listener that aggregates metrics across all cache instances with the given name.
151-
new(cacheName: string) = new CacheMetricsListener(TagList(), nameOnlyFilter = cacheName)
152-
153-
interface IDisposable with
154-
member _.Dispose() = listener.Dispose()
155-
156-
/// Gets the current totals for each metric type.
157-
member _.GetTotals() = stats.GetTotals()
158-
159-
/// Gets the current hit ratio (hits / (hits + misses)).
160-
member _.Ratio = stats.Ratio
161-
162-
/// Gets the total number of cache hits.
163-
member _.Hits = stats.GetTotals().[hits.Name]
164-
165-
/// Gets the total number of cache misses.
166-
member _.Misses = stats.GetTotals().[misses.Name]
167-
168-
override _.ToString() = stats.ToString()
169-
170128
[<RequireQualifiedAccess>]
171129
type EvictionMode =
172130
| NoEviction
@@ -361,10 +319,6 @@ type Cache<'Key, 'Value when 'Key: not null> internal (options: CacheOptions<'Ke
361319

362320
post, dispose
363321

364-
#if DEBUG
365-
let debugListener = new CacheMetrics.CacheMetricsListener(tags)
366-
#endif
367-
368322
do CacheMetrics.Created &tags
369323

370324
member val Evicted = evicted.Publish
@@ -430,9 +384,6 @@ type Cache<'Key, 'Value when 'Key: not null> internal (options: CacheOptions<'Ke
430384
CacheMetrics.Update &tags
431385
post (EvictionQueueMessage.Update result)
432386

433-
member _.CreateMetricsListener() =
434-
new CacheMetrics.CacheMetricsListener(tags)
435-
436387
member _.Dispose() =
437388
if Interlocked.Exchange(&disposed, 1) = 0 then
438389
disposeEvictionProcessor ()
@@ -447,5 +398,8 @@ type Cache<'Key, 'Value when 'Key: not null> internal (options: CacheOptions<'Ke
447398
override this.Finalize() = this.Dispose()
448399

449400
#if DEBUG
450-
member _.DebugDisplay() = debugListener.ToString()
401+
// Shows the totals aggregated for this cache's name. Populated only while a metrics listener
402+
// (CacheMetrics.ListenToAll, e.g. under --times or the editor's metrics view) is running.
403+
member _.DebugDisplay() =
404+
(CacheMetrics.getStatsByName name).ToString()
451405
#endif

‎src/fsharp/src/Compiler/Utilities/Caches.fsi‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,18 @@ module CacheMetrics =
88
/// Global telemetry Meter for all caches. Exposed for testing purposes.
99
/// Set FSHARP_OTEL_EXPORT environment variable to enable OpenTelemetry export to external collectors in tests.
1010
val Meter: Meter
11+
12+
/// Current metric totals aggregated across all cache instances with the given name.
13+
/// Totals only accumulate while a listener from ListenToAll is running.
14+
val internal getTotalsByName: name: string -> Map<string, int64>
15+
16+
/// Current hit ratio (hits / (hits + misses)) aggregated across all cache instances with the given name.
17+
val internal getRatioByName: name: string -> float
18+
1119
val internal ListenToAll: unit -> IDisposable
1220
val internal StatsToString: unit -> string
1321
val internal CaptureStatsAndWriteToConsole: unit -> IDisposable
1422

15-
/// A listener that captures cache metrics, matching by cache name or exact cache tags.
16-
[<Sealed>]
17-
type CacheMetricsListener =
18-
/// Creates a listener that aggregates metrics across all cache instances with the given name.
19-
new: cacheName: string -> CacheMetricsListener
20-
/// Gets the current totals for each metric type.
21-
member GetTotals: unit -> Map<string, int64>
22-
/// Gets the current hit ratio (hits / (hits + misses)).
23-
member Ratio: float
24-
/// Gets the total number of cache hits.
25-
member Hits: int64
26-
/// Gets the total number of cache misses.
27-
member Misses: int64
28-
interface IDisposable
29-
3023
[<RequireQualifiedAccess; NoComparison>]
3124
type internal EvictionMode =
3225
/// Do not evict items, cache is effectively a ConcurrentDictionary.
@@ -74,5 +67,3 @@ type internal Cache<'Key, 'Value when 'Key: not null> =
7467
member Evicted: IEvent<unit>
7568
/// For testing only.
7669
member EvictionFailed: IEvent<unit>
77-
/// For testing only. Creates a local telemetry listener for this cache instance.
78-
member CreateMetricsListener: unit -> CacheMetrics.CacheMetricsListener

0 commit comments

Comments
 (0)