-
Notifications
You must be signed in to change notification settings - Fork 798
/
Copy pathCompilerOptions.fs
2462 lines (2114 loc) · 88 KB
/
CompilerOptions.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.
// # FSComp.SR.opts
module internal FSharp.Compiler.CompilerOptions
open System
open System.Diagnostics
open System.IO
open FSharp.Compiler.Optimizer
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.ILPdbWriter
open FSharp.Compiler.AbstractIL.Diagnostics
open FSharp.Compiler.CompilerConfig
open FSharp.Compiler.CompilerDiagnostics
open FSharp.Compiler.Diagnostics
open FSharp.Compiler.Features
open FSharp.Compiler.IO
open FSharp.Compiler.Text.Range
open FSharp.Compiler.Text
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.DiagnosticsLogger
open Internal.Utilities
open System.Text
module Attributes =
open System.Runtime.CompilerServices
//[<assembly: System.Security.SecurityTransparent>]
[<Dependency("FSharp.Core", LoadHint.Always)>]
do ()
//----------------------------------------------------------------------------
// Compiler option parser
//
// The argument parser is used by both the VS plug-in and the fsc.exe to
// parse the include file path and other front-end arguments.
//
// The language service uses this function too. It's important to continue
// processing flags even if an error is seen in one so that the best possible
// intellisense can be show.
//--------------------------------------------------------------------------
[<RequireQualifiedAccess>]
type OptionSwitch =
| On
| Off
type OptionSpec =
| OptionClear of bool ref
| OptionFloat of (float -> unit)
| OptionInt of (int -> unit)
| OptionSwitch of (OptionSwitch -> unit)
| OptionIntList of (int -> unit)
| OptionIntListSwitch of (int -> OptionSwitch -> unit)
| OptionRest of (string -> unit)
| OptionSet of bool ref
| OptionString of (string -> unit)
| OptionStringList of (string -> unit)
| OptionStringListSwitch of (string -> OptionSwitch -> unit)
| OptionUnit of (unit -> unit)
| OptionConsoleOnly of (CompilerOptionBlock list -> unit)
| OptionGeneral of (string list -> bool) * (string list -> string list) // Applies? * (ApplyReturningResidualArgs)
and CompilerOption =
| CompilerOption of
name: string *
argumentDescriptionString: string *
actionSpec: OptionSpec *
deprecationError: exn option *
helpText: string option
and CompilerOptionBlock =
| PublicOptions of heading: string * options: CompilerOption list
| PrivateOptions of options: CompilerOption list
let GetOptionsOfBlock block =
match block with
| PublicOptions(_, opts) -> opts
| PrivateOptions opts -> opts
let FilterCompilerOptionBlock pred block =
match block with
| PublicOptions(heading, opts) -> PublicOptions(heading, List.filter pred opts)
| PrivateOptions opts -> PrivateOptions(List.filter pred opts)
let compilerOptionUsage (CompilerOption(s, tag, spec, _, _)) =
let s =
if s = "--" then
""
else
s (* s="flag" for "--flag" options. s="--" for "--" option. Adjust printing here for "--" case. *)
match spec with
| OptionUnit _
| OptionSet _
| OptionClear _
| OptionConsoleOnly _ -> sprintf "--%s" s
| OptionStringList _ -> sprintf "--%s:%s" s tag
| OptionIntList _ -> sprintf "--%s:%s" s tag
| OptionSwitch _ -> sprintf "--%s[+|-]" s
| OptionStringListSwitch _ -> sprintf "--%s[+|-]:%s" s tag
| OptionIntListSwitch _ -> sprintf "--%s[+|-]:%s" s tag
| OptionString _ -> sprintf "--%s:%s" s tag
| OptionInt _ -> sprintf "--%s:%s" s tag
| OptionFloat _ -> sprintf "--%s:%s" s tag
| OptionRest _ -> sprintf "--%s ..." s
| OptionGeneral _ ->
if String.IsNullOrEmpty(tag) then
sprintf "%s" s
else
sprintf "%s:%s" s tag (* still being decided *)
let nl = Environment.NewLine
let getCompilerOption (CompilerOption(_s, _tag, _spec, _, help) as compilerOption) width =
let sb = StringBuilder()
let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded}
let defaultLineWidth = 80 // the fallback width
let lineWidth =
match width with
| None ->
try
Console.BufferWidth
with _ ->
defaultLineWidth
| Some w -> w
let lineWidth =
if lineWidth = 0 then
defaultLineWidth
else
lineWidth (* Have seen BufferWidth=0 on Linux/Mono Coreclr for sure *)
// Lines have this form: <flagWidth><space><description>
// flagWidth chars - for flags description or padding on continuation lines.
// single space - space.
// description - words upto but excluding the final character of the line.
let _ = sb.Append $"{compilerOptionUsage compilerOption, -40}"
let printWord column (word: string) =
// Have printed upto column.
// Now print the next word including any preceding whitespace.
// Returns the column printed to (suited to folding).
if column + 1 (*space*) + word.Length >= lineWidth then // NOTE: "equality" ensures final character of the line is never printed
let _ = sb.Append $"{nl}"
let _ = sb.Append $"{String.Empty, -40} {word}"
flagWidth + 1 + word.Length
else
let _ = sb.Append $" {word}"
column + 1 + word.Length
let words =
match help with
| None -> [||]
| Some s -> s.Split [| ' ' |]
let _finalColumn = Array.fold printWord flagWidth words
let _ = sb.Append $"{nl}"
sb.ToString()
let getPublicOptions heading opts width =
match opts with
| [] -> ""
| _ ->
$"{nl}{nl} {heading}{nl}"
+ (opts |> List.map (fun t -> getCompilerOption t width) |> String.concat "")
let GetCompilerOptionBlocks blocks width =
let sb = new StringBuilder()
let publicBlocks =
blocks
|> List.choose (function
| PrivateOptions _ -> None
| PublicOptions(heading, opts) -> Some(heading, opts))
let consider doneHeadings (heading, _opts) =
if Set.contains heading doneHeadings then
doneHeadings
else
let headingOptions =
publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd
let _ = sb.Append(getPublicOptions heading headingOptions width)
Set.add heading doneHeadings
List.fold consider Set.empty publicBlocks |> ignore<Set<string>>
sb.ToString()
(* For QA *)
let dumpCompilerOption prefix (CompilerOption(str, _, spec, _, _)) =
printf "section='%-25s' ! option=%-30s kind=" prefix str
match spec with
| OptionUnit _ -> printf "OptionUnit"
| OptionSet _ -> printf "OptionSet"
| OptionClear _ -> printf "OptionClear"
| OptionConsoleOnly _ -> printf "OptionConsoleOnly"
| OptionStringList _ -> printf "OptionStringList"
| OptionIntList _ -> printf "OptionIntList"
| OptionSwitch _ -> printf "OptionSwitch"
| OptionStringListSwitch _ -> printf "OptionStringListSwitch"
| OptionIntListSwitch _ -> printf "OptionIntListSwitch"
| OptionString _ -> printf "OptionString"
| OptionInt _ -> printf "OptionInt"
| OptionFloat _ -> printf "OptionFloat"
| OptionRest _ -> printf "OptionRest"
| OptionGeneral _ -> printf "OptionGeneral"
printf "\n"
let dumpCompilerOptionBlock =
function
| PublicOptions(heading, opts) -> List.iter (dumpCompilerOption heading) opts
| PrivateOptions opts -> List.iter (dumpCompilerOption "NoSection") opts
let DumpCompilerOptionBlocks blocks =
List.iter dumpCompilerOptionBlock blocks
let isSlashOpt (opt: string) =
opt[0] = '/' && (opt.Length = 1 || not (opt[1..].Contains "/"))
module ResponseFile =
type ResponseFileData = ResponseFileLine list
and ResponseFileLine =
| CompilerOptionSpec of string
| Comment of string
let parseFile path : Choice<ResponseFileData, Exception> =
let parseLine (l: string) =
match l with
| s when String.IsNullOrWhiteSpace s -> None
| s when l.StartsWithOrdinal("#") -> Some(ResponseFileLine.Comment(s.TrimStart('#')))
| s -> Some(ResponseFileLine.CompilerOptionSpec(s.Trim()))
try
use stream = FileSystem.OpenFileForReadShim(path)
use reader = new StreamReader(stream, true)
let data =
seq {
while not reader.EndOfStream do
!! reader.ReadLine()
}
|> Seq.choose parseLine
|> List.ofSeq
Choice1Of2 data
with e ->
Choice2Of2 e
let ParseCompilerOptions (collectOtherArgument: string -> unit, blocks: CompilerOptionBlock list, args) =
use _ = UseBuildPhase BuildPhase.Parameter
let specs = List.collect GetOptionsOfBlock blocks
// returns a tuple - the option minus switchchars, the option tokenand the option argument string
let parseOption (option: string) =
// Get option arguments, I.e everything following first:
let opts = option.Split([| ':' |])
let optArgs = String.Join(":", opts[1..])
let opt =
if String.IsNullOrEmpty(option) then
""
// if it doesn't start with a '-' or '/', reject outright
elif option[0] <> '-' && option[0] <> '/' then
""
elif option <> "--" then
// is it an abbreviated or MSFT-style option?
// if so, strip the first character and move on with your life
// Weirdly a -- option can't have only a 1 character name
if option.Length = 2 || isSlashOpt option then
option[1..]
elif option.Length >= 3 && option[2] = ':' then
option[1..]
elif option.StartsWithOrdinal("--") then
match option.Length with
| l when l >= 4 && option[3] = ':' -> ""
| l when l > 3 -> option[2..]
| _ -> ""
else
""
else
option
// grab the option token
let token = opt.Split([| ':' |])[0]
opt, token, optArgs
let getOptionArg compilerOption (argString: string) =
if String.IsNullOrEmpty(argString) then
errorR (Error(FSComp.SR.buildOptionRequiresParameter (compilerOptionUsage compilerOption), rangeCmdArgs))
argString
let getOptionArgList compilerOption (argString: string) =
if String.IsNullOrEmpty(argString) then
errorR (Error(FSComp.SR.buildOptionRequiresParameter (compilerOptionUsage compilerOption), rangeCmdArgs))
[]
else
argString.Split([| ','; ';' |]) |> List.ofArray
let getSwitchOpt (opt: string) =
// if opt is a switch, strip the '+' or '-'
if
opt <> "--"
&& opt.Length > 1
&& (opt.EndsWithOrdinal("+") || opt.EndsWithOrdinal("-"))
then
opt[0 .. opt.Length - 2]
else
opt
let getSwitch (s: string) =
let s = (s.Split([| ':' |]))[0]
if s <> "--" && s.EndsWithOrdinal("-") then
OptionSwitch.Off
else
OptionSwitch.On
let rec processArg args =
match args with
| [] -> ()
| opt: string :: t when opt.StartsWithOrdinal("@") ->
let responseFileOptions =
let fullpath =
try
Some(opt.TrimStart('@') |> FileSystem.GetFullPathShim)
with _ ->
None
match fullpath with
| None ->
errorR (Error(FSComp.SR.optsResponseFileNameInvalid opt, rangeCmdArgs))
[]
| Some path when not (FileSystem.FileExistsShim path) ->
errorR (Error(FSComp.SR.optsResponseFileNotFound (opt, path), rangeCmdArgs))
[]
| Some path ->
match ResponseFile.parseFile path with
| Choice2Of2 _ ->
errorR (Error(FSComp.SR.optsInvalidResponseFile (opt, path), rangeCmdArgs))
[]
| Choice1Of2 rspData ->
let onlyOptions l =
match l with
| ResponseFile.ResponseFileLine.Comment _ -> None
| ResponseFile.ResponseFileLine.CompilerOptionSpec opt -> Some opt
rspData |> List.choose onlyOptions
processArg (responseFileOptions @ t)
| opt :: t ->
let option, optToken, argString = parseOption opt
let reportDeprecatedOption errOpt =
match errOpt with
| Some e -> warning e
| None -> ()
let rec attempt l =
match l with
| CompilerOption(s, _, OptionConsoleOnly f, d, _) :: _ when option = s ->
reportDeprecatedOption d
f blocks
t
| CompilerOption(s, _, OptionUnit f, d, _) :: _ when optToken = s && String.IsNullOrEmpty(argString) ->
reportDeprecatedOption d
f ()
t
| CompilerOption(s, _, OptionSwitch f, d, _) :: _ when getSwitchOpt optToken = s && String.IsNullOrEmpty(argString) ->
reportDeprecatedOption d
f (getSwitch opt)
t
| CompilerOption(s, _, OptionSet f, d, _) :: _ when optToken = s && String.IsNullOrEmpty(argString) ->
reportDeprecatedOption d
f.Value <- true
t
| CompilerOption(s, _, OptionClear f, d, _) :: _ when optToken = s && String.IsNullOrEmpty(argString) ->
reportDeprecatedOption d
f.Value <- false
t
| CompilerOption(s, _, OptionString f, d, _) as compilerOption :: _ when optToken = s ->
reportDeprecatedOption d
let oa = getOptionArg compilerOption argString
if oa <> "" then
f (getOptionArg compilerOption oa)
t
| CompilerOption(s, _, OptionInt f, d, _) as compilerOption :: _ when optToken = s ->
reportDeprecatedOption d
let oa = getOptionArg compilerOption argString
if oa <> "" then
f (
try
int32 oa
with _ ->
errorR (Error(FSComp.SR.buildArgInvalidInt (getOptionArg compilerOption argString), rangeCmdArgs))
0
)
t
| CompilerOption(s, _, OptionFloat f, d, _) as compilerOption :: _ when optToken = s ->
reportDeprecatedOption d
let oa = getOptionArg compilerOption argString
if oa <> "" then
f (
try
float oa
with _ ->
errorR (Error(FSComp.SR.buildArgInvalidFloat (getOptionArg compilerOption argString), rangeCmdArgs))
0.0
)
t
| CompilerOption(s, _, OptionRest f, d, _) :: _ when optToken = s ->
reportDeprecatedOption d
List.iter f t
[]
| CompilerOption(s, _, OptionIntList f, d, _) as compilerOption :: _ when optToken = s ->
reportDeprecatedOption d
let al = getOptionArgList compilerOption argString
if al <> [] then
List.iter
(fun i ->
f (
try
int32 i
with _ ->
errorR (Error(FSComp.SR.buildArgInvalidInt i, rangeCmdArgs))
0
))
al
t
| CompilerOption(s, _, OptionIntListSwitch f, d, _) as compilerOption :: _ when getSwitchOpt optToken = s ->
reportDeprecatedOption d
let al = getOptionArgList compilerOption argString
if al <> [] then
let switch = getSwitch opt
List.iter
(fun i ->
f
(try
int32 i
with _ ->
errorR (Error(FSComp.SR.buildArgInvalidInt i, rangeCmdArgs))
0)
switch)
al
t
// here
| CompilerOption(s, _, OptionStringList f, d, _) as compilerOption :: _ when optToken = s ->
reportDeprecatedOption d
let al = getOptionArgList compilerOption argString
if al <> [] then
List.iter f (getOptionArgList compilerOption argString)
t
| CompilerOption(s, _, OptionStringListSwitch f, d, _) as compilerOption :: _ when getSwitchOpt optToken = s ->
reportDeprecatedOption d
let al = getOptionArgList compilerOption argString
if al <> [] then
let switch = getSwitch opt
List.iter (fun s -> f s switch) (getOptionArgList compilerOption argString)
t
| CompilerOption(_, _, OptionGeneral(pred, exec), d, _) :: _ when pred args ->
reportDeprecatedOption d
let rest = exec args in
rest // arguments taken, rest remaining
| _ :: more -> attempt more
| [] ->
if opt.Length = 0 || opt[0] = '-' || isSlashOpt opt then
// want the whole opt token - delimiter and all
let unrecOpt = opt.Split([| ':' |]).[0]
errorR (Error(FSComp.SR.buildUnrecognizedOption unrecOpt, rangeCmdArgs))
t
else
(collectOtherArgument opt
t)
let rest = attempt specs
processArg rest
processArg args
//----------------------------------------------------------------------------
// Compiler options
//--------------------------------------------------------------------------
let mutable enableConsoleColoring = true // global state
let setFlag r n =
match n with
| 0 -> r false
| 1 -> r true
| _ -> raise (Failure "expected 0/1")
let SetOptimizeOff (tcConfigB: TcConfigBuilder) =
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
jitOptUser = Some false
localOptUser = Some false
crossAssemblyOptimizationUser = Some false
lambdaInlineThreshold = 0
}
tcConfigB.onlyEssentialOptimizationData <- true
tcConfigB.doDetuple <- false
tcConfigB.doTLR <- false
tcConfigB.doFinalSimplify <- false
let SetOptimizeOn (tcConfigB: TcConfigBuilder) =
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
jitOptUser = Some true
}
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
localOptUser = Some true
}
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
crossAssemblyOptimizationUser = Some true
}
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
lambdaInlineThreshold = 6
}
tcConfigB.doDetuple <- true
tcConfigB.doTLR <- true
tcConfigB.doFinalSimplify <- true
let SetOptimizeSwitch (tcConfigB: TcConfigBuilder) switch =
if (switch = OptionSwitch.On) then
SetOptimizeOn tcConfigB
else
SetOptimizeOff tcConfigB
let SetTailcallSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.emitTailcalls <- (switch = OptionSwitch.On)
let SetDeterministicSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.deterministic <- (switch = OptionSwitch.On)
let SetRealsig (tcConfigB: TcConfigBuilder) switch =
tcConfigB.realsig <- (switch = OptionSwitch.On)
let SetReferenceAssemblyOnlySwitch (tcConfigB: TcConfigBuilder) switch =
match tcConfigB.emitMetadataAssembly with
| MetadataAssemblyGeneration.None when (not tcConfigB.standalone) && tcConfigB.extraStaticLinkRoots.IsEmpty ->
tcConfigB.emitMetadataAssembly <-
if (switch = OptionSwitch.On) then
MetadataAssemblyGeneration.ReferenceOnly
else
MetadataAssemblyGeneration.None
| _ -> error (Error(FSComp.SR.optsInvalidRefAssembly (), rangeCmdArgs))
let SetReferenceAssemblyOutSwitch (tcConfigB: TcConfigBuilder) outputPath =
match tcConfigB.emitMetadataAssembly with
| MetadataAssemblyGeneration.None when (not tcConfigB.standalone) && tcConfigB.extraStaticLinkRoots.IsEmpty ->
if FileSystem.IsInvalidPathShim outputPath then
error (Error(FSComp.SR.optsInvalidRefOut (), rangeCmdArgs))
else
tcConfigB.emitMetadataAssembly <- MetadataAssemblyGeneration.ReferenceOut outputPath
| _ -> error (Error(FSComp.SR.optsInvalidRefAssembly (), rangeCmdArgs))
let AddPathMapping (tcConfigB: TcConfigBuilder) (pathPair: string) =
match pathPair.Split([| '=' |], 2) with
| [| oldPrefix; newPrefix |] -> tcConfigB.AddPathMapping(oldPrefix, newPrefix)
| _ -> error (Error(FSComp.SR.optsInvalidPathMapFormat (), rangeCmdArgs))
let jitoptimizeSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
jitOptUser = Some(switch = OptionSwitch.On)
}
let localoptimizeSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
localOptUser = Some(switch = OptionSwitch.On)
}
let crossOptimizeSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
crossAssemblyOptimizationUser = Some(switch = OptionSwitch.On)
}
let splittingSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
abstractBigTargets = switch = OptionSwitch.On
}
let callVirtSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.alwaysCallVirt <- switch = OptionSwitch.On
let callParallelCompilationSwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.parallelIlxGen <- switch = OptionSwitch.On
let (graphCheckingMode, optMode) =
match switch with
| OptionSwitch.On -> TypeCheckingMode.Graph, OptimizationProcessingMode.Parallel
| OptionSwitch.Off -> TypeCheckingMode.Sequential, OptimizationProcessingMode.Sequential
if tcConfigB.typeCheckingConfig.Mode <> graphCheckingMode then
tcConfigB.typeCheckingConfig <-
{ tcConfigB.typeCheckingConfig with
Mode = graphCheckingMode
}
if tcConfigB.optSettings.processingMode <> optMode then
tcConfigB.optSettings <-
{ tcConfigB.optSettings with
processingMode = optMode
}
let useHighEntropyVASwitch (tcConfigB: TcConfigBuilder) switch =
tcConfigB.useHighEntropyVA <- switch = OptionSwitch.On
let subSystemVersionSwitch (tcConfigB: TcConfigBuilder) (text: string) =
let fail () =
error (Error(FSComp.SR.optsInvalidSubSystemVersion text, rangeCmdArgs))
// per spec for 357994: Validate input string, should be two positive integers x.y when x>=4 and y>=0 and both <= 65535
if String.IsNullOrEmpty text then
fail ()
else
match text.Split('.') with
| [| majorStr; minorStr |] ->
match (Int32.TryParse majorStr), (Int32.TryParse minorStr) with
| (true, major), (true, minor) when major >= 4 && major <= 65535 && minor >= 0 && minor <= 65535 ->
tcConfigB.subsystemVersion <- (major, minor)
| _ -> fail ()
| _ -> fail ()
let SetUseSdkSwitch (tcConfigB: TcConfigBuilder) switch =
let useSdkRefs = (switch = OptionSwitch.On)
tcConfigB.SetUseSdkRefs useSdkRefs
let (++) x s = x @ [ s ]
let SetTarget (tcConfigB: TcConfigBuilder) (s: string) =
match s.ToLowerInvariant() with
| "exe" -> tcConfigB.target <- CompilerTarget.ConsoleExe
| "winexe" -> tcConfigB.target <- CompilerTarget.WinExe
| "library" -> tcConfigB.target <- CompilerTarget.Dll
| "module" -> tcConfigB.target <- CompilerTarget.Module
| _ -> error (Error(FSComp.SR.optsUnrecognizedTarget s, rangeCmdArgs))
let SetDebugSwitch (tcConfigB: TcConfigBuilder) (dtype: string option) (s: OptionSwitch) =
match dtype with
| Some s ->
tcConfigB.portablePDB <- true
tcConfigB.jitTracking <- true
match s with
| "full"
| "pdbonly"
| "portable" -> tcConfigB.embeddedPDB <- false
| "embedded" -> tcConfigB.embeddedPDB <- true
| _ -> error (Error(FSComp.SR.optsUnrecognizedDebugType s, rangeCmdArgs))
| None ->
tcConfigB.portablePDB <- s = OptionSwitch.On
tcConfigB.embeddedPDB <- false
tcConfigB.jitTracking <- s = OptionSwitch.On
tcConfigB.debuginfo <- s = OptionSwitch.On
let SetEmbedAllSourceSwitch (tcConfigB: TcConfigBuilder) switch =
if (switch = OptionSwitch.On) then
tcConfigB.embedAllSource <- true
else
tcConfigB.embedAllSource <- false
let setOutFileName tcConfigB (path: string) =
let outputDir = !! Path.GetDirectoryName(path)
tcConfigB.outputDir <- Some outputDir
tcConfigB.outputFile <- Some path
let setSignatureFile tcConfigB s =
tcConfigB.printSignature <- true
tcConfigB.printSignatureFile <- s
let setAllSignatureFiles tcConfigB () =
tcConfigB.printAllSignatureFiles <- true
// option tags
let tagString = "<string>"
let tagExe = "exe"
let tagWinExe = "winexe"
let tagLibrary = "library"
let tagModule = "module"
let tagFile = "<file>"
let tagFileList = "<file;...>"
let tagDirList = "<dir;...>"
let tagResInfo = "<resinfo>"
let tagFullPDBOnlyPortable = "{full|pdbonly|portable|embedded}"
let tagWarnList = "<warn;...>"
let tagAddress = "<address>"
let tagAlgorithm = "{SHA1|SHA256}"
let tagInt = "<n>"
let tagPathMap = "<path=sourcePath;...>"
let tagNone = ""
let tagLangVersionValues = "{version|latest|preview}"
// PrintOptionInfo
//----------------
/// Print internal "option state" information for diagnostics and regression tests.
let PrintOptionInfo (tcConfigB: TcConfigBuilder) =
printfn " jitOptUser . . . . . . : %+A" tcConfigB.optSettings.jitOptUser
printfn " localOptUser . . . . . : %+A" tcConfigB.optSettings.localOptUser
printfn " crossAssemblyOptimizationUser . . : %+A" tcConfigB.optSettings.crossAssemblyOptimizationUser
printfn " lambdaInlineThreshold : %+A" tcConfigB.optSettings.lambdaInlineThreshold
printfn " doDetuple . . . . . . : %+A" tcConfigB.doDetuple
printfn " doTLR . . . . . . . . : %+A" tcConfigB.doTLR
printfn " doFinalSimplify. . . . : %+A" tcConfigB.doFinalSimplify
printfn " jitTracking . . . . . : %+A" tcConfigB.jitTracking
printfn " portablePDB. . . . . . : %+A" tcConfigB.portablePDB
printfn " embeddedPDB. . . . . . : %+A" tcConfigB.embeddedPDB
printfn " embedAllSource . . . . : %+A" tcConfigB.embedAllSource
printfn " embedSourceList. . . . : %+A" tcConfigB.embedSourceList
printfn " sourceLink . . . . . . : %+A" tcConfigB.sourceLink
printfn " debuginfo . . . . . . : %+A" tcConfigB.debuginfo
printfn " resolutionEnvironment : %+A" tcConfigB.resolutionEnvironment
printfn " product . . . . . . . : %+A" tcConfigB.productNameForBannerText
printfn " copyFSharpCore . . . . : %+A" tcConfigB.copyFSharpCore
tcConfigB.includes
|> List.sort
|> List.iter (printfn " include . . . . . . . : %A")
// OptionBlock: Input files
//-------------------------
let inputFileFlagsBoth (tcConfigB: TcConfigBuilder) =
[
CompilerOption(
"reference",
tagFile,
OptionString(fun s -> tcConfigB.AddReferencedAssemblyByPath(rangeStartup, s)),
None,
Some(FSComp.SR.optsReference ())
)
CompilerOption("compilertool", tagFile, OptionString tcConfigB.AddCompilerToolsByPath, None, Some(FSComp.SR.optsCompilerTool ()))
]
let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
let inputFileFlagsFsiBase (_tcConfigB: TcConfigBuilder) =
[
if FSharpEnvironment.isRunningOnCoreClr then
yield CompilerOption("usesdkrefs", tagNone, OptionSwitch(SetUseSdkSwitch _tcConfigB), None, Some(FSComp.SR.useSdkRefs ()))
]
let inputFileFlagsFsi (tcConfigB: TcConfigBuilder) =
List.append (inputFileFlagsBoth tcConfigB) (inputFileFlagsFsiBase tcConfigB)
// OptionBlock: Errors and warnings
//---------------------------------
let errorsAndWarningsFlags (tcConfigB: TcConfigBuilder) =
let trimFS (s: string) =
if s.StartsWithOrdinal "FS" then s.Substring 2 else s
let trimFStoInt (s: string) =
match Int32.TryParse(trimFS s) with
| true, n -> Some n
| false, _ -> None
[
CompilerOption(
"warnaserror",
tagNone,
OptionSwitch(fun switch ->
tcConfigB.diagnosticsOptions <-
{ tcConfigB.diagnosticsOptions with
GlobalWarnAsError = switch <> OptionSwitch.Off
}),
None,
Some(FSComp.SR.optsWarnaserrorPM ())
)
CompilerOption(
"warnaserror",
tagWarnList,
OptionStringListSwitch(fun n switch ->
match trimFStoInt n with
| Some n ->
let options = tcConfigB.diagnosticsOptions
tcConfigB.diagnosticsOptions <-
if switch = OptionSwitch.Off then
{ options with
WarnAsError = ListSet.remove (=) n options.WarnAsError
WarnAsWarn = ListSet.insert (=) n options.WarnAsWarn
}
else
{ options with
WarnAsError = ListSet.insert (=) n options.WarnAsError
WarnAsWarn = ListSet.remove (=) n options.WarnAsWarn
}
| None -> ()),
None,
Some(FSComp.SR.optsWarnaserror ())
)
CompilerOption(
"warn",
tagInt,
OptionInt(fun n ->
tcConfigB.diagnosticsOptions <-
{ tcConfigB.diagnosticsOptions with
WarnLevel =
if (n >= 0 && n <= 5) then
n
else
error (Error(FSComp.SR.optsInvalidWarningLevel n, rangeCmdArgs))
}),
None,
Some(FSComp.SR.optsWarn ())
)
CompilerOption(
"nowarn",
tagWarnList,
OptionStringList(fun n -> tcConfigB.TurnWarningOff(rangeCmdArgs, n)),
None,
Some(FSComp.SR.optsNowarn ())
)
CompilerOption(
"warnon",
tagWarnList,
OptionStringList(fun n -> tcConfigB.TurnWarningOn(rangeCmdArgs, n)),
None,
Some(FSComp.SR.optsWarnOn ())
)
CompilerOption(
"checknulls",
tagNone,
OptionSwitch(fun switch -> tcConfigB.checkNullness <- switch = OptionSwitch.On),
None,
Some(FSComp.SR.optsCheckNulls ())
)
CompilerOption(
"consolecolors",
tagNone,
OptionSwitch(fun switch -> enableConsoleColoring <- switch = OptionSwitch.On),
None,
Some(FSComp.SR.optsConsoleColors ())
)
]
// OptionBlock: Output files
//--------------------------
let outputFileFlagsFsi (_tcConfigB: TcConfigBuilder) = []
let outputFileFlagsFsc (tcConfigB: TcConfigBuilder) =
[
CompilerOption("out", tagFile, OptionString(setOutFileName tcConfigB), None, Some(FSComp.SR.optsNameOfOutputFile ()))
CompilerOption("target", tagExe, OptionString(SetTarget tcConfigB), None, Some(FSComp.SR.optsBuildConsole ()))
CompilerOption("target", tagWinExe, OptionString(SetTarget tcConfigB), None, Some(FSComp.SR.optsBuildWindows ()))
CompilerOption("target", tagLibrary, OptionString(SetTarget tcConfigB), None, Some(FSComp.SR.optsBuildLibrary ()))
CompilerOption("target", tagModule, OptionString(SetTarget tcConfigB), None, Some(FSComp.SR.optsBuildModule ()))
CompilerOption(
"delaysign",
tagNone,
OptionSwitch(fun s -> tcConfigB.delaysign <- (s = OptionSwitch.On)),
None,
Some(FSComp.SR.optsDelaySign ())
)
CompilerOption(
"publicsign",
tagNone,
OptionSwitch(fun s -> tcConfigB.publicsign <- (s = OptionSwitch.On)),
None,
Some(FSComp.SR.optsPublicSign ())
)
CompilerOption("doc", tagFile, OptionString(fun s -> tcConfigB.xmlDocOutputFile <- Some s), None, Some(FSComp.SR.optsWriteXml ()))
CompilerOption("keyfile", tagFile, OptionString(fun s -> tcConfigB.signer <- Some s), None, Some(FSComp.SR.optsStrongKeyFile ()))
CompilerOption(
"platform",
tagString,
OptionString(fun s ->
tcConfigB.platform <-
match s with
| "x86" -> Some X86
| "x64" -> Some AMD64
| "arm" -> Some ARM
| "arm64" -> Some ARM64
| "Itanium" -> Some IA64
| "anycpu32bitpreferred" ->
tcConfigB.prefer32Bit <- true
None
| "anycpu" -> None
| _ -> error (Error(FSComp.SR.optsUnknownPlatform s, rangeCmdArgs))),
None,
Some(FSComp.SR.optsPlatform ())
)
CompilerOption(
"compressmetadata",
tagNone,
OptionSwitch(fun switch -> tcConfigB.compressMetadata <- switch = OptionSwitch.On),
None,
Some(FSComp.SR.optsCompressMetadata ())
)
CompilerOption(
"nooptimizationdata",
tagNone,
OptionUnit(fun () -> tcConfigB.onlyEssentialOptimizationData <- true),
None,
Some(FSComp.SR.optsNoOpt ())
)
CompilerOption(
"nointerfacedata",
tagNone,
OptionUnit(fun () -> tcConfigB.noSignatureData <- true),
None,
Some(FSComp.SR.optsNoInterface ())
)
CompilerOption("sig", tagFile, OptionString(setSignatureFile tcConfigB), None, Some(FSComp.SR.optsSig ()))
CompilerOption("allsigs", tagNone, OptionUnit(setAllSignatureFiles tcConfigB), None, Some(FSComp.SR.optsAllSigs ()))
CompilerOption(
"nocopyfsharpcore",
tagNone,
OptionUnit(fun () -> tcConfigB.copyFSharpCore <- CopyFSharpCoreFlag.No),
None,
Some(FSComp.SR.optsNoCopyFsharpCore ())
)
CompilerOption("refonly", tagNone, OptionSwitch(SetReferenceAssemblyOnlySwitch tcConfigB), None, Some(FSComp.SR.optsRefOnly ()))
CompilerOption("refout", tagFile, OptionString(SetReferenceAssemblyOutSwitch tcConfigB), None, Some(FSComp.SR.optsRefOut ()))
]
// OptionBlock: Resources
//-----------------------
let resourcesFlagsFsi (_tcConfigB: TcConfigBuilder) = []
let resourcesFlagsFsc (tcConfigB: TcConfigBuilder) =
[
CompilerOption("win32icon", tagFile, OptionString(fun s -> tcConfigB.win32icon <- s), None, Some(FSComp.SR.optsWin32icon ()))
CompilerOption("win32res", tagFile, OptionString(fun s -> tcConfigB.win32res <- s), None, Some(FSComp.SR.optsWin32res ()))
CompilerOption(
"win32manifest",
tagFile,
OptionString(fun s -> tcConfigB.win32manifest <- s),
None,
Some(FSComp.SR.optsWin32manifest ())
)