-
Notifications
You must be signed in to change notification settings - Fork 789
/
infos.fs
executable file
·2612 lines (2220 loc) · 122 KB
/
infos.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
module internal FSharp.Compiler.Infos
open System
open FSharp.Compiler
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.Internal.Library
open FSharp.Compiler.ErrorLogger
open FSharp.Compiler.Lib
open FSharp.Compiler.Range
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.SyntaxTreeOps
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeBasics
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.TypedTreeOps.DebugPrint
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.XmlDoc
#if !NO_EXTENSIONTYPING
open FSharp.Compiler.ExtensionTyping
#endif
//-------------------------------------------------------------------------
// From IL types to F# types
//-------------------------------------------------------------------------
/// Import an IL type as an F# type. importInst gives the context for interpreting type variables.
let ImportILType scoref amap m importInst ilty =
ilty |> rescopeILType scoref |> Import.ImportILType amap m importInst
let CanImportILType scoref amap m ilty =
ilty |> rescopeILType scoref |> Import.CanImportILType amap m
//-------------------------------------------------------------------------
// Fold the hierarchy.
// REVIEW: this code generalizes the iteration used below for member lookup.
//-------------------------------------------------------------------------
/// Indicates if an F# type is the type associated with an F# exception declaration
let isExnDeclTy g ty =
match tryTcrefOfAppTy g ty with
| ValueSome tcref -> tcref.IsExceptionDecl
| _ -> false
/// Get the base type of a type, taking into account type instantiations. Return None if the
/// type has no base type.
let GetSuperTypeOfType g amap m ty =
#if !NO_EXTENSIONTYPING
let ty =
match tryTcrefOfAppTy g ty with
| ValueSome tcref when tcref.IsProvided -> stripTyEqns g ty
| _ -> stripTyEqnsAndMeasureEqns g ty
#else
let ty = stripTyEqnsAndMeasureEqns g ty
#endif
match metadataOfTy g ty with
#if !NO_EXTENSIONTYPING
| ProvidedTypeMetadata info ->
let st = info.ProvidedType
let superOpt = st.PApplyOption((fun st -> match st.BaseType with null -> None | t -> Some t), m)
match superOpt with
| None -> None
| Some super -> Some(Import.ImportProvidedType amap m super)
#endif
| ILTypeMetadata (TILObjectReprData(scoref, _, tdef)) ->
let tinst = argsOfAppTy g ty
match tdef.Extends with
| None -> None
| Some ilty -> Some (ImportILType scoref amap m tinst ilty)
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
if isFSharpObjModelTy g ty || isExnDeclTy g ty then
let tcref = tcrefOfAppTy g ty
Some (instType (mkInstForAppTy g ty) (superOfTycon g tcref.Deref))
elif isArrayTy g ty then
Some g.system_Array_ty
elif isRefTy g ty && not (isObjTy g ty) then
Some g.obj_ty
elif isStructTupleTy g ty then
Some g.system_Value_ty
elif isFSharpStructOrEnumTy g ty then
if isFSharpEnumTy g ty then
Some g.system_Enum_ty
else
Some g.system_Value_ty
elif isStructAnonRecdTy g ty then
Some g.system_Value_ty
elif isAnonRecdTy g ty then
Some g.obj_ty
elif isRecdTy g ty || isUnionTy g ty then
Some g.obj_ty
else
None
/// Make a type for System.Collections.Generic.IList<ty>
let mkSystemCollectionsGenericIListTy (g: TcGlobals) ty = TType_app(g.tcref_System_Collections_Generic_IList, [ty])
[<RequireQualifiedAccess>]
/// Indicates whether we can skip interface types that lie outside the reference set
type SkipUnrefInterfaces = Yes | No
/// Collect the set of immediate declared interface types for an F# type, but do not
/// traverse the type hierarchy to collect further interfaces.
let rec GetImmediateInterfacesOfType skipUnref g amap m ty =
let itys =
match tryAppTy g ty with
| ValueSome(tcref, tinst) ->
if tcref.IsMeasureableReprTycon then
[ match tcref.TypeReprInfo with
| TMeasureableRepr reprTy ->
for ity in GetImmediateInterfacesOfType skipUnref g amap m reprTy do
match tryTcrefOfAppTy g ity with
| ValueNone -> ()
| ValueSome itcref ->
if not (tyconRefEq g itcref g.system_GenericIComparable_tcref) &&
not (tyconRefEq g itcref g.system_GenericIEquatable_tcref) then
yield ity
| _ -> ()
yield mkAppTy g.system_GenericIComparable_tcref [ty]
yield mkAppTy g.system_GenericIEquatable_tcref [ty]]
else
match metadataOfTy g ty with
#if !NO_EXTENSIONTYPING
| ProvidedTypeMetadata info ->
[ for ity in info.ProvidedType.PApplyArray((fun st -> st.GetInterfaces()), "GetInterfaces", m) do
yield Import.ImportProvidedType amap m ity ]
#endif
| ILTypeMetadata (TILObjectReprData(scoref, _, tdef)) ->
// ImportILType may fail for an interface if the assembly load set is incomplete and the interface
// comes from another assembly. In this case we simply skip the interface:
// if we don't skip it, then compilation will just fail here, and if type checking
// succeeds with fewer non-dereferencable interfaces reported then it would have
// succeeded with more reported. There are pathological corner cases where this
// doesn't apply: e.g. for mscorlib interfaces like IComparable, but we can always
// assume those are present.
tdef.Implements |> List.choose (fun ity ->
if skipUnref = SkipUnrefInterfaces.No || CanImportILType scoref amap m ity then
Some (ImportILType scoref amap m tinst ity)
else None)
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
tcref.ImmediateInterfaceTypesOfFSharpTycon |> List.map (instType (mkInstForAppTy g ty))
| _ -> []
// NOTE: Anonymous record types are not directly considered to implement IComparable,
// IComparable<T> or IEquatable<T>. This is because whether they support these interfaces depend on their
// consitutent types, which may not yet be known in type inference.
//
// NOTE: Tuples could in theory always support IComparable etc. because this
// is in the .NET metadata for System.Tuple etc. However from the F# perspective tuple types don't
// always support the 'comparable' and 'equality' constraints (again, it depends on their constitutent types).
// .NET array types are considered to implement IList<T>
let itys =
if isArray1DTy g ty then
mkSystemCollectionsGenericIListTy g (destArrayTy g ty) :: itys
else
itys
itys
[<RequireQualifiedAccess>]
/// Indicates whether we should visit multiple instantiations of the same generic interface or not
type AllowMultiIntfInstantiations = Yes | No
/// Traverse the type hierarchy, e.g. f D (f C (f System.Object acc)).
/// Visit base types and interfaces first.
let private FoldHierarchyOfTypeAux followInterfaces allowMultiIntfInst skipUnref visitor g amap m ty acc =
let rec loop ndeep ty ((visitedTycon, visited: TyconRefMultiMap<_>, acc) as state) =
let seenThisTycon =
match tryTcrefOfAppTy g ty with
| ValueSome tcref -> Set.contains tcref.Stamp visitedTycon
| _ -> false
// Do not visit the same type twice. Could only be doing this if we've seen this tycon
if seenThisTycon && List.exists (typeEquiv g ty) (visited.Find (tcrefOfAppTy g ty)) then state else
// Do not visit the same tycon twice, e.g. I<int> and I<string>, collect I<int> only, unless directed to allow this
if seenThisTycon && allowMultiIntfInst = AllowMultiIntfInstantiations.No then state else
let state =
match tryTcrefOfAppTy g ty with
| ValueSome tcref ->
let visitedTycon = Set.add tcref.Stamp visitedTycon
visitedTycon, visited.Add (tcref, ty), acc
| _ ->
state
if ndeep > 100 then (errorR(Error((FSComp.SR.recursiveClassHierarchy (showType ty)), m)); (visitedTycon, visited, acc)) else
let visitedTycon, visited, acc =
if isInterfaceTy g ty then
List.foldBack
(loop (ndeep+1))
(GetImmediateInterfacesOfType skipUnref g amap m ty)
(loop ndeep g.obj_ty state)
else
match tryDestTyparTy g ty with
| ValueSome tp ->
let state = loop (ndeep+1) g.obj_ty state
List.foldBack
(fun x vacc ->
match x with
| TyparConstraint.MayResolveMember _
| TyparConstraint.DefaultsTo _
| TyparConstraint.SupportsComparison _
| TyparConstraint.SupportsEquality _
| TyparConstraint.IsEnum _
| TyparConstraint.IsDelegate _
| TyparConstraint.SupportsNull _
| TyparConstraint.IsNonNullableStruct _
| TyparConstraint.IsUnmanaged _
| TyparConstraint.IsReferenceType _
| TyparConstraint.SimpleChoice _
| TyparConstraint.RequiresDefaultConstructor _ -> vacc
| TyparConstraint.CoercesTo(cty, _) ->
loop (ndeep + 1) cty vacc)
tp.Constraints
state
| _ ->
let state =
if followInterfaces then
List.foldBack
(loop (ndeep+1))
(GetImmediateInterfacesOfType skipUnref g amap m ty)
state
else
state
let state =
Option.foldBack
(loop (ndeep+1))
(GetSuperTypeOfType g amap m ty)
state
state
let acc = visitor ty acc
(visitedTycon, visited, acc)
loop 0 ty (Set.empty, TyconRefMultiMap<_>.Empty, acc) |> p33
/// Fold, do not follow interfaces (unless the type is itself an interface)
let FoldPrimaryHierarchyOfType f g amap m allowMultiIntfInst ty acc =
FoldHierarchyOfTypeAux false allowMultiIntfInst SkipUnrefInterfaces.No f g amap m ty acc
/// Fold, following interfaces. Skipping interfaces that lie outside the referenced assembly set is allowed.
let FoldEntireHierarchyOfType f g amap m allowMultiIntfInst ty acc =
FoldHierarchyOfTypeAux true allowMultiIntfInst SkipUnrefInterfaces.Yes f g amap m ty acc
/// Iterate, following interfaces. Skipping interfaces that lie outside the referenced assembly set is allowed.
let IterateEntireHierarchyOfType f g amap m allowMultiIntfInst ty =
FoldHierarchyOfTypeAux true allowMultiIntfInst SkipUnrefInterfaces.Yes (fun ty () -> f ty) g amap m ty ()
/// Search for one element satisfying a predicate, following interfaces
let ExistsInEntireHierarchyOfType f g amap m allowMultiIntfInst ty =
FoldHierarchyOfTypeAux true allowMultiIntfInst SkipUnrefInterfaces.Yes (fun ty acc -> acc || f ty ) g amap m ty false
/// Search for one element where a function returns a 'Some' result, following interfaces
let SearchEntireHierarchyOfType f g amap m ty =
FoldHierarchyOfTypeAux true AllowMultiIntfInstantiations.Yes SkipUnrefInterfaces.Yes
(fun ty acc ->
match acc with
| None -> if f ty then Some ty else None
| Some _ -> acc)
g amap m ty None
/// Get all super types of the type, including the type itself
let AllSuperTypesOfType g amap m allowMultiIntfInst ty =
FoldHierarchyOfTypeAux true allowMultiIntfInst SkipUnrefInterfaces.No (ListSet.insert (typeEquiv g)) g amap m ty []
/// Get all interfaces of a type, including the type itself if it is an interface
let AllInterfacesOfType g amap m allowMultiIntfInst ty =
AllSuperTypesOfType g amap m allowMultiIntfInst ty |> List.filter (isInterfaceTy g)
/// Check if two types have the same nominal head type
let HaveSameHeadType g ty1 ty2 =
match tryTcrefOfAppTy g ty1 with
| ValueSome tcref1 ->
match tryTcrefOfAppTy g ty2 with
| ValueSome tcref2 -> tyconRefEq g tcref1 tcref2
| _ -> false
| _ -> false
/// Check if a type has a particular head type
let HasHeadType g tcref ty2 =
match tryTcrefOfAppTy g ty2 with
| ValueSome tcref2 -> tyconRefEq g tcref tcref2
| ValueNone -> false
/// Check if a type exists somewhere in the hierarchy which has the same head type as the given type (note, the given type need not have a head type at all)
let ExistsSameHeadTypeInHierarchy g amap m typeToSearchFrom typeToLookFor =
ExistsInEntireHierarchyOfType (HaveSameHeadType g typeToLookFor) g amap m AllowMultiIntfInstantiations.Yes typeToSearchFrom
/// Check if a type exists somewhere in the hierarchy which has the given head type.
let ExistsHeadTypeInEntireHierarchy g amap m typeToSearchFrom tcrefToLookFor =
ExistsInEntireHierarchyOfType (HasHeadType g tcrefToLookFor) g amap m AllowMultiIntfInstantiations.Yes typeToSearchFrom
/// Read an Abstract IL type from metadata and convert to an F# type.
let ImportILTypeFromMetadata amap m scoref tinst minst ilty =
ImportILType scoref amap m (tinst@minst) ilty
/// Read an Abstract IL type from metadata, including any attributes that may affect the type itself, and convert to an F# type.
let ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst ilty cattrs =
let ty = ImportILType scoref amap m (tinst@minst) ilty
// If the type is a byref and one of attributes from a return or parameter has IsReadOnly, then it's a inref.
if isByrefTy amap.g ty && TryFindILAttribute amap.g.attrib_IsReadOnlyAttribute cattrs then
mkInByrefTy amap.g (destByrefTy amap.g ty)
else
ty
/// Get the parameter type of an IL method.
let ImportParameterTypeFromMetadata amap m ilty cattrs scoref tinst mist =
ImportILTypeFromMetadataWithAttributes amap m scoref tinst mist ilty cattrs
/// Get the return type of an IL method, taking into account instantiations for type, return attributes and method generic parameters, and
/// translating 'void' to 'None'.
let ImportReturnTypeFromMetadata amap m ilty cattrs scoref tinst minst =
match ilty with
| ILType.Void -> None
| retTy -> Some(ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst retTy cattrs)
/// Copy constraints. If the constraint comes from a type parameter associated
/// with a type constructor then we are simply renaming type variables. If it comes
/// from a generic method in a generic class (e.g. ty.M<_>) then we may be both substituting the
/// instantiation associated with 'ty' as well as copying the type parameters associated with
/// M and instantiating their constraints
///
/// Note: this now looks identical to constraint instantiation.
let CopyTyparConstraints m tprefInst (tporig: Typar) =
tporig.Constraints
|> List.map (fun tpc ->
match tpc with
| TyparConstraint.CoercesTo(ty, _) ->
TyparConstraint.CoercesTo (instType tprefInst ty, m)
| TyparConstraint.DefaultsTo(priority, ty, _) ->
TyparConstraint.DefaultsTo (priority, instType tprefInst ty, m)
| TyparConstraint.SupportsNull _ ->
TyparConstraint.SupportsNull m
| TyparConstraint.IsEnum (uty, _) ->
TyparConstraint.IsEnum (instType tprefInst uty, m)
| TyparConstraint.SupportsComparison _ ->
TyparConstraint.SupportsComparison m
| TyparConstraint.SupportsEquality _ ->
TyparConstraint.SupportsEquality m
| TyparConstraint.IsDelegate(aty, bty, _) ->
TyparConstraint.IsDelegate (instType tprefInst aty, instType tprefInst bty, m)
| TyparConstraint.IsNonNullableStruct _ ->
TyparConstraint.IsNonNullableStruct m
| TyparConstraint.IsUnmanaged _ ->
TyparConstraint.IsUnmanaged m
| TyparConstraint.IsReferenceType _ ->
TyparConstraint.IsReferenceType m
| TyparConstraint.SimpleChoice (tys, _) ->
TyparConstraint.SimpleChoice (List.map (instType tprefInst) tys, m)
| TyparConstraint.RequiresDefaultConstructor _ ->
TyparConstraint.RequiresDefaultConstructor m
| TyparConstraint.MayResolveMember(traitInfo, _) ->
TyparConstraint.MayResolveMember (instTrait tprefInst traitInfo, m))
/// The constraints for each typar copied from another typar can only be fixed up once
/// we have generated all the new constraints, e.g. f<A :> List<B>, B :> List<A>> ...
let FixupNewTypars m (formalEnclosingTypars: Typars) (tinst: TType list) (tpsorig: Typars) (tps: Typars) =
// Checks.. These are defensive programming against early reported errors.
let n0 = formalEnclosingTypars.Length
let n1 = tinst.Length
let n2 = tpsorig.Length
let n3 = tps.Length
if n0 <> n1 then error(Error((FSComp.SR.tcInvalidTypeArgumentCount(n0, n1)), m))
if n2 <> n3 then error(Error((FSComp.SR.tcInvalidTypeArgumentCount(n2, n3)), m))
// The real code..
let renaming, tptys = mkTyparToTyparRenaming tpsorig tps
let tprefInst = mkTyparInst formalEnclosingTypars tinst @ renaming
(tpsorig, tps) ||> List.iter2 (fun tporig tp -> tp.SetConstraints (CopyTyparConstraints m tprefInst tporig))
renaming, tptys
//-------------------------------------------------------------------------
// Predicates and properties on values and members
type ValRef with
/// Indicates if an F#-declared function or member value is a CLIEvent property compiled as a .NET event
member x.IsFSharpEventProperty g =
x.IsMember && CompileAsEvent g x.Attribs && not x.IsExtensionMember
/// Check if an F#-declared member value is a virtual method
member vref.IsVirtualMember =
let flags = vref.MemberInfo.Value.MemberFlags
flags.IsDispatchSlot || flags.IsOverrideOrExplicitImpl
/// Check if an F#-declared member value is a dispatch slot
member vref.IsDispatchSlotMember =
let membInfo = vref.MemberInfo.Value
membInfo.MemberFlags.IsDispatchSlot
/// Check if an F#-declared member value is an 'override' or explicit member implementation
member vref.IsDefiniteFSharpOverrideMember =
let membInfo = vref.MemberInfo.Value
let flags = membInfo.MemberFlags
not flags.IsDispatchSlot && (flags.IsOverrideOrExplicitImpl || not (isNil membInfo.ImplementedSlotSigs))
/// Check if an F#-declared member value is an explicit interface member implementation
member vref.IsFSharpExplicitInterfaceImplementation g =
match vref.MemberInfo with
| None -> false
| Some membInfo ->
not membInfo.MemberFlags.IsDispatchSlot &&
(match membInfo.ImplementedSlotSigs with
| TSlotSig(_, oty, _, _, _, _) :: _ -> isInterfaceTy g oty
| [] -> false)
member vref.ImplementedSlotSignatures =
match vref.MemberInfo with
| None -> []
| Some membInfo -> membInfo.ImplementedSlotSigs
//-------------------------------------------------------------------------
// Helper methods associated with using TAST metadata (F# members, values etc.)
// as backing data for MethInfo, PropInfo etc.
#if !NO_EXTENSIONTYPING
/// Get the return type of a provided method, where 'void' is returned as 'None'
let GetCompiledReturnTyOfProvidedMethodInfo amap m (mi: Tainted<ProvidedMethodBase>) =
let returnType =
if mi.PUntaint((fun mi -> mi.IsConstructor), m) then
mi.PApply((fun mi -> mi.DeclaringType), m)
else mi.Coerce<ProvidedMethodInfo>(m).PApply((fun mi -> mi.ReturnType), m)
let ty = Import.ImportProvidedType amap m returnType
if isVoidTy amap.g ty then None else Some ty
#endif
/// The slotsig returned by methInfo.GetSlotSig is in terms of the type parameters on the parent type of the overriding method.
/// Reverse-map the slotsig so it is in terms of the type parameters for the overriding method
let ReparentSlotSigToUseMethodTypars g m ovByMethValRef slotsig =
match PartitionValRefTypars g ovByMethValRef with
| Some(_, enclosingTypars, _, _, _) ->
let parentToMemberInst, _ = mkTyparToTyparRenaming (ovByMethValRef.MemberApparentEntity.Typars m) enclosingTypars
let res = instSlotSig parentToMemberInst slotsig
res
| None ->
// Note: it appears PartitionValRefTypars should never return 'None'
slotsig
/// Construct the data representing a parameter in the signature of an abstract method slot
let MakeSlotParam (ty, argInfo: ArgReprInfo) = TSlotParam(Option.map textOfId argInfo.Name, ty, false, false, false, argInfo.Attribs)
/// Construct the data representing the signature of an abstract method slot
let MakeSlotSig (nm, ty, ctps, mtps, paraml, retTy) = copySlotSig (TSlotSig(nm, ty, ctps, mtps, paraml, retTy))
/// Split the type of an F# member value into
/// - the type parameters associated with method but matching those of the enclosing type
/// - the type parameters associated with a generic method
/// - the return type of the method
/// - the actual type arguments of the enclosing type.
let private AnalyzeTypeOfMemberVal isCSharpExt g (ty, vref: ValRef) =
let memberAllTypars, _, _, retTy, _ = GetTypeOfMemberInMemberForm g vref
if isCSharpExt || vref.IsExtensionMember then
[], memberAllTypars, retTy, []
else
let parentTyArgs = argsOfAppTy g ty
let memberParentTypars, memberMethodTypars = List.splitAt parentTyArgs.Length memberAllTypars
memberParentTypars, memberMethodTypars, retTy, parentTyArgs
/// Get the object type for a member value which is an extension method (C#-style or F#-style)
let private GetObjTypeOfInstanceExtensionMethod g (vref: ValRef) =
let numEnclosingTypars = CountEnclosingTyparsOfActualParentOfVal vref.Deref
let _, _, curriedArgInfos, _, _ = GetTopValTypeInCompiledForm g vref.ValReprInfo.Value numEnclosingTypars vref.Type vref.Range
curriedArgInfos.Head.Head |> fst
/// Get the object type for a member value, which might be a C#-style extension method
let private GetArgInfosOfMember isCSharpExt g (vref: ValRef) =
if isCSharpExt then
let numEnclosingTypars = CountEnclosingTyparsOfActualParentOfVal vref.Deref
let _, _, curriedArgInfos, _, _ = GetTopValTypeInCompiledForm g vref.ValReprInfo.Value numEnclosingTypars vref.Type vref.Range
[ curriedArgInfos.Head.Tail ]
else
ArgInfosOfMember g vref
/// Combine the type instantiation and generic method instantiation
let private CombineMethInsts ttps mtps tinst minst = (mkTyparInst ttps tinst @ mkTyparInst mtps minst)
/// Work out the instantiation relevant to interpret the backing metadata for a member.
///
/// The 'methTyArgs' is the instantiation of any generic method type parameters (this instantiation is
/// not included in the MethInfo objects, but carried separately).
let private GetInstantiationForMemberVal g isCSharpExt (ty, vref, methTyArgs: TypeInst) =
let memberParentTypars, memberMethodTypars, _retTy, parentTyArgs = AnalyzeTypeOfMemberVal isCSharpExt g (ty, vref)
/// In some recursive inference cases involving constraints this may need to be
/// fixed up - we allow uniform generic recursion but nothing else.
/// See https://github.com/Microsoft/visualfsharp/issues/3038#issuecomment-309429410
let methTyArgsFixedUp =
if methTyArgs.Length < memberMethodTypars.Length then
methTyArgs @ (List.skip methTyArgs.Length memberMethodTypars |> generalizeTypars)
else
methTyArgs
CombineMethInsts memberParentTypars memberMethodTypars parentTyArgs methTyArgsFixedUp
/// Work out the instantiation relevant to interpret the backing metadata for a property.
let private GetInstantiationForPropertyVal g (ty, vref) =
let memberParentTypars, memberMethodTypars, _retTy, parentTyArgs = AnalyzeTypeOfMemberVal false g (ty, vref)
CombineMethInsts memberParentTypars memberMethodTypars parentTyArgs (generalizeTypars memberMethodTypars)
/// Describes the sequence order of the introduction of an extension method. Extension methods that are introduced
/// later through 'open' get priority in overload resolution.
type ExtensionMethodPriority = uint64
//-------------------------------------------------------------------------
// OptionalArgCallerSideValue, OptionalArgInfo
/// The caller-side value for the optional arg, if any
type OptionalArgCallerSideValue =
| Constant of IL.ILFieldInit
| DefaultValue
| MissingValue
| WrapperForIDispatch
| WrapperForIUnknown
| PassByRef of TType * OptionalArgCallerSideValue
/// Represents information about a parameter indicating if it is optional.
type OptionalArgInfo =
/// The argument is not optional
| NotOptional
/// The argument is optional, and is an F# callee-side optional arg
| CalleeSide
/// The argument is optional, and is a caller-side .NET optional or default arg.
/// Note this is correctly termed caller side, even though the default value is optically specified on the callee:
/// in fact the default value is read from the metadata and passed explicitly to the callee on the caller side.
| CallerSide of OptionalArgCallerSideValue
member x.IsOptional = match x with CalleeSide | CallerSide _ -> true | NotOptional -> false
/// Compute the OptionalArgInfo for an IL parameter
///
/// This includes the Visual Basic rules for IDispatchConstant and IUnknownConstant and optional arguments.
static member FromILParameter g amap m ilScope ilTypeInst (ilParam: ILParameter) =
if ilParam.IsOptional then
match ilParam.Default with
| None ->
// Do a type-directed analysis of the IL type to determine the default value to pass.
// The same rules as Visual Basic are applied here.
let rec analyze ty =
if isByrefTy g ty then
let ty = destByrefTy g ty
PassByRef (ty, analyze ty)
elif isObjTy g ty then
match ilParam.Marshal with
| Some(ILNativeType.IUnknown | ILNativeType.IDispatch | ILNativeType.Interface) -> Constant ILFieldInit.Null
| _ ->
if TryFindILAttributeOpt g.attrib_IUnknownConstantAttribute ilParam.CustomAttrs then WrapperForIUnknown
elif TryFindILAttributeOpt g.attrib_IDispatchConstantAttribute ilParam.CustomAttrs then WrapperForIDispatch
else MissingValue
else
DefaultValue
CallerSide (analyze (ImportILTypeFromMetadata amap m ilScope ilTypeInst [] ilParam.Type))
| Some v ->
CallerSide (Constant v)
else
NotOptional
static member ValueOfDefaultParameterValueAttrib (Attrib (_, _, exprs, _, _, _, _)) =
let (AttribExpr (_, defaultValueExpr)) = List.head exprs
match defaultValueExpr with
| Expr.Const (_, _, _) -> Some defaultValueExpr
| _ -> None
static member FieldInitForDefaultParameterValueAttrib attrib =
match OptionalArgInfo.ValueOfDefaultParameterValueAttrib attrib with
| Some (Expr.Const (ConstToILFieldInit fi, _, _)) -> Some fi
| _ -> None
type CallerInfo =
| NoCallerInfo
| CallerLineNumber
| CallerMemberName
| CallerFilePath
override x.ToString() = sprintf "%+A" x
[<RequireQualifiedAccess>]
type ReflectedArgInfo =
| None
| Quote of bool
member x.AutoQuote = match x with None -> false | Quote _ -> true
//-------------------------------------------------------------------------
// ParamNameAndType, ParamData
[<NoComparison; NoEquality>]
/// Partial information about a parameter returned for use by the Language Service
type ParamNameAndType =
| ParamNameAndType of Ident option * TType
static member FromArgInfo (ty, argInfo : ArgReprInfo) = ParamNameAndType(argInfo.Name, ty)
static member FromMember isCSharpExtMem g vref = GetArgInfosOfMember isCSharpExtMem g vref |> List.mapSquared ParamNameAndType.FromArgInfo
static member Instantiate inst p = let (ParamNameAndType(nm, ty)) = p in ParamNameAndType(nm, instType inst ty)
static member InstantiateCurried inst paramTypes = paramTypes |> List.mapSquared (ParamNameAndType.Instantiate inst)
[<NoComparison; NoEquality>]
/// Full information about a parameter returned for use by the type checker and language service.
type ParamData =
ParamData of isParamArray: bool * isInArg: bool * isOut: bool * optArgInfo: OptionalArgInfo * callerInfo: CallerInfo * nameOpt: Ident option * reflArgInfo: ReflectedArgInfo * ttype: TType
//-------------------------------------------------------------------------
// Helper methods associated with type providers
#if !NO_EXTENSIONTYPING
type ILFieldInit with
/// Compute the ILFieldInit for the given provided constant value for a provided enum type.
static member FromProvidedObj m (v: obj) =
match v with
| null -> ILFieldInit.Null
| _ ->
let objTy = v.GetType()
let v = if objTy.IsEnum then objTy.GetField("value__").GetValue v else v
match v with
| :? single as i -> ILFieldInit.Single i
| :? double as i -> ILFieldInit.Double i
| :? bool as i -> ILFieldInit.Bool i
| :? char as i -> ILFieldInit.Char (uint16 i)
| :? string as i -> ILFieldInit.String i
| :? sbyte as i -> ILFieldInit.Int8 i
| :? byte as i -> ILFieldInit.UInt8 i
| :? int16 as i -> ILFieldInit.Int16 i
| :? uint16 as i -> ILFieldInit.UInt16 i
| :? int as i -> ILFieldInit.Int32 i
| :? uint32 as i -> ILFieldInit.UInt32 i
| :? int64 as i -> ILFieldInit.Int64 i
| :? uint64 as i -> ILFieldInit.UInt64 i
| _ -> error(Error(FSComp.SR.infosInvalidProvidedLiteralValue(try v.ToString() with _ -> "?"), m))
/// Compute the OptionalArgInfo for a provided parameter.
///
/// This is the same logic as OptionalArgInfoOfILParameter except we do not apply the
/// Visual Basic rules for IDispatchConstant and IUnknownConstant to optional
/// provided parameters.
let OptionalArgInfoOfProvidedParameter (amap: Import.ImportMap) m (provParam : Tainted<ProvidedParameterInfo>) =
let g = amap.g
if provParam.PUntaint((fun p -> p.IsOptional), m) then
match provParam.PUntaint((fun p -> p.HasDefaultValue), m) with
| false ->
// Do a type-directed analysis of the IL type to determine the default value to pass.
let rec analyze ty =
if isByrefTy g ty then
let ty = destByrefTy g ty
PassByRef (ty, analyze ty)
elif isObjTy g ty then MissingValue
else DefaultValue
let pty = Import.ImportProvidedType amap m (provParam.PApply((fun p -> p.ParameterType), m))
CallerSide (analyze pty)
| _ ->
let v = provParam.PUntaint((fun p -> p.RawDefaultValue), m)
CallerSide (Constant (ILFieldInit.FromProvidedObj m v))
else
NotOptional
/// Compute the ILFieldInit for the given provided constant value for a provided enum type.
let GetAndSanityCheckProviderMethod m (mi: Tainted<'T :> ProvidedMemberInfo>) (get : 'T -> ProvidedMethodInfo) err =
match mi.PApply((fun mi -> (get mi :> ProvidedMethodBase)), m) with
| Tainted.Null -> error(Error(err(mi.PUntaint((fun mi -> mi.Name), m), mi.PUntaint((fun mi -> mi.DeclaringType.Name), m)), m))
| meth -> meth
/// Try to get an arbitrary ProvidedMethodInfo associated with a property.
let ArbitraryMethodInfoOfPropertyInfo (pi: Tainted<ProvidedPropertyInfo>) m =
if pi.PUntaint((fun pi -> pi.CanRead), m) then
GetAndSanityCheckProviderMethod m pi (fun pi -> pi.GetGetMethod()) FSComp.SR.etPropertyCanReadButHasNoGetter
elif pi.PUntaint((fun pi -> pi.CanWrite), m) then
GetAndSanityCheckProviderMethod m pi (fun pi -> pi.GetSetMethod()) FSComp.SR.etPropertyCanWriteButHasNoSetter
else
error(Error(FSComp.SR.etPropertyNeedsCanWriteOrCanRead(pi.PUntaint((fun mi -> mi.Name), m), pi.PUntaint((fun mi -> mi.DeclaringType.Name), m)), m))
#endif
//-------------------------------------------------------------------------
// ILTypeInfo
/// Describes an F# use of an IL type, including the type instantiation associated with the type at a particular usage point.
///
/// This is really just 1:1 with the subset ot TType which result from building types using IL type definitions.
[<NoComparison; NoEquality>]
type ILTypeInfo =
/// ILTypeInfo (tyconRef, ilTypeRef, typeArgs, ilTypeDef).
| ILTypeInfo of TcGlobals * TType * ILTypeRef * ILTypeDef
member x.TcGlobals = let (ILTypeInfo(g, _, _, _)) = x in g
member x.ILTypeRef = let (ILTypeInfo(_, _, tref, _)) = x in tref
member x.RawMetadata = let (ILTypeInfo(_, _, _, tdef)) = x in tdef
member x.ToType = let (ILTypeInfo(_, ty, _, _)) = x in ty
/// Get the compiled nominal type. In the case of tuple types, this is a .NET tuple type
member x.ToAppType = convertToTypeWithMetadataIfPossible x.TcGlobals x.ToType
member x.TyconRefOfRawMetadata = tcrefOfAppTy x.TcGlobals x.ToAppType
member x.TypeInstOfRawMetadata = argsOfAppTy x.TcGlobals x.ToAppType
member x.ILScopeRef = x.ILTypeRef.Scope
member x.Name = x.ILTypeRef.Name
member x.IsValueType = x.RawMetadata.IsStructOrEnum
member x.Instantiate inst =
let (ILTypeInfo(g, ty, tref, tdef)) = x
ILTypeInfo(g, instType inst ty, tref, tdef)
static member FromType g ty =
if isAnyTupleTy g ty then
// When getting .NET metadata for the properties and methods
// of an F# tuple type, use the compiled nominal type, which is a .NET tuple type
let metadataTy = convertToTypeWithMetadataIfPossible g ty
assert (isILAppTy g metadataTy)
let metadataTyconRef = tcrefOfAppTy g metadataTy
let (TILObjectReprData(scoref, enc, tdef)) = metadataTyconRef.ILTyconInfo
let metadataILTypeRef = mkRefForNestedILTypeDef scoref (enc, tdef)
ILTypeInfo(g, ty, metadataILTypeRef, tdef)
elif isILAppTy g ty then
let tcref = tcrefOfAppTy g ty
let (TILObjectReprData(scoref, enc, tdef)) = tcref.ILTyconInfo
let tref = mkRefForNestedILTypeDef scoref (enc, tdef)
ILTypeInfo(g, ty, tref, tdef)
else
failwith "ILTypeInfo.FromType - no IL metadata for type"
//-------------------------------------------------------------------------
// ILMethInfo
/// Describes an F# use of an IL method.
[<NoComparison; NoEquality>]
type ILMethInfo =
/// ILMethInfo(g, ilApparentType, ilDeclaringTyconRefOpt, ilMethodDef, ilGenericMethodTyArgs)
///
/// Describes an F# use of an IL method.
///
/// If ilDeclaringTyconRefOpt is 'Some' then this is an F# use of an C#-style extension method.
/// If ilDeclaringTyconRefOpt is 'None' then ilApparentType is an IL type definition.
| ILMethInfo of TcGlobals * TType * TyconRef option * ILMethodDef * Typars
member x.TcGlobals = match x with ILMethInfo(g, _, _, _, _) -> g
/// Get the apparent declaring type of the method as an F# type.
/// If this is a C#-style extension method then this is the type which the method
/// appears to extend. This may be a variable type.
member x.ApparentEnclosingType = match x with ILMethInfo(_, ty, _, _, _) -> ty
/// Like ApparentEnclosingType but use the compiled nominal type if this is a method on a tuple type
member x.ApparentEnclosingAppType = convertToTypeWithMetadataIfPossible x.TcGlobals x.ApparentEnclosingType
/// Get the declaring type associated with an extension member, if any.
member x.ILExtensionMethodDeclaringTyconRef = match x with ILMethInfo(_, _, tcrefOpt, _, _) -> tcrefOpt
/// Get the Abstract IL metadata associated with the method.
member x.RawMetadata = match x with ILMethInfo(_, _, _, md, _) -> md
/// Get the formal method type parameters associated with a method.
member x.FormalMethodTypars = match x with ILMethInfo(_, _, _, _, fmtps) -> fmtps
/// Get the IL name of the method
member x.ILName = x.RawMetadata.Name
/// Indicates if the method is an extension method
member x.IsILExtensionMethod = x.ILExtensionMethodDeclaringTyconRef.IsSome
/// Get the declaring type of the method. If this is an C#-style extension method then this is the IL type
/// holding the static member that is the extension method.
member x.DeclaringTyconRef =
match x.ILExtensionMethodDeclaringTyconRef with
| Some tcref -> tcref
| None -> tcrefOfAppTy x.TcGlobals x.ApparentEnclosingAppType
/// Get the instantiation of the declaring type of the method.
/// If this is an C#-style extension method then this is empty because extension members
/// are never in generic classes.
member x.DeclaringTypeInst =
if x.IsILExtensionMethod then []
else argsOfAppTy x.TcGlobals x.ApparentEnclosingAppType
/// Get the Abstract IL scope information associated with interpreting the Abstract IL metadata that backs this method.
member x.MetadataScope = x.DeclaringTyconRef.CompiledRepresentationForNamedType.Scope
/// Get the Abstract IL metadata corresponding to the parameters of the method.
/// If this is an C#-style extension method then drop the object argument.
member x.ParamMetadata =
let ps = x.RawMetadata.Parameters
if x.IsILExtensionMethod then List.tail ps else ps
/// Get the number of parameters of the method
member x.NumParams = x.ParamMetadata.Length
/// Indicates if the method is a constructor
member x.IsConstructor = x.RawMetadata.IsConstructor
/// Indicates if the method is a class initializer.
member x.IsClassConstructor = x.RawMetadata.IsClassInitializer
/// Indicates if the method has protected accessibility,
member x.IsProtectedAccessibility =
let md = x.RawMetadata
not md.IsConstructor &&
not md.IsClassInitializer &&
(md.Access = ILMemberAccess.Family || md.Access = ILMemberAccess.FamilyOrAssembly)
/// Indicates if the IL method is marked virtual.
member x.IsVirtual = x.RawMetadata.IsVirtual
/// Indicates if the IL method is marked final.
member x.IsFinal = x.RawMetadata.IsFinal
/// Indicates if the IL method is marked abstract.
member x.IsAbstract = x.RawMetadata.IsAbstract
/// Does it appear to the user as a static method?
member x.IsStatic =
not x.IsILExtensionMethod && // all C#-declared extension methods are instance
x.RawMetadata.CallingConv.IsStatic
/// Does it have the .NET IL 'newslot' flag set, and is also a virtual?
member x.IsNewSlot = x.RawMetadata.IsNewSlot
/// Does it appear to the user as an instance method?
member x.IsInstance = not x.IsConstructor && not x.IsStatic
/// Get the argument types of the the IL method. If this is an C#-style extension method
/// then drop the object argument.
member x.GetParamTypes(amap, m, minst) =
x.ParamMetadata |> List.map (fun p -> ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst)
/// Get all the argument types of the IL method. Include the object argument even if this is
/// an C#-style extension method.
member x.GetRawArgTypes(amap, m, minst) =
x.RawMetadata.Parameters |> List.map (fun p -> ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst)
/// Get info about the arguments of the IL method. If this is an C#-style extension method then
/// drop the object argument.
///
/// Any type parameters of the enclosing type are instantiated in the type returned.
member x.GetParamNamesAndTypes(amap, m, minst) =
x.ParamMetadata |> List.map (fun p -> ParamNameAndType(Option.map (mkSynId m) p.Name, ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst) )
/// Get a reference to the method (dropping all generic instantiations), as an Abstract IL ILMethodRef.
member x.ILMethodRef =
let mref = mkRefToILMethod (x.DeclaringTyconRef.CompiledRepresentationForNamedType, x.RawMetadata)
rescopeILMethodRef x.MetadataScope mref
/// Indicates if the method is marked as a DllImport (a PInvoke). This is done by looking at the IL custom attributes on
/// the method.
member x.IsDllImport (g: TcGlobals) =
match g.attrib_DllImportAttribute with
| None -> false
| Some attr ->
x.RawMetadata.CustomAttrs
|> TryFindILAttribute attr
/// Indicates if the method is marked with the [<IsReadOnly>] attribute. This is done by looking at the IL custom attributes on
/// the method.
member x.IsReadOnly (g: TcGlobals) =
x.RawMetadata.CustomAttrs
|> TryFindILAttribute g.attrib_IsReadOnlyAttribute
/// Get the (zero or one) 'self'/'this'/'object' arguments associated with an IL method.
/// An instance extension method returns one object argument.
member x.GetObjArgTypes(amap, m, minst) =
// All C#-style extension methods are instance. We have to re-read the 'obj' type w.r.t. the
// method instantiation.
if x.IsILExtensionMethod then
let p = x.RawMetadata.Parameters.Head
[ ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst ]
else if x.IsInstance then
[ x.ApparentEnclosingType ]
else
[]
/// Get the compiled return type of the method, where 'void' is None.
member x.GetCompiledReturnTy (amap, m, minst) =
ImportReturnTypeFromMetadata amap m x.RawMetadata.Return.Type x.RawMetadata.Return.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst
/// Get the F# view of the return type of the method, where 'void' is 'unit'.
member x.GetFSharpReturnTy (amap, m, minst) =
x.GetCompiledReturnTy(amap, m, minst)
|> GetFSharpViewOfReturnType amap.g
//-------------------------------------------------------------------------
// MethInfo
[<System.Diagnostics.DebuggerDisplayAttribute("{DebuggerDisplayName}")>]
/// Describes an F# use of a method
[<NoComparison; NoEquality>]
type MethInfo =
/// FSMeth(tcGlobals, enclosingType, valRef, extensionMethodPriority).
///
/// Describes a use of a method declared in F# code and backed by F# metadata.
| FSMeth of TcGlobals * TType * ValRef * ExtensionMethodPriority option
/// ILMeth(tcGlobals, ilMethInfo, extensionMethodPriority).
///
/// Describes a use of a method backed by Abstract IL # metadata
| ILMeth of TcGlobals * ILMethInfo * ExtensionMethodPriority option
/// Describes a use of a pseudo-method corresponding to the default constructor for a .NET struct type
| DefaultStructCtor of TcGlobals * TType
#if !NO_EXTENSIONTYPING
/// Describes a use of a method backed by provided metadata
| ProvidedMeth of Import.ImportMap * Tainted<ProvidedMethodBase> * ExtensionMethodPriority option * range
#endif
/// Get the enclosing type of the method info.
///
/// If this is an extension member, then this is the apparent parent, i.e. the type the method appears to extend.
/// This may be a variable type.
member x.ApparentEnclosingType =
match x with
| ILMeth(_, ilminfo, _) -> ilminfo.ApparentEnclosingType
| FSMeth(_, ty, _, _) -> ty
| DefaultStructCtor(_, ty) -> ty
#if !NO_EXTENSIONTYPING
| ProvidedMeth(amap, mi, _, m) ->
Import.ImportProvidedType amap m (mi.PApply((fun mi -> mi.DeclaringType), m))
#endif
/// Get the enclosing type of the method info, using a nominal type for tuple types
member x.ApparentEnclosingAppType =
convertToTypeWithMetadataIfPossible x.TcGlobals x.ApparentEnclosingType
member x.ApparentEnclosingTyconRef =
tcrefOfAppTy x.TcGlobals x.ApparentEnclosingAppType
/// Get the declaring type or module holding the method. If this is an C#-style extension method then this is the type
/// holding the static member that is the extension method. If this is an F#-style extension method it is the logical module
/// holding the value for the extension method.
member x.DeclaringTyconRef =
match x with
| ILMeth(_, ilminfo, _) when x.IsExtensionMember -> ilminfo.DeclaringTyconRef
| FSMeth(_, _, vref, _) when x.IsExtensionMember && vref.HasDeclaringEntity -> vref.TopValDeclaringEntity
| _ -> x.ApparentEnclosingTyconRef
/// Get the information about provided static parameters, if any
member x.ProvidedStaticParameterInfo =
match x with
| ILMeth _ -> None
| FSMeth _ -> None
#if !NO_EXTENSIONTYPING
| ProvidedMeth (_, mb, _, m) ->
let staticParams = mb.PApplyWithProvider((fun (mb, provider) -> mb.GetStaticParametersForMethod provider), range=m)
let staticParams = staticParams.PApplyArray(id, "GetStaticParametersForMethod", m)
match staticParams with
| [| |] -> None
| _ -> Some (mb, staticParams)
#endif
| DefaultStructCtor _ -> None
/// Get the extension method priority of the method, if it has one.
member x.ExtensionMemberPriorityOption =
match x with
| ILMeth(_, _, pri) -> pri
| FSMeth(_, _, _, pri) -> pri
#if !NO_EXTENSIONTYPING
| ProvidedMeth(_, _, pri, _) -> pri
#endif
| DefaultStructCtor _ -> None
/// Get the extension method priority of the method. If it is not an extension method
/// then use the highest possible value since non-extension methods always take priority
/// over extension members.
member x.ExtensionMemberPriority = defaultArg x.ExtensionMemberPriorityOption System.UInt64.MaxValue
/// Get the method name in DebuggerDisplayForm
member x.DebuggerDisplayName =
match x with
| ILMeth(_, y, _) -> "ILMeth: " + y.ILName
| FSMeth(_, _, vref, _) -> "FSMeth: " + vref.LogicalName
#if !NO_EXTENSIONTYPING
| ProvidedMeth(_, mi, _, m) -> "ProvidedMeth: " + mi.PUntaint((fun mi -> mi.Name), m)
#endif
| DefaultStructCtor _ -> ".ctor"
/// Get the method name in LogicalName form, i.e. the name as it would be stored in .NET metadata
member x.LogicalName =
match x with
| ILMeth(_, y, _) -> y.ILName
| FSMeth(_, _, vref, _) -> vref.LogicalName