-
Notifications
You must be signed in to change notification settings - Fork 773
/
prim-types.fs
7074 lines (6090 loc) · 426 KB
/
prim-types.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.
#nowarn "25" // Incomplete match expressions
#nowarn "35" // This construct is deprecated: the treatment of this operator is now handled directly by the F# compiler and its meaning may not be redefined.
#nowarn "44" // This construct is deprecated. This function is for use by compiled F# code and should not be used directly
#nowarn "52" // The value has been copied to ensure the original is not mutated by this operation
#nowarn "60" // Override implementations in augmentations are now deprecated. Override implementations should be given as part of the initial declaration of a type.
#nowarn "61" // The containing type can use 'null' as a representation value for its nullary union case. This member will be compiled as a static member.
#nowarn "69" // Interface implementations should normally be given on the initial declaration of a type. Interface implementations in augmentations may lead to accessing static bindings before they are initialized, though only if the interface implementation is invoked during initialization of the static data, and in turn access the static data. You may remove this warning using #nowarn "69" if you have checked this is not the case.
#nowarn "77" // Member constraints with the name 'Exp' are given special status by the F# compiler...
#nowarn "3218" // mismatch of parameter name for 'fst' and 'snd'
namespace Microsoft.FSharp.Core
open System
open System.Collections
open System.Collections.Generic
open System.Diagnostics
open System.Globalization
open System.Reflection
open System.Text
type Unit() =
override _.GetHashCode() = 0
override _.Equals(obj:obj) =
match obj with null -> true | :? Unit -> true | _ -> false
interface System.IComparable with
member _.CompareTo(_obj:obj) = 0
and unit = Unit
type SourceConstructFlags =
| None = 0
| SumType = 1
| RecordType = 2
| ObjectType = 3
| Field = 4
| Exception = 5
| Closure = 6
| Module = 7
| UnionCase = 8
| Value = 9
| KindMask = 31
| NonPublicRepresentation = 32
[<Flags>]
type CompilationRepresentationFlags =
| None = 0
| Static = 1
| Instance = 2
/// append 'Module' to the end of a non-unique module
| ModuleSuffix = 4
| UseNullAsTrueValue = 8
| Event = 16
[<AttributeUsage(AttributeTargets.Class, AllowMultiple=false)>]
type SealedAttribute(value:bool) =
inherit Attribute()
member _.Value = value
new() = new SealedAttribute(true)
[<AttributeUsage(AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type AbstractClassAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.GenericParameter, AllowMultiple=false)>]
[<Sealed>]
type EqualityConditionalOnAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.GenericParameter, AllowMultiple=false)>]
[<Sealed>]
type ComparisonConditionalOnAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type AllowNullLiteralAttribute(value: bool) =
inherit Attribute()
member _.Value = value
new () = new AllowNullLiteralAttribute(true)
[<AttributeUsage(AttributeTargets.Field, AllowMultiple=false)>]
[<Sealed>]
type VolatileFieldAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type DefaultAugmentationAttribute(value:bool) =
inherit Attribute()
member _.Value = value
[<AttributeUsage (AttributeTargets.Property, AllowMultiple=false)>]
[<Sealed>]
type CLIEventAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type CLIMutableAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type AutoSerializableAttribute(value:bool) =
inherit Attribute()
member _.Value = value
[<AttributeUsage (AttributeTargets.Field ||| AttributeTargets.Method, AllowMultiple=false)>]
[<Sealed>]
type DefaultValueAttribute(check:bool) =
inherit Attribute()
member _.Check = check
new() = new DefaultValueAttribute(true)
[<AttributeUsage (AttributeTargets.Method, AllowMultiple=false)>]
[<Sealed>]
type EntryPointAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type ReferenceEqualityAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type StructuralComparisonAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type StructuralEqualityAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class ||| AttributeTargets.Interface |||
AttributeTargets.Delegate ||| AttributeTargets.Struct |||
AttributeTargets.Enum, AllowMultiple=false)>]
[<Sealed>]
type NoEqualityAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class ||| AttributeTargets.Struct, AllowMultiple=false)>]
[<Sealed>]
type CustomEqualityAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class ||| AttributeTargets.Struct, AllowMultiple=false)>]
[<Sealed>]
type CustomComparisonAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class ||| AttributeTargets.Interface |||
AttributeTargets.Delegate ||| AttributeTargets.Struct |||
AttributeTargets.Enum, AllowMultiple=false)>]
[<Sealed>]
type NoComparisonAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class ||| AttributeTargets.Parameter |||
AttributeTargets.Method ||| AttributeTargets.Property |||
AttributeTargets.Constructor, AllowMultiple=false)>]
[<Sealed>]
type ReflectedDefinitionAttribute(includeValue: bool) =
inherit Attribute()
new() = ReflectedDefinitionAttribute(false)
member _.IncludeValue = includeValue
[<AttributeUsage (AttributeTargets.Method ||| AttributeTargets.Class |||
AttributeTargets.Field ||| AttributeTargets.Interface |||
AttributeTargets.Struct ||| AttributeTargets.Delegate |||
AttributeTargets.Enum ||| AttributeTargets.Property, AllowMultiple=false)>]
[<Sealed>]
type CompiledNameAttribute(compiledName:string) =
inherit Attribute()
member _.CompiledName = compiledName
[<AttributeUsage (AttributeTargets.Struct ||| AttributeTargets.ReturnValue, AllowMultiple=false)>]
[<Sealed>]
type StructAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.GenericParameter ||| AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type MeasureAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type MeasureAnnotatedAbbreviationAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Interface, AllowMultiple=false)>]
[<Sealed>]
type InterfaceAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type ClassAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Field, AllowMultiple=false)>]
[<Sealed>]
type LiteralAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)>]
[<Sealed>]
type FSharpInterfaceDataVersionAttribute(major:int,minor:int,release:int) =
inherit Attribute()
member _.Major = major
member _.Minor = minor
member _.Release = release
[<AttributeUsage(AttributeTargets.All, AllowMultiple=false)>]
[<Sealed>]
type CompilationMappingAttribute(sourceConstructFlags:SourceConstructFlags,
variantNumber:int,
sequenceNumber:int,
resourceName:string,
typeDefinitions:System.Type array) =
inherit Attribute()
member _.SourceConstructFlags = sourceConstructFlags
member _.SequenceNumber = sequenceNumber
member _.VariantNumber = variantNumber
new(sourceConstructFlags) = CompilationMappingAttribute(sourceConstructFlags,0,0)
new(sourceConstructFlags,sequenceNumber) = CompilationMappingAttribute(sourceConstructFlags,0,sequenceNumber)
new(sourceConstructFlags,variantNumber,sequenceNumber) = CompilationMappingAttribute(sourceConstructFlags,variantNumber,sequenceNumber,null,null)
new(resourceName, typeDefinitions) = CompilationMappingAttribute(SourceConstructFlags.None,0,0,resourceName, typeDefinitions)
member _.TypeDefinitions = typeDefinitions
member _.ResourceName = resourceName
[<AttributeUsage(AttributeTargets.All, AllowMultiple=false)>]
[<Sealed>]
type CompilationSourceNameAttribute(sourceName:string) =
inherit Attribute()
member _.SourceName = sourceName
//-------------------------------------------------------------------------
[<AttributeUsage(AttributeTargets.All, AllowMultiple=false)>]
[<Sealed>]
type CompilationRepresentationAttribute (flags : CompilationRepresentationFlags) =
inherit Attribute()
member _.Flags = flags
module internal ExperimentalAttributeMessages =
[<Literal>]
let RequiresPreview: string = "Experimental library feature, requires '--langversion:preview'"
[<Literal>]
let NotSupportedYet: string = "This construct is not supported by your version of the F# compiler"
[<AttributeUsage(AttributeTargets.All, AllowMultiple=false)>]
[<Sealed>]
type ExperimentalAttribute(message:string) =
inherit Attribute()
member _.Message = message
[<AttributeUsage (AttributeTargets.Parameter,AllowMultiple=false)>]
[<Sealed>]
type InlineIfLambdaAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method, AllowMultiple=false)>]
[<Sealed>]
type CompilationArgumentCountsAttribute(counts:int array) =
inherit Attribute()
member _.Counts =
let unboxPrim(x:obj) = (# "unbox.any !0" type ('T) x : 'T #)
(unboxPrim(counts.Clone()) : IEnumerable<int>)
[<AttributeUsage(AttributeTargets.Method, AllowMultiple=false)>]
[<Sealed>]
type CustomOperationAttribute(name:string) =
inherit Attribute()
let mutable isBinary = false
let mutable allowInto = false
let mutable isJoin = false
let mutable isGroupJoin = false
let mutable maintainsVarSpace = false
let mutable maintainsVarSpaceWithBind = false
let mutable joinOnWord = ""
new() = CustomOperationAttribute("")
member _.Name = name
member _.AllowIntoPattern with get() = allowInto and set v = allowInto <- v
member _.IsLikeZip with get() = isBinary and set v = isBinary <- v
member _.IsLikeJoin with get() = isJoin and set v = isJoin <- v
member _.IsLikeGroupJoin with get() = isGroupJoin and set v = isGroupJoin <- v
member _.JoinConditionWord with get() = joinOnWord and set v = joinOnWord <- v
member _.MaintainsVariableSpace with get() = maintainsVarSpace and set v = maintainsVarSpace <- v
member _.MaintainsVariableSpaceUsingBind with get() = maintainsVarSpaceWithBind and set v = maintainsVarSpaceWithBind <- v
[<AttributeUsage(AttributeTargets.Parameter, AllowMultiple=false)>]
[<Sealed>]
type ProjectionParameterAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Interface ||| AttributeTargets.Struct ||| AttributeTargets.Delegate ||| AttributeTargets.Enum, AllowMultiple=false)>]
[<Sealed>]
type StructuredFormatDisplayAttribute(value:string) =
inherit Attribute()
member _.Value = value
[<AttributeUsage(AttributeTargets.All, AllowMultiple=false)>]
[<Sealed>]
type CompilerMessageAttribute(message:string, messageNumber : int) =
inherit Attribute()
let mutable isError = false
let mutable isHidden = false
member _.Message = message
member _.MessageNumber = messageNumber
member _.IsError with get() = isError and set v = isError <- v
member _.IsHidden with get() = isHidden and set v = isHidden <- v
[<AttributeUsage(AttributeTargets.Method ||| AttributeTargets.Property, AllowMultiple=false)>]
[<Sealed>]
type UnverifiableAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method ||| AttributeTargets.Property, AllowMultiple=false)>]
[<Sealed>]
type NoDynamicInvocationAttribute(isLegacy: bool) =
inherit Attribute()
new () = NoDynamicInvocationAttribute(false)
member _.IsLegacy = isLegacy
[<AttributeUsage(AttributeTargets.Parameter,AllowMultiple=false)>]
[<Sealed>]
type OptionalArgumentAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method, AllowMultiple=false)>]
[<Sealed>]
type GeneralizableValueAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method, AllowMultiple=false)>]
[<Sealed>]
type RequiresExplicitTypeArgumentsAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Class, AllowMultiple=false)>]
[<Sealed>]
type RequireQualifiedAccessAttribute() =
inherit Attribute()
[<AttributeUsage (AttributeTargets.Class ||| AttributeTargets.Assembly, AllowMultiple=true)>]
[<Sealed>]
type AutoOpenAttribute(path:string) =
inherit Attribute()
member _.Path = path
new() = AutoOpenAttribute("")
/// This Attribute is used to make Value bindings like
/// let x = some code
/// operate like static properties.
[<AttributeUsage(AttributeTargets.Property, AllowMultiple=false)>]
[<Sealed>]
type ValueAsStaticPropertyAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method ||| AttributeTargets.Property, AllowMultiple=false)>]
[<Sealed>]
type NoCompilerInliningAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method,AllowMultiple=false)>]
[<Sealed>]
type TailCallAttribute() =
inherit System.Attribute()
#if !NET5_0_OR_GREATER
namespace System.Diagnostics.CodeAnalysis
open System
open Microsoft.FSharp.Core
/// <summary>
/// Specifies the types of members that are dynamically accessed.
///
/// This enumeration has a <see cref="FlagsAttribute"/> attribute that allows a
/// bitwise combination of its member values.
/// </summary>
[<Flags; RequireQualifiedAccessAttribute>]
type internal DynamicallyAccessedMemberTypes =
| None = 0
| PublicParameterlessConstructor = 0x0001
| PublicConstructors = 0x0003
| NonPublicConstructors = 0x0004
| PublicMethods = 0x0008
| NonPublicMethods = 0x0010
| PublicFields = 0x0020
| NonPublicFields = 0x0040
| PublicNestedTypes = 0x0080
| NonPublicNestedTypes = 0x0100
| PublicProperties = 0x0200
| NonPublicProperties = 0x0400
| PublicEvents = 0x0800
| NonPublicEvents = 0x1000
| Interfaces = 0x2000
| All = 0xffffffff
[<AttributeUsage(
AttributeTargets.Field ||| AttributeTargets.ReturnValue ||| AttributeTargets.GenericParameter |||
AttributeTargets.Parameter ||| AttributeTargets.Property ||| AttributeTargets.Method,
Inherited = false)>]
type internal DynamicallyAccessedMembersAttribute (memberTypes: DynamicallyAccessedMemberTypes) =
inherit Attribute ()
member val MemberTypes = memberTypes with get, set
member this.DynamicallyAccessedMembersAttribute(memberTypes: DynamicallyAccessedMemberTypes) =
this.MemberTypes <- memberTypes
namespace Microsoft.FSharp.Core
open System
open System.Collections
open System.Collections.Generic
open System.Diagnostics
open System.Globalization
open System.Reflection
open System.Text
#endif
[<MeasureAnnotatedAbbreviation>] type float<[<Measure>] 'Measure> = float
[<MeasureAnnotatedAbbreviation>] type float32<[<Measure>] 'Measure> = float32
[<MeasureAnnotatedAbbreviation>] type decimal<[<Measure>] 'Measure> = decimal
[<MeasureAnnotatedAbbreviation>] type int<[<Measure>] 'Measure> = int
[<MeasureAnnotatedAbbreviation>] type sbyte<[<Measure>] 'Measure> = sbyte
[<MeasureAnnotatedAbbreviation>] type int16<[<Measure>] 'Measure> = int16
[<MeasureAnnotatedAbbreviation>] type int64<[<Measure>] 'Measure> = int64
[<MeasureAnnotatedAbbreviation>]
type nativeint<[<Measure>] 'Measure> = nativeint
[<MeasureAnnotatedAbbreviation>]
type uint<[<Measure>] 'Measure> = uint
[<MeasureAnnotatedAbbreviation>]
type byte<[<Measure>] 'Measure> = byte
[<MeasureAnnotatedAbbreviation>]
type uint16<[<Measure>] 'Measure> = uint16
[<MeasureAnnotatedAbbreviation>]
type uint64<[<Measure>] 'Measure> = uint64
[<MeasureAnnotatedAbbreviation>]
type unativeint<[<Measure>] 'Measure> = unativeint
type double<[<Measure>] 'Measure> = float<'Measure>
type single<[<Measure>] 'Measure> = float32<'Measure>
type int8<[<Measure>] 'Measure> = sbyte<'Measure>
type int32<[<Measure>] 'Measure> = int<'Measure>
type uint8<[<Measure>] 'Measure> = byte<'Measure>
type uint32<[<Measure>] 'Measure> = uint<'Measure>
/// <summary>Represents a managed pointer in F# code.</summary>
type byref<'T> = (# "!0&" #)
/// <summary>Represents a managed pointer in F# code.</summary>
type byref<'T, 'Kind> = (# "!0&" #)
/// Represents the types of byrefs in F# 4.5+
module ByRefKinds =
/// Represents a byref that can be written
[<Sealed>]
type Out() = class end
/// Represents a byref that can be read
[<Sealed>]
type In() = class end
/// Represents a byref that can be both read and written
[<Sealed>]
type InOut = class end
/// <summary>Represents a in-argument or readonly managed pointer in F# code. This type should only be used with F# 4.5+.</summary>
type inref<'T> = byref<'T, ByRefKinds.In>
/// <summary>Represents a out-argument managed pointer in F# code. This type should only be used with F# 4.5+.</summary>
type outref<'T> = byref<'T, ByRefKinds.Out>
module internal BasicInlinedOperations =
let inline unboxPrim<'T>(x:obj) = (# "unbox.any !0" type ('T) x : 'T #)
let inline box (x:'T) = (# "box !0" type ('T) x : obj #)
let inline convPrim<'T1, 'T2>(x: 'T1) : 'T2 = unboxPrim<'T2> (box x)
let inline not (b:bool) = (# "ceq" b false : bool #)
let inline (=) (x:int) (y:int) = (# "ceq" x y : bool #)
let inline (<>) (x:int) (y:int) = not(# "ceq" x y : bool #)
let inline (<=) (x:int) (y:int) = not(# "cgt" x y : bool #)
let inline (>=) (x:int) (y:int) = not(# "clt" x y : bool #)
let inline (>=.) (x:int64) (y:int64) = not(# "clt" x y : bool #)
let inline (>=...) (x:char) (y:char) = not(# "clt" x y : bool #)
let inline (<=...) (x:char) (y:char) = not(# "cgt" x y : bool #)
let inline (/) (x:int) (y:int) = (# "div" x y : int #)
let inline (+) (x:int) (y:int) = (# "add" x y : int #)
let inline (+.) (x:int64) (y:int64) = (# "add" x y : int64 #)
let inline (+..) (x:uint64) (y:uint64) = (# "add" x y : uint64 #)
let inline ( *. ) (x:int64) (y:int64) = (# "mul" x y : int64 #)
let inline ( *.. ) (x:uint64) (y:uint64) = (# "mul" x y : uint64 #)
let inline (^) (x:string) (y:string) = System.String.Concat(x,y)
let inline (<<<) (x:int) (y:int) = (# "shl" x y : int #)
let inline ( * ) (x:int) (y:int) = (# "mul" x y : int #)
let inline (-) (x:int) (y:int) = (# "sub" x y : int #)
let inline (-.) (x:int64) (y:int64) = (# "sub" x y : int64 #)
let inline (-..) (x:uint64) (y:uint64) = (# "sub" x y : uint64 #)
let inline (>) (x:int) (y:int) = (# "cgt" x y : bool #)
let inline (<) (x:int) (y:int) = (# "clt" x y : bool #)
let inline ignore _ = ()
let inline intOfByte (b:byte) = (# "" b : int #)
let inline raise (e: System.Exception) = (# "throw" e : 'U #)
let inline length (x: 'T array) = (# "ldlen conv.i4" x : int #)
let inline zeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #)
let inline get (arr: 'T array) (n:int) = (# "ldelem.any !0" type ('T) arr n : 'T #)
let set (arr: 'T array) (n:int) (x:'T) = (# "stelem.any !0" type ('T) arr n x #)
let inline objEq (xobj:obj) (yobj:obj) = (# "ceq" xobj yobj : bool #)
let inline int64Eq (x:int64) (y:int64) = (# "ceq" x y : bool #)
let inline int32Eq (x:int32) (y:int32) = (# "ceq" x y : bool #)
let inline floatEq (x:float) (y:float) = (# "ceq" x y : bool #)
let inline float32Eq (x:float32) (y:float32) = (# "ceq" x y : bool #)
let inline charEq (x:char) (y:char) = (# "ceq" x y : bool #)
let inline intOrder (x:int) (y:int) = (# "cgt" x y : int #) - (# "clt" x y : int #)
let inline int64Order (x:int64) (y:int64) = (# "cgt" x y : int #) - (# "clt" x y : int #)
let inline byteOrder (x:byte) (y:byte) = (# "cgt" x y: int #) - (# "clt" x y: int #)
let inline byteEq (x:byte) (y:byte) = (# "ceq" x y : bool #)
let inline int64 (x:int) = (# "conv.i8" x : int64 #)
let inline int32 (x:int64) = (# "conv.i4" x : int32 #)
let inline typeof<'T> =
let tok = (# "ldtoken !0" type('T) : System.RuntimeTypeHandle #)
System.Type.GetTypeFromHandle(tok)
let inline typedefof<'T> =
let ty = typeof<'T>
if ty.IsGenericType then ty.GetGenericTypeDefinition() else ty
let inline sizeof<'T> =
(# "sizeof !0" type('T) : int #)
let inline unsafeDefault<'T> : 'T = (# "ilzero !0" type ('T) : 'T #)
let inline isinstPrim<'T>(x:obj) = (# "isinst !0" type ('T) x : obj #)
let inline castclassPrim<'T>(x:obj) = (# "castclass !0" type ('T) x : 'T #)
let inline notnullPrim<'T when 'T : not struct>(x:'T) = (# "ldnull cgt.un" x : bool #)
let inline iscastPrim<'T when 'T : not struct>(x:obj) = (# "isinst !0" type ('T) x : 'T #)
let inline mask (n:int) (m:int) = (# "and" n m : int #)
open BasicInlinedOperations
module TupleUtils =
// adapted from System.Tuple::CombineHashCodes
let inline opshl (x:int) (n:int) : int = (# "shl" x (mask n 31) : int #)
let inline opxor (x:int) (y:int) : int = (# "xor" x y : int32 #)
let inline combineTupleHashes (h1 : int) (h2 : int) = (opxor ((opshl h1 5) + h1) h2)
let combineTupleHashCodes (codes : int array) =
let mutable (num : int32) = codes.Length - 1
while (num > 1) do
let mutable i = 0
while ((i * 2) < (num+1)) do
let index = i * 2
let num' = index + 1
if index = num then
set codes i (get codes index)
num <- i
else
set codes i (combineTupleHashes (get codes index) (get codes num))
if num' = num then
num <- i
i <- i + 1
combineTupleHashes (get codes 0) (get codes 1)
//-------------------------------------------------------------------------
// The main aim here is to bootstrap the definition of structural hashing
// and comparison. Calls to these form part of the auto-generated
// code for each new datatype.
module LanguagePrimitives =
module (* internal *) ErrorStrings =
// inline functions cannot call GetString, so we must make these bits public
[<ValueAsStaticProperty>]
let AddressOpNotFirstClassString = SR.GetString(SR.addressOpNotFirstClass)
[<ValueAsStaticProperty>]
let NoNegateMinValueString = SR.GetString(SR.noNegateMinValue)
// needs to be public to be visible from inline function 'average' and others
[<ValueAsStaticProperty>]
let InputSequenceEmptyString = SR.GetString(SR.inputSequenceEmpty)
// needs to be public to be visible from inline function 'average' and others
[<ValueAsStaticProperty>]
let InputArrayEmptyString = SR.GetString(SR.arrayWasEmpty)
// needs to be public to be visible from inline function 'average' and others
[<ValueAsStaticProperty>]
let InputMustBeNonNegativeString = SR.GetString(SR.inputMustBeNonNegative)
module IntrinsicOperators =
//-------------------------------------------------------------------------
// Lazy and/or. Laziness added by the F# compiler.
let (&) e1 e2 = if e1 then e2 else false
let (&&) e1 e2 = if e1 then e2 else false
[<CompiledName("Or")>]
let (or) e1 e2 = if e1 then true else e2
let (||) e1 e2 = if e1 then true else e2
//-------------------------------------------------------------------------
// Address-of
// Note, "raise<'T> : exn -> 'T" is manually inlined below.
// Byref usage checks prohibit type instantiations involving byrefs.
[<NoDynamicInvocation>]
let inline (~&) (obj : 'T) : byref<'T> =
ignore obj // pretend the variable is used
let e = new System.ArgumentException(ErrorStrings.AddressOpNotFirstClassString)
(# "throw" (e :> System.Exception) : byref<'T> #)
[<NoDynamicInvocation>]
let inline (~&&) (obj : 'T) : nativeptr<'T> =
ignore obj // pretend the variable is used
let e = new System.ArgumentException(ErrorStrings.AddressOpNotFirstClassString)
(# "throw" (e :> System.Exception) : nativeptr<'T> #)
open IntrinsicOperators
module IntrinsicFunctions =
// Unboxing, type casts, type tests
type TypeNullnessSemantics = int
// CLI reference types
let TypeNullnessSemantics_NullIsExtraValue = 1
// F# types with [<UseNullAsTrueValue>]
let TypeNullnessSemantics_NullTrueValue = 2
// F# record, union, tuple, function types
let TypeNullnessSemantics_NullNotLiked = 3
// structs
let TypeNullnessSemantics_NullNever = 4
// duplicated from above since we're using integers in this section
let CompilationRepresentationFlags_PermitNull = 8
let private getTypeInfo<'T> =
if typeof<'T>.IsValueType
then TypeNullnessSemantics_NullNever else
if not (typeof<'T>.IsDefined(typeof<CompilationMappingAttribute>, false))
then TypeNullnessSemantics_NullIsExtraValue
elif Type.op_Equality (typeof<'T>, typeof<unit>) then
TypeNullnessSemantics_NullTrueValue
elif typeof<Delegate>.IsAssignableFrom(typeof<'T>) then
TypeNullnessSemantics_NullIsExtraValue
elif typeof<'T>.IsDefined(typeof<AllowNullLiteralAttribute>, false) then
TypeNullnessSemantics_NullIsExtraValue
else
let reprAttrs = typeof<'T>.GetCustomAttributes(typeof<CompilationRepresentationAttribute>, false)
if reprAttrs.Length = 0 then
TypeNullnessSemantics_NullNotLiked
else
let reprAttr = get reprAttrs 0
let reprAttr = (# "unbox.any !0" type (CompilationRepresentationAttribute) reprAttr : CompilationRepresentationAttribute #)
if (# "and" reprAttr.Flags CompilationRepresentationFlags_PermitNull : int #) = 0
then TypeNullnessSemantics_NullNotLiked
else TypeNullnessSemantics_NullTrueValue
type TypeInfo<'T>() =
// Compute an on-demand per-instantiation static field
static let info = getTypeInfo<'T>
// Publish the results of that computation
static member TypeInfo = info
// Note: cheap nullness test for generic value:
// IL_0000: ldarg.1
// IL_0001: box !TKey
// IL_0006: brtrue.s IL_000e
// worst case: nothing known about source or destination
let UnboxGeneric<'T>(source: obj) =
if notnullPrim(source) or TypeInfo<'T>.TypeInfo <> TypeNullnessSemantics_NullNotLiked then
unboxPrim<'T>(source)
else
//System.Console.WriteLine("UnboxGeneric, x = {0}, 'T = {1}", x, typeof<'T>)
raise (System.NullReferenceException())
// better: source is NOT TypeNullnessSemantics_NullNotLiked
let inline UnboxFast<'T>(source: obj) =
// assert not(TypeInfo<'T>.TypeInfo = TypeNullnessSemantics_NullNotLiked)
unboxPrim<'T>(source)
// worst case: nothing known about source or destination
let TypeTestGeneric<'T>(source: obj) =
if notnullPrim(isinstPrim<'T>(source)) then true
elif notnullPrim(source) then false
else (TypeInfo<'T>.TypeInfo = TypeNullnessSemantics_NullTrueValue)
// quick entry: source is NOT TypeNullnessSemantics_NullTrueValue
let inline TypeTestFast<'T>(source: obj) =
//assert not(TypeInfo<'T>.TypeInfo = TypeNullnessSemantics_NullTrueValue)
notnullPrim(isinstPrim<'T>(source))
let Dispose<'T when 'T :> IDisposable >(resource:'T) =
match box resource with
| null -> ()
| _ -> resource.Dispose()
let FailInit() : unit = raise (InvalidOperationException(SR.GetString(SR.checkInit)))
let FailStaticInit() : unit = raise (InvalidOperationException(SR.GetString(SR.checkStaticInit)))
let CheckThis (x : 'T when 'T : not struct) =
match box x with
| null -> raise (InvalidOperationException(SR.GetString(SR.checkInit)))
| _ -> x
let inline MakeDecimal low medium high isNegative scale = Decimal(low,medium,high,isNegative,scale)
let inline GetString (source: string) (index:int) = source.Chars(index)
let inline CreateInstance<'T when 'T : (new : unit -> 'T) >() =
(System.Activator.CreateInstance() : 'T)
let inline GetArray (source: 'T array) (index:int) = (# "ldelem.any !0" type ('T) source index : 'T #)
let inline SetArray (target: 'T array) (index:int) (value:'T) = (# "stelem.any !0" type ('T) target index value #)
let inline GetArraySub arr (start:int) (len:int) =
let len = if len < 0 then 0 else len
let dst = zeroCreate len
for i = 0 to len - 1 do
SetArray dst i (GetArray arr (start + i))
dst
let inline SetArraySub arr (start:int) (len:int) (src:_ array) =
for i = 0 to len - 1 do
SetArray arr (start+i) (GetArray src i)
let inline GetArray2D (source: 'T[,]) (index1: int) (index2: int) = (# "ldelem.multi 2 !0" type ('T) source index1 index2 : 'T #)
let inline SetArray2D (target: 'T[,]) (index1: int) (index2: int) (value: 'T) = (# "stelem.multi 2 !0" type ('T) target index1 index2 value #)
let inline GetArray2DLength1 (arr: 'T[,]) = (# "ldlen.multi 2 0" arr : int #)
let inline GetArray2DLength2 (arr: 'T[,]) = (# "ldlen.multi 2 1" arr : int #)
let inline GetArray2DLength (arr: 'T[,]) (dim: int) =
match dim with
| 0 -> GetArray2DLength1 arr
| 1 -> GetArray2DLength2 arr
| _ -> raise (System.IndexOutOfRangeException())
let inline Array2DZeroCreate (n:int) (m:int) = (# "newarr.multi 2 !0" type ('T) n m : 'T[,] #)
let inline GetArray2DSub (src: 'T[,]) src1 src2 len1 len2 =
let len1 = (if len1 < 0 then 0 else len1)
let len2 = (if len2 < 0 then 0 else len2)
let dst = Array2DZeroCreate len1 len2
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
SetArray2D dst i j (GetArray2D src (src1 + i) (src2 + j))
dst
let inline SetArray2DSub (dst: 'T[,]) src1 src2 len1 len2 src =
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
SetArray2D dst (src1+i) (src2+j) (GetArray2D src i j)
let inline GetArray3D (source: 'T[,,]) (index1: int) (index2: int) (index3: int) =
(# "ldelem.multi 3 !0" type ('T) source index1 index2 index3 : 'T #)
let inline SetArray3D (target: 'T[,,]) (index1: int) (index2: int) (index3: int) (value:'T) =
(# "stelem.multi 3 !0" type ('T) target index1 index2 index3 value #)
let inline GetArray3DLength1 (arr: 'T[,,]) = (# "ldlen.multi 3 0" arr : int #)
let inline GetArray3DLength2 (arr: 'T[,,]) = (# "ldlen.multi 3 1" arr : int #)
let inline GetArray3DLength3 (arr: 'T[,,]) = (# "ldlen.multi 3 2" arr : int #)
let inline GetArray3DLength (arr: 'T[,,]) (dim: int) =
match dim with
| 0 -> GetArray3DLength1 arr
| 1 -> GetArray3DLength2 arr
| 2 -> GetArray3DLength3 arr
| _ -> raise (System.IndexOutOfRangeException())
let inline Array3DZeroCreate (n1:int) (n2:int) (n3:int) = (# "newarr.multi 3 !0" type ('T) n1 n2 n3 : 'T[,,] #)
let inline GetArray3DSub (src: 'T[,,]) src1 src2 src3 len1 len2 len3 =
let len1 = (if len1 < 0 then 0 else len1)
let len2 = (if len2 < 0 then 0 else len2)
let len3 = (if len3 < 0 then 0 else len3)
let dst = Array3DZeroCreate len1 len2 len3
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
SetArray3D dst i j k (GetArray3D src (src1+i) (src2+j) (src3+k))
dst
let inline SetArray3DSub (dst: 'T[,,]) src1 src2 src3 len1 len2 len3 src =
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
SetArray3D dst (src1+i) (src2+j) (src3+k) (GetArray3D src i j k)
let inline GetArray4D (source: 'T[,,,]) (index1: int) (index2: int) (index3: int) (index4: int) =
(# "ldelem.multi 4 !0" type ('T) source index1 index2 index3 index4 : 'T #)
let inline SetArray4D (target: 'T[,,,]) (index1: int) (index2: int) (index3: int) (index4: int) (value:'T) =
(# "stelem.multi 4 !0" type ('T) target index1 index2 index3 index4 value #)
let inline GetArray4DLength1 (arr: 'T[,,,]) = (# "ldlen.multi 4 0" arr : int #)
let inline GetArray4DLength2 (arr: 'T[,,,]) = (# "ldlen.multi 4 1" arr : int #)
let inline GetArray4DLength3 (arr: 'T[,,,]) = (# "ldlen.multi 4 2" arr : int #)
let inline GetArray4DLength4 (arr: 'T[,,,]) = (# "ldlen.multi 4 3" arr : int #)
let inline GetArray4DLength (arr: 'T[,,,]) (dim: int) =
match dim with
| 0 -> GetArray4DLength1 arr
| 1 -> GetArray4DLength2 arr
| 2 -> GetArray4DLength3 arr
| 3 -> GetArray4DLength4 arr
| _ -> raise (System.IndexOutOfRangeException())
let inline Array4DZeroCreate (n1:int) (n2:int) (n3:int) (n4:int) = (# "newarr.multi 4 !0" type ('T) n1 n2 n3 n4 : 'T[,,,] #)
let inline GetArray4DSub (src: 'T[,,,]) src1 src2 src3 src4 len1 len2 len3 len4 =
let len1 = (if len1 < 0 then 0 else len1)
let len2 = (if len2 < 0 then 0 else len2)
let len3 = (if len3 < 0 then 0 else len3)
let len4 = (if len4 < 0 then 0 else len4)
let dst = Array4DZeroCreate len1 len2 len3 len4
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
for m = 0 to len4 - 1 do
SetArray4D dst i j k m (GetArray4D src (src1+i) (src2+j) (src3+k) (src4+m))
dst
let inline SetArray4DSub (dst: 'T[,,,]) src1 src2 src3 src4 len1 len2 len3 len4 src =
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
for m = 0 to len4 - 1 do
SetArray4D dst (src1+i) (src2+j) (src3+k) (src4+m) (GetArray4D src i j k m)
let inline anyToString nullStr x =
match box x with
| :? IFormattable as f -> f.ToString(null, CultureInfo.InvariantCulture)
| null -> nullStr
| _ -> x.ToString()
let anyToStringShowingNull x = anyToString "null" x
module HashCompare =
//-------------------------------------------------------------------------
// LanguagePrimitives.HashCompare: HASHING.
//-------------------------------------------------------------------------
let defaultHashNodes = 18
/// The implementation of IEqualityComparer, using depth-limited for hashing and PER semantics for NaN equality.
type CountLimitedHasherPER(sz:int) =
[<DefaultValue>]
val mutable nodeCount : int
member x.Fresh() =
if (System.Threading.Interlocked.CompareExchange(&(x.nodeCount), sz, 0) = 0) then
x
else
new CountLimitedHasherPER(sz)
interface IEqualityComparer
/// The implementation of IEqualityComparer, using unlimited depth for hashing and ER semantics for NaN equality.
type UnlimitedHasherER() =
interface IEqualityComparer
/// The implementation of IEqualityComparer, using unlimited depth for hashing and PER semantics for NaN equality.
type UnlimitedHasherPER() =
interface IEqualityComparer
/// The unique object for unlimited depth for hashing and ER semantics for equality.
let fsEqualityComparerUnlimitedHashingER = UnlimitedHasherER()
/// The unique object for unlimited depth for hashing and PER semantics for equality.
let fsEqualityComparerUnlimitedHashingPER = UnlimitedHasherPER()
let inline HashCombine nr x y = (x <<< 1) + y + 631 * nr
let GenericHashObjArray (iec : IEqualityComparer) (x: obj array) : int =
let len = x.Length
let mutable i = len - 1
if i > defaultHashNodes then i <- defaultHashNodes // limit the hash
let mutable acc = 0
while (i >= 0) do
// NOTE: GenericHash* call decreases nr
acc <- HashCombine i acc (iec.GetHashCode(x.GetValue(i)));
i <- i - 1
acc
// optimized case - byte arrays
let GenericHashByteArray (x: byte array) : int =
let len = length x
let mutable i = len - 1
if i > defaultHashNodes then i <- defaultHashNodes // limit the hash
let mutable acc = 0
while (i >= 0) do
acc <- HashCombine i acc (intOfByte (get x i));
i <- i - 1
acc
// optimized case - int arrays
let GenericHashInt32Array (x: int array) : int =
let len = length x
let mutable i = len - 1
if i > defaultHashNodes then i <- defaultHashNodes // limit the hash
let mutable acc = 0
while (i >= 0) do
acc <- HashCombine i acc (get x i);
i <- i - 1
acc
// optimized case - int arrays
let GenericHashInt64Array (x: int64 array) : int =
let len = length x
let mutable i = len - 1
if i > defaultHashNodes then i <- defaultHashNodes // limit the hash
let mutable acc = 0
while (i >= 0) do
acc <- HashCombine i acc (int32 (get x i));
i <- i - 1
acc
// special case - arrays do not by default have a decent structural hashing function
let GenericHashArbArray (iec : IEqualityComparer) (x: System.Array) : int =
match x.Rank with
| 1 ->
let b = x.GetLowerBound(0)
let len = x.Length
let mutable i = b + len - 1
if i > b + defaultHashNodes then i <- b + defaultHashNodes // limit the hash
let mutable acc = 0
while (i >= b) do
// NOTE: GenericHash* call decreases nr
acc <- HashCombine i acc (iec.GetHashCode(x.GetValue(i)));
i <- i - 1
acc
| _ ->
HashCombine 10 (x.GetLength(0)) (x.GetLength(1))
// Core implementation of structural hashing, corresponds to pseudo-code in the
// F# Language spec. Searches for the IStructuralHash interface, otherwise uses GetHashCode().
// Arrays are structurally hashed through a separate technique.
//
// "iec" is either fsEqualityComparerUnlimitedHashingER, fsEqualityComparerUnlimitedHashingPER or a CountLimitedHasherPER.
let rec GenericHashParamObj (iec : IEqualityComparer) (x: obj) : int =
match x with
| null -> 0
| (:? System.Array as a) ->
match a with
| :? (obj array) as oa -> GenericHashObjArray iec oa
| :? (byte array) as ba -> GenericHashByteArray ba
| :? (int array) as ba -> GenericHashInt32Array ba
| :? (int64 array) as ba -> GenericHashInt64Array ba
| _ -> GenericHashArbArray iec a