Skip to content
Merged
Changes from 1 commit
Commits
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
19 changes: 12 additions & 7 deletions src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -879,11 +879,12 @@ module StackGuardMetrics =
description = "Tracks the number of times the stack guard has jumped to a new thread"
)

let countJump memberName location =
let countJump memberName location depth =
let tags =
let mutable tags = TagList()
tags.Add(Activity.Tags.callerMemberName, memberName)
tags.Add("source", location)
tags.Add("depth", depth)
tags

jumpCounter.Add(1L, &tags)
Expand Down Expand Up @@ -932,7 +933,9 @@ module StackGuardMetrics =
/// Guard against depth of expression nesting, by moving to new stack when a maximum depth is reached
type StackGuard(maxDepth: int, name: string) =

let mutable depth = 1
do ignore maxDepth

let mutable depth = 0

[<DebuggerHidden; DebuggerStepThrough>]
member _.Guard
Expand All @@ -946,20 +949,22 @@ type StackGuard(maxDepth: int, name: string) =
depth <- depth + 1

try
if depth % maxDepth = 0 then
try
RuntimeHelpers.EnsureSufficientExecutionStack()
f ()
with :? InsufficientExecutionStackException ->
// If we hit the execution stack limit, jump to a new thread regardless of depth.

let fileName = System.IO.Path.GetFileName(path)

StackGuardMetrics.countJump memberName $"{fileName}:{line}"
StackGuardMetrics.countJump memberName $"{fileName}:{line}" depth

async {
do! Async.SwitchToNewThread()
Thread.CurrentThread.Name <- $"F# Extra Compilation Thread for {name} (depth {depth})"
return f ()
}
|> Async.RunImmediate
else
f ()
finally
depth <- depth - 1

Expand Down
Loading