@@ -16,6 +16,8 @@ open FSharp.Compiler.Text.Range
16
16
open FSharp.Compiler .TypedTree
17
17
open FSharp.Compiler .TypedTreeBasics
18
18
open FSharp.Compiler .Syntax .PrettyNaming
19
+ open FSharp.Compiler .TypedTreeOps
20
+ open FSharp.Compiler .TcGlobals
19
21
20
22
#nowarn " 9"
21
23
#nowarn " 51"
@@ -96,8 +98,82 @@ module ItemKeyTags =
96
98
[<Literal>]
97
99
let parameters = " p$p$"
98
100
101
+ [<AutoOpen>]
102
+ module DebugKeyStore =
103
+
104
+ /// A debugging tool to show what's being written into the ItemKeyStore in a more human readable way in the debugger.
105
+ type DebugKeyStore () =
106
+
107
+ let mutable debugCurrentItem = ResizeArray()
108
+
109
+ member val Items = ResizeArray()
110
+
111
+ member _.WriteRange ( m : range ) = debugCurrentItem.Add( " range" , $" {m}" )
112
+
113
+ member _.WriteEntityRef ( eref : EntityRef ) =
114
+ debugCurrentItem.Add( " EntityRef" , $" {eref}" )
115
+
116
+ member _.WriteILType ( ilTy : ILType ) =
117
+ debugCurrentItem.Add( " ILType" , $" %A {ilTy}" )
118
+
119
+ member _.WriteType isStandalone ( ty : TType ) =
120
+ debugCurrentItem.Add( " Type" , $" {isStandalone} %A {ty}" )
121
+
122
+ member _.WriteMeasure isStandalone ( ms : Measure ) =
123
+ debugCurrentItem.Add( " Measure" , $" {isStandalone} %A {ms}" )
124
+
125
+ member _.WriteTypar ( isStandalone : bool ) ( typar : Typar ) =
126
+ debugCurrentItem.Add( " Typar" , $" {isStandalone} %A {typar}" )
127
+
128
+ member _.WriteValRef ( vref : ValRef ) =
129
+ debugCurrentItem.Add( " ValRef" , $" {vref}" )
130
+
131
+ member _.WriteValue ( vref : ValRef ) =
132
+ debugCurrentItem.Add( " Value" , $" {vref}" )
133
+
134
+ member _.WriteActivePatternCase ( apInfo : ActivePatternInfo ) index =
135
+ debugCurrentItem.Add( " ActivePatternCase" , $" {apInfo} {index}" )
136
+
137
+ member this.FinishItem ( item , length ) =
138
+ debugCurrentItem.Add( " length" , $" {length}" )
139
+ this.Items.Add( item, debugCurrentItem)
140
+ let itemCount = this.Items.Count
141
+ assert ( itemCount > 0 )
142
+ debugCurrentItem <- ResizeArray()
143
+
144
+ member _.New () = DebugKeyStore()
145
+
146
+ /// A replacement for DebugKeyStore for when we're not debugging.
147
+ type _DebugKeyStoreNoop () =
148
+
149
+ member inline _.Items = Unchecked.defaultof<_>
150
+
151
+ member inline _.WriteRange ( _m : range ) = ()
152
+
153
+ member inline _.WriteEntityRef ( _eref : EntityRef ) = ()
154
+
155
+ member inline _.WriteILType ( _ilTy : ILType ) = ()
156
+
157
+ member inline _.WriteType _isStandalone ( _ty : TType ) = ()
158
+
159
+ member inline _.WriteMeasure _isStandalone ( _ms : Measure ) = ()
160
+
161
+ member inline _.WriteTypar ( _isStandalone : bool ) ( _typar : Typar ) = ()
162
+
163
+ member inline _.WriteValRef ( _vref : ValRef ) = ()
164
+
165
+ member inline _.WriteValue ( _vref : ValRef ) = ()
166
+
167
+ member inline _.WriteActivePatternCase ( _apInfo : ActivePatternInfo ) _index = ()
168
+
169
+ member inline _.FinishItem ( _item , _length ) = ()
170
+
171
+ member inline this.New () = this
172
+
173
+ let DebugKeyStoreNoop = _ DebugKeyStoreNoop ()
174
+
99
175
[<Sealed>]
100
- type ItemKeyStore ( mmf : MemoryMappedFile , length ) =
176
+ type ItemKeyStore ( mmf : MemoryMappedFile , length , tcGlobals , debugStore ) =
101
177
102
178
let rangeBuffer = Array.zeroCreate< byte> sizeof< range>
103
179
@@ -107,6 +183,8 @@ type ItemKeyStore(mmf: MemoryMappedFile, length) =
107
183
if isDisposed then
108
184
raise ( ObjectDisposedException( " ItemKeyStore" ))
109
185
186
+ member _.DebugStore = debugStore
187
+
110
188
member _.ReadRange ( reader : byref < BlobReader >) =
111
189
reader.ReadBytes( sizeof< range>, rangeBuffer, 0 )
112
190
MemoryMarshal.Cast< byte, range>( Span( rangeBuffer)).[ 0 ]
@@ -133,7 +211,7 @@ type ItemKeyStore(mmf: MemoryMappedFile, length) =
133
211
member this.FindAll ( item : Item ) =
134
212
checkDispose ()
135
213
136
- let builder = ItemKeyStoreBuilder()
214
+ let builder = ItemKeyStoreBuilder( tcGlobals )
137
215
builder.Write( range0, item)
138
216
139
217
match builder.TryBuildAndReset() with
@@ -166,10 +244,13 @@ type ItemKeyStore(mmf: MemoryMappedFile, length) =
166
244
isDisposed <- true
167
245
mmf.Dispose()
168
246
169
- and [<Sealed>] ItemKeyStoreBuilder () =
247
+ and [<Sealed>] ItemKeyStoreBuilder ( tcGlobals : TcGlobals ) =
170
248
171
249
let b = BlobBuilder()
172
250
251
+ // Change this to DebugKeyStore() for debugging (DebugStore will be available on ItemKeyStore)
252
+ let mutable debug = DebugKeyStoreNoop
253
+
173
254
let writeChar ( c : char ) = b.WriteUInt16( uint16 c)
174
255
175
256
let writeUInt16 ( i : uint16 ) = b.WriteUInt16 i
@@ -181,16 +262,20 @@ and [<Sealed>] ItemKeyStoreBuilder() =
181
262
let writeString ( str : string ) = b.WriteUTF16 str
182
263
183
264
let writeRange ( m : range ) =
265
+ debug.WriteRange m
184
266
let mutable m = m
185
267
let ptr = && m |> NativePtr.toNativeInt |> NativePtr.ofNativeInt< byte>
186
268
b.WriteBytes( ptr, sizeof< range>)
187
269
188
270
let writeEntityRef ( eref : EntityRef ) =
271
+ debug.WriteEntityRef eref
189
272
writeString ItemKeyTags.entityRef
190
273
writeString eref.CompiledName
191
274
eref.CompilationPath.MangledPath |> List.iter ( fun str -> writeString str)
192
275
193
276
let rec writeILType ( ilTy : ILType ) =
277
+ debug.WriteILType ilTy
278
+
194
279
match ilTy with
195
280
| ILType.TypeVar n ->
196
281
writeString " !"
@@ -231,6 +316,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
231
316
writeILType mref.ReturnType
232
317
233
318
let rec writeType isStandalone ( ty : TType ) =
319
+ debug.WriteType isStandalone ty
320
+
234
321
match stripTyparEqns ty with
235
322
| TType_ forall (_, ty) -> writeType false ty
236
323
@@ -268,6 +355,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
268
355
writeString nm
269
356
270
357
and writeMeasure isStandalone ( ms : Measure ) =
358
+ debug.WriteMeasure isStandalone ms
359
+
271
360
match ms with
272
361
| Measure.Var typar ->
273
362
writeString ItemKeyTags.typeMeasureVar
@@ -278,20 +367,38 @@ and [<Sealed>] ItemKeyStoreBuilder() =
278
367
| _ -> ()
279
368
280
369
and writeTypar ( isStandalone : bool ) ( typar : Typar ) =
370
+ debug.WriteTypar isStandalone typar
371
+
281
372
match typar.Solution with
282
373
| Some ty -> writeType isStandalone ty
283
374
| _ ->
284
375
if isStandalone then
285
376
writeInt64 typar.Stamp
286
377
287
378
let writeValRef ( vref : ValRef ) =
379
+ debug.WriteValRef vref
380
+
288
381
match vref.MemberInfo with
289
382
| Some memberInfo ->
290
383
writeString ItemKeyTags.itemValueMember
291
- writeEntityRef memberInfo.ApparentEnclosingEntity
384
+
385
+ match vref.IsOverrideOrExplicitImpl, vref.MemberInfo with
386
+ | true ,
387
+ Some {
388
+ ImplementedSlotSigs = slotSig :: _ tail
389
+ } -> slotSig.DeclaringType |> writeType false
390
+ | _ -> writeEntityRef memberInfo.ApparentEnclosingEntity
391
+
292
392
writeString vref.LogicalName
293
393
writeString ItemKeyTags.parameters
294
- writeType false vref.Type
394
+
395
+ match vref.IsInstanceMember, tryDestFunTy tcGlobals vref.Type with
396
+ // In case of an instance member, we will skip the type of "this" because it will differ
397
+ // between the definition and overrides. Also it's not needed to uniquely identify the reference.
398
+ | true , ValueSome (_ thisTy, funTy) -> funTy
399
+ | _ -> vref.Type
400
+ |> writeType false
401
+
295
402
| _ ->
296
403
writeString ItemKeyTags.itemValue
297
404
writeString vref.LogicalName
@@ -307,6 +414,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
307
414
| Parent eref -> writeEntityRef eref
308
415
309
416
let writeValue ( vref : ValRef ) =
417
+ debug.WriteValue vref
418
+
310
419
if vref.IsPropertyGetterMethod || vref.IsPropertySetterMethod then
311
420
writeString ItemKeyTags.itemProperty
312
421
writeString vref.PropertyName
@@ -322,6 +431,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
322
431
writeValRef vref
323
432
324
433
let writeActivePatternCase ( apInfo : ActivePatternInfo ) index =
434
+ debug.WriteActivePatternCase apInfo index
435
+
325
436
writeString ItemKeyTags.itemActivePattern
326
437
327
438
match apInfo.ActiveTagsWithRanges with
@@ -474,6 +585,7 @@ and [<Sealed>] ItemKeyStoreBuilder() =
474
585
let postCount = b.Count
475
586
476
587
fixup.WriteInt32( postCount - preCount)
588
+ debug.FinishItem( item, postCount - preCount)
477
589
478
590
member _.TryBuildAndReset () =
479
591
if b.Count > 0 then
@@ -495,7 +607,10 @@ and [<Sealed>] ItemKeyStoreBuilder() =
495
607
496
608
b.Clear()
497
609
498
- Some( new ItemKeyStore( mmf, length))
610
+ let result = Some( new ItemKeyStore( mmf, length, tcGlobals, debug.Items))
611
+ debug <- debug.New()
612
+ result
499
613
else
500
614
b.Clear()
615
+ debug <- debug.New()
501
616
None
0 commit comments