File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,42 @@ type env = | NoEnv
19
19
20
20
let FindUnsolvedStackGuardDepth = StackGuard.GetDepthOption " FindUnsolved"
21
21
22
+ type SyncStackGuard ( maxDepth ) =
23
+ let mutable stack = Unchecked.defaultof<_>
24
+ let mutable depth = 0
25
+ let mutable running = false
26
+
27
+ let run f =
28
+ running <- true
29
+ try
30
+ stack <- System.Collections.Generic.Stack<_>()
31
+ stack.Push f
32
+ while stack.Count > 0 do
33
+ let f = stack.Pop()
34
+ f()
35
+ finally
36
+ running <- false
37
+
38
+ let push f =
39
+ if not running then run f else stack.Push f
40
+
41
+ member _.Guard f =
42
+ depth <- depth + 1
43
+ try
44
+ if depth % maxDepth = 0 then
45
+ push f
46
+ else
47
+ f()
48
+ finally
49
+ depth <- depth - 1
50
+
22
51
/// The environment and collector
23
52
type cenv =
24
53
{ g: TcGlobals
25
54
amap: Import .ImportMap
26
55
denv: DisplayEnv
27
56
mutable unsolved: Typars
28
- stackGuard: StackGuard }
57
+ stackGuard: SyncStackGuard }
29
58
30
59
override _.ToString () = " <cenv>"
31
60
@@ -318,7 +347,7 @@ let UnsolvedTyparsOfModuleDef g amap denv mdef extraAttribs =
318
347
amap= amap
319
348
denv= denv
320
349
unsolved = []
321
- stackGuard = StackGuard ( FindUnsolvedStackGuardDepth , " UnsolvedTyparsOfModuleDef " ) }
350
+ stackGuard = SyncStackGuard FindUnsolvedStackGuardDepth }
322
351
accModuleOrNamespaceDef cenv NoEnv mdef
323
352
accAttribs cenv NoEnv extraAttribs
324
353
List.rev cenv.unsolved
You can’t perform that action at this time.
0 commit comments