forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompileOptions.fs
More file actions
1380 lines (1173 loc) · 76.4 KB
/
Copy pathCompileOptions.fs
File metadata and controls
1380 lines (1173 loc) · 76.4 KB
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. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// # FSComp.SR.opts
module internal Microsoft.FSharp.Compiler.CompileOptions
open Internal.Utilities
open System
open System.Collections.Generic
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.AbstractIL
open Microsoft.FSharp.Compiler.AbstractIL.IL
open Microsoft.FSharp.Compiler.AbstractIL.Internal
open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
open Microsoft.FSharp.Compiler.AbstractIL.Extensions.ILX
open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
open Microsoft.FSharp.Compiler.CompileOps
open Microsoft.FSharp.Compiler.TcGlobals
open Microsoft.FSharp.Compiler.TypeChecker
open Microsoft.FSharp.Compiler.Tast
open Microsoft.FSharp.Compiler.Tastops
open Microsoft.FSharp.Compiler.Tastops.DebugPrint
open Microsoft.FSharp.Compiler.Ast
open Microsoft.FSharp.Compiler.ErrorLogger
open Microsoft.FSharp.Compiler.AbstractIL.IL
open Microsoft.FSharp.Compiler.Lib
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.Lexhelp
open Microsoft.FSharp.Compiler.IlxGen
#if FX_RESHAPED_REFLECTION
open Microsoft.FSharp.Core.ReflectionAdapters
#endif
module Attributes =
open System.Runtime.CompilerServices
//[<assembly: System.Security.SecurityTransparent>]
#if !FX_NO_DEFAULT_DEPENDENCY_TYPE
[<Dependency("FSharp.Core",LoadHint.Always)>]
#endif
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)
| OptionHelp of (CompilerOptionBlock list -> unit) // like OptionUnit, but given the "options"
| OptionGeneral of (string list -> bool) * (string list -> string list) // Applies? * (ApplyReturningResidualArgs)
and CompilerOption = CompilerOption of string * string * OptionSpec * Option<exn> * string option
and CompilerOptionBlock = PublicOptions of string * CompilerOption list | PrivateOptions of 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 _ | OptionHelp _) -> 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 tag="" then sprintf "%s" s else sprintf "%s:%s" s tag (* still being decided *)
let PrintCompilerOption (CompilerOption(_s,_tag,_spec,_,help) as compilerOption) =
let flagWidth = 30 // fixed width for printing of flags, e.g. --warnaserror:<warn...>
let defaultLineWidth = 80 // the fallback width
let lineWidth =
try
System.Console.BufferWidth
with e -> defaultLineWidth
let lineWidth = if lineWidth=0 then defaultLineWidth else lineWidth (* Have seen BufferWidth=0 on Linux/Mono *)
// 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.
assert(flagWidth = 30)
printf "%-40s" (compilerOptionUsage compilerOption)
let printWord column (word:string) =
// Have printed upto column.
// Now print the next word including any preceeding 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
printfn "" (* newline *)
assert(flagWidth = 30)
printf "%-40s %s" ""(*<--flags*) word
flagWidth + 1 + word.Length
else
printf " %s" word
column + 1 + word.Length
let words = match help with None -> [| |] | Some s -> s.Split [| ' ' |]
let _finalColumn = Array.fold printWord flagWidth words
printfn "" (* newline *)
let PrintPublicOptions (heading,opts) =
if not (isNil opts) then
printfn ""
printfn ""
printfn "\t\t%s" heading
List.iter PrintCompilerOption opts
let PrintCompilerOptionBlocks blocks =
let equals x y = x=y
let publicBlocks = List.choose (function PrivateOptions _ -> None | PublicOptions (heading,opts) -> Some (heading,opts)) blocks
let consider doneHeadings (heading, _opts) =
if Set.contains heading doneHeadings then
doneHeadings
else
let headingOptions = List.filter (fst >> equals heading) publicBlocks |> List.collect snd
PrintPublicOptions (heading,headingOptions)
Set.add heading doneHeadings
List.fold consider Set.empty publicBlocks |> ignore<Set<string>>
(* 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"
| OptionHelp _ -> printf "OptionHelp"
| 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.StartsWith("#") -> Some (ResponseFileLine.Comment (s.TrimStart('#')))
| s -> Some (ResponseFileLine.CompilerOptionSpec (s.Trim()))
try
use stream = FileSystem.FileStreamReadShim path
use reader = new System.IO.StreamReader(stream, true)
let data =
seq { while not reader.EndOfStream do yield reader.ReadLine () }
|> Seq.choose parseLine
|> List.ofSeq
Choice1Of2 data
with e ->
Choice2Of2 e
let ParseCompilerOptions (collectOtherArgument : string -> unit, blocks: CompilerOptionBlock list, args) =
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
let specs = List.collect GetOptionsOfBlock blocks
// returns a tuple - the option token, the option argument string
let parseOption (s : string) =
// grab the option token
let opts = s.Split([|':'|])
let mutable opt = opts.[0]
if opt = "" then
()
// if it doesn't start with a '-' or '/', reject outright
elif opt.[0] <> '-' && opt.[0] <> '/' then
opt <- ""
elif opt <> "--" then
// is it an abbreviated or MSFT-style option?
// if so, strip the first character and move on with your life
if opt.Length = 2 || isSlashOpt opt then
opt <- opt.[1 ..]
// else, it should be a non-abbreviated option starting with "--"
elif opt.Length > 3 && opt.StartsWith("--") then
opt <- opt.[2 ..]
else
opt <- ""
// get the argument string
let optArgs = if opts.Length > 1 then String.Join(":",opts.[1 ..]) else ""
opt, optArgs
let getOptionArg compilerOption (argString : string) =
if argString = "" then
errorR(Error(FSComp.SR.buildOptionRequiresParameter(compilerOptionUsage compilerOption),rangeCmdArgs))
argString
let getOptionArgList compilerOption (argString : string) =
if 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.EndsWith("+",StringComparison.Ordinal) || opt.EndsWith("-",StringComparison.Ordinal)) then
opt.[0 .. opt.Length - 2]
else
opt
let getSwitch (s: string) =
let s = (s.Split([|':'|])).[0]
if s <> "--" && s.EndsWith("-",StringComparison.Ordinal) then OptionSwitch.Off else OptionSwitch.On
let rec processArg args =
match args with
| [] -> ()
| ((rsp: string) :: t) when rsp.StartsWith("@") ->
let responseFileOptions =
let fullpath =
try
Some (rsp.TrimStart('@') |> FileSystem.GetFullPathShim)
with _ ->
None
match fullpath with
| None ->
errorR(Error(FSComp.SR.optsResponseFileNameInvalid(rsp),rangeCmdArgs))
[]
| Some(path) when not (FileSystem.SafeExists path) ->
errorR(Error(FSComp.SR.optsResponseFileNotFound(rsp, path),rangeCmdArgs))
[]
| Some path ->
match ResponseFile.parseFile path with
| Choice2Of2 _ ->
errorR(Error(FSComp.SR.optsInvalidResponseFile(rsp, 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 optToken, argString = parseOption opt
let reportDeprecatedOption errOpt =
match errOpt with
| Some(e) -> warning(e)
| None -> ()
let rec attempt l =
match l with
| (CompilerOption(s, _, OptionHelp f, d, _) :: _) when optToken = s && argString = "" ->
reportDeprecatedOption d
f blocks; t
| (CompilerOption(s, _, OptionUnit f, d, _) :: _) when optToken = s && argString = "" ->
reportDeprecatedOption d
f (); t
| (CompilerOption(s, _, OptionSwitch f, d, _) :: _) when getSwitchOpt(optToken) = s && argString = "" ->
reportDeprecatedOption d
f (getSwitch opt); t
| (CompilerOption(s, _, OptionSet f, d, _) :: _) when optToken = s && argString = "" ->
reportDeprecatedOption d
f := true; t
| (CompilerOption(s, _, OptionClear f, d, _) :: _) when optToken = s && argString = "" ->
reportDeprecatedOption d
f := 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
let result = processArg args
result
//----------------------------------------------------------------------------
// Compiler options
//--------------------------------------------------------------------------
let lexFilterVerbose = false
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 }
tcConfigB.optSettings <- { tcConfigB.optSettings with localOptUser = Some false }
tcConfigB.optSettings <- { tcConfigB.optSettings with crossModuleOptUser = Some false }
tcConfigB.optSettings <- { tcConfigB.optSettings with lambdaInlineThreshold = 0 }
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 crossModuleOptUser = 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 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 crossModuleOptUser = 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 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 System.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 (++) x s = x @ [s]
let SetTarget (tcConfigB : TcConfigBuilder)(s : string) =
match s.ToLowerInvariant() with
| "exe" -> tcConfigB.target <- ConsoleExe
| "winexe" -> tcConfigB.target <- WinExe
| "library" -> tcConfigB.target <- Dll
| "module" -> tcConfigB.target <- Module
| _ -> error(Error(FSComp.SR.optsUnrecognizedTarget(s),rangeCmdArgs))
let SetDebugSwitch (tcConfigB : TcConfigBuilder) (dtype : string option) (s : OptionSwitch) =
match dtype with
| Some(s) ->
match s with
| "portable" -> tcConfigB.portablePDB <- true ; tcConfigB.embeddedPDB <- false; tcConfigB.jitTracking <- true; tcConfigB.ignoreSymbolStoreSequencePoints <- true
| "pdbonly" -> tcConfigB.portablePDB <- false; tcConfigB.embeddedPDB <- false; tcConfigB.jitTracking <- false
| "embedded" -> tcConfigB.portablePDB <- true; tcConfigB.embeddedPDB <- true; tcConfigB.jitTracking <- true; tcConfigB.ignoreSymbolStoreSequencePoints <- true
| "full" -> tcConfigB.portablePDB <- false; tcConfigB.embeddedPDB <- false; tcConfigB.jitTracking <- true
| _ -> error(Error(FSComp.SR.optsUnrecognizedDebugType(s), rangeCmdArgs))
| None -> tcConfigB.portablePDB <- false; 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 s =
tcConfigB.outputFile <- Some s
let setSignatureFile tcConfigB s =
tcConfigB.printSignature <- true
tcConfigB.printSignatureFile <- s
// 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 tagPathList = "<path;...>"
let tagResInfo = "<resinfo>"
let tagFullPDBOnlyPortable = "{full|pdbonly|portable|embedded}"
let tagWarnList = "<warn;...>"
let tagSymbolList = "<symbol;...>"
let tagAddress = "<address>"
let tagInt = "<n>"
let tagNone = ""
// 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 " crossModuleOptUser . . : %+A" tcConfigB.optSettings.crossModuleOptUser
printfn " lambdaInlineThreshold : %+A" tcConfigB.optSettings.lambdaInlineThreshold
printfn " ignoreSymStoreSeqPts . : %+A" tcConfigB.ignoreSymbolStoreSequencePoints
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()) );
]
let referenceFlagAbbrev (tcConfigB : TcConfigBuilder) =
CompilerOption("r", tagFile, OptionString (fun s -> tcConfigB.AddReferencedAssemblyByPath (rangeStartup,s)), None,
Some(FSComp.SR.optsShortFormOf("--reference")) )
let inputFileFlagsFsi tcConfigB = inputFileFlagsBoth tcConfigB
let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
// OptionBlock: Errors and warnings
//---------------------------------
let errorsAndWarningsFlags (tcConfigB : TcConfigBuilder) =
[
CompilerOption("warnaserror", tagNone, OptionSwitch(fun switch -> tcConfigB.globalWarnAsError <- switch <> OptionSwitch.Off), None,
Some (FSComp.SR.optsWarnaserrorPM()));
CompilerOption("warnaserror", tagWarnList, OptionIntListSwitch (fun n switch ->
if switch = OptionSwitch.Off then
tcConfigB.specificWarnAsError <- ListSet.remove (=) n tcConfigB.specificWarnAsError ;
tcConfigB.specificWarnAsWarn <- ListSet.insert (=) n tcConfigB.specificWarnAsWarn
else
tcConfigB.specificWarnAsWarn <- ListSet.remove (=) n tcConfigB.specificWarnAsWarn ;
tcConfigB.specificWarnAsError <- ListSet.insert (=) n tcConfigB.specificWarnAsError), None,
Some (FSComp.SR.optsWarnaserror()));
CompilerOption("warn", tagInt, OptionInt (fun n ->
tcConfigB.globalWarnLevel <-
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("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("keycontainer", tagString, OptionString(fun s -> tcConfigB.container <- Some(s)),None,
Some(FSComp.SR.optsStrongKeyContainer()))
CompilerOption("platform", tagString, OptionString (fun s -> tcConfigB.platform <- match s with | "x86" -> Some X86 | "x64" -> Some AMD64 | "Itanium" -> Some IA64 | "anycpu32bitpreferred" -> (tcConfigB.prefer32Bit <- true; None) | "anycpu" -> None | _ -> error(Error(FSComp.SR.optsUnknownPlatform(s),rangeCmdArgs))), None,
Some(FSComp.SR.optsPlatform()))
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("nocopyfsharpcore", tagNone, OptionUnit (fun () -> tcConfigB.copyFSharpCore <- false), None, Some (FSComp.SR.optsNoCopyFsharpCore()))
]
// OptionBlock: Resources
//-----------------------
let resourcesFlagsFsi (_tcConfigB : TcConfigBuilder) = []
let resourcesFlagsFsc (tcConfigB : TcConfigBuilder) =
[
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()))
CompilerOption("nowin32manifest", tagNone, OptionUnit (fun () -> tcConfigB.includewin32manifest <- false), None,
Some (FSComp.SR.optsNowin32manifest()))
CompilerOption("resource", tagResInfo, OptionString (fun s -> tcConfigB.AddEmbeddedResource s), None,
Some (FSComp.SR.optsResource()))
CompilerOption("linkresource", tagResInfo, OptionString (fun s -> tcConfigB.linkResources <- tcConfigB.linkResources ++ s), None,
Some (FSComp.SR.optsLinkresource()))
]
// OptionBlock: Code generation
//-----------------------------
let codeGenerationFlags isFsi (tcConfigB : TcConfigBuilder) =
let debug =
[CompilerOption("debug", tagNone, OptionSwitch (SetDebugSwitch tcConfigB None), None,
Some (FSComp.SR.optsDebugPM()))
CompilerOption("debug", tagFullPDBOnlyPortable, OptionString (fun s -> SetDebugSwitch tcConfigB (Some(s)) OptionSwitch.On), None,
Some (FSComp.SR.optsDebug(if isFsi then "pdbonly" else "full")))
]
let embed =
[CompilerOption("embed", tagNone, OptionSwitch (SetEmbedAllSourceSwitch tcConfigB) , None,
Some (FSComp.SR.optsEmbedAllSource()))
CompilerOption("embed", tagFileList, OptionStringList (fun f -> tcConfigB.AddEmbeddedSourceFile f), None,
Some ( FSComp.SR.optsEmbedSource()));
CompilerOption("sourcelink", tagFile, OptionString (fun f -> tcConfigB.sourceLink <- f), None,
Some ( FSComp.SR.optsSourceLink()));
]
let codegen =
[CompilerOption("optimize", tagNone, OptionSwitch (SetOptimizeSwitch tcConfigB) , None,
Some (FSComp.SR.optsOptimize()))
CompilerOption("tailcalls", tagNone, OptionSwitch (SetTailcallSwitch tcConfigB), None,
Some (FSComp.SR.optsTailcalls()))
CompilerOption("crossoptimize", tagNone, OptionSwitch (crossOptimizeSwitch tcConfigB), None,
Some (FSComp.SR.optsCrossoptimize()))
]
if isFsi then debug @ codegen
else debug @ embed @ codegen
// OptionBlock: Language
//----------------------
let defineSymbol tcConfigB s = tcConfigB.conditionalCompilationDefines <- s :: tcConfigB.conditionalCompilationDefines
let mlCompatibilityFlag (tcConfigB : TcConfigBuilder) =
CompilerOption("mlcompatibility", tagNone, OptionUnit (fun () -> tcConfigB.mlCompatibility<-true; tcConfigB.TurnWarningOff(rangeCmdArgs,"62")), None,
Some (FSComp.SR.optsMlcompatibility()))
let languageFlags tcConfigB =
[
CompilerOption("checked", tagNone, OptionSwitch (fun switch -> tcConfigB.checkOverflow <- (switch = OptionSwitch.On)), None,
Some (FSComp.SR.optsChecked()))
CompilerOption("define", tagString, OptionString (defineSymbol tcConfigB), None,
Some (FSComp.SR.optsDefine()))
mlCompatibilityFlag tcConfigB
]
// OptionBlock: Advanced user options
//-----------------------------------
let libFlag (tcConfigB : TcConfigBuilder) =
CompilerOption("lib", tagDirList, OptionStringList (fun s -> tcConfigB.AddIncludePath (rangeStartup,s,tcConfigB.implicitIncludeDir)), None,
Some (FSComp.SR.optsLib()))
let libFlagAbbrev (tcConfigB : TcConfigBuilder) =
CompilerOption("I", tagDirList, OptionStringList (fun s -> tcConfigB.AddIncludePath (rangeStartup,s,tcConfigB.implicitIncludeDir)), None,
Some (FSComp.SR.optsShortFormOf("--lib")))
let codePageFlag (tcConfigB : TcConfigBuilder) =
CompilerOption("codepage", tagInt, OptionInt (fun n ->
try
System.Text.Encoding.GetEncodingShim(n) |> ignore
with :? System.ArgumentException as err ->
error(Error(FSComp.SR.optsProblemWithCodepage(n,err.Message),rangeCmdArgs))
tcConfigB.inputCodePage <- Some(n)), None,
Some (FSComp.SR.optsCodepage()))
#if PREFERRED_UI_LANG
let preferredUiLang (tcConfigB: TcConfigBuilder) =
CompilerOption("preferreduilang", tagString, OptionString (fun s -> tcConfigB.preferredUiLang <- Some(s)), None, Some(FSComp.SR.optsStrongKeyContainer()))
#endif
let utf8OutputFlag (tcConfigB: TcConfigBuilder) =
CompilerOption("utf8output", tagNone, OptionUnit (fun () -> tcConfigB.utf8output <- true), None,
Some (FSComp.SR.optsUtf8output()))
let fullPathsFlag (tcConfigB : TcConfigBuilder) =
CompilerOption("fullpaths", tagNone, OptionUnit (fun () -> tcConfigB.showFullPaths <- true), None,
Some (FSComp.SR.optsFullpaths()))
let cliRootFlag (_tcConfigB : TcConfigBuilder) =
CompilerOption("cliroot", tagString, OptionString (fun _ -> ()), Some(DeprecatedCommandLineOptionFull(FSComp.SR.optsClirootDeprecatedMsg(), rangeCmdArgs)),
Some(FSComp.SR.optsClirootDescription()))
let SetTargetProfile tcConfigB v =
tcConfigB.primaryAssembly <-
match v with
| "mscorlib" -> PrimaryAssembly.Mscorlib
| "netcore" -> PrimaryAssembly.DotNetCore
| _ -> error(Error(FSComp.SR.optsInvalidTargetProfile(v), rangeCmdArgs))
let advancedFlagsBoth tcConfigB =
[
yield codePageFlag tcConfigB
yield utf8OutputFlag tcConfigB
#if PREFERRED_UI_LANG
yield preferredUiLang tcConfigB
#endif
yield fullPathsFlag tcConfigB
yield libFlag tcConfigB
yield CompilerOption("simpleresolution",
tagNone,
OptionUnit (fun () -> tcConfigB.useSimpleResolution<-true),
None,
Some (FSComp.SR.optsSimpleresolution()))
yield CompilerOption("targetprofile", tagString, OptionString (SetTargetProfile tcConfigB), None, Some(FSComp.SR.optsTargetProfile()))
]
let noFrameworkFlag isFsc tcConfigB =
CompilerOption("noframework", tagNone, OptionUnit (fun () ->
tcConfigB.framework <- false
if isFsc then
tcConfigB.implicitlyResolveAssemblies <- false), None,
Some (FSComp.SR.optsNoframework()))
let advancedFlagsFsi tcConfigB =
advancedFlagsBoth tcConfigB @
[
yield noFrameworkFlag false tcConfigB
]
let advancedFlagsFsc tcConfigB =
advancedFlagsBoth tcConfigB @
[
yield CompilerOption("baseaddress", tagAddress, OptionString (fun s -> tcConfigB.baseAddress <- Some(int32 s)), None, Some (FSComp.SR.optsBaseaddress()))
yield noFrameworkFlag true tcConfigB
yield CompilerOption("standalone", tagNone, OptionUnit (fun _ ->
tcConfigB.openDebugInformationForLaterStaticLinking <- true
tcConfigB.standalone <- true
tcConfigB.implicitlyResolveAssemblies <- true), None,
Some (FSComp.SR.optsStandalone()))
yield CompilerOption("staticlink", tagFile, OptionString (fun s -> tcConfigB.extraStaticLinkRoots <- tcConfigB.extraStaticLinkRoots @ [s]), None,
Some (FSComp.SR.optsStaticlink()))
#if ENABLE_MONO_SUPPORT
if runningOnMono then
yield CompilerOption("resident", tagFile, OptionUnit (fun () -> ()), None,
Some (FSComp.SR.optsResident()))
#endif
yield CompilerOption("pdb", tagString, OptionString (fun s -> tcConfigB.debugSymbolFile <- Some s), None,
Some (FSComp.SR.optsPdb()))
yield CompilerOption("highentropyva", tagNone, OptionSwitch (useHighEntropyVASwitch tcConfigB), None, Some (FSComp.SR.optsUseHighEntropyVA()))
yield CompilerOption("subsystemversion", tagString, OptionString (subSystemVersionSwitch tcConfigB), None, Some (FSComp.SR.optsSubSystemVersion()))
yield CompilerOption("quotations-debug", tagNone, OptionSwitch(fun switch -> tcConfigB.emitDebugInfoInQuotations <- switch = OptionSwitch.On), None, Some(FSComp.SR.optsEmitDebugInfoInQuotations()))
]
// OptionBlock: Internal options (test use only)
//--------------------------------------------------
let testFlag tcConfigB =
CompilerOption("test", tagString, OptionString (fun s ->
match s with
| "ErrorRanges" -> tcConfigB.errorStyle <- ErrorStyle.TestErrors
| "MemberBodyRanges" -> PostTypeCheckSemanticChecks.testFlagMemberBody := true
| "Tracking" -> Lib.tracking := true (* general purpose on/off diagnostics flag *)
| "NoNeedToTailcall" -> tcConfigB.optSettings <- { tcConfigB.optSettings with reportNoNeedToTailcall = true }
| "FunctionSizes" -> tcConfigB.optSettings <- { tcConfigB.optSettings with reportFunctionSizes = true }
| "TotalSizes" -> tcConfigB.optSettings <- { tcConfigB.optSettings with reportTotalSizes = true }
| "HasEffect" -> tcConfigB.optSettings <- { tcConfigB.optSettings with reportHasEffect = true }
| "NoErrorText" -> FSComp.SR.SwallowResourceText <- true
| "EmitFeeFeeAs100001" -> tcConfigB.testFlagEmitFeeFeeAs100001 <- true
| "DumpDebugInfo" -> tcConfigB.dumpDebugInfo <- true
| "ShowLoadedAssemblies" -> tcConfigB.showLoadedAssemblies <- true
| "ContinueAfterParseFailure" -> tcConfigB.continueAfterParseFailure <- true
| str -> warning(Error(FSComp.SR.optsUnknownArgumentToTheTestSwitch(str),rangeCmdArgs))), None,
None)
// not shown in fsc.exe help, no warning on use, motiviation is for use from VS
let vsSpecificFlags (tcConfigB: TcConfigBuilder) =
[ CompilerOption("vserrors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.VSErrors), None, None)
CompilerOption("validate-type-providers", tagNone, OptionUnit (id), None, None) // preserved for compatibility's sake, no longer has any effect
#if PREFERRED_UI_LANG
CompilerOption("LCID", tagInt, OptionInt (fun _n -> ()), None, None)
#else
CompilerOption("LCID", tagInt, OptionInt (fun n -> tcConfigB.lcid <- Some(n)), None, None)
#endif
CompilerOption("flaterrors", tagNone, OptionUnit (fun () -> tcConfigB.flatErrors <- true), None, None)
CompilerOption("sqmsessionguid", tagNone, OptionString (fun s -> tcConfigB.sqmSessionGuid <- try System.Guid(s) |> Some with e -> None), None, None)
CompilerOption("gccerrors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.GccErrors), None, None)
CompilerOption("exename", tagNone, OptionString (fun s -> tcConfigB.exename <- Some(s)), None, None)
CompilerOption("maxerrors", tagInt, OptionInt (fun n -> tcConfigB.maxErrors <- n), None, None) ]
let internalFlags (tcConfigB:TcConfigBuilder) =
[
CompilerOption("stamps", tagNone, OptionUnit (fun () -> ()), Some(InternalCommandLineOption("--stamps", rangeCmdArgs)), None)
CompilerOption("ranges", tagNone, OptionSet Tastops.DebugPrint.layoutRanges, Some(InternalCommandLineOption("--ranges", rangeCmdArgs)), None)
CompilerOption("terms" , tagNone, OptionUnit (fun () -> tcConfigB.showTerms <- true), Some(InternalCommandLineOption("--terms", rangeCmdArgs)), None)
CompilerOption("termsfile" , tagNone, OptionUnit (fun () -> tcConfigB.writeTermsToFiles <- true), Some(InternalCommandLineOption("--termsfile", rangeCmdArgs)), None)
#if DEBUG
CompilerOption("debug-parse", tagNone, OptionUnit (fun () -> Internal.Utilities.Text.Parsing.Flags.debug <- true), Some(InternalCommandLineOption("--debug-parse", rangeCmdArgs)), None)
#endif
CompilerOption("pause", tagNone, OptionUnit (fun () -> tcConfigB.pause <- true), Some(InternalCommandLineOption("--pause", rangeCmdArgs)), None)
CompilerOption("detuple", tagNone, OptionInt (setFlag (fun v -> tcConfigB.doDetuple <- v)), Some(InternalCommandLineOption("--detuple", rangeCmdArgs)), None)
CompilerOption("simulateException", tagNone, OptionString (fun s -> tcConfigB.simulateException <- Some(s)), Some(InternalCommandLineOption("--simulateException", rangeCmdArgs)), Some "Simulate an exception from some part of the compiler")
CompilerOption("stackReserveSize", tagNone, OptionString (fun s -> tcConfigB.stackReserveSize <- Some(int32 s)), Some(InternalCommandLineOption("--stackReserveSize", rangeCmdArgs)), Some ("for an exe, set stack reserve size"))
CompilerOption("tlr", tagInt, OptionInt (setFlag (fun v -> tcConfigB.doTLR <- v)), Some(InternalCommandLineOption("--tlr", rangeCmdArgs)), None)
CompilerOption("finalSimplify", tagInt, OptionInt (setFlag (fun v -> tcConfigB.doFinalSimplify <- v)), Some(InternalCommandLineOption("--finalSimplify", rangeCmdArgs)), None)
#if TLR_LIFT
CompilerOption("tlrlift", tagNone, OptionInt (setFlag (fun v -> InnerLambdasToTopLevelFuncs.liftTLR := v)), Some(InternalCommandLineOption("--tlrlift", rangeCmdArgs)), None)
#endif
CompilerOption("parseonly", tagNone, OptionUnit (fun () -> tcConfigB.parseOnly <- true), Some(InternalCommandLineOption("--parseonly", rangeCmdArgs)), None)
CompilerOption("typecheckonly", tagNone, OptionUnit (fun () -> tcConfigB.typeCheckOnly <- true), Some(InternalCommandLineOption("--typecheckonly", rangeCmdArgs)), None)
CompilerOption("ast", tagNone, OptionUnit (fun () -> tcConfigB.printAst <- true), Some(InternalCommandLineOption("--ast", rangeCmdArgs)), None)
CompilerOption("tokenize", tagNone, OptionUnit (fun () -> tcConfigB.tokenizeOnly <- true), Some(InternalCommandLineOption("--tokenize", rangeCmdArgs)), None)
CompilerOption("testInteractionParser", tagNone, OptionUnit (fun () -> tcConfigB.testInteractionParser <- true), Some(InternalCommandLineOption("--testInteractionParser", rangeCmdArgs)), None)
CompilerOption("testparsererrorrecovery", tagNone, OptionUnit (fun () -> tcConfigB.reportNumDecls <- true), Some(InternalCommandLineOption("--testparsererrorrecovery", rangeCmdArgs)), None)
CompilerOption("inlinethreshold", tagInt, OptionInt (fun n -> tcConfigB.optSettings <- { tcConfigB.optSettings with lambdaInlineThreshold = n }), Some(InternalCommandLineOption("--inlinethreshold", rangeCmdArgs)), None)
CompilerOption("extraoptimizationloops", tagNone, OptionInt (fun n -> tcConfigB.extraOptimizationIterations <- n), Some(InternalCommandLineOption("--extraoptimizationloops", rangeCmdArgs)), None)
CompilerOption("abortonerror", tagNone, OptionUnit (fun () -> tcConfigB.abortOnError <- true), Some(InternalCommandLineOption("--abortonerror", rangeCmdArgs)), None)
CompilerOption("implicitresolution", tagNone, OptionUnit (fun _ -> tcConfigB.implicitlyResolveAssemblies <- true), Some(InternalCommandLineOption("--implicitresolution", rangeCmdArgs)), None)
CompilerOption("resolutions", tagNone, OptionUnit (fun () -> tcConfigB.showReferenceResolutions <- true), Some(InternalCommandLineOption("", rangeCmdArgs)), None) // "Display assembly reference resolution information")
CompilerOption("resolutionframeworkregistrybase", tagString, OptionString (fun _ -> ()), Some(InternalCommandLineOption("", rangeCmdArgs)), None) // "The base registry key to use for assembly resolution. This part in brackets here: HKEY_LOCAL_MACHINE\[SOFTWARE\Microsoft\.NETFramework]\v2.0.50727\AssemblyFoldersEx")
CompilerOption("resolutionassemblyfoldersuffix", tagString, OptionString (fun _ -> ()), Some(InternalCommandLineOption("resolutionassemblyfoldersuffix", rangeCmdArgs)), None) // "The base registry key to use for assembly resolution. This part in brackets here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\[AssemblyFoldersEx]")
CompilerOption("resolutionassemblyfoldersconditions", tagString, OptionString (fun _ -> ()), Some(InternalCommandLineOption("resolutionassemblyfoldersconditions", rangeCmdArgs)), None) // "Additional reference resolution conditions. For example \"OSVersion=5.1.2600.0,PlatformID=id")
CompilerOption("msbuildresolution", tagNone, OptionUnit (fun () -> tcConfigB.useSimpleResolution<-false), Some(InternalCommandLineOption("msbuildresolution", rangeCmdArgs)), None) // "Resolve assembly references using MSBuild resolution rules rather than directory based (Default=true except when running fsc.exe under mono)")
CompilerOption("alwayscallvirt",tagNone,OptionSwitch(callVirtSwitch tcConfigB),Some(InternalCommandLineOption("alwayscallvirt",rangeCmdArgs)), None)
CompilerOption("nodebugdata",tagNone, OptionUnit (fun () -> tcConfigB.noDebugData<-true),Some(InternalCommandLineOption("--nodebugdata",rangeCmdArgs)), None)
testFlag tcConfigB ] @
vsSpecificFlags tcConfigB @
[ CompilerOption("jit", tagNone, OptionSwitch (jitoptimizeSwitch tcConfigB), Some(InternalCommandLineOption("jit", rangeCmdArgs)), None)
CompilerOption("localoptimize", tagNone, OptionSwitch(localoptimizeSwitch tcConfigB),Some(InternalCommandLineOption("localoptimize", rangeCmdArgs)), None)
CompilerOption("splitting", tagNone, OptionSwitch(splittingSwitch tcConfigB),Some(InternalCommandLineOption("splitting", rangeCmdArgs)), None)
CompilerOption("versionfile", tagString, OptionString (fun s -> tcConfigB.version <- VersionFile s), Some(InternalCommandLineOption("versionfile", rangeCmdArgs)), None)
CompilerOption("times" , tagNone, OptionUnit (fun () -> tcConfigB.showTimes <- true), Some(InternalCommandLineOption("times", rangeCmdArgs)), None) // "Display timing profiles for compilation")
#if EXTENSIONTYPING
CompilerOption("showextensionresolution" , tagNone, OptionUnit (fun () -> tcConfigB.showExtensionTypeMessages <- true), Some(InternalCommandLineOption("showextensionresolution", rangeCmdArgs)), None) // "Display information about extension type resolution")
#endif
(* BEGIN: Consider as public Retail option? *)
// Some System.Console do not have operational colors, make this available in Retail?
CompilerOption("metadataversion", tagString, OptionString (fun s -> tcConfigB.metadataVersion <- Some(s)), Some(InternalCommandLineOption("metadataversion", rangeCmdArgs)), None)
]
// OptionBlock: Deprecated flags (fsc, service only)
//--------------------------------------------------
let compilingFsLibFlag (tcConfigB : TcConfigBuilder) =
CompilerOption("compiling-fslib", tagNone, OptionUnit (fun () -> tcConfigB.compilingFslib <- true
tcConfigB.TurnWarningOff(rangeStartup,"42")
ErrorLogger.reportLibraryOnlyFeatures <- false
IlxSettings.ilxCompilingFSharpCoreLib := true), Some(InternalCommandLineOption("--compiling-fslib", rangeCmdArgs)), None)
let compilingFsLib20Flag (tcConfigB : TcConfigBuilder) =
CompilerOption("compiling-fslib-20", tagNone, OptionString (fun s -> tcConfigB.compilingFslib20 <- Some s ), Some(InternalCommandLineOption("--compiling-fslib-20", rangeCmdArgs)), None)
let compilingFsLib40Flag (tcConfigB : TcConfigBuilder) =
CompilerOption("compiling-fslib-40", tagNone, OptionUnit (fun () -> tcConfigB.compilingFslib40 <- true ), Some(InternalCommandLineOption("--compiling-fslib-40", rangeCmdArgs)), None)
let compilingFsLibNoBigIntFlag (tcConfigB : TcConfigBuilder) =
CompilerOption("compiling-fslib-nobigint", tagNone, OptionUnit (fun () -> tcConfigB.compilingFslibNoBigInt <- true ), Some(InternalCommandLineOption("--compiling-fslib-nobigint", rangeCmdArgs)), None)
let mlKeywordsFlag =
CompilerOption("ml-keywords", tagNone, OptionUnit (fun () -> ()), Some(DeprecatedCommandLineOptionNoDescription("--ml-keywords", rangeCmdArgs)), None)
let gnuStyleErrorsFlag tcConfigB =
CompilerOption("gnu-style-errors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.EmacsErrors), Some(DeprecatedCommandLineOptionNoDescription("--gnu-style-errors", rangeCmdArgs)), None)
let deprecatedFlagsBoth tcConfigB =
[
CompilerOption("light", tagNone, OptionUnit (fun () -> tcConfigB.light <- Some(true)), Some(DeprecatedCommandLineOptionNoDescription("--light", rangeCmdArgs)), None)
CompilerOption("indentation-syntax", tagNone, OptionUnit (fun () -> tcConfigB.light <- Some(true)), Some(DeprecatedCommandLineOptionNoDescription("--indentation-syntax", rangeCmdArgs)), None)
CompilerOption("no-indentation-syntax", tagNone, OptionUnit (fun () -> tcConfigB.light <- Some(false)), Some(DeprecatedCommandLineOptionNoDescription("--no-indentation-syntax", rangeCmdArgs)), None)
]
let deprecatedFlagsFsi tcConfigB = deprecatedFlagsBoth tcConfigB
let deprecatedFlagsFsc tcConfigB =
deprecatedFlagsBoth tcConfigB @
[
cliRootFlag tcConfigB
CompilerOption("jit-optimize", tagNone, OptionUnit (fun _ -> tcConfigB.optSettings <- { tcConfigB.optSettings with jitOptUser = Some true }), Some(DeprecatedCommandLineOptionNoDescription("--jit-optimize", rangeCmdArgs)), None)
CompilerOption("no-jit-optimize", tagNone, OptionUnit (fun _ -> tcConfigB.optSettings <- { tcConfigB.optSettings with jitOptUser = Some false }), Some(DeprecatedCommandLineOptionNoDescription("--no-jit-optimize", rangeCmdArgs)), None)
CompilerOption("jit-tracking", tagNone, OptionUnit (fun _ -> (tcConfigB.jitTracking <- true) ), Some(DeprecatedCommandLineOptionNoDescription("--jit-tracking", rangeCmdArgs)), None)
CompilerOption("no-jit-tracking", tagNone, OptionUnit (fun _ -> (tcConfigB.jitTracking <- false) ), Some(DeprecatedCommandLineOptionNoDescription("--no-jit-tracking", rangeCmdArgs)), None)
CompilerOption("progress", tagNone, OptionUnit (fun () -> progress := true), Some(DeprecatedCommandLineOptionNoDescription("--progress", rangeCmdArgs)), None)
(compilingFsLibFlag tcConfigB)
(compilingFsLib20Flag tcConfigB)
(compilingFsLib40Flag tcConfigB)
(compilingFsLibNoBigIntFlag tcConfigB)
CompilerOption("version", tagString, OptionString (fun s -> tcConfigB.version <- VersionString s), Some(DeprecatedCommandLineOptionNoDescription("--version", rangeCmdArgs)), None)
// "--clr-mscorlib", OptionString (fun s -> warning(Some(DeprecatedCommandLineOptionNoDescription("--clr-mscorlib", rangeCmdArgs))) tcConfigB.Build.mscorlib_assembly_name <- s), "\n\tThe name of mscorlib on the target CLR"
CompilerOption("local-optimize", tagNone, OptionUnit (fun _ -> tcConfigB.optSettings <- { tcConfigB.optSettings with localOptUser = Some true }), Some(DeprecatedCommandLineOptionNoDescription("--local-optimize", rangeCmdArgs)), None)
CompilerOption("no-local-optimize", tagNone, OptionUnit (fun _ -> tcConfigB.optSettings <- { tcConfigB.optSettings with localOptUser = Some false }), Some(DeprecatedCommandLineOptionNoDescription("--no-local-optimize", rangeCmdArgs)), None)
CompilerOption("cross-optimize", tagNone, OptionUnit (fun _ -> tcConfigB.optSettings <- { tcConfigB.optSettings with crossModuleOptUser = Some true }), Some(DeprecatedCommandLineOptionNoDescription("--cross-optimize", rangeCmdArgs)), None)
CompilerOption("no-cross-optimize", tagNone, OptionUnit (fun _ -> tcConfigB.optSettings <- { tcConfigB.optSettings with crossModuleOptUser = Some false }), Some(DeprecatedCommandLineOptionNoDescription("--no-cross-optimize", rangeCmdArgs)), None)
CompilerOption("no-string-interning", tagNone, OptionUnit (fun () -> tcConfigB.internConstantStrings <- false), Some(DeprecatedCommandLineOptionNoDescription("--no-string-interning", rangeCmdArgs)), None)
CompilerOption("statistics", tagNone, OptionUnit (fun () -> tcConfigB.stats <- true), Some(DeprecatedCommandLineOptionNoDescription("--statistics", rangeCmdArgs)), None)
CompilerOption("generate-filter-blocks", tagNone, OptionUnit (fun () -> tcConfigB.generateFilterBlocks <- true), Some(DeprecatedCommandLineOptionNoDescription("--generate-filter-blocks", rangeCmdArgs)), None)
//CompilerOption("no-generate-filter-blocks", tagNone, OptionUnit (fun () -> tcConfigB.generateFilterBlocks <- false), Some(DeprecatedCommandLineOptionNoDescription("--generate-filter-blocks", rangeCmdArgs)), None)
CompilerOption("max-errors", tagInt, OptionInt (fun n -> tcConfigB.maxErrors <- n), Some(DeprecatedCommandLineOptionSuggestAlternative("--max-errors", "--maxerrors", rangeCmdArgs)),None)
CompilerOption("debug-file", tagNone, OptionString (fun s -> tcConfigB.debugSymbolFile <- Some s), Some(DeprecatedCommandLineOptionSuggestAlternative("--debug-file", "--pdb", rangeCmdArgs)), None)
CompilerOption("no-debug-file", tagNone, OptionUnit (fun () -> tcConfigB.debuginfo <- false), Some(DeprecatedCommandLineOptionSuggestAlternative("--no-debug-file", "--debug-", rangeCmdArgs)), None)
CompilerOption("Ooff", tagNone, OptionUnit (fun () -> SetOptimizeOff(tcConfigB)), Some(DeprecatedCommandLineOptionSuggestAlternative("-Ooff", "--optimize-", rangeCmdArgs)), None)
mlKeywordsFlag
gnuStyleErrorsFlag tcConfigB
]
// OptionBlock: Miscellaneous options
//-----------------------------------
let DisplayBannerText tcConfigB =
if tcConfigB.showBanner then (
printfn "%s" tcConfigB.productNameForBannerText
printfn "%s" (FSComp.SR.optsCopyright())
)
/// FSC only help. (FSI has it's own help function).
let displayHelpFsc tcConfigB (blocks:CompilerOptionBlock list) =
DisplayBannerText tcConfigB
PrintCompilerOptionBlocks blocks
exit 0
let miscFlagsBoth tcConfigB =
[ CompilerOption("nologo", tagNone, OptionUnit (fun () -> tcConfigB.showBanner <- false), None, Some (FSComp.SR.optsNologo()))
]
let miscFlagsFsc tcConfigB =
miscFlagsBoth tcConfigB @
[ CompilerOption("help", tagNone, OptionHelp (fun blocks -> displayHelpFsc tcConfigB blocks), None, Some (FSComp.SR.optsHelp()))
CompilerOption("@<file>", tagNone, OptionUnit ignore, None, Some (FSComp.SR.optsResponseFile()))
]
let miscFlagsFsi tcConfigB = miscFlagsBoth tcConfigB
// OptionBlock: Abbreviations of existing options
//-----------------------------------------------
let abbreviatedFlagsBoth tcConfigB =
[
CompilerOption("d", tagString, OptionString (defineSymbol tcConfigB), None, Some(FSComp.SR.optsShortFormOf("--define")))
CompilerOption("O", tagNone, OptionSwitch (SetOptimizeSwitch tcConfigB) , None, Some(FSComp.SR.optsShortFormOf("--optimize[+|-]")))
CompilerOption("g", tagNone, OptionSwitch (SetDebugSwitch tcConfigB None), None, Some(FSComp.SR.optsShortFormOf("--debug")))
CompilerOption("i", tagString, OptionUnit (fun () -> tcConfigB.printSignature <- true), None, Some(FSComp.SR.optsShortFormOf("--sig")))
referenceFlagAbbrev tcConfigB (* -r <dll> *)
libFlagAbbrev tcConfigB (* -I <dir> *)
]
let abbreviatedFlagsFsi tcConfigB = abbreviatedFlagsBoth tcConfigB
let abbreviatedFlagsFsc tcConfigB =
abbreviatedFlagsBoth tcConfigB @
[ (* FSC only abbreviated options *)
CompilerOption("o", tagString, OptionString (setOutFileName tcConfigB), None, Some(FSComp.SR.optsShortFormOf("--out")))
CompilerOption("a", tagString, OptionUnit (fun () -> tcConfigB.target <- Dll), None, Some(FSComp.SR.optsShortFormOf("--target library")))
(* FSC help abbreviations. FSI has it's own help options... *)