Skip to content

Commit bc95eff

Browse files
authored
Merge pull request #1545 from Microsoft/forki-i1536
This takes Steffens repro and has a slightly different fix -- Fixes I1556
2 parents 4d87596 + 9dc2ed8 commit bc95eff

File tree

7 files changed

+550
-33
lines changed

7 files changed

+550
-33
lines changed

src/absil/ilwritepdb.fs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ let writePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info cvChunk =
493493
match Map.tryFind k res with
494494
| Some xsR -> xsR := sp :: !xsR; res
495495
| None -> Map.add k (ref [sp]) res
496-
496+
497497
let res = Array.fold add res sps
498498
let res = Map.toList res // ordering may not be stable
499499
List.map (fun (_,x) -> Array.ofList !x) res
@@ -502,22 +502,27 @@ let writePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info cvChunk =
502502
if spset.Length > 0 then
503503
Array.sortInPlaceWith SequencePoint.orderByOffset spset
504504
let sps =
505-
spset |> Array.map (fun sp ->
506-
// Ildiag.dprintf "token 0x%08lx has an sp at offset 0x%08x\n" minfo.MethToken sp.Offset
507-
(sp.Offset, sp.Line, sp.Column,sp.EndLine, sp.EndColumn))
508-
// Use of alloca in implementation of pdbDefineSequencePoints can give stack overflow here
505+
spset |> Array.map (fun sp ->
506+
// Ildiag.dprintf "token 0x%08lx has an sp at offset 0x%08x\n" minfo.MethToken sp.Offset
507+
(sp.Offset, sp.Line, sp.Column,sp.EndLine, sp.EndColumn))
508+
// Use of alloca in implementation of pdbDefineSequencePoints can give stack overflow here
509509
if sps.Length < 5000 then
510-
pdbDefineSequencePoints !pdbw (getDocument spset.[0].Document) sps)
510+
pdbDefineSequencePoints !pdbw (getDocument spset.[0].Document) sps)
511511

512512
// Write the scopes
513-
let rec writePdbScope top sco =
514-
if top || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
515-
pdbOpenScope !pdbw sco.StartOffset
513+
let rec writePdbScope parent sco =
514+
if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
515+
// Only nest scopes if the child scope is a different size from
516+
let nested =
517+
match parent with
518+
| Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
519+
| None -> true
520+
if nested then pdbOpenScope !pdbw sco.StartOffset
516521
sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
517-
sco.Children |> Array.iter (writePdbScope false)
518-
pdbCloseScope !pdbw sco.EndOffset
519-
writePdbScope true minfo.RootScope
522+
sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
523+
if nested then pdbCloseScope !pdbw sco.EndOffset
520524

525+
writePdbScope None minfo.RootScope
521526
pdbCloseMethod !pdbw
522527
end)
523528
reportTime showTimes "PDB: Wrote methods"

tests/fsharpqa/Source/CodeGen/EmittedIL/SerializableAttribute/ToplevelModule.il.bsl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,21 +1720,19 @@
17201720
{
17211721
// Code size 14 (0xe)
17221722
.maxstack 3
1723-
.locals init ([0] string V_0,
1724-
[1] string greeting)
1725-
.line 12,12 : 9,31
1723+
.locals init ([0] string greeting,
1724+
[1] string V_1)
1725+
.line 12,12 : 9,31 ''
17261726
IL_0000: nop
17271727
IL_0001: call string ABC::get_greeting()
17281728
IL_0006: stloc.0
1729-
.line 22,22 : 13,35
1729+
.line 22,22 : 13,35 ''
17301730
IL_0007: call string ABC/ABC::get_greeting()
17311731
IL_000c: stloc.1
17321732
IL_000d: ret
17331733
} // end of method $ABC::.cctor
1734-
17351734
} // end of class '<StartupCode$TopLevelModule>'.$ABC
17361735

1737-
17381736
// =============================================================
17391737

17401738
// *********** DISASSEMBLY COMPLETE ***********************

tests/fsharpqa/Source/CodeGen/EmittedIL/SerializableAttribute/ToplevelModuleP.il.bsl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,18 +1692,17 @@
16921692
{
16931693
// Code size 14 (0xe)
16941694
.maxstack 3
1695-
.locals init ([0] string V_0,
1696-
[1] string greeting)
1697-
.line 12,12 : 9,31
1695+
.locals init ([0] string greeting,
1696+
[1] string V_1)
1697+
.line 12,12 : 9,31 ''
16981698
IL_0000: nop
16991699
IL_0001: call string ABC::get_greeting()
17001700
IL_0006: stloc.0
1701-
.line 22,22 : 13,35
1701+
.line 22,22 : 13,35 ''
17021702
IL_0007: call string ABC/ABC::get_greeting()
17031703
IL_000c: stloc.1
17041704
IL_000d: ret
17051705
} // end of method $ABC::.cctor
1706-
17071706
} // end of class '<StartupCode$ToplevelModuleP>'.$ABC
17081707

17091708

tests/fsharpqa/Source/CodeGen/EmittedIL/SerializableAttribute/ToplevelNamespace.il.bsl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,18 +2513,17 @@
25132513
{
25142514
// Code size 14 (0xe)
25152515
.maxstack 3
2516-
.locals init ([0] string V_0,
2517-
[1] string greeting)
2518-
.line 19,19 : 9,31
2516+
.locals init ([0] string greeting,
2517+
[1] string V_1)
2518+
.line 19,19 : 9,31 ''
25192519
IL_0000: nop
25202520
IL_0001: call string XYZ.ABC::get_greeting()
25212521
IL_0006: stloc.0
2522-
.line 29,29 : 13,35
2522+
.line 29,29 : 13,35 ''
25232523
IL_0007: call string XYZ.ABC/ABC::get_greeting()
25242524
IL_000c: stloc.1
25252525
IL_000d: ret
25262526
} // end of method $ToplevelNamespace::.cctor
2527-
25282527
} // end of class '<StartupCode$ToplevelNamespace>'.$ToplevelNamespace
25292528

25302529

tests/fsharpqa/Source/CodeGen/EmittedIL/SerializableAttribute/ToplevelNamespaceP.il.bsl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,18 +2471,17 @@
24712471
{
24722472
// Code size 14 (0xe)
24732473
.maxstack 3
2474-
.locals init ([0] string V_0,
2475-
[1] string greeting)
2476-
.line 19,19 : 9,31
2474+
.locals init ([0] string greeting,
2475+
[1] string V_1)
2476+
.line 19,19 : 9,31 ''
24772477
IL_0000: nop
24782478
IL_0001: call string XYZ.ABC::get_greeting()
24792479
IL_0006: stloc.0
2480-
.line 29,29 : 13,35
2480+
.line 29,29 : 13,35 ''
24812481
IL_0007: call string XYZ.ABC/ABC::get_greeting()
24822482
IL_000c: stloc.1
24832483
IL_000d: ret
24842484
} // end of method $ToplevelNamespace::.cctor
2485-
24862485
} // end of class '<StartupCode$ToplevelNamespaceP>'.$ToplevelNamespace
24872486

24882487

0 commit comments

Comments
 (0)