-
Notifications
You must be signed in to change notification settings - Fork 812
/
Copy pathinfos.fs
2517 lines (2142 loc) · 117 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 Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open FSharp.Compiler
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.Import
open FSharp.Compiler.Import.Nullness
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTreeOps
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.Text
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeBasics
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.TypedTreeOps.DebugPrint
open FSharp.Compiler.TypeHierarchy
open FSharp.Compiler.Xml
#if !NO_TYPEPROVIDERS
open FSharp.Compiler.TypeProviders
open FSharp.Compiler.AbstractIL
#endif
//-------------------------------------------------------------------------
// 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
| slotSig :: _ -> isInterfaceTy g slotSig.DeclaringType
| [] -> 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_TYPEPROVIDERS
/// 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 -> nonNull<ProvidedType> mi.DeclaringType), m)
else mi.Coerce<ProvidedMethodInfo>(m).PApply((fun mi -> mi.ReturnType), m)
let ty = 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, _, _ = GetValReprTypeInCompiledForm 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, _, _ = GetValReprTypeInCompiledForm 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/dotnet/fsharp/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)
let private HasExternalInit (mref: ILMethodRef) : bool =
match mref.ReturnType with
| ILType.Modified(_, cls, _) -> cls.FullName = "System.Runtime.CompilerServices.IsExternalInit"
| _ -> false
/// 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 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
| _ ->
let attrs = ilParam.CustomAttrs
if TryFindILAttributeOpt g.attrib_IUnknownConstantAttribute attrs then WrapperForIUnknown
elif TryFindILAttributeOpt g.attrib_IDispatchConstantAttribute attrs then WrapperForIDispatch
else MissingValue
else
DefaultValue
// See above - the typpe is imported only in order to be analyzed for optional default value, nullness is irrelevant here.
CallerSide (analyze (ImportILTypeFromMetadataSkipNullness 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
| CallerArgumentExpression of paramName: string
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
/// Partial information about a parameter returned for use by the Language Service
[<NoComparison; NoEquality>]
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)
/// Full information about a parameter returned for use by the type checker and language service.
[<NoComparison; NoEquality>]
type ParamData =
ParamData of
isParamArray: bool *
isInArg: bool *
isOut: bool *
optArgInfo: OptionalArgInfo *
callerInfo: CallerInfo *
nameOpt: Ident option *
reflArgInfo: ReflectedArgInfo *
ttype: TType
type ParamAttribs = ParamAttribs of isParamArrayArg: bool * isInArg: bool * isOutArg: bool * optArgInfo: OptionalArgInfo * callerInfo: CallerInfo * reflArgInfo: ReflectedArgInfo
let CrackParamAttribsInfo g (ty: TType, argInfo: ArgReprInfo) =
let isParamArrayArg = HasFSharpAttribute g g.attrib_ParamArrayAttribute argInfo.Attribs
let reflArgInfo =
match TryFindFSharpBoolAttributeAssumeFalse g g.attrib_ReflectedDefinitionAttribute argInfo.Attribs with
| Some b -> ReflectedArgInfo.Quote b
| None -> ReflectedArgInfo.None
let isOutArg = (HasFSharpAttribute g g.attrib_OutAttribute argInfo.Attribs && isByrefTy g ty) || isOutByrefTy g ty
let isInArg = (HasFSharpAttribute g g.attrib_InAttribute argInfo.Attribs && isByrefTy g ty) || isInByrefTy g ty
let isCalleeSideOptArg = HasFSharpAttribute g g.attrib_OptionalArgumentAttribute argInfo.Attribs
let isCallerSideOptArg = HasFSharpAttributeOpt g g.attrib_OptionalAttribute argInfo.Attribs
let optArgInfo =
if isCalleeSideOptArg then
CalleeSide
elif isCallerSideOptArg then
let defaultParameterValueAttribute = TryFindFSharpAttributeOpt g g.attrib_DefaultParameterValueAttribute argInfo.Attribs
match defaultParameterValueAttribute with
| None ->
// Do a type-directed analysis of the type to determine the default value to pass.
// Similar rules as OptionalArgInfo.FromILParameter are applied here, except for the COM and byref-related stuff.
CallerSide (if isObjTy g ty then MissingValue else DefaultValue)
| Some attr ->
let defaultValue = OptionalArgInfo.ValueOfDefaultParameterValueAttrib attr
match defaultValue with
| Some (Expr.Const (_, m, ty2)) when not (typeEquiv g ty2 ty) ->
// the type of the default value does not match the type of the argument.
// Emit a warning, and ignore the DefaultParameterValue argument altogether.
warning(Error(FSComp.SR.DefaultParameterValueNotAppropriateForArgument(), m))
NotOptional
| Some (Expr.Const (ConstToILFieldInit fi, _, _)) ->
// Good case - all is well.
CallerSide (Constant fi)
| _ ->
// Default value is not appropriate, i.e. not a constant.
// Compiler already gives an error in that case, so just ignore here.
NotOptional
else NotOptional
let isCallerLineNumberArg = HasFSharpAttribute g g.attrib_CallerLineNumberAttribute argInfo.Attribs
let isCallerFilePathArg = HasFSharpAttribute g g.attrib_CallerFilePathAttribute argInfo.Attribs
let isCallerMemberNameArg = HasFSharpAttribute g g.attrib_CallerMemberNameAttribute argInfo.Attribs
let callerArgumentExpressionArg = TryFindFSharpAttributeOpt g g.attrib_CallerArgumentExpressionAttribute argInfo.Attribs
let callerInfo =
match isCallerLineNumberArg, isCallerFilePathArg, isCallerMemberNameArg, callerArgumentExpressionArg with
| false, false, false, None -> NoCallerInfo
| true, false, false, None -> CallerLineNumber
| false, true, false, None -> CallerFilePath
| false, false, true, None -> CallerMemberName
| false, false, false, Some(Attrib(_, _, (AttribStringArg x :: _), _, _, _, _)) ->
CallerArgumentExpression(x)
| false, true, true, _ ->
match TryFindFSharpAttribute g g.attrib_CallerMemberNameAttribute argInfo.Attribs with
| Some(Attrib(_, _, _, _, _, _, callerMemberNameAttributeRange)) ->
warning(Error(FSComp.SR.CallerMemberNameIsOverriden(argInfo.Name.Value.idText), callerMemberNameAttributeRange))
CallerFilePath
| _ -> failwith "Impossible"
| _, _, _, _ ->
// if multiple caller info attributes are specified, pick the "wrong" one here
// so that we get an error later
match tryDestOptionTy g ty with
| ValueSome optTy when typeEquiv g g.int32_ty optTy -> CallerFilePath
| _ -> CallerLineNumber
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)
#if !NO_TYPEPROVIDERS
type ILFieldInit with
/// Compute the ILFieldInit for the given provided constant value for a provided enum type.
static member FromProvidedObj m (v: obj MaybeNull) =
match v with
| Null -> ILFieldInit.Null
| NonNull v ->
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: 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 paramTy = ImportProvidedType amap m (provParam.PApply((fun p -> p.ParameterType), m))
CallerSide (analyze paramTy)
| _ ->
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 MaybeNull) err =
match mi.PApply((fun mi -> (get mi :> ProvidedMethodBase MaybeNull)),m) with
| Tainted.Null -> error(Error(err(mi.PUntaint((fun mi -> mi.Name),m),mi.PUntaint((fun mi -> (nonNull mi.DeclaringType).Name), m)), m))
| Tainted.NonNull 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 -> (nonNull<ProvidedType> mi.DeclaringType).Name), m)), m))
#endif
/// 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
/// Indicates if the type is marked with the [<IsReadOnly>] attribute.
member x.IsReadOnly (g: TcGlobals) =
x.RawMetadata.CustomAttrs
|> TryFindILAttribute g.attrib_IsReadOnlyAttribute
member x.Instantiate inst =
let (ILTypeInfo(g, ty, tref, tdef)) = x
ILTypeInfo(g, instType inst ty, tref, tdef)
member x.NullableAttributes = AttributesFromIL(x.RawMetadata.MetadataIndex,x.RawMetadata.CustomAttrsStored)
member x.NullableClassSource = FromClass(x.NullableAttributes)
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" + System.Environment.StackTrace)
[<NoComparison; NoEquality>]
type ILMethParentTypeInfo =
| IlType of ILTypeInfo
| CSharpStyleExtension of declaring:TyconRef * apparent:TType
member x.ToType =
match x with
| IlType x -> x.ToType
| CSharpStyleExtension(apparent=x) -> x
/// Describes an F# use of an IL method.
[<NoComparison; NoEquality>]
type ILMethInfo =
/// 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 g: TcGlobals * ilType:ILMethParentTypeInfo * ilMethodDef: ILMethodDef * ilGenericMethodTyArgs: 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.ToType
/// 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(ilType=CSharpStyleExtension(declaring= x)) -> Some x
| _ -> None
/// 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 =
match x with
| ILMethInfo(ilType=CSharpStyleExtension _) -> true
| _ -> false
/// 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
member x.NullableFallback =
let raw = x.RawMetadata
let classAttrs =
match x with
| ILMethInfo(ilType=CSharpStyleExtension(declaring= t)) when t.IsILTycon -> AttributesFromIL(t.ILTyconRawMetadata.MetadataIndex,t.ILTyconRawMetadata.CustomAttrsStored)
// C#-style extension defined in F# -> we do not support manually adding NullableContextAttribute by F# users.
| ILMethInfo(ilType=CSharpStyleExtension _) -> AttributesFromIL(0,Given(ILAttributes.Empty))
| ILMethInfo(ilType=IlType(t)) -> t.NullableAttributes
FromMethodAndClass(AttributesFromIL(raw.MetadataIndex,raw.CustomAttrsStored),classAttrs)
member x.GetNullness(p:ILParameter) = {DirectAttributes = AttributesFromIL(p.MetadataIndex,p.CustomAttrsStored); Fallback = x.NullableFallback}
/// 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 (x.GetNullness(p)) p.Type 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 (x.GetNullness(p)) p.Type 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) =
let scope = x.MetadataScope
let tinst = x.DeclaringTypeInst
x.ParamMetadata |> List.map (fun p -> ParamNameAndType(Option.map (mkSynId m) p.Name, ImportParameterTypeFromMetadata amap m (x.GetNullness(p)) p.Type scope tinst 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
let nullableSource = {DirectAttributes = AttributesFromIL(p.MetadataIndex,p.CustomAttrsStored); Fallback = x.NullableFallback}
[ ImportParameterTypeFromMetadata amap m nullableSource p.Type 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.GetCompiledReturnType (amap, m, minst) =
let ilReturn = x.RawMetadata.Return
let nullableSource = {DirectAttributes = AttributesFromIL(ilReturn.MetadataIndex,ilReturn.CustomAttrsStored); Fallback = x.NullableFallback}
ImportReturnTypeFromMetadata amap m nullableSource ilReturn.Type x.MetadataScope x.DeclaringTypeInst minst
/// Get the F# view of the return type of the method, where 'void' is 'unit'.
member x.GetFSharpReturnType (amap, m, minst) =
x.GetCompiledReturnType(amap, m, minst)
|> GetFSharpViewOfReturnType amap.g
/// Describes an F# use of a method
[<System.Diagnostics.DebuggerDisplay("{DebuggerDisplayName}")>]
[<NoComparison; NoEquality>]
type MethInfo =
/// Describes a use of a method declared in F# code and backed by F# metadata.
| FSMeth of tcGlobals: TcGlobals * enclosingType: TType * valRef: ValRef * extensionMethodPriority: ExtensionMethodPriority option
/// Describes a use of a method backed by Abstract IL # metadata
| ILMeth of tcGlobals: TcGlobals * ilMethInfo: ILMethInfo * extensionMethodPriority: ExtensionMethodPriority option
/// Describes a use of a pseudo-method corresponding to the default constructor for a .NET struct type
| DefaultStructCtor of tcGlobals: TcGlobals * structTy: TType
#if !NO_TYPEPROVIDERS
/// Describes a use of a method backed by provided metadata
| ProvidedMeth of amap: ImportMap * methodBase: Tainted<ProvidedMethodBase> * extensionMethodPriority: ExtensionMethodPriority option * m: 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_TYPEPROVIDERS
| ProvidedMeth(amap, mi, _, m) ->
ImportProvidedType amap m (mi.PApply((fun mi -> nonNull<ProvidedType> 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.DeclaringEntity
| _ -> x.ApparentEnclosingTyconRef
/// Get the information about provided static parameters, if any
member x.ProvidedStaticParameterInfo =
match x with
| ILMeth _ -> None
| FSMeth _ -> None
#if !NO_TYPEPROVIDERS
| 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_TYPEPROVIDERS
| 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 UInt64.MaxValue
/// Get the method name in DebuggerDisplayForm
member x.DebuggerDisplayName =
match x with
| ILMeth(_, y, _) -> y.DeclaringTyconRef.DisplayNameWithStaticParametersAndUnderscoreTypars + "::" + y.ILName
| FSMeth(_, AbbrevOrAppTy(tcref, _), vref, _) -> tcref.DisplayNameWithStaticParametersAndUnderscoreTypars + "::" + vref.LogicalName
| FSMeth(_, _, vref, _) -> "??::" + vref.LogicalName
#if !NO_TYPEPROVIDERS
| 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
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.Name), m)
#endif
| DefaultStructCtor _ -> ".ctor"
/// Get the method name in DisplayName form
member x.DisplayName =
match x with
| FSMeth(_, _, vref, _) -> vref.DisplayName
| _ -> x.LogicalName |> PrettyNaming.ConvertValLogicalNameToDisplayName false
/// Get the method name in DisplayName form
member x.DisplayNameCore =
match x with
| FSMeth(_, _, vref, _) -> vref.DisplayNameCore
| _ -> x.LogicalName |> PrettyNaming.ConvertValLogicalNameToDisplayNameCore
/// Indicates if this is a method defined in this assembly with an internal XML comment
member x.HasDirectXmlComment =
match x with
| FSMeth(g, _, vref, _) -> valRefInThisAssembly g.compilingFSharpCore vref
#if !NO_TYPEPROVIDERS
| ProvidedMeth _ -> true
#endif
| _ -> false
override x.ToString() = x.ApparentEnclosingType.ToString() + "::" + x.LogicalName
/// Get the actual type instantiation of the declaring type associated with this use of the method.
///
/// For extension members this is empty (the instantiation of the declaring type).
member x.DeclaringTypeInst =
if x.IsExtensionMember then [] else argsOfAppTy x.TcGlobals x.ApparentEnclosingAppType
/// Get the TcGlobals value that governs the method declaration
member x.TcGlobals =
match x with
| ILMeth(g, _, _) -> g
| FSMeth(g, _, _, _) -> g
| DefaultStructCtor (g, _) -> g
#if !NO_TYPEPROVIDERS
| ProvidedMeth(amap, _, _, _) -> amap.g
#endif
/// Get the formal generic method parameters for the method as a list of type variables.
///
/// For an extension method this includes all type parameters, even if it is extending a generic type.
member x.FormalMethodTypars =
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.FormalMethodTypars
| FSMeth(g, _, vref, _) ->
let ty = x.ApparentEnclosingAppType
let _, memberMethodTypars, _, _ = AnalyzeTypeOfMemberVal x.IsCSharpStyleExtensionMember g (ty, vref)
memberMethodTypars
| DefaultStructCtor _ -> []
#if !NO_TYPEPROVIDERS
| ProvidedMeth _ -> [] // There will already have been an error if there are generic parameters here.
#endif
/// Get the formal generic method parameters for the method as a list of variable types.
member x.FormalMethodInst = generalizeTypars x.FormalMethodTypars
member x.FormalMethodTyparInst = mkTyparInst x.FormalMethodTypars x.FormalMethodInst
/// Get the XML documentation associated with the method
member x.XmlDoc =
match x with
| ILMeth _ -> XmlDoc.Empty
| FSMeth(_, _, vref, _) -> vref.XmlDoc
| DefaultStructCtor _ -> XmlDoc.Empty
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m)->
let lines = mi.PUntaint((fun mix -> (mix :> IProvidedCustomAttributeProvider).GetXmlDocAttributes(mi.TypeProvider.PUntaintNoFailure id)), m)
XmlDoc (lines, m)
#endif
/// Try to get an arbitrary F# ValRef associated with the member. This is to determine if the member is virtual, amongst other things.
member x.ArbitraryValRef =
match x with
| FSMeth(_g, _, vref, _) -> Some vref
| _ -> None
/// Get a list of argument-number counts, one count for each set of curried arguments.
///
/// For an extension member, drop the 'this' argument.
member x.NumArgs =
match x with
| ILMeth(_, ilminfo, _) -> [ilminfo.NumParams]
| FSMeth(g, _, vref, _) -> GetArgInfosOfMember x.IsCSharpStyleExtensionMember g vref |> List.map List.length
| DefaultStructCtor _ -> [0]
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> [mi.PUntaint((fun mi -> mi.GetParameters().Length), m)] // Why is this a list? Answer: because the method might be curried
#endif
/// Indicates if the property is a IsABC union case tester implied by a union case definition
member x.IsUnionCaseTester =
let tcref = x.ApparentEnclosingTyconRef
tcref.IsUnionTycon &&
x.LogicalName.StartsWithOrdinal("get_Is") &&
match x.ArbitraryValRef with
| Some v -> v.IsImplied
| None -> false
member x.IsCurried = x.NumArgs.Length > 1
/// Does the method appear to the user as an instance method?
member x.IsInstance =
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.IsInstance
| FSMeth(_, _, vref, _) -> vref.IsInstanceMember || x.IsCSharpStyleExtensionMember
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> not mi.IsConstructor && not mi.IsStatic), m)
#endif
/// Get the number of generic method parameters for a method.
/// For an extension method this includes all type parameters, even if it is extending a generic type.
member x.GenericArity = x.FormalMethodTypars.Length
member x.IsProtectedAccessibility =
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.IsProtectedAccessibility
| FSMeth _ -> false
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsFamily), m)
#endif
member x.IsVirtual =
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.IsVirtual
| FSMeth(_, _, vref, _) -> vref.IsVirtualMember
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsVirtual), m)
#endif
member x.IsConstructor =
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.IsConstructor
| FSMeth(_g, _, vref, _) -> (vref.MemberInfo.Value.MemberFlags.MemberKind = SynMemberKind.Constructor)
| DefaultStructCtor _ -> true
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsConstructor), m)
#endif
member x.IsClassConstructor =
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.IsClassConstructor
| FSMeth(_, _, vref, _) ->
match vref.TryDeref with
| ValueSome x -> x.IsClassConstructor
| _ -> false
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsConstructor && mi.IsStatic), m) // Note: these are never public anyway
#endif
member x.IsDispatchSlot =
match x with
| ILMeth(_g, ilmeth, _) -> ilmeth.IsVirtual
| FSMeth(_, _, vref, _) -> vref.MemberInfo.Value.MemberFlags.IsDispatchSlot
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth _ -> x.IsVirtual // Note: follow same implementation as ILMeth
#endif
member x.IsFinal =
not x.IsVirtual ||
match x with
| ILMeth(_, ilmeth, _) -> ilmeth.IsFinal
| FSMeth(_g, _, _vref, _) -> false
| DefaultStructCtor _ -> true
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsFinal), m)
#endif
// This means 'is this particular MethInfo one that doesn't provide an implementation?'.
// For F# methods, this is 'true' for the MethInfos corresponding to 'abstract' declarations,
// and false for the (potentially) matching 'default' implementation MethInfos that eventually
// provide an implementation for the dispatch slot.
//
// For IL methods, this is 'true' for abstract methods, and 'false' for virtual methods
member minfo.IsAbstract =
match minfo with
| ILMeth(_, ilmeth, _) -> ilmeth.IsAbstract
| FSMeth(g, _, vref, _) -> isInterfaceTy g minfo.ApparentEnclosingType || vref.IsDispatchSlotMember
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsAbstract), m)
#endif
member x.IsNewSlot =
(x.IsVirtual &&
(match x with
| ILMeth(_, x, _) -> x.IsNewSlot || (isInterfaceTy x.TcGlobals x.ApparentEnclosingType && not x.IsFinal)
| FSMeth(_, _, vref, _) -> vref.IsDispatchSlotMember
#if !NO_TYPEPROVIDERS
| ProvidedMeth(_, mi, _, m) -> mi.PUntaint((fun mi -> mi.IsHideBySig), m) // REVIEW: Check this is correct
#endif
| DefaultStructCtor _ -> false))
/// Indicates if this is an IL method.
member x.IsILMethod =
match x with
| ILMeth _ -> true
| _ -> false
/// Check if this method is an explicit implementation of an interface member
member x.IsFSharpExplicitInterfaceImplementation =
match x with
| ILMeth _ -> false
| FSMeth(g, _, vref, _) -> vref.IsFSharpExplicitInterfaceImplementation g
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth _ -> false
#endif
/// Check if this method is marked 'override' and thus definitely overrides another method.
member x.IsDefiniteFSharpOverride =
match x with
| ILMeth _ -> false
| FSMeth(_, _, vref, _) -> vref.IsDefiniteFSharpOverrideMember
| DefaultStructCtor _ -> false
#if !NO_TYPEPROVIDERS
| ProvidedMeth _ -> false
#endif
member x.ImplementedSlotSignatures =
match x with
| FSMeth(_, _, vref, _) -> vref.ImplementedSlotSignatures
| _ -> failwith "not supported"
/// Indicates if this is an extension member.
member x.IsExtensionMember =
match x with
| FSMeth (_, _, vref, pri) -> pri.IsSome || vref.IsExtensionMember
| ILMeth (_, _, Some _) -> true
| _ -> false
/// Indicates if this is an extension member (e.g. on a struct) that takes a byref arg