-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathFSharp2Fable.Util.fs
1558 lines (1373 loc) · 73.5 KB
/
FSharp2Fable.Util.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
namespace rec Fable.Transforms.FSharp2Fable
open System
open System.Collections.Generic
open FSharp.Compiler
open FSharp.Compiler.SourceCodeServices
open Fable
open Fable.Core
open Fable.AST
open Fable.Transforms
type FsField(name, typ: Lazy<Fable.Type>, ?isMutable, ?isStatic, ?literalValue) =
new (fi: FSharpField) =
let getFSharpFieldName (fi: FSharpField) =
let rec countConflictingCases acc (ent: FSharpEntity) (name: string) =
match TypeHelpers.getBaseEntity ent with
| None -> acc
| Some (baseClass, _) ->
let conflicts =
baseClass.FSharpFields
|> Seq.exists (fun fi -> fi.Name = name)
let acc = if conflicts then acc + 1 else acc
countConflictingCases acc baseClass name
let name = fi.Name
match fi.DeclaringEntity with
| None -> name
| Some ent when ent.IsFSharpRecord || ent.IsFSharpUnion -> name
| Some ent ->
match countConflictingCases 0 ent name with
| 0 -> name
| n -> name + "_" + (string n)
let typ = lazy TypeHelpers.makeType Map.empty fi.FieldType
FsField(getFSharpFieldName fi, typ, isMutable=fi.IsMutable, isStatic=fi.IsStatic, ?literalValue=fi.LiteralValue)
interface Fable.Field with
member _.Name = name
member _.FieldType = typ.Value
member _.LiteralValue = literalValue
member _.IsStatic = defaultArg isStatic false
member _.IsMutable = defaultArg isMutable false
type FsUnionCase(uci: FSharpUnionCase) =
/// FSharpUnionCase.CompiledName doesn't give the value of CompiledNameAttribute
/// We must check the attributes explicitly
static member CompiledName (uci: FSharpUnionCase) =
uci.Attributes
|> Helpers.tryFindAtt Atts.compiledName
|> Option.map (fun (att: FSharpAttribute) -> att.ConstructorArguments.[0] |> snd |> string)
interface Fable.UnionCase with
member _.Name = uci.Name
member _.CompiledName = FsUnionCase.CompiledName uci
member _.UnionCaseFields = uci.UnionCaseFields |> Seq.mapToList (fun x -> upcast FsField(x))
type FsAtt(att: FSharpAttribute) =
interface Fable.Attribute with
member _.Entity = FsEnt.Ref att.AttributeType
member _.ConstructorArgs = att.ConstructorArguments |> Seq.mapToList snd
type FsGenParam(gen: FSharpGenericParameter) =
interface Fable.GenericParam with
member _.Name = TypeHelpers.genParamName gen
type FsParam(p: FSharpParameter) =
interface Fable.Parameter with
member _.Name = p.Name
member _.Type = TypeHelpers.makeType Map.empty p.Type
type FsDeclaredType(ent: FSharpEntity, genArgs: IList<FSharpType>) =
interface Fable.DeclaredType with
member _.Entity = FsEnt.Ref ent
member _.GenericArgs = genArgs |> Seq.mapToList (TypeHelpers.makeType Map.empty)
type FsMemberFunctionOrValue(m: FSharpMemberOrFunctionOrValue) =
static member CurriedParameterGroups(m: FSharpMemberOrFunctionOrValue): Fable.Parameter list list =
m.CurriedParameterGroups
|> Seq.mapToList (Seq.mapToList (fun p -> upcast FsParam(p)))
static member CallMemberInfo(m: FSharpMemberOrFunctionOrValue): Fable.CallMemberInfo =
{ CurriedParameterGroups = FsMemberFunctionOrValue.CurriedParameterGroups(m)
IsInstance = m.IsInstanceMember
FullName = m.FullName
CompiledName = m.CompiledName
DeclaringEntity = m.DeclaringEntity |> Option.map (FsEnt.Ref) }
interface Fable.MemberFunctionOrValue with
member _.Attributes =
m.Attributes |> Seq.map (fun x -> FsAtt(x) :> Fable.Attribute)
// These two properties are only used for member declarations,
// setting them to false for now
member _.IsMangled = false
member _.IsEnumerator = false
member _.HasSpread = Helpers.hasParamArray m
member _.IsPublic = Helpers.isPublicMember m
// NOTE: Using memb.IsValue doesn't work for function values
// See isModuleValueForDeclarations below
member _.IsValue = m.IsValue
member _.IsInstance = m.IsInstanceMember
member _.IsMutable = m.IsMutable
member _.IsGetter = m.IsPropertyGetterMethod
member _.IsSetter = m.IsPropertySetterMethod
member _.DisplayName = Naming.removeGetSetPrefix m.DisplayName
member _.CompiledName = m.CompiledName
member _.FullName = m.FullName
member _.CurriedParameterGroups = FsMemberFunctionOrValue.CurriedParameterGroups(m)
member _.ReturnParameter = upcast FsParam(m.ReturnParameter)
member _.IsExplicitInterfaceImplementation = m.IsExplicitInterfaceImplementation
member _.ApparentEnclosingEntity = FsEnt.Ref m.ApparentEnclosingEntity
type FsEnt(ent: FSharpEntity) =
static let tryArrayFullName (ent: FSharpEntity) =
if ent.IsArrayType then
let rank =
match ent.ArrayRank with
| rank when rank > 1 -> "`" + string rank
| _ -> ""
Some("System.Array" + rank)
else None
member _.FSharpEntity = ent
static member SourcePath (ent: FSharpEntity) =
ent.DeclarationLocation.FileName
|> Path.normalizePathAndEnsureFsExtension
static member IsPublic (ent: FSharpEntity) =
not ent.Accessibility.IsPrivate
static member FullName (ent: FSharpEntity): string =
let ent = Helpers.nonAbbreviatedDefinition ent
match tryArrayFullName ent with
| Some fullName -> fullName
| None when ent.IsNamespace ->
match ent.Namespace with
| Some ns -> ns + "." + ent.CompiledName
| None -> ent.CompiledName
#if !FABLE_COMPILER
| None when ent.IsProvided ->
ent.LogicalName
#endif
| None ->
match ent.TryFullName with
| Some n -> n
| None -> ent.LogicalName
static member Ref (ent: FSharpEntity): Fable.EntityRef =
let path =
match ent.Assembly.FileName with
// When compiling with netcoreapp target, netstandard only contains redirects
// Find the actual assembly name from the entity qualified name
| Some asmPath when asmPath.EndsWith("netstandard.dll") ->
ent.QualifiedName.Split(',').[1].Trim() |> Fable.CoreAssemblyName
| Some asmPath -> Path.normalizePath asmPath |> Fable.AssemblyPath
| None -> FsEnt.SourcePath ent |> Fable.SourcePath
{ FullName = FsEnt.FullName ent
Path = path }
interface Fable.Entity with
member _.Ref = FsEnt.Ref ent
member _.DisplayName = ent.DisplayName
member _.FullName = FsEnt.FullName ent
member _.BaseType =
match TypeHelpers.getBaseEntity ent with
| Some(baseEntity, baseGenArgs) -> Some(upcast FsDeclaredType(baseEntity, baseGenArgs))
| _ -> None
member _.Attributes =
ent.Attributes |> Seq.map (fun x -> FsAtt(x) :> Fable.Attribute)
member _.MembersFunctionsAndValues =
ent.TryGetMembersFunctionsAndValues |> Seq.map (fun x ->
FsMemberFunctionOrValue(x) :> Fable.MemberFunctionOrValue)
member _.AllInterfaces =
ent.AllInterfaces |> Seq.choose (fun ifc ->
if ifc.HasTypeDefinition then
Some(upcast FsDeclaredType(ifc.TypeDefinition, ifc.GenericArguments))
else None)
member _.GenericParameters =
ent.GenericParameters |> Seq.mapToList (fun x -> FsGenParam(x) :> Fable.GenericParam)
member _.FSharpFields =
ent.FSharpFields |> Seq.mapToList (fun x -> FsField(x) :> Fable.Field)
member _.UnionCases =
ent.UnionCases |> Seq.mapToList (fun x -> FsUnionCase(x) :> Fable.UnionCase)
member _.IsPublic = FsEnt.IsPublic ent
member _.IsFSharpUnion = ent.IsFSharpUnion
member _.IsFSharpRecord = ent.IsFSharpRecord
member _.IsFSharpExceptionDeclaration = ent.IsFSharpExceptionDeclaration
member _.IsValueType = ent.IsValueType
member _.IsInterface = ent.IsInterface
type MemberInfo(?attributes: FSharpAttribute seq,
?hasSpread: bool,
?isPublic: bool,
?isInstance: bool,
?isValue: bool,
?isMutable: bool,
?isGetter: bool,
?isSetter: bool,
?isEnumerator: bool,
?isMangled: bool) =
interface Fable.MemberInfo with
member _.Attributes =
match attributes with
| Some atts -> atts |> Seq.map (fun x -> FsAtt(x) :> Fable.Attribute)
| None -> upcast []
member _.HasSpread = defaultArg hasSpread false
member _.IsPublic = defaultArg isPublic true
member _.IsInstance = defaultArg isInstance true
member _.IsValue = defaultArg isValue false
member _.IsMutable = defaultArg isMutable false
member _.IsGetter = defaultArg isGetter false
member _.IsSetter = defaultArg isSetter false
member _.IsEnumerator = defaultArg isEnumerator false
member _.IsMangled = defaultArg isMangled false
type Witness =
{ TraitName: string
IsInstance: bool
Expr: Fable.Expr }
member this.ArgTypes =
match this.Expr with
| Fable.Delegate(args,_,_) -> args |> List.map (fun a -> a.Type)
| _ -> []
type Context =
{ Scope: (FSharpMemberOrFunctionOrValue * Fable.Ident * Fable.Expr option) list
ScopeInlineValues: (FSharpMemberOrFunctionOrValue * FSharpExpr) list
UsedNamesInRootScope: Set<string>
UseNamesInDeclarationScope: HashSet<string>
GenericArgs: Map<string, Fable.Type>
EnclosingMember: FSharpMemberOrFunctionOrValue option
InlinedFunction: FSharpMemberOrFunctionOrValue option
CaughtException: Fable.Ident option
BoundConstructorThis: Fable.Ident option
BoundMemberThis: Fable.Ident option
InlinePath: Log.InlinePath list
CaptureBaseConsCall: (FSharpEntity * (Fable.Expr -> unit)) option
Witnesses: Witness list
}
static member Create(usedRootNames) =
{ Scope = []
ScopeInlineValues = []
UsedNamesInRootScope = usedRootNames
UseNamesInDeclarationScope = Unchecked.defaultof<_>
GenericArgs = Map.empty
EnclosingMember = None
InlinedFunction = None
CaughtException = None
BoundConstructorThis = None
BoundMemberThis = None
InlinePath = []
CaptureBaseConsCall = None
Witnesses = []
}
type IFableCompiler =
inherit Compiler
abstract Transform: Context * FSharpExpr -> Fable.Expr
abstract TryReplace: Context * SourceLocation option * Fable.Type *
info: Fable.ReplaceCallInfo * thisArg: Fable.Expr option * args: Fable.Expr list -> Fable.Expr option
abstract InjectArgument: Context * SourceLocation option *
genArgs: ((string * Fable.Type) list) * FSharpParameter -> Fable.Expr
abstract GetInlineExpr: FSharpMemberOrFunctionOrValue -> InlineExpr
module Helpers =
let rec nonAbbreviatedDefinition (ent: FSharpEntity): FSharpEntity =
if ent.IsFSharpAbbreviation then
let t = ent.AbbreviatedType
if t.HasTypeDefinition then nonAbbreviatedDefinition t.TypeDefinition
else ent
else ent
let rec nonAbbreviatedType (t: FSharpType): FSharpType =
let isSameType (t1: FSharpType) (t2: FSharpType) =
t1.HasTypeDefinition && t2.HasTypeDefinition && (t1.TypeDefinition = t2.TypeDefinition)
if t.IsAbbreviation && not (isSameType t t.AbbreviatedType) then
nonAbbreviatedType t.AbbreviatedType
// TODO!!! Do we still need to make a special check for units of measure
// or can we just hardcode the names? We may need to do it anyway to fix #1962
elif t.HasTypeDefinition then
let abbr = t.AbbreviatedType
// .IsAbbreviation doesn't eval to true for generic numbers
// See https://github.com/Microsoft/visualfsharp/issues/5992
if t.GenericArguments.Count = abbr.GenericArguments.Count then t
else abbr
else t
let getGenericArguments (t: FSharpType) =
// Accessing .GenericArguments for a generic parameter will fail
if t.IsGenericParameter
then [||] :> IList<_>
else (nonAbbreviatedType t).GenericArguments
let private getEntityMangledName (com: Compiler) trimRootModule (ent: Fable.EntityRef) =
let fullName = ent.FullName
match trimRootModule, ent.SourcePath with
| true, Some sourcePath ->
let rootMod = com.GetRootModule(sourcePath)
if fullName.StartsWith(rootMod) then
fullName.Substring(rootMod.Length).TrimStart('.')
else fullName
| _ -> fullName
let cleanNameAsJsIdentifier (name: string) =
if name = ".ctor" then "$ctor"
else name.Replace('.','_').Replace('`','$')
let getEntityDeclarationName (com: Compiler) (ent: Fable.EntityRef) =
let entityName = getEntityMangledName com true ent |> cleanNameAsJsIdentifier
(entityName, Naming.NoMemberPart)
||> Naming.sanitizeIdent (fun _ -> false)
let private getMemberMangledName (com: Compiler) trimRootModule (memb: FSharpMemberOrFunctionOrValue) =
if memb.IsExtensionMember then
let overloadSuffix = OverloadSuffix.getExtensionHash memb
let entName = FsEnt.Ref memb.ApparentEnclosingEntity |> getEntityMangledName com false
entName, Naming.InstanceMemberPart(memb.CompiledName, overloadSuffix)
else
match memb.DeclaringEntity with
| Some ent ->
let entFullName = FsEnt.Ref ent
if ent.IsFSharpModule then
match getEntityMangledName com trimRootModule entFullName with
| "" -> memb.CompiledName, Naming.NoMemberPart
| moduleName -> moduleName, Naming.StaticMemberPart(memb.CompiledName, "")
else
let overloadSuffix = OverloadSuffix.getHash ent memb
let entName = getEntityMangledName com trimRootModule entFullName
if memb.IsInstanceMember
then entName, Naming.InstanceMemberPart(memb.CompiledName, overloadSuffix)
else entName, Naming.StaticMemberPart(memb.CompiledName, overloadSuffix)
| None -> memb.CompiledName, Naming.NoMemberPart
/// Returns the sanitized name for the member declaration and whether it has an overload suffix
let getMemberDeclarationName (com: Compiler) (memb: FSharpMemberOrFunctionOrValue) =
let name, part = getMemberMangledName com true memb
let name = cleanNameAsJsIdentifier name
let part = part.Replace(cleanNameAsJsIdentifier)
let sanitizedName = Naming.sanitizeIdent (fun _ -> false) name part
sanitizedName, not(String.IsNullOrEmpty(part.OverloadSuffix))
/// Used to identify members uniquely in the inline expressions dictionary
let getMemberUniqueName (com: Compiler) (memb: FSharpMemberOrFunctionOrValue): string =
getMemberMangledName com false memb
||> Naming.buildNameWithoutSanitation
let getMemberDisplayName (memb: FSharpMemberOrFunctionOrValue) =
Naming.removeGetSetPrefix memb.DisplayName
let isUsedName (ctx: Context) name =
ctx.UsedNamesInRootScope.Contains name || ctx.UseNamesInDeclarationScope.Contains name
let getIdentUniqueName (ctx: Context) name =
let name = (name, Naming.NoMemberPart) ||> Naming.sanitizeIdent (isUsedName ctx)
ctx.UseNamesInDeclarationScope.Add(name) |> ignore
name
let isUnit (typ: FSharpType) =
let typ = nonAbbreviatedType typ
if typ.HasTypeDefinition then
typ.TypeDefinition.TryFullName = Some Types.unit
else false
let tryFindAtt fullName (atts: FSharpAttribute seq) =
atts |> Seq.tryPick (fun att ->
match (nonAbbreviatedDefinition att.AttributeType).TryFullName with
| Some fullName' ->
if fullName = fullName' then Some att else None
| None -> None)
let hasAttribute attFullName (attributes: FSharpAttribute seq) =
let mutable found = false
let attFullName = Some attFullName
for att in attributes do
if not found then
found <- (nonAbbreviatedDefinition att.AttributeType).TryFullName = attFullName
found
let tryPickAttribute attFullNames (attributes: FSharpAttribute seq) =
let attFullNames = Map attFullNames
attributes |> Seq.tryPick (fun att ->
match (nonAbbreviatedDefinition att.AttributeType).TryFullName with
| Some fullName -> Map.tryFind fullName attFullNames
| None -> None)
let tryAttributeConsArg (att: FSharpAttribute) index (defValue: 'T) (f: obj -> 'T option) =
let consArgs = att.ConstructorArguments
if consArgs.Count <= index then defValue
else
consArgs.[index] |> snd |> f
|> Option.defaultValue defValue
let tryBoolean: obj -> bool option = function (:? bool as x) -> Some x | _ -> None
let tryString: obj -> string option = function (:? string as x) -> Some x | _ -> None
let tryDefinition (typ: FSharpType) =
let typ = nonAbbreviatedType typ
if typ.HasTypeDefinition then
let tdef = typ.TypeDefinition
Some(tdef, tdef.TryFullName)
else None
let getFsTypeFullName (typ: FSharpType) =
match tryDefinition typ with
| Some(_, Some fullName) -> fullName
| _ -> Naming.unknown
let isInline (memb: FSharpMemberOrFunctionOrValue) =
match memb.InlineAnnotation with
| FSharpInlineAnnotation.NeverInline
// TODO: Add compiler option to inline also `OptionalInline`
| FSharpInlineAnnotation.OptionalInline -> false
| FSharpInlineAnnotation.PseudoValue
| FSharpInlineAnnotation.AlwaysInline
| FSharpInlineAnnotation.AggressiveInline -> true
let isPublicMember (memb: FSharpMemberOrFunctionOrValue) =
if memb.IsCompilerGenerated
then false
else not memb.Accessibility.IsPrivate
let makeRange (r: Range.range) =
{ start = { line = r.StartLine; column = r.StartColumn }
``end``= { line = r.EndLine; column = r.EndColumn }
identifierName = None }
let makeRangeFrom (fsExpr: FSharpExpr) =
Some (makeRange fsExpr.Range)
let unionCaseTag (ent: FSharpEntity) (unionCase: FSharpUnionCase) =
try
ent.UnionCases |> Seq.findIndex (fun uci -> unionCase.Name = uci.Name)
with _ ->
failwithf "Cannot find case %s in %s" unionCase.Name (FsEnt.FullName ent)
/// Apply case rules to case name if there's no explicit compiled name
let transformStringEnum (rule: CaseRules) (unionCase: FSharpUnionCase) =
match FsUnionCase.CompiledName unionCase with
| Some name -> name
| None -> Naming.applyCaseRule rule unionCase.Name
|> makeStrConst
// let isModuleMember (memb: FSharpMemberOrFunctionOrValue) =
// match memb.DeclaringEntity with
// | Some ent -> ent.IsFSharpModule
// | None -> true // Compiler-generated members
/// Using memb.IsValue doesn't work for function values
/// (e.g. `let ADD = adder()` when adder returns a function)
let isModuleValueForDeclarations (memb: FSharpMemberOrFunctionOrValue) =
memb.CurriedParameterGroups.Count = 0 && memb.GenericParameters.Count = 0
let isModuleValueForCalls (declaringEntity: FSharpEntity) (memb: FSharpMemberOrFunctionOrValue) =
declaringEntity.IsFSharpModule
&& isModuleValueForDeclarations memb
// Mutable public values must be called as functions (see #986)
&& (not memb.IsMutable || not (isPublicMember memb))
let rec getAllInterfaceMembers (ent: FSharpEntity) =
seq {
yield! ent.MembersFunctionsAndValues
for parent in ent.DeclaredInterfaces do
match tryDefinition parent with
| Some(e, _) -> yield! getAllInterfaceMembers e
| None -> ()
}
/// Test if the name corresponds to this interface or anyone in its hierarchy
let rec testInterfaceHierarchy interfaceFullname interfaceType =
match tryDefinition interfaceType with
| Some(e, Some fullname2) ->
if interfaceFullname = fullname2
then true
else e.DeclaredInterfaces
|> Seq.exists (testInterfaceHierarchy interfaceFullname)
| _ -> false
let hasParamArray (memb: FSharpMemberOrFunctionOrValue) =
let hasParamArray (memb: FSharpMemberOrFunctionOrValue) =
if memb.CurriedParameterGroups.Count <> 1 then false else
let args = memb.CurriedParameterGroups.[0]
args.Count > 0 && args.[args.Count - 1].IsParamArrayArg
let hasParamSeq (memb: FSharpMemberOrFunctionOrValue) =
Seq.tryLast memb.CurriedParameterGroups
|> Option.bind Seq.tryLast
|> Option.map (fun lastParam -> hasAttribute "Fable.Core.ParamListAttribute" lastParam.Attributes)
|> Option.defaultValue false
hasParamArray memb || hasParamSeq memb
module Patterns =
open BasicPatterns
open Helpers
let inline (|Rev|) x = List.rev x
let inline (|AsArray|) x = Array.ofSeq x
let inline (|LazyValue|) (x: Lazy<'T>) = x.Value
let inline (|Transform|) (com: IFableCompiler) ctx e = com.Transform(ctx, e)
let inline (|FieldName|) (fi: FSharpField) = fi.Name
let (|CommonNamespace|_|) = function
| (FSharpImplementationFileDeclaration.Entity(ent, subDecls))::restDecls
when ent.IsNamespace ->
let commonName = ent.CompiledName
(Some subDecls, restDecls) ||> List.fold (fun acc decl ->
match acc, decl with
| (Some subDecls), (FSharpImplementationFileDeclaration.Entity(ent, subDecls2)) ->
if ent.CompiledName = commonName
then Some(subDecls@subDecls2)
else None
| _ -> None)
|> Option.map (fun subDecls -> ent, subDecls)
| _ -> None
let inline (|NonAbbreviatedType|) (t: FSharpType) =
nonAbbreviatedType t
let (|TypeDefinition|_|) (NonAbbreviatedType t) =
if t.HasTypeDefinition then Some t.TypeDefinition else None
/// DOES NOT check if the type is abbreviated, mainly intended to identify Fable.Core.Applicable
let (|FSharpExprTypeFullName|_|) (e: FSharpExpr) =
let t = e.Type
if t.HasTypeDefinition then t.TypeDefinition.TryFullName else None
let (|MemberFullName|) (memb: FSharpMemberOrFunctionOrValue) =
memb.FullName
let (|RefType|_|) = function
| TypeDefinition tdef as t when tdef.TryFullName = Some Types.reference -> Some t
| _ -> None
/// Detects AST pattern of "raise MatchFailureException()"
let (|RaisingMatchFailureExpr|_|) (expr: FSharpExpr) =
match expr with
| Call(None, methodInfo, [ ], [_unitType], [value]) ->
match methodInfo.FullName with
| "Microsoft.FSharp.Core.Operators.raise" ->
match value with
| NewRecord(recordType, [Const (value, _valueT) ; _rangeFrom; _rangeTo]) ->
match recordType.TypeDefinition.TryFullName with
| Some "Microsoft.FSharp.Core.MatchFailureException" -> Some (value.ToString())
| _ -> None
| _ -> None
| _ -> None
| _ -> None
let (|NestedLambda|_|) x =
let rec nestedLambda args = function
| Lambda(arg, body) -> nestedLambda (arg::args) body
| body -> List.rev args, body
match x with
| Lambda(arg, body) -> nestedLambda [arg] body |> Some
| _ -> None
let (|ForOf|_|) = function
| Let((_, value), // Coercion to seq
Let((_, Call(None, meth, _, [], [])),
TryFinally(
WhileLoop(_,
Let((ident, _), body)), _)))
| Let((_, Call(Some value, meth, _, [], [])),
TryFinally(
WhileLoop(_,
Let((ident, _), body)), _))
// Using only the compiled name is riskier but with the fullname we miss some cases
// TODO: Check the return type of meth is or implements IEnumerator
when meth.CompiledName = "GetEnumerator" ->
// when meth.FullName = "System.Collections.Generic.IEnumerable.GetEnumerator" ->
Some(ident, value, body)
// optimized "for x in list"
| Let((_, UnionCaseGet(value, typ, unionCase, field)),
WhileLoop(_, Let((ident, _), body)))
when (getFsTypeFullName typ) = Types.list
&& unionCase.Name = "op_ColonColon" && field.Name = "Tail" ->
Some (ident, value, body)
// optimized "for _x in list"
| Let((ident, UnionCaseGet(value, typ, unionCase, field)),
WhileLoop(_, body))
when (getFsTypeFullName typ) = Types.list
&& unionCase.Name = "op_ColonColon" && field.Name = "Tail" ->
Some (ident, value, body)
| _ -> None
/// This matches the boilerplate generated for TryGetValue/TryParse/DivRem (see #154, or #1744)
/// where the F# compiler automatically passes a byref arg and returns it as a tuple
let (|ByrefArgToTuple|_|) = function
| Let((outArg1, (DefaultValue _ as def)),
NewTuple(_, [Call(callee, memb, ownerGenArgs, membGenArgs, callArgs); Value outArg3]))
when List.isMultiple callArgs && outArg1.IsCompilerGenerated && outArg1 = outArg3 ->
match List.splitLast callArgs with
| callArgs, AddressOf(Value outArg2) when outArg1 = outArg2 ->
Some (callee, memb, ownerGenArgs, membGenArgs, callArgs@[def])
| _ -> None
| _ -> None
/// This matches the boilerplate generated for TryGetValue/TryParse/DivRem (--optimize+)
let (|ByrefArgToTupleOptimizedIf|_|) = function
| Let((outArg1, (DefaultValue _ as def)), IfThenElse
(Call(callee, memb, ownerGenArgs, membGenArgs, callArgs), thenExpr, elseExpr))
when List.isMultiple callArgs && outArg1.IsCompilerGenerated ->
match List.splitLast callArgs with
| callArgs, AddressOf(Value outArg2) when outArg1 = outArg2 ->
Some (outArg1, callee, memb, ownerGenArgs, membGenArgs, callArgs@[def], thenExpr, elseExpr)
| _ -> None
| _ -> None
/// This matches another boilerplate generated for TryGetValue/TryParse/DivRem (--optimize+)
let (|ByrefArgToTupleOptimizedTree|_|) = function
| Let((outArg1, (DefaultValue _ as def)), DecisionTree(IfThenElse
(Call(callee, memb, ownerGenArgs, membGenArgs, callArgs), thenExpr, elseExpr), targetsExpr))
when List.isMultiple callArgs && outArg1.IsCompilerGenerated ->
match List.splitLast callArgs with
| callArgs, AddressOf(Value outArg2) when outArg1 = outArg2 ->
Some (outArg1, callee, memb, ownerGenArgs, membGenArgs, callArgs@[def], thenExpr, elseExpr, targetsExpr)
| _ -> None
| _ -> None
/// This matches another boilerplate generated for TryGetValue/TryParse/DivRem (--crossoptimize-)
let (|ByrefArgToTupleOptimizedLet|_|) = function
| Let((outArg1, (DefaultValue _ as def)),
Let((arg_0, Call(callee, memb, ownerGenArgs, membGenArgs, callArgs)), restExpr))
when List.isMultiple callArgs && outArg1.IsCompilerGenerated ->
match List.splitLast callArgs with
| callArgs, AddressOf(Value outArg2) when outArg1 = outArg2 ->
Some (arg_0, outArg1, callee, memb, ownerGenArgs, membGenArgs, callArgs@[def], restExpr)
| _ -> None
| _ -> None
/// This matches the boilerplate generated to wrap .NET events from F#
let (|CreateEvent|_|) = function
| Call(None,createEvent,_,_,
[Lambda(_eventDelegate, Call(Some callee, addEvent,[],[],[Value _eventDelegate']));
Lambda(_eventDelegate2, Call(Some _callee2, _removeEvent,[],[],[Value _eventDelegate2']));
Lambda(_callback, NewDelegate(_, Lambda(_delegateArg0, Lambda(_delegateArg1, Application(Value _callback',[],[Value _delegateArg0'; Value _delegateArg1'])))))])
when createEvent.FullName = Types.createEvent ->
let eventName = addEvent.CompiledName.Replace("add_","")
Some (callee, eventName)
| _ -> None
let (|ConstructorCall|_|) = function
| NewObject(baseCall, genArgs, baseArgs) -> Some(baseCall, genArgs, baseArgs)
| Call(None, baseCall, genArgs1, genArgs2, baseArgs) when baseCall.IsConstructor ->
Some(baseCall, genArgs1 @ genArgs2, baseArgs)
| _ -> None
let (|OptimizedOperator|_|) (com: Compiler) fsExpr =
if com.Options.OptimizeFSharpAst then
match fsExpr with
// work-around for optimized string operator (Operators.string)
| Let((var, Call(None, memb, _, membArgTypes, membArgs)),
DecisionTree(IfThenElse(_, _, IfThenElse
(TypeTest(tt, Value vv), _, _)), _))
when var.FullName = "matchValue" && memb.FullName = "Microsoft.FSharp.Core.Operators.box"
&& vv.FullName = "matchValue" && (getFsTypeFullName tt) = "System.IFormattable" ->
Some(memb, None, "toString", membArgTypes, membArgs)
// work-around for optimized hash operator (Operators.hash)
| Call(Some expr, memb, _, [], [Call(None, comp, [], [], [])])
when memb.FullName.EndsWith(".GetHashCode") &&
comp.FullName = "Microsoft.FSharp.Core.LanguagePrimitives.GenericEqualityERComparer" ->
Some(memb, Some comp, "GenericHash", [expr.Type], [expr])
// work-around for optimized equality operator (Operators.(=))
| Call(Some e1, memb, _, [], [Coerce (t2, e2); Call(None, comp, [], [], [])])
when memb.FullName.EndsWith(".Equals") && t2.HasTypeDefinition && t2.TypeDefinition.CompiledName = "obj" &&
comp.FullName = "Microsoft.FSharp.Core.LanguagePrimitives.GenericEqualityComparer" ->
Some(memb, Some comp, "GenericEquality", [e1.Type; e2.Type], [e1; e2])
| _ -> None
else None
let (|OptionUnion|ListUnion|ErasedUnion|ErasedUnionCase|StringEnum|DiscriminatedUnion|)
(NonAbbreviatedType typ: FSharpType, unionCase: FSharpUnionCase) =
let getCaseRule (att: FSharpAttribute) =
match Seq.tryHead att.ConstructorArguments with
| Some(_, (:? int as rule)) -> enum<CaseRules>(rule)
| _ -> CaseRules.LowerFirst
unionCase.Attributes |> Seq.tryPick (fun att ->
match att.AttributeType.TryFullName with
| Some Atts.erase -> Some ErasedUnionCase
| _ -> None)
|> Option.defaultWith (fun () ->
match tryDefinition typ with
| None -> failwith "Union without definition"
| Some(tdef, fullName) ->
match defaultArg fullName tdef.CompiledName with
| Types.valueOption
| Types.option -> OptionUnion typ.GenericArguments.[0]
| Types.list -> ListUnion typ.GenericArguments.[0]
| _ ->
tdef.Attributes |> Seq.tryPick (fun att ->
match att.AttributeType.TryFullName with
| Some Atts.erase -> Some (ErasedUnion(tdef, typ.GenericArguments, getCaseRule att))
| Some Atts.stringEnum -> Some (StringEnum(tdef, getCaseRule att))
| _ -> None)
|> Option.defaultValue (DiscriminatedUnion(tdef, typ.GenericArguments))
)
let (|ContainsAtt|_|) (fullName: string) (ent: FSharpEntity) =
tryFindAtt fullName ent.Attributes
module TypeHelpers =
open Helpers
open Patterns
// Sometimes the names of user-declared and compiler-generated clash, see #1900
let genParamName (genParam: FSharpGenericParameter) =
if genParam.IsCompilerGenerated
then genParam.Name.Replace("?", "$") + "$"
else genParam.Name
let resolveGenParam ctxTypeArgs (genParam: FSharpGenericParameter) =
let name = genParamName genParam
match Map.tryFind name ctxTypeArgs with
| None -> Fable.GenericParam name
| Some typ -> typ
let makeGenArgs ctxTypeArgs (genArgs: IList<FSharpType>) =
genArgs |> Seq.map (fun genArg ->
if genArg.IsGenericParameter
then resolveGenParam ctxTypeArgs genArg.GenericParameter
else makeType ctxTypeArgs genArg)
|> Seq.toList
let makeTypeFromDelegate ctxTypeArgs (genArgs: IList<FSharpType>) (tdef: FSharpEntity) =
let argTypes, returnType =
try
tdef.FSharpDelegateSignature.DelegateArguments |> Seq.map snd,
tdef.FSharpDelegateSignature.DelegateReturnType
with _ -> // tdef.FSharpDelegateSignature doesn't work with System.Func & friends
let invokeMember =
tdef.MembersFunctionsAndValues
|> Seq.find (fun f -> f.DisplayName = "Invoke")
invokeMember.CurriedParameterGroups.[0] |> Seq.map (fun p -> p.Type),
invokeMember.ReturnParameter.Type
let genArgs = Seq.zip (tdef.GenericParameters |> Seq.map genParamName) genArgs |> Map
let resolveType (t: FSharpType) =
if t.IsGenericParameter then Map.find (genParamName t.GenericParameter) genArgs else t
let argTypes = argTypes |> Seq.map (resolveType >> makeType ctxTypeArgs) |> Seq.toList
let returnType = returnType |> resolveType |> makeType ctxTypeArgs
Fable.DelegateType(argTypes, returnType)
let numberTypes =
dict [Types.int8, Int8
Types.uint8, UInt8
Types.int16, Int16
Types.uint16, UInt16
Types.int32, Int32
Types.uint32 , UInt32
Types.float32, Float32
Types.float64, Float64
// Units of measure
"Microsoft.FSharp.Core.sbyte`1", Int8
"Microsoft.FSharp.Core.int16`1", Int16
"Microsoft.FSharp.Core.int`1", Int32
"Microsoft.FSharp.Core.float32`1", Float32
"Microsoft.FSharp.Core.float`1", Float64]
let fsharpUMX =
dict ["bool`1", Choice1Of2 Fable.Boolean
"byte`1", Choice1Of2 (Fable.Number UInt8)
"string`1", Choice1Of2 Fable.String
"uint64`1", Choice2Of2("System.Runtime", Types.uint64)
"Guid`1", Choice2Of2("System.Runtime", Types.guid)
"TimeSpan`1", Choice2Of2("System.Runtime", Types.timespan)
"DateTime`1", Choice2Of2("System.Runtime", Types.datetime)
"DateTimeOffset`1", Choice2Of2("System.Runtime", Types.datetimeOffset)]
let makeTypeFromDef ctxTypeArgs (genArgs: IList<FSharpType>) (tdef: FSharpEntity) =
if tdef.IsArrayType then
makeGenArgs ctxTypeArgs genArgs |> List.head |> Fable.Array
elif tdef.IsDelegate then
makeTypeFromDelegate ctxTypeArgs genArgs tdef
elif tdef.IsEnum then
Fable.Enum(FsEnt.Ref tdef)
else
match FsEnt.FullName tdef with
// Fable "primitives"
| Types.object -> Fable.Any
| Types.unit -> Fable.Unit
| Types.bool -> Fable.Boolean
| Types.char -> Fable.Char
| Types.string -> Fable.String
| Types.regex -> Fable.Regex
| Types.type_ -> Fable.MetaType
| Types.valueOption
| Types.option -> makeGenArgs ctxTypeArgs genArgs |> List.head |> Fable.Option
| Types.resizeArray -> makeGenArgs ctxTypeArgs genArgs |> List.head |> Fable.Array
| Types.list -> makeGenArgs ctxTypeArgs genArgs |> List.head |> Fable.List
| DicContains numberTypes kind -> Fable.Number kind
// TODO: FCS doesn't expose the abbreviated type of a MeasureAnnotatedAbbreviation,
// so we need to hard-cde FSharp.UMX types
| Naming.StartsWith "FSharp.UMX." (DicContains fsharpUMX choice) ->
match choice with
| Choice1Of2 t -> t
| Choice2Of2(dllName, fullName) ->
let r: Fable.EntityRef =
{ FullName = fullName
Path = Fable.CoreAssemblyName dllName }
Fable.DeclaredType(r, [])
| _ ->
// Special attributes
tdef.Attributes |> tryPickAttribute [
Atts.stringEnum, Fable.String
Atts.erase, Fable.Any
]
// Rest of declared types
|> Option.defaultWith (fun () ->
Fable.DeclaredType(FsEnt.Ref tdef, makeGenArgs ctxTypeArgs genArgs))
let rec makeType (ctxTypeArgs: Map<string, Fable.Type>) (NonAbbreviatedType t) =
// Generic parameter (try to resolve for inline functions)
if t.IsGenericParameter then
resolveGenParam ctxTypeArgs t.GenericParameter
// Tuple
elif t.IsTupleType then
makeGenArgs ctxTypeArgs t.GenericArguments |> Fable.Tuple
// Function
elif t.IsFunctionType then
let argType = makeType ctxTypeArgs t.GenericArguments.[0]
let returnType = makeType ctxTypeArgs t.GenericArguments.[1]
Fable.LambdaType(argType, returnType)
elif t.IsAnonRecordType then
let genArgs = makeGenArgs ctxTypeArgs t.GenericArguments
Fable.AnonymousRecordType(t.AnonRecordTypeDetails.SortedFieldNames, genArgs)
elif t.HasTypeDefinition then
// No support for provided types when compiling FCS+Fable to JS
#if !FABLE_COMPILER
// TODO: Discard provided generated types too?
if t.TypeDefinition.IsProvidedAndErased then Fable.Any
else
#endif
makeTypeFromDef ctxTypeArgs t.GenericArguments t.TypeDefinition
else Fable.Any // failwithf "Unexpected non-declared F# type: %A" t
let getBaseEntity (tdef: FSharpEntity): (FSharpEntity * IList<FSharpType>) option =
match tdef.BaseType with
| Some(TypeDefinition baseEnt as baseType) when baseEnt.TryFullName <> Some Types.object ->
Some(baseEnt, baseType.GenericArguments)
| _ -> None
let rec getOwnAndInheritedFsharpMembers (tdef: FSharpEntity) = seq {
yield! tdef.TryGetMembersFunctionsAndValues
match getBaseEntity tdef with
| Some(baseDef, _) -> yield! getOwnAndInheritedFsharpMembers baseDef
| _ -> ()
}
let getArgTypes _com (memb: FSharpMemberOrFunctionOrValue) =
// FSharpParameters don't contain the `this` arg
Seq.concat memb.CurriedParameterGroups
// The F# compiler "untuples" the args in methods
|> Seq.map (fun x -> makeType Map.empty x.Type)
|> Seq.toList
let isAbstract (ent: FSharpEntity) =
hasAttribute Atts.abstractClass ent.Attributes
let tryGetInterfaceTypeFromMethod (meth: FSharpMemberOrFunctionOrValue) =
if meth.ImplementedAbstractSignatures.Count > 0
then nonAbbreviatedType meth.ImplementedAbstractSignatures.[0].DeclaringType |> Some
else None
let tryGetInterfaceDefinitionFromMethod (meth: FSharpMemberOrFunctionOrValue) =
if meth.ImplementedAbstractSignatures.Count > 0 then
let t = nonAbbreviatedType meth.ImplementedAbstractSignatures.[0].DeclaringType
if t.HasTypeDefinition then Some t.TypeDefinition else None
else None
let tryFindMember _com (entity: Fable.Entity) genArgs compiledName isInstance (argTypes: Fable.Type list) =
let argsEqual (args1: Fable.Type list) args1Length (args2: IList<IList<FSharpParameter>>) =
let args2Length = args2 |> Seq.sumBy (fun g -> g.Count)
if args1Length = args2Length then
let args2 =
args2
|> Seq.collect (fun g ->
g |> Seq.map (fun p -> makeType genArgs p.Type) |> Seq.toList)
listEquals (typeEquals false) args1 (Seq.toList args2)
else false
match entity with
| :? FsEnt as entity ->
let argTypesLength = List.length argTypes
getOwnAndInheritedFsharpMembers entity.FSharpEntity |> Seq.tryFind (fun m2 ->
if m2.IsInstanceMember = isInstance && m2.CompiledName = compiledName
then argsEqual argTypes argTypesLength m2.CurriedParameterGroups
else false)
| _ -> None
let fitsAnonRecordInInterface _com (argExprs: Fable.Expr list) fieldNames (interface_: Fable.Entity) =
match interface_ with
| :? FsEnt as fsEnt ->
let interface_ = fsEnt.FSharpEntity
// TODO: Check also if there are extra fields in the record not present in the interface?
(Ok (), getAllInterfaceMembers interface_ |> Seq.filter (fun memb -> memb.IsPropertyGetterMethod))
||> Seq.fold (fun res memb ->
match res with
| Error _ -> res
| Ok _ ->
let expectedType = memb.ReturnParameter.Type |> makeType Map.empty
Array.tryFindIndex ((=) memb.DisplayName) fieldNames
|> function
| None ->
match expectedType with
| Fable.Option _ -> Ok () // Optional fields can be missing
| _ -> sprintf "Object doesn't contain field '%s'" memb.DisplayName |> Error
| Some i ->
let e = List.item i argExprs
match expectedType, e.Type with
| Fable.Any, _ -> true
| Fable.Option t1, Fable.Option t2
| Fable.Option t1, t2
| t1, t2 -> typeEquals false t1 t2
|> function
| true -> Ok ()
| false ->
let typeName = getTypeFullName true expectedType
sprintf "Expecting type '%s' for field '%s'" typeName memb.DisplayName |> Error)
| _ -> Ok () // TODO: Error instead if we cannot check the interface?
let inline (|FableType|) _com (ctx: Context) t = makeType ctx.GenericArgs t
module Identifiers =
open Helpers
open TypeHelpers
let putIdentInScope (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue) (ident: Fable.Ident) value =
{ ctx with Scope = (fsRef, ident, value)::ctx.Scope}
let makeIdentFrom (_com: IFableCompiler) (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue): Fable.Ident =
let sanitizedName = (fsRef.CompiledName, Naming.NoMemberPart)
||> Naming.sanitizeIdent (isUsedName ctx)
ctx.UseNamesInDeclarationScope.Add(sanitizedName) |> ignore
{ Name = sanitizedName
Type = makeType ctx.GenericArgs fsRef.FullType
IsThisArgument = false
IsCompilerGenerated = fsRef.IsCompilerGenerated
IsMutable = fsRef.IsMutable
Range = { makeRange fsRef.DeclarationLocation
with identifierName = Some fsRef.DisplayName } |> Some }
let putArgInScope com ctx (fsRef: FSharpMemberOrFunctionOrValue): Context*Fable.Ident =
let ident = makeIdentFrom com ctx fsRef
putIdentInScope ctx fsRef ident None, ident
let (|PutArgInScope|) com ctx fsRef = putArgInScope com ctx fsRef
let putBindingInScope com ctx (fsRef: FSharpMemberOrFunctionOrValue) value: Context*Fable.Ident =
let ident = makeIdentFrom com ctx fsRef
putIdentInScope ctx fsRef ident (Some value), ident
let identWithRange r (ident: Fable.Ident) =
let originalName = ident.Range |> Option.bind (fun r -> r.identifierName)
{ ident with Range = r |> Option.map (fun r -> { r with identifierName = originalName }) }
let tryGetIdentFromScopeIf (ctx: Context) r predicate =
ctx.Scope |> List.tryPick (fun (fsRef, ident, _) ->
if predicate fsRef then identWithRange r ident |> Fable.IdentExpr |> Some
else None)
/// Get corresponding identifier to F# value in current scope
let tryGetIdentFromScope (ctx: Context) r (fsRef: FSharpMemberOrFunctionOrValue) =
tryGetIdentFromScopeIf ctx r (fun fsRef' -> obj.Equals(fsRef, fsRef'))
let rec tryGetBoundValueFromScope (ctx: Context) identName =
match ctx.Scope |> List.tryFind (fun (_,ident,_) -> ident.Name = identName) with
| Some(_,_,value) ->
match value with
| Some(Fable.IdentExpr ident) when not ident.IsMutable ->
tryGetBoundValueFromScope ctx ident.Name
| v -> v
| None -> None
module Util =
open Helpers
open Patterns
open TypeHelpers
open Identifiers
let makeFunctionArgs com ctx (args: FSharpMemberOrFunctionOrValue list) =
let ctx, args =
((ctx, []), args)
||> List.fold (fun (ctx, accArgs) var ->
let newContext, arg = putArgInScope com ctx var
newContext, arg::accArgs)
ctx, List.rev args