Skip to content

Commit b91057c

Browse files
authored
Merge branch 'main' into async2
2 parents 9d6c6f3 + 80da32a commit b91057c

File tree

49 files changed

+293
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+293
-255
lines changed

docs/release-notes/.FSharp.Compiler.Service/10.0.100.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
* Parser: Capture named fields block separators. ([PR #18857](https://github.com/dotnet/fsharp/pull/18857))
4343
* Type checker: use inner expr range in upcast constraints errors ([PR #18850](https://github.com/dotnet/fsharp/pull/18850))
4444
* Import `IEnumerable` as `seq`. ([PR #18865](https://github.com/dotnet/fsharp/pull/18865))
45-
* Parser: Capture multiple block separators ([PR #18899](https://github.com/dotnet/fsharp/pull/18899))
4645

4746
### Breaking Changes
4847

eng/Version.Details.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ This file should be imported by eng/Versions.props
66
<Project>
77
<PropertyGroup>
88
<!-- dotnet/msbuild dependencies -->
9-
<MicrosoftBuildPackageVersion>18.0.0-preview-25472-05</MicrosoftBuildPackageVersion>
10-
<MicrosoftBuildFrameworkPackageVersion>18.0.0-preview-25472-05</MicrosoftBuildFrameworkPackageVersion>
11-
<MicrosoftBuildTasksCorePackageVersion>18.0.0-preview-25472-05</MicrosoftBuildTasksCorePackageVersion>
12-
<MicrosoftBuildUtilitiesCorePackageVersion>18.0.0-preview-25472-05</MicrosoftBuildUtilitiesCorePackageVersion>
9+
<MicrosoftBuildPackageVersion>18.0.0-preview-25476-03</MicrosoftBuildPackageVersion>
10+
<MicrosoftBuildFrameworkPackageVersion>18.0.0-preview-25476-03</MicrosoftBuildFrameworkPackageVersion>
11+
<MicrosoftBuildTasksCorePackageVersion>18.0.0-preview-25476-03</MicrosoftBuildTasksCorePackageVersion>
12+
<MicrosoftBuildUtilitiesCorePackageVersion>18.0.0-preview-25476-03</MicrosoftBuildUtilitiesCorePackageVersion>
1313
<!-- dotnet/runtime dependencies -->
1414
<SystemCollectionsImmutablePackageVersion>9.0.0</SystemCollectionsImmutablePackageVersion>
1515
<SystemComponentModelCompositionPackageVersion>9.0.0</SystemComponentModelCompositionPackageVersion>

eng/Version.Details.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
<Dependencies>
33
<Source Uri="https://github.com/dotnet/dotnet" Mapping="fsharp" Sha="2dea164f01d307c409cfe0d0ee5cb8a0691e3c94" BarId="283828" />
44
<ProductDependencies>
5-
<Dependency Name="Microsoft.Build" Version="18.0.0-preview-25472-05">
5+
<Dependency Name="Microsoft.Build" Version="18.0.0-preview-25476-03">
66
<Uri>https://github.com/dotnet/msbuild</Uri>
7-
<Sha>bf373edc7ed1110a03d28fde1e2cd258fce88a74</Sha>
7+
<Sha>5480b47bbc592c6feedca7c57c9863ba01e0c52c</Sha>
88
</Dependency>
9-
<Dependency Name="Microsoft.Build.Framework" Version="18.0.0-preview-25472-05">
9+
<Dependency Name="Microsoft.Build.Framework" Version="18.0.0-preview-25476-03">
1010
<Uri>https://github.com/dotnet/msbuild</Uri>
11-
<Sha>bf373edc7ed1110a03d28fde1e2cd258fce88a74</Sha>
11+
<Sha>5480b47bbc592c6feedca7c57c9863ba01e0c52c</Sha>
1212
</Dependency>
13-
<Dependency Name="Microsoft.Build.Tasks.Core" Version="18.0.0-preview-25472-05">
13+
<Dependency Name="Microsoft.Build.Tasks.Core" Version="18.0.0-preview-25476-03">
1414
<Uri>https://github.com/dotnet/msbuild</Uri>
15-
<Sha>bf373edc7ed1110a03d28fde1e2cd258fce88a74</Sha>
15+
<Sha>5480b47bbc592c6feedca7c57c9863ba01e0c52c</Sha>
1616
</Dependency>
17-
<Dependency Name="Microsoft.Build.Utilities.Core" Version="18.0.0-preview-25472-05">
17+
<Dependency Name="Microsoft.Build.Utilities.Core" Version="18.0.0-preview-25476-03">
1818
<Uri>https://github.com/dotnet/msbuild</Uri>
19-
<Sha>bf373edc7ed1110a03d28fde1e2cd258fce88a74</Sha>
19+
<Sha>5480b47bbc592c6feedca7c57c9863ba01e0c52c</Sha>
2020
</Dependency>
2121
<Dependency Name="System.Reflection.Metadata" Version="9.0.0">
2222
<Uri>https://github.com/dotnet/runtime</Uri>

src/Compiler/Checking/CheckRecordSyntaxHelpers.fs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,19 @@ let TransformAstForNestedUpdates (cenv: TcFileState) (env: TcEnv) overallTy (lid
9090
let totalRange (origId: Ident) (id: Ident) =
9191
withStartEnd origId.idRange.End id.idRange.Start origId.idRange
9292

93-
match withExpr with
94-
| SynExpr.Ident origId, (blockSep: BlockSeparator) ->
95-
let lid, rng = upToId blockSep.Range id (origId :: ids)
93+
let rangeOfBlockSeparator (id: Ident) =
94+
let idEnd = id.idRange.End
95+
let blockSeparatorStartCol = idEnd.Column
96+
let blockSeparatorEndCol = blockSeparatorStartCol + 4
97+
let blockSeparatorStartPos = mkPos idEnd.Line blockSeparatorStartCol
98+
let blockSeparatorEndPos = mkPos idEnd.Line blockSeparatorEndCol
99+
100+
withStartEnd blockSeparatorStartPos blockSeparatorEndPos id.idRange
96101

97-
Some(
98-
SynExpr.LongIdent(false, LongIdentWithDots(lid, rng), None, totalRange origId id),
99-
BlockSeparator.Offside(blockSep.Range, None)
100-
)
102+
match withExpr with
103+
| SynExpr.Ident origId, (sepRange, _) ->
104+
let lid, rng = upToId sepRange id (origId :: ids)
105+
Some(SynExpr.LongIdent(false, LongIdentWithDots(lid, rng), None, totalRange origId id), (rangeOfBlockSeparator id, None))
101106
| _ -> None
102107

103108
let rec synExprRecd copyInfo (outerFieldId: Ident) innerFields exprBeingAssigned =

src/Compiler/Checking/CheckRecordSyntaxHelpers.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ open FSharp.Compiler.TypedTree
1010
val GroupUpdatesToNestedFields:
1111
fields: ((Ident list * Ident) * SynExpr option) list -> ((Ident list * Ident) * SynExpr option) list
1212

13-
val TransformAstForNestedUpdates:
13+
val TransformAstForNestedUpdates<'a> :
1414
cenv: TcFileState ->
1515
env: TcEnv ->
1616
overallTy: TType ->
1717
lid: LongIdent ->
1818
exprBeingAssigned: SynExpr ->
19-
withExpr: SynExpr * BlockSeparator ->
19+
withExpr: SynExpr * (range * 'a) ->
2020
(Ident list * Ident) * SynExpr option
2121

2222
val BindOriginalRecdExpr:

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7763,7 +7763,7 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, m
77637763

77647764
match withExprOpt, synLongId.LongIdent, exprBeingAssigned with
77657765
| _, [ id ], _ -> ([], id), exprBeingAssigned
7766-
| Some (origExpr, blockSep), lid, Some exprBeingAssigned -> TransformAstForNestedUpdates cenv env overallTy lid exprBeingAssigned (origExpr, blockSep)
7766+
| Some withExpr, lid, Some exprBeingAssigned -> TransformAstForNestedUpdates cenv env overallTy lid exprBeingAssigned withExpr
77677767
| _ -> List.frontAndBack synLongId.LongIdent, exprBeingAssigned)
77687768

77697769
let flds = if hasOrigExpr then GroupUpdatesToNestedFields flds else flds

src/Compiler/Driver/fsc.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ let main1
569569
exiter.Exit 1
570570

571571
if tcConfig.showTimes then
572+
StackGuardMetrics.CaptureStatsAndWriteToConsole() |> disposables.Register
572573
Caches.CacheMetrics.CaptureStatsAndWriteToConsole() |> disposables.Register
573574
Activity.Profiling.addConsoleListener () |> disposables.Register
574575

src/Compiler/Facilities/DiagnosticsLogger.fs

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ open System.Runtime.InteropServices
1616
open Internal.Utilities.Library
1717
open Internal.Utilities.Library.Extras
1818
open System.Threading.Tasks
19+
open System.Collections.Concurrent
1920

2021
/// Represents the style being used to format errors
2122
[<RequireQualifiedAccess; NoComparison; NoEquality>]
@@ -868,6 +869,66 @@ let internal languageFeatureNotSupportedInLibraryError (langFeature: LanguageFea
868869
let suggestedVersionStr = LanguageVersion.GetFeatureVersionString langFeature
869870
error (Error(FSComp.SR.chkFeatureNotSupportedInLibrary (featureStr, suggestedVersionStr), m))
870871

872+
module StackGuardMetrics =
873+
874+
let meter = FSharp.Compiler.Diagnostics.Metrics.Meter
875+
876+
let jumpCounter =
877+
meter.CreateCounter<int64>(
878+
"stackguard-jumps",
879+
description = "Tracks the number of times the stack guard has jumped to a new thread"
880+
)
881+
882+
let countJump memberName location =
883+
let tags =
884+
let mutable tags = TagList()
885+
tags.Add(Activity.Tags.callerMemberName, memberName)
886+
tags.Add("source", location)
887+
tags
888+
889+
jumpCounter.Add(1L, &tags)
890+
891+
// Used by the self-listener.
892+
let jumpsByFunctionName = ConcurrentDictionary<_, int64 ref>()
893+
894+
let Listen () =
895+
let listener = new Metrics.MeterListener()
896+
897+
listener.EnableMeasurementEvents jumpCounter
898+
899+
listener.SetMeasurementEventCallback(fun _ v tags _ ->
900+
let memberName = nonNull tags[0].Value :?> string
901+
let source = nonNull tags[1].Value :?> string
902+
let counter = jumpsByFunctionName.GetOrAdd((memberName, source), fun _ -> ref 0L)
903+
Interlocked.Add(counter, v) |> ignore)
904+
905+
listener.Start()
906+
listener :> IDisposable
907+
908+
let StatsToString () =
909+
let headers = [ "caller"; "source"; "jumps" ]
910+
911+
let data =
912+
[
913+
for kvp in jumpsByFunctionName do
914+
let (memberName, source) = kvp.Key
915+
[ memberName; source; string kvp.Value.Value ]
916+
]
917+
918+
if List.isEmpty data then
919+
""
920+
else
921+
$"StackGuard jumps:\n{Metrics.printTable headers data}"
922+
923+
let CaptureStatsAndWriteToConsole () =
924+
let listener = Listen()
925+
926+
{ new IDisposable with
927+
member _.Dispose() =
928+
listener.Dispose()
929+
StatsToString() |> printfn "%s"
930+
}
931+
871932
/// Guard against depth of expression nesting, by moving to new stack when a maximum depth is reached
872933
type StackGuard(maxDepth: int, name: string) =
873934

@@ -882,22 +943,15 @@ type StackGuard(maxDepth: int, name: string) =
882943
[<CallerLineNumber; Optional; DefaultParameterValue(0)>] line: int
883944
) =
884945

885-
Activity.addEventWithTags
886-
"DiagnosticsLogger.StackGuard.Guard"
887-
(seq {
888-
Activity.Tags.stackGuardName, box name
889-
Activity.Tags.stackGuardCurrentDepth, depth
890-
Activity.Tags.stackGuardMaxDepth, maxDepth
891-
Activity.Tags.callerMemberName, memberName
892-
Activity.Tags.callerFilePath, path
893-
Activity.Tags.callerLineNumber, line
894-
})
895-
896946
depth <- depth + 1
897947

898948
try
899949
if depth % maxDepth = 0 then
900950

951+
let fileName = System.IO.Path.GetFileName(path)
952+
953+
StackGuardMetrics.countJump memberName $"{fileName}:{line}"
954+
901955
async {
902956
do! Async.SwitchToNewThread()
903957
Thread.CurrentThread.Name <- $"F# Extra Compilation Thread for {name} (depth {depth})"

src/Compiler/Facilities/DiagnosticsLogger.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ val tryLanguageFeatureErrorOption:
461461

462462
val languageFeatureNotSupportedInLibraryError: langFeature: LanguageFeature -> m: range -> 'T
463463

464+
module internal StackGuardMetrics =
465+
val Listen: unit -> IDisposable
466+
val StatsToString: unit -> string
467+
val CaptureStatsAndWriteToConsole: unit -> IDisposable
468+
464469
type StackGuard =
465470
new: maxDepth: int * name: string -> StackGuard
466471

src/Compiler/Service/ServiceParseTreeWalk.fs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,12 @@ module SyntaxTraversal =
445445
| SynExpr.AnonRecd(copyInfo = copyOpt; recordFields = fields) ->
446446
[
447447
match copyOpt with
448-
| Some(expr, blockSep) ->
448+
| Some(expr, (withRange, _)) ->
449449
yield dive expr expr.Range traverseSynExpr
450450

451451
yield
452-
dive () blockSep.Range (fun () ->
453-
if posGeq pos blockSep.Range.End then
452+
dive () withRange (fun () ->
453+
if posGeq pos withRange.End then
454454
// special case: caret is after WITH
455455
// { x with $ }
456456
visitor.VisitRecordField(path, Some expr, None)
@@ -498,24 +498,24 @@ module SyntaxTraversal =
498498
traverseSynExpr expr)
499499

500500
match sepOpt with
501-
| Some blockSep ->
501+
| Some(sep, scPosOpt) ->
502502
yield
503-
dive () blockSep.Range (fun () ->
503+
dive () sep (fun () ->
504504
// special case: caret is below 'inherit' + one or more fields are already defined
505505
// inherit A()
506506
// $
507507
// field1 = 5
508-
diveIntoSeparator inheritRange.StartColumn blockSep.Position None)
508+
diveIntoSeparator inheritRange.StartColumn scPosOpt None)
509509
| None -> ()
510510
| _ -> ()
511511

512512
match copyOpt with
513-
| Some(expr, blockSep) ->
513+
| Some(expr, (withRange, _)) ->
514514
yield dive expr expr.Range traverseSynExpr
515515

516516
yield
517-
dive () blockSep.Range (fun () ->
518-
if posGeq pos blockSep.Range.End then
517+
dive () withRange (fun () ->
518+
if posGeq pos withRange.End then
519519
// special case: caret is after WITH
520520
// { x with $ }
521521
visitor.VisitRecordField(path, Some expr, None)
@@ -556,14 +556,14 @@ module SyntaxTraversal =
556556
| None -> ()
557557

558558
match sepOpt with
559-
| Some blockSep ->
559+
| Some(sep, scPosOpt) ->
560560
yield
561-
dive () blockSep.Range (fun () ->
561+
dive () sep (fun () ->
562562
// special case: caret is between field bindings
563563
// field1 = 5
564564
// $
565565
// field2 = 5
566-
diveIntoSeparator offsideColumn blockSep.Position copyOpt)
566+
diveIntoSeparator offsideColumn scPosOpt copyOpt)
567567
| _ -> ()
568568

569569
]

0 commit comments

Comments
 (0)