Initial set of Ward sgen annotations (#5705)
[mono.git] / packaging / MacSDK / patches / fsharp-metadata-table-size-fix.patch
1 From a7ac2facce91c15940e466f67a4ba9a31f687a1a Mon Sep 17 00:00:00 2001
2 From: Kevin Ransom <kevinr@microsoft.com>
3 Date: Sun, 3 Sep 2017 17:00:18 -0700
4 Subject: [PATCH 1/3] Fix MethodDebugTable for portablePDBs
5
6 ---
7  src/absil/ilwritepdb.fs | 27 ++++++++++++++-------------
8  1 file changed, 14 insertions(+), 13 deletions(-)
9
10 diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs
11 index 009d39f653..3d68edee38 100644
12 --- a/src/absil/ilwritepdb.fs
13 +++ b/src/absil/ilwritepdb.fs
14 @@ -330,17 +330,22 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
15                      | None -> Array.empty<PdbSequencePoint>
16                      | Some (_,_) -> minfo.SequencePoints
17  
18 -            let getDocumentHandle d =
19 -                if docs.Length = 0 || d < 0 || d > docs.Length then
20 -                    Unchecked.defaultof<DocumentHandle>
21 -                else 
22 -                    match documentIndex.TryGetValue(docs.[d].File) with
23 -                    | false, _ -> Unchecked.defaultof<DocumentHandle>
24 -                    | true, h -> h
25 -
26 -            if sps.Length = 0 then
27 +            let builder = new BlobBuilder()
28 +            builder.WriteCompressedInteger(minfo.LocalSignatureToken)
29 +
30 +            if sps = Array.empty then
31 +                builder.WriteCompressedInteger( 0 )
32 +                builder.WriteCompressedInteger( 0 )
33                  Unchecked.defaultof<DocumentHandle>, Unchecked.defaultof<BlobHandle>
34              else
35 +                let getDocumentHandle d =
36 +                    if docs.Length = 0 || d < 0 || d > docs.Length then
37 +                        Unchecked.defaultof<DocumentHandle>
38 +                    else 
39 +                        match documentIndex.TryGetValue(docs.[d].File) with
40 +                        | false, _ -> Unchecked.defaultof<DocumentHandle>
41 +                        | true, h -> h
42 +
43                  // Return a document that the entire method body is declared within.
44                  // If part of the method body is in another document returns nil handle.
45                  let tryGetSingleDocumentIndex =
46 @@ -350,12 +355,8 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
47                              singleDocumentIndex <- -1
48                      singleDocumentIndex
49  
50 -                let builder = new BlobBuilder()
51 -                builder.WriteCompressedInteger(minfo.LocalSignatureToken)
52 -
53                  // Initial document:  When sp's spread over more than one document we put the initial document here.
54                  let singleDocumentIndex = tryGetSingleDocumentIndex
55 -
56                  if singleDocumentIndex = -1 then
57                      builder.WriteCompressedInteger( MetadataTokens.GetRowNumber(DocumentHandle.op_Implicit(getDocumentHandle (sps.[0].Document))) )
58  
59
60 From 01d3e175e7e5c8c554c92bf121adba44e1287f9a Mon Sep 17 00:00:00 2001
61 From: Kevin Ransom <kevinr@microsoft.com>
62 Date: Tue, 5 Sep 2017 02:59:55 -0700
63 Subject: [PATCH 2/3] ensure that pdb gets a record for abstract methods
64
65 ---
66  src/absil/ilread.fs      |   1 -
67  src/absil/ilsupp.fs      |   3 --
68  src/absil/ilsupp.fsi     |   1 -
69  src/absil/ilwrite.fs     |  17 +++++--
70  src/absil/ilwritepdb.fs  | 113 ++++++++++++++++++++++++++---------------------
71  src/absil/ilwritepdb.fsi |   2 +-
72  6 files changed, 77 insertions(+), 60 deletions(-)
73
74 diff --git a/src/absil/ilread.fs b/src/absil/ilread.fs
75 index c7a435291c..2d42a6abd8 100644
76 --- a/src/absil/ilread.fs
77 +++ b/src/absil/ilread.fs
78 @@ -2903,7 +2903,6 @@ and seekReadMethodRVA ctxt (idx,nm,_internalcall,noinline,aggressiveinline,numty
79                 try 
80  
81                   let pdbm = pdbReaderGetMethod pdbr (uncodedToken TableNames.Method idx)
82 -                 //let rootScope = pdbMethodGetRootScope pdbm 
83                   let sps = pdbMethodGetSequencePoints pdbm
84                   (*dprintf "#sps for 0x%x = %d\n" (uncodedToken TableNames.Method idx) (Array.length sps)  *)
85                   (* let roota,rootb = pdbScopeGetOffsets rootScope in  *)
86 diff --git a/src/absil/ilsupp.fs b/src/absil/ilsupp.fs
87 index c95480bc06..66a1a6aa16 100644
88 --- a/src/absil/ilsupp.fs
89 +++ b/src/absil/ilsupp.fs
90 @@ -1230,9 +1230,6 @@ let pdbMethodGetToken (meth:PdbMethod) : int32 =
91      let token = meth.symMethod.Token
92      token.GetToken()
93    
94 -let pdbMethodGetRootScope (meth:PdbMethod) : PdbMethodScope = 
95 -    { symScope = meth.symMethod.RootScope }
96 -
97  let pdbMethodGetSequencePoints (meth:PdbMethod) : PdbSequencePoint array =
98      let  pSize = meth.symMethod.SequencePointCount
99      let offsets = Array.zeroCreate pSize
100 diff --git a/src/absil/ilsupp.fsi b/src/absil/ilsupp.fsi
101 index 15da0aa215..3a3748c6d2 100644
102 --- a/src/absil/ilsupp.fsi
103 +++ b/src/absil/ilsupp.fsi
104 @@ -73,7 +73,6 @@ val pdbDocumentGetLanguageVendor: PdbDocument -> byte[] (* guid *)
105  val pdbDocumentFindClosestLine: PdbDocument -> int -> int
106  
107  val pdbMethodGetToken: PdbMethod -> int32
108 -val pdbMethodGetRootScope: PdbMethod ->  PdbMethodScope
109  val pdbMethodGetSequencePoints: PdbMethod -> PdbSequencePoint array
110  
111  val pdbScopeGetChildren: PdbMethodScope -> PdbMethodScope array
112 diff --git a/src/absil/ilwrite.fs b/src/absil/ilwrite.fs
113 index 838b78783b..3b10ff4340 100644
114 --- a/src/absil/ilwrite.fs
115 +++ b/src/absil/ilwrite.fs
116 @@ -2577,7 +2577,7 @@ let GenMethodDefAsRow cenv env midx (md: ILMethodDef) =
117                  MethName=md.Name
118                  LocalSignatureToken=localToken
119                  Params= [| |] (* REVIEW *)
120 -                RootScope = rootScope
121 +                RootScope = Some rootScope
122                  Range=  
123                    match ilmbody.SourceMarker with 
124                    | Some m  when cenv.generatePdb -> 
125 @@ -2592,9 +2592,20 @@ let GenMethodDefAsRow cenv env midx (md: ILMethodDef) =
126                                Column=m.EndColumn })
127                    | _ -> None
128                  SequencePoints=seqpoints }
129 -         
130            cenv.AddCode code
131 -          addr 
132 +          addr
133 +      | MethodBody.Abstract ->
134 +          // Now record the PDB record for this method - we write this out later. 
135 +          if cenv.generatePdb then 
136 +            cenv.pdbinfo.Add  
137 +              { MethToken = getUncodedToken TableNames.Method midx
138 +                MethName = md.Name
139 +                LocalSignatureToken = 0x0                   // No locals it's abstract
140 +                Params = [| |]
141 +                RootScope = None
142 +                Range = None
143 +                SequencePoints = [| |] }
144 +          0x0000
145        | MethodBody.Native -> 
146            failwith "cannot write body of native method - Abstract IL cannot roundtrip mixed native/managed binaries"
147        | _  -> 0x0000)
148 diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs
149 index 3d68edee38..996110e9b7 100644
150 --- a/src/absil/ilwritepdb.fs
151 +++ b/src/absil/ilwritepdb.fs
152 @@ -81,7 +81,7 @@ type PdbMethodData =
153        MethName:string
154        LocalSignatureToken: int32
155        Params: PdbLocalVar array
156 -      RootScope: PdbMethodScope
157 +      RootScope: PdbMethodScope option
158        Range: (PdbSourceLoc * PdbSourceLoc) option
159        SequencePoints: PdbSequencePoint array }
160  
161 @@ -224,7 +224,7 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
162      let externalRowCounts = getRowCounts info.TableRowCounts
163      let docs = 
164          match info.Documents with
165 -        | null -> Array.empty<PdbDocumentData>
166 +        | null -> Array.empty
167          | _ -> info.Documents
168  
169      let metadata = MetadataBuilder()
170 @@ -324,16 +324,16 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
171          let docHandle, sequencePointBlob =
172              let sps =
173                  match minfo.SequencePoints with
174 -                | null -> Array.empty<PdbSequencePoint>
175 +                | null -> Array.empty
176                  | _ ->
177                      match minfo.Range with
178 -                    | None -> Array.empty<PdbSequencePoint>
179 +                    | None -> Array.empty
180                      | Some (_,_) -> minfo.SequencePoints
181  
182              let builder = new BlobBuilder()
183              builder.WriteCompressedInteger(minfo.LocalSignatureToken)
184  
185 -            if sps = Array.empty then
186 +            if sps.Length = 0 then
187                  builder.WriteCompressedInteger( 0 )
188                  builder.WriteCompressedInteger( 0 )
189                  Unchecked.defaultof<DocumentHandle>, Unchecked.defaultof<BlobHandle>
190 @@ -407,38 +407,41 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
191          // Write the scopes
192          let nextHandle handle = MetadataTokens.LocalVariableHandle(MetadataTokens.GetRowNumber(LocalVariableHandle.op_Implicit(handle)) + 1)
193          let writeMethodScope scope =
194 -            let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
195 -                if scope1.StartOffset > scope2.StartOffset then 1
196 -                elif scope1.StartOffset < scope2.StartOffset then -1
197 -                elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
198 -                elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
199 -                else 0
200 -
201 -            let collectScopes scope =
202 -                let list = new List<PdbMethodScope>()
203 -                let rec toList scope =
204 -                    list.Add scope
205 -                    scope.Children |> Seq.iter(fun s -> toList s)
206 -                toList scope
207 -                list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
208 -
209 -            collectScopes scope |> Seq.iter(fun s ->
210 -                                    if s.Children.Length = 0 then
211 -                                        metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
212 -                                                               Unchecked.defaultof<ImportScopeHandle>,
213 -                                                               nextHandle lastLocalVariableHandle,
214 -                                                               Unchecked.defaultof<LocalConstantHandle>,
215 -                                                               0, s.EndOffset - s.StartOffset ) |>ignore
216 -                                    else
217 -                                        metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
218 -                                                               Unchecked.defaultof<ImportScopeHandle>,
219 -                                                               nextHandle lastLocalVariableHandle,
220 -                                                               Unchecked.defaultof<LocalConstantHandle>,
221 -                                                               s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
222 -
223 -                                    for localVariable in s.Locals do
224 -                                        lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
225 -                                    )
226 +            match scope with
227 +            | Some scope ->
228 +                let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
229 +                    if scope1.StartOffset > scope2.StartOffset then 1
230 +                    elif scope1.StartOffset < scope2.StartOffset then -1
231 +                    elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
232 +                    elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
233 +                    else 0
234 +
235 +                let collectScopes scope =
236 +                    let list = new List<PdbMethodScope>()
237 +                    let rec toList scope =
238 +                        list.Add scope
239 +                        scope.Children |> Seq.iter(fun s -> toList s)
240 +                    toList scope
241 +                    list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
242 +
243 +                collectScopes scope |> Seq.iter(fun s ->
244 +                                        if s.Children.Length = 0 then
245 +                                            metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
246 +                                                                   Unchecked.defaultof<ImportScopeHandle>,
247 +                                                                   nextHandle lastLocalVariableHandle,
248 +                                                                   Unchecked.defaultof<LocalConstantHandle>,
249 +                                                                   0, s.EndOffset - s.StartOffset ) |>ignore
250 +                                        else
251 +                                            metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
252 +                                                                   Unchecked.defaultof<ImportScopeHandle>,
253 +                                                                   nextHandle lastLocalVariableHandle,
254 +                                                                   Unchecked.defaultof<LocalConstantHandle>,
255 +                                                                   s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
256 +
257 +                                        for localVariable in s.Locals do
258 +                                            lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
259 +                                        )
260 +            | None -> ()
261          writeMethodScope minfo.RootScope )
262  
263      let entryPoint =
264 @@ -554,18 +557,20 @@ let writePdbInfo showTimes f fpdb info cvChunk =
265  
266                // Write the scopes 
267                let rec writePdbScope parent sco = 
268 -                  if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
269 -                      // Only nest scopes if the child scope is a different size from 
270 -                      let nested =
271 -                          match parent with
272 -                          | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
273 -                          | None -> true
274 -                      if nested then pdbOpenScope !pdbw sco.StartOffset
275 -                      sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
276 -                      sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
277 -                      if nested then pdbCloseScope !pdbw sco.EndOffset
278 -
279 -              writePdbScope None minfo.RootScope 
280 +                    if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
281 +                        // Only nest scopes if the child scope is a different size from 
282 +                        let nested =
283 +                            match parent with
284 +                            | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
285 +                            | None -> true
286 +                        if nested then pdbOpenScope !pdbw sco.StartOffset
287 +                        sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
288 +                        sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
289 +                        if nested then pdbCloseScope !pdbw sco.EndOffset
290 +
291 +              match minfo.RootScope with
292 +              | None -> ()
293 +              | Some rootscope -> writePdbScope None rootscope 
294                pdbCloseMethod !pdbw
295            end)
296      reportTime showTimes "PDB: Wrote methods"
297 @@ -675,7 +680,10 @@ let writeMdbInfo fmdb f info =
298                  for child in scope.Children do 
299                      writeScope(child)
300                  wr?CloseScope(scope.EndOffset)          
301 -            writeScope(meth.RootScope)
302 +            match meth.RootScope with
303 +            | None -> ()
304 +            | Some rootscope -> writeScope(rootscope)
305 +
306  
307              // Finished generating debug information for the curretn method
308              wr?CloseMethod()
309 @@ -722,5 +730,8 @@ let logDebugInfo (outfile:string) (info:PdbData) =
310          if scope.Locals.Length > 0 then
311            fprintfn sw "      %s  Locals: %A" offs [ for p in scope.Locals -> sprintf "%d: %s" p.Index p.Name ]
312          for child in scope.Children do writeScope (offs + "  ") child
313 -      writeScope "" meth.RootScope
314 +
315 +      match meth.RootScope with
316 +      | None -> ()
317 +      | Some rootscope -> writeScope "" rootscope
318        fprintfn sw ""
319 diff --git a/src/absil/ilwritepdb.fsi b/src/absil/ilwritepdb.fsi
320 index e5d1c8d03a..af9f16be9e 100644
321 --- a/src/absil/ilwritepdb.fsi
322 +++ b/src/absil/ilwritepdb.fsi
323 @@ -44,7 +44,7 @@ type PdbMethodData =
324        MethName:string
325        LocalSignatureToken: int32
326        Params: PdbLocalVar array
327 -      RootScope: PdbMethodScope
328 +      RootScope: PdbMethodScope option
329        Range: (PdbSourceLoc * PdbSourceLoc) option
330        SequencePoints: PdbSequencePoint array }
331  
332
333 From 64ecadb27b24c1486610deb32c3044ad0b3449ae Mon Sep 17 00:00:00 2001
334 From: Kevin Ransom <kevinr@microsoft.com>
335 Date: Tue, 5 Sep 2017 03:13:04 -0700
336 Subject: [PATCH 3/3] minimise diff
337
338 ---
339  src/absil/ilwritepdb.fs | 92 ++++++++++++++++++++++++-------------------------
340  1 file changed, 46 insertions(+), 46 deletions(-)
341
342 diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs
343 index 996110e9b7..f8baa3aea4 100644
344 --- a/src/absil/ilwritepdb.fs
345 +++ b/src/absil/ilwritepdb.fs
346 @@ -407,42 +407,42 @@ let generatePortablePdb (embedAllSource:bool) (embedSourceList:string list) (sou
347          // Write the scopes
348          let nextHandle handle = MetadataTokens.LocalVariableHandle(MetadataTokens.GetRowNumber(LocalVariableHandle.op_Implicit(handle)) + 1)
349          let writeMethodScope scope =
350 -            match scope with
351 -            | Some scope ->
352 -                let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
353 -                    if scope1.StartOffset > scope2.StartOffset then 1
354 -                    elif scope1.StartOffset < scope2.StartOffset then -1
355 -                    elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
356 -                    elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
357 -                    else 0
358 -
359 -                let collectScopes scope =
360 -                    let list = new List<PdbMethodScope>()
361 -                    let rec toList scope =
362 -                        list.Add scope
363 -                        scope.Children |> Seq.iter(fun s -> toList s)
364 -                    toList scope
365 -                    list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
366 -
367 -                collectScopes scope |> Seq.iter(fun s ->
368 -                                        if s.Children.Length = 0 then
369 -                                            metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
370 -                                                                   Unchecked.defaultof<ImportScopeHandle>,
371 -                                                                   nextHandle lastLocalVariableHandle,
372 -                                                                   Unchecked.defaultof<LocalConstantHandle>,
373 -                                                                   0, s.EndOffset - s.StartOffset ) |>ignore
374 -                                        else
375 -                                            metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
376 -                                                                   Unchecked.defaultof<ImportScopeHandle>,
377 -                                                                   nextHandle lastLocalVariableHandle,
378 -                                                                   Unchecked.defaultof<LocalConstantHandle>,
379 -                                                                   s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
380 -
381 -                                        for localVariable in s.Locals do
382 -                                            lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
383 -                                        )
384 -            | None -> ()
385 -        writeMethodScope minfo.RootScope )
386 +            let scopeSorter (scope1:PdbMethodScope) (scope2:PdbMethodScope) =
387 +                if scope1.StartOffset > scope2.StartOffset then 1
388 +                elif scope1.StartOffset < scope2.StartOffset then -1
389 +                elif (scope1.EndOffset - scope1.StartOffset) > (scope2.EndOffset - scope2.StartOffset) then -1
390 +                elif (scope1.EndOffset - scope1.StartOffset) < (scope2.EndOffset - scope2.StartOffset) then 1
391 +                else 0
392 +
393 +            let collectScopes scope =
394 +                let list = new List<PdbMethodScope>()
395 +                let rec toList scope =
396 +                    list.Add scope
397 +                    scope.Children |> Seq.iter(fun s -> toList s)
398 +                toList scope
399 +                list.ToArray() |> Array.sortWith<PdbMethodScope> scopeSorter
400 +
401 +            collectScopes scope |> Seq.iter(fun s ->
402 +                                    if s.Children.Length = 0 then
403 +                                        metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
404 +                                                               Unchecked.defaultof<ImportScopeHandle>,
405 +                                                               nextHandle lastLocalVariableHandle,
406 +                                                               Unchecked.defaultof<LocalConstantHandle>,
407 +                                                               0, s.EndOffset - s.StartOffset ) |>ignore
408 +                                    else
409 +                                        metadata.AddLocalScope(MetadataTokens.MethodDefinitionHandle(minfo.MethToken),
410 +                                                               Unchecked.defaultof<ImportScopeHandle>,
411 +                                                               nextHandle lastLocalVariableHandle,
412 +                                                               Unchecked.defaultof<LocalConstantHandle>,
413 +                                                               s.StartOffset, s.EndOffset - s.StartOffset) |>ignore
414 +
415 +                                    for localVariable in s.Locals do
416 +                                        lastLocalVariableHandle <- metadata.AddLocalVariable(LocalVariableAttributes.None, localVariable.Index, metadata.GetOrAddString(localVariable.Name))
417 +                                    )
418 +
419 +        match minfo.RootScope with
420 +        | None -> ()
421 +        | Some scope -> writeMethodScope scope )
422  
423      let entryPoint =
424          match info.EntryPoint with
425 @@ -557,16 +557,16 @@ let writePdbInfo showTimes f fpdb info cvChunk =
426  
427                // Write the scopes 
428                let rec writePdbScope parent sco = 
429 -                    if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
430 -                        // Only nest scopes if the child scope is a different size from 
431 -                        let nested =
432 -                            match parent with
433 -                            | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
434 -                            | None -> true
435 -                        if nested then pdbOpenScope !pdbw sco.StartOffset
436 -                        sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
437 -                        sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
438 -                        if nested then pdbCloseScope !pdbw sco.EndOffset
439 +                  if parent = None || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
440 +                      // Only nest scopes if the child scope is a different size from 
441 +                      let nested =
442 +                          match parent with
443 +                          | Some p -> sco.StartOffset <> p.StartOffset || sco.EndOffset <> p.EndOffset
444 +                          | None -> true
445 +                      if nested then pdbOpenScope !pdbw sco.StartOffset
446 +                      sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
447 +                      sco.Children |> Array.iter (writePdbScope (if nested then Some sco else parent))
448 +                      if nested then pdbCloseScope !pdbw sco.EndOffset
449  
450                match minfo.RootScope with
451                | None -> ()