forked from nosami/visualfsharp
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CompilerConfig.fs
1175 lines (1032 loc) · 52.5 KB
/
CompilerConfig.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.
/// The configuration of the compiler (TcConfig and TcConfigBuilder)
module internal FSharp.Compiler.CompilerConfig
open System
open System.Collections.Generic
open System.Collections.Concurrent
open System.Diagnostics
open System.IO
open System.Text
open Internal.Utilities
open Internal.Utilities.Filename
open FSharp.Compiler
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.ILBinaryReader
open FSharp.Compiler.AbstractIL.ILPdbWriter
open FSharp.Compiler.AbstractIL.Internal
open FSharp.Compiler.AbstractIL.Internal.Library
open FSharp.Compiler.AbstractIL.Internal.Utils
open FSharp.Compiler.DotNetFrameworkDependencies
open FSharp.Compiler.ErrorLogger
open FSharp.Compiler.Features
open FSharp.Compiler.Lib
open FSharp.Compiler.Range
open FSharp.Compiler.ReferenceResolver
open FSharp.Compiler.TypedTree
open Microsoft.DotNet.DependencyManager
#if !NO_EXTENSIONTYPING
open FSharp.Compiler.ExtensionTyping
open Microsoft.FSharp.Core.CompilerServices
#endif
let (++) x s = x @ [s]
//----------------------------------------------------------------------------
// Some Globals
//--------------------------------------------------------------------------
let FSharpSigFileSuffixes = [".mli";".fsi"]
let mlCompatSuffixes = [".mli";".ml"]
let FSharpImplFileSuffixes = [".ml";".fs";".fsscript";".fsx"]
let FSharpScriptFileSuffixes = [".fsscript";".fsx"]
let doNotRequireNamespaceOrModuleSuffixes = [".mli";".ml"] @ FSharpScriptFileSuffixes
let FSharpLightSyntaxFileSuffixes: string list = [ ".fs";".fsscript";".fsx";".fsi" ]
//--------------------------------------------------------------------------
// General file name resolver
//--------------------------------------------------------------------------
exception FileNameNotResolved of (*filename*) string * (*description of searched locations*) string * range
exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
/// Will return None if the filename is not found.
let TryResolveFileUsingPaths(paths, m, name) =
let () =
try FileSystem.IsPathRootedShim name |> ignore
with :? System.ArgumentException as e -> error(Error(FSComp.SR.buildProblemWithFilename(name, e.Message), m))
if FileSystem.IsPathRootedShim name && FileSystem.SafeExists name
then Some name
else
let res = paths |> List.tryPick (fun path ->
let n = Path.Combine (path, name)
if FileSystem.SafeExists n then Some n
else None)
res
/// Will raise FileNameNotResolved if the filename was not found
let ResolveFileUsingPaths(paths, m, name) =
match TryResolveFileUsingPaths(paths, m, name) with
| Some res -> res
| None ->
let searchMessage = String.concat "\n " paths
raise (FileNameNotResolved(name, searchMessage, m))
let GetWarningNumber(m, warningNumber: string) =
try
// Okay so ...
// #pragma strips FS of the #pragma "FS0004" and validates the warning number
// therefore if we have warning id that starts with a numeric digit we convert it to Some (int32)
// anything else is ignored None
if Char.IsDigit(warningNumber.[0]) then Some (int32 warningNumber)
elif warningNumber.StartsWithOrdinal("FS") = true then raise (new ArgumentException())
else None
with _ ->
warning(Error(FSComp.SR.buildInvalidWarningNumber warningNumber, m))
None
let ComputeMakePathAbsolute implicitIncludeDir (path: string) =
try
// remove any quotation marks from the path first
let path = path.Replace("\"", "")
if not (FileSystem.IsPathRootedShim path)
then Path.Combine (implicitIncludeDir, path)
else path
with
:? System.ArgumentException -> path
//----------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------
[<RequireQualifiedAccess>]
type CompilerTarget =
| WinExe
| ConsoleExe
| Dll
| Module
member x.IsExe = (match x with ConsoleExe | WinExe -> true | _ -> false)
[<RequireQualifiedAccess>]
type ResolveAssemblyReferenceMode = Speculative | ReportErrors
[<RequireQualifiedAccess>]
type CopyFSharpCoreFlag = Yes | No
/// Represents the file or string used for the --version flag
type VersionFlag =
| VersionString of string
| VersionFile of string
| VersionNone
member x.GetVersionInfo implicitIncludeDir =
let vstr = x.GetVersionString implicitIncludeDir
try
IL.parseILVersion vstr
with _ -> errorR(Error(FSComp.SR.buildInvalidVersionString vstr, rangeStartup)); IL.parseILVersion "0.0.0.0"
member x.GetVersionString implicitIncludeDir =
match x with
| VersionString s -> s
| VersionFile s ->
let s = if FileSystem.IsPathRootedShim s then s else Path.Combine(implicitIncludeDir, s)
if not(FileSystem.SafeExists s) then
errorR(Error(FSComp.SR.buildInvalidVersionFile s, rangeStartup)); "0.0.0.0"
else
use is = System.IO.File.OpenText s
is.ReadLine()
| VersionNone -> "0.0.0.0"
/// Represents a reference to an assembly. May be backed by a real assembly on disk, or a cross-project
/// reference backed by information generated by the the compiler service.
type IRawFSharpAssemblyData =
/// The raw list AutoOpenAttribute attributes in the assembly
abstract GetAutoOpenAttributes: ILGlobals -> string list
/// The raw list InternalsVisibleToAttribute attributes in the assembly
abstract GetInternalsVisibleToAttributes: ILGlobals -> string list
/// The raw IL module definition in the assembly, if any. This is not present for cross-project references
/// in the language service
abstract TryGetILModuleDef: unit -> ILModuleDef option
/// The raw F# signature data in the assembly, if any
abstract GetRawFSharpSignatureData: range * ilShortAssemName: string * fileName: string -> (string * (unit -> ReadOnlyByteMemory)) list
/// The raw F# optimization data in the assembly, if any
abstract GetRawFSharpOptimizationData: range * ilShortAssemName: string * fileName: string -> (string * (unit -> ReadOnlyByteMemory)) list
/// The table of type forwarders in the assembly
abstract GetRawTypeForwarders: unit -> ILExportedTypesAndForwarders
/// The identity of the module
abstract ILScopeRef: ILScopeRef
abstract ILAssemblyRefs: ILAssemblyRef list
abstract ShortAssemblyName: string
abstract HasAnyFSharpSignatureDataAttribute: bool
abstract HasMatchingFSharpSignatureDataAttribute: ILGlobals -> bool
/// Cache of time stamps as we traverse a project description
type TimeStampCache(defaultTimeStamp: DateTime) =
let files = ConcurrentDictionary<string, DateTime>()
let projects = ConcurrentDictionary<IProjectReference, DateTime>(HashIdentity.Reference)
member cache.GetFileTimeStamp fileName =
let ok, v = files.TryGetValue fileName
if ok then v else
let v =
try
FileSystem.GetLastWriteTimeShim fileName
with
| :? FileNotFoundException ->
defaultTimeStamp
files.[fileName] <- v
v
member cache.GetProjectReferenceTimeStamp (pr: IProjectReference, ctok) =
let ok, v = projects.TryGetValue pr
if ok then v else
let v = defaultArg (pr.TryGetLogicalTimeStamp (cache, ctok)) defaultTimeStamp
projects.[pr] <- v
v
and IProjectReference =
/// The name of the assembly file generated by the project
abstract FileName: string
/// Evaluate raw contents of the assembly file generated by the project
abstract EvaluateRawContents: CompilationThreadToken -> Cancellable<IRawFSharpAssemblyData option>
/// Get the logical timestamp that would be the timestamp of the assembly file generated by the project
///
/// For project references this is maximum of the timestamps of all dependent files.
/// The project is not actually built, nor are any assemblies read, but the timestamps for each dependent file
/// are read via the FileSystem. If the files don't exist, then a default timestamp is used.
///
/// The operation returns None only if it is not possible to create an IncrementalBuilder for the project at all, e.g. if there
/// are fatal errors in the options for the project.
abstract TryGetLogicalTimeStamp: TimeStampCache * CompilationThreadToken -> System.DateTime option
type AssemblyReference =
| AssemblyReference of range * string * IProjectReference option
member x.Range = (let (AssemblyReference(m, _, _)) = x in m)
member x.Text = (let (AssemblyReference(_, text, _)) = x in text)
member x.ProjectReference = (let (AssemblyReference(_, _, contents)) = x in contents)
member x.SimpleAssemblyNameIs name =
(String.Compare(fileNameWithoutExtensionWithValidate false x.Text, name, StringComparison.OrdinalIgnoreCase) = 0) ||
(let text = x.Text.ToLowerInvariant()
not (text.Contains "/") && not (text.Contains "\\") && not (text.Contains ".dll") && not (text.Contains ".exe") &&
try let aname = System.Reflection.AssemblyName x.Text in aname.Name = name
with _ -> false)
override x.ToString() = sprintf "AssemblyReference(%s)" x.Text
type UnresolvedAssemblyReference = UnresolvedAssemblyReference of string * AssemblyReference list
#if !NO_EXTENSIONTYPING
type ResolvedExtensionReference = ResolvedExtensionReference of string * AssemblyReference list * Tainted<ITypeProvider> list
#endif
type ImportedAssembly =
{ ILScopeRef: ILScopeRef
FSharpViewOfMetadata: CcuThunk
AssemblyAutoOpenAttributes: string list
AssemblyInternalsVisibleToAttributes: string list
#if !NO_EXTENSIONTYPING
IsProviderGenerated: bool
mutable TypeProviders: Tainted<Microsoft.FSharp.Core.CompilerServices.ITypeProvider> list
#endif
FSharpOptimizationData: Microsoft.FSharp.Control.Lazy<Option<Optimizer.LazyModuleInfo>> }
type AvailableImportedAssembly =
| ResolvedImportedAssembly of ImportedAssembly
| UnresolvedImportedAssembly of string
type CcuLoadFailureAction =
| RaiseError
| ReturnNone
type Directive =
| Resolution
| Include
type LStatus =
| Unprocessed
| Processed
type PackageManagerLine =
{ Directive: Directive
LineStatus: LStatus
Line: string
Range: range }
static member AddLineWithKey (packageKey: string) (directive:Directive) (line: string) (m: range) (packageManagerLines: Map<string, PackageManagerLine list>): Map<string, PackageManagerLine list> =
let path = PackageManagerLine.StripDependencyManagerKey packageKey line
let map =
let mutable found = false
let result =
packageManagerLines
|> Map.map(fun key lines ->
if key = packageKey then
found <- true
lines |> List.append [{Directive=directive; LineStatus=LStatus.Unprocessed; Line=path; Range=m}]
else
lines)
if found then
result
else
result.Add(packageKey, [{Directive=directive; LineStatus=LStatus.Unprocessed; Line=path; Range=m}])
map
static member RemoveUnprocessedLines (packageKey: string) (packageManagerLines: Map<string, PackageManagerLine list>): Map<string, PackageManagerLine list> =
let map =
packageManagerLines
|> Map.map(fun key lines ->
if key = packageKey then
lines |> List.filter(fun line -> line.LineStatus=LStatus.Processed)
else
lines)
map
static member SetLinesAsProcessed (packageKey:string) (packageManagerLines: Map<string, PackageManagerLine list>): Map<string, PackageManagerLine list> =
let map =
packageManagerLines
|> Map.map(fun key lines ->
if key = packageKey then
lines |> List.map(fun line -> {line with LineStatus = LStatus.Processed;})
else
lines)
map
static member StripDependencyManagerKey (packageKey: string) (line: string): string =
line.Substring(packageKey.Length + 1).Trim()
[<NoEquality; NoComparison>]
type TcConfigBuilder =
{ mutable primaryAssembly: PrimaryAssembly
mutable noFeedback: bool
mutable stackReserveSize: int32 option
mutable implicitIncludeDir: string (* normally "." *)
mutable openDebugInformationForLaterStaticLinking: bool (* only for --standalone *)
defaultFSharpBinariesDir: string
mutable compilingFslib: bool
mutable useIncrementalBuilder: bool
mutable includes: string list
mutable implicitOpens: string list
mutable useFsiAuxLib: bool
mutable framework: bool
mutable resolutionEnvironment: ReferenceResolver.ResolutionEnvironment
mutable implicitlyResolveAssemblies: bool
mutable light: bool option
mutable conditionalCompilationDefines: string list
mutable loadedSources: (range * string * string) list
mutable compilerToolPaths: string list
mutable referencedDLLs: AssemblyReference list
mutable packageManagerLines: Map<string, PackageManagerLine list>
mutable projectReferences: IProjectReference list
mutable knownUnresolvedReferences: UnresolvedAssemblyReference list
reduceMemoryUsage: ReduceMemoryFlag
mutable subsystemVersion: int * int
mutable useHighEntropyVA: bool
mutable inputCodePage: int option
mutable embedResources: string list
mutable errorSeverityOptions: FSharpErrorSeverityOptions
mutable mlCompatibility: bool
mutable checkOverflow: bool
mutable showReferenceResolutions: bool
mutable outputDir : string option
mutable outputFile: string option
mutable platform: ILPlatform option
mutable prefer32Bit: bool
mutable useSimpleResolution: bool
mutable target: CompilerTarget
mutable debuginfo: bool
mutable testFlagEmitFeeFeeAs100001: bool
mutable dumpDebugInfo: bool
mutable debugSymbolFile: string option
(* Backend configuration *)
mutable typeCheckOnly: bool
mutable parseOnly: bool
mutable importAllReferencesOnly: bool
mutable simulateException: string option
mutable printAst: bool
mutable tokenizeOnly: bool
mutable testInteractionParser: bool
mutable reportNumDecls: bool
mutable printSignature: bool
mutable printSignatureFile: string
mutable xmlDocOutputFile: string option
mutable stats: bool
mutable generateFilterBlocks: bool (* don't generate filter blocks due to bugs on Mono *)
mutable signer: string option
mutable container: string option
mutable delaysign: bool
mutable publicsign: bool
mutable version: VersionFlag
mutable metadataVersion: string option
mutable standalone: bool
mutable extraStaticLinkRoots: string list
mutable noSignatureData: bool
mutable onlyEssentialOptimizationData: bool
mutable useOptimizationDataFile: bool
mutable jitTracking: bool
mutable portablePDB: bool
mutable embeddedPDB: bool
mutable embedAllSource: bool
mutable embedSourceList: string list
mutable sourceLink: string
mutable ignoreSymbolStoreSequencePoints: bool
mutable internConstantStrings: bool
mutable extraOptimizationIterations: int
mutable win32res: string
mutable win32manifest: string
mutable includewin32manifest: bool
mutable linkResources: string list
mutable legacyReferenceResolver: ReferenceResolver.Resolver
mutable showFullPaths: bool
mutable errorStyle: ErrorStyle
mutable utf8output: bool
mutable flatErrors: bool
mutable maxErrors: int
mutable abortOnError: bool (* intended for fsi scripts that should exit on first error *)
mutable baseAddress: int32 option
mutable checksumAlgorithm: HashAlgorithm
#if DEBUG
mutable showOptimizationData: bool
#endif
mutable showTerms: bool (* show terms between passes? *)
mutable writeTermsToFiles: bool (* show terms to files? *)
mutable doDetuple: bool (* run detuple pass? *)
mutable doTLR: bool (* run TLR pass? *)
mutable doFinalSimplify: bool (* do final simplification pass *)
mutable optsOn: bool (* optimizations are turned on *)
mutable optSettings: Optimizer.OptimizationSettings
mutable emitTailcalls: bool
mutable deterministic: bool
mutable preferredUiLang: string option
mutable lcid: int option
mutable productNameForBannerText: string
/// show the MS (c) notice, e.g. with help or fsi?
mutable showBanner: bool
/// show times between passes?
mutable showTimes: bool
mutable showLoadedAssemblies: bool
mutable continueAfterParseFailure: bool
#if !NO_EXTENSIONTYPING
/// show messages about extension type resolution?
mutable showExtensionTypeMessages: bool
#endif
/// pause between passes?
mutable pause: bool
/// whenever possible, emit callvirt instead of call
mutable alwaysCallVirt: bool
/// if true, strip away data that would not be of use to end users, but is useful to us for debugging
// REVIEW: "stripDebugData"?
mutable noDebugData: bool
/// if true, indicates all type checking and code generation is in the context of fsi.exe
isInteractive: bool
isInvalidationSupported: bool
/// used to log sqm data
/// if true - every expression in quotations will be augmented with full debug info (filename, location in file)
mutable emitDebugInfoInQuotations: bool
mutable exename: string option
// If true - the compiler will copy FSharp.Core.dll along the produced binaries
mutable copyFSharpCore: CopyFSharpCoreFlag
/// When false FSI will lock referenced assemblies requiring process restart, false = disable Shadow Copy false (*default*)
mutable shadowCopyReferences: bool
mutable useSdkRefs: bool
/// A function to call to try to get an object that acts as a snapshot of the metadata section of a .NET binary,
/// and from which we can read the metadata. Only used when metadataOnly=true.
mutable tryGetMetadataSnapshot: ILReaderTryGetMetadataSnapshot
mutable internalTestSpanStackReferring: bool
mutable noConditionalErasure: bool
mutable pathMap: PathMap
mutable langVersion: LanguageVersion
}
static member Initial =
{
primaryAssembly = PrimaryAssembly.Mscorlib // default value, can be overridden using the command line switch
light = None
noFeedback = false
stackReserveSize = None
conditionalCompilationDefines = []
implicitIncludeDir = String.Empty
openDebugInformationForLaterStaticLinking = false
defaultFSharpBinariesDir = String.Empty
compilingFslib = false
useIncrementalBuilder = false
useFsiAuxLib = false
implicitOpens = []
includes = []
resolutionEnvironment = ResolutionEnvironment.EditingOrCompilation false
framework = true
implicitlyResolveAssemblies = true
compilerToolPaths = []
referencedDLLs = []
packageManagerLines = Map.empty
projectReferences = []
knownUnresolvedReferences = []
loadedSources = []
errorSeverityOptions = FSharpErrorSeverityOptions.Default
embedResources = []
inputCodePage = None
reduceMemoryUsage = ReduceMemoryFlag.Yes // always gets set explicitly
subsystemVersion = 4, 0 // per spec for 357994
useHighEntropyVA = false
mlCompatibility = false
checkOverflow = false
showReferenceResolutions = false
outputDir = None
outputFile = None
platform = None
prefer32Bit = false
useSimpleResolution = runningOnMono
target = CompilerTarget.ConsoleExe
debuginfo = false
testFlagEmitFeeFeeAs100001 = false
dumpDebugInfo = false
debugSymbolFile = None
(* Backend configuration *)
typeCheckOnly = false
parseOnly = false
importAllReferencesOnly = false
simulateException = None
printAst = false
tokenizeOnly = false
testInteractionParser = false
reportNumDecls = false
printSignature = false
printSignatureFile = ""
xmlDocOutputFile = None
stats = false
generateFilterBlocks = false (* don't generate filter blocks *)
signer = None
container = None
maxErrors = 100
abortOnError = false
baseAddress = None
checksumAlgorithm = HashAlgorithm.Sha256
delaysign = false
publicsign = false
version = VersionNone
metadataVersion = None
standalone = false
extraStaticLinkRoots = []
noSignatureData = false
onlyEssentialOptimizationData = false
useOptimizationDataFile = false
jitTracking = true
portablePDB = true
embeddedPDB = false
embedAllSource = false
embedSourceList = []
sourceLink = ""
ignoreSymbolStoreSequencePoints = false
internConstantStrings = true
extraOptimizationIterations = 0
win32res = ""
win32manifest = ""
includewin32manifest = true
linkResources = []
legacyReferenceResolver = null
showFullPaths = false
errorStyle = ErrorStyle.DefaultErrors
utf8output = false
flatErrors = false
#if DEBUG
showOptimizationData = false
#endif
showTerms = false
writeTermsToFiles = false
doDetuple = false
doTLR = false
doFinalSimplify = false
optsOn = false
optSettings = Optimizer.OptimizationSettings.Defaults
emitTailcalls = true
deterministic = false
preferredUiLang = None
lcid = None
productNameForBannerText = FSharpEnvironment.FSharpProductName
showBanner = true
showTimes = false
showLoadedAssemblies = false
continueAfterParseFailure = false
#if !NO_EXTENSIONTYPING
showExtensionTypeMessages = false
#endif
pause = false
alwaysCallVirt = true
noDebugData = false
isInteractive = false
isInvalidationSupported = false
emitDebugInfoInQuotations = false
exename = None
copyFSharpCore = CopyFSharpCoreFlag.No
shadowCopyReferences = false
useSdkRefs = true
tryGetMetadataSnapshot = (fun _ -> None)
internalTestSpanStackReferring = false
noConditionalErasure = false
pathMap = PathMap.empty
langVersion = LanguageVersion("default")
}
// Directories to start probing in
// Algorithm:
// Search for native libraries using:
// 1. Include directories
// 2. compilerToolPath directories
// 3. reference dll's
// 4. The implicit include directory
//
// NOTE: it is important this is a delayed IEnumerable sequence. It is recomputed
// each time a resolution happens and additional paths may be added as a result.
member tcConfigB.GetNativeProbingRoots () =
seq {
yield! tcConfigB.includes
yield! tcConfigB.compilerToolPaths
yield! (tcConfigB.referencedDLLs |> Seq.map(fun ref -> Path.GetDirectoryName(ref.Text)))
yield tcConfigB.implicitIncludeDir
}
|> Seq.distinct
static member CreateNew(legacyReferenceResolver, defaultFSharpBinariesDir, reduceMemoryUsage, implicitIncludeDir,
isInteractive, isInvalidationSupported, defaultCopyFSharpCore, tryGetMetadataSnapshot) =
Debug.Assert(FileSystem.IsPathRootedShim implicitIncludeDir, sprintf "implicitIncludeDir should be absolute: '%s'" implicitIncludeDir)
if (String.IsNullOrEmpty defaultFSharpBinariesDir) then
failwith "Expected a valid defaultFSharpBinariesDir"
let tcConfigBuilder =
{ TcConfigBuilder.Initial with
implicitIncludeDir = implicitIncludeDir
defaultFSharpBinariesDir = defaultFSharpBinariesDir
reduceMemoryUsage = reduceMemoryUsage
legacyReferenceResolver = legacyReferenceResolver
isInteractive = isInteractive
isInvalidationSupported = isInvalidationSupported
copyFSharpCore = defaultCopyFSharpCore
tryGetMetadataSnapshot = tryGetMetadataSnapshot
useFsiAuxLib = isInteractive
}
tcConfigBuilder
member tcConfigB.ResolveSourceFile(m, nm, pathLoadedFrom) =
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
ResolveFileUsingPaths(tcConfigB.includes @ [pathLoadedFrom], m, nm)
/// Decide names of output file, pdb and assembly
member tcConfigB.DecideNames (sourceFiles) =
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
if sourceFiles = [] then errorR(Error(FSComp.SR.buildNoInputsSpecified(), rangeCmdArgs))
let ext() = match tcConfigB.target with CompilerTarget.Dll -> ".dll" | CompilerTarget.Module -> ".netmodule" | CompilerTarget.ConsoleExe | CompilerTarget.WinExe -> ".exe"
let implFiles = sourceFiles |> List.filter (fun lower -> List.exists (Filename.checkSuffix (String.lowercase lower)) FSharpImplFileSuffixes)
let outfile =
match tcConfigB.outputFile, List.rev implFiles with
| None, [] -> "out" + ext()
| None, h :: _ ->
let basic = fileNameOfPath h
let modname = try Filename.chopExtension basic with _ -> basic
modname+(ext())
| Some f, _ -> f
let assemblyName =
let baseName = fileNameOfPath outfile
(fileNameWithoutExtension baseName)
let pdbfile =
if tcConfigB.debuginfo then
Some (match tcConfigB.debugSymbolFile with
| None -> FSharp.Compiler.AbstractIL.ILPdbWriter.getDebugFileName outfile tcConfigB.portablePDB
#if ENABLE_MONO_SUPPORT
| Some _ when runningOnMono ->
// On Mono, the name of the debug file has to be "<assemblyname>.mdb" so specifying it explicitly is an error
warning(Error(FSComp.SR.ilwriteMDBFileNameCannotBeChangedWarning(), rangeCmdArgs))
FSharp.Compiler.AbstractIL.ILPdbWriter.getDebugFileName outfile tcConfigB.portablePDB
#endif
| Some f -> f)
elif (tcConfigB.debugSymbolFile <> None) && (not (tcConfigB.debuginfo)) then
error(Error(FSComp.SR.buildPdbRequiresDebug(), rangeStartup))
else
None
tcConfigB.outputFile <- Some outfile
outfile, pdbfile, assemblyName
member tcConfigB.TurnWarningOff(m, s: string) =
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
match GetWarningNumber(m, s) with
| None -> ()
| Some n ->
// nowarn:62 turns on mlCompatibility, e.g. shows ML compat items in intellisense menus
if n = 62 then tcConfigB.mlCompatibility <- true
tcConfigB.errorSeverityOptions <-
{ tcConfigB.errorSeverityOptions with WarnOff = ListSet.insert (=) n tcConfigB.errorSeverityOptions.WarnOff }
member tcConfigB.TurnWarningOn(m, s: string) =
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
match GetWarningNumber(m, s) with
| None -> ()
| Some n ->
// warnon 62 turns on mlCompatibility, e.g. shows ML compat items in intellisense menus
if n = 62 then tcConfigB.mlCompatibility <- false
tcConfigB.errorSeverityOptions <-
{ tcConfigB.errorSeverityOptions with WarnOn = ListSet.insert (=) n tcConfigB.errorSeverityOptions.WarnOn }
member tcConfigB.AddIncludePath (m, path, pathIncludedFrom) =
let absolutePath = ComputeMakePathAbsolute pathIncludedFrom path
let ok =
let existsOpt =
try Some(Directory.Exists absolutePath)
with e -> warning(Error(FSComp.SR.buildInvalidSearchDirectory path, m)); None
match existsOpt with
| Some exists ->
if not exists then warning(Error(FSComp.SR.buildSearchDirectoryNotFound absolutePath, m))
exists
| None -> false
if ok && not (List.contains absolutePath tcConfigB.includes) then
tcConfigB.includes <- tcConfigB.includes ++ absolutePath
member tcConfigB.AddLoadedSource(m, originalPath, pathLoadedFrom) =
if FileSystem.IsInvalidPathShim originalPath then
warning(Error(FSComp.SR.buildInvalidFilename originalPath, m))
else
let path =
match TryResolveFileUsingPaths(tcConfigB.includes @ [pathLoadedFrom], m, originalPath) with
| Some path -> path
| None ->
// File doesn't exist in the paths. Assume it will be in the load-ed from directory.
ComputeMakePathAbsolute pathLoadedFrom originalPath
if not (List.contains path (List.map (fun (_, _, path) -> path) tcConfigB.loadedSources)) then
tcConfigB.loadedSources <- tcConfigB.loadedSources ++ (m, originalPath, path)
member tcConfigB.AddEmbeddedSourceFile (file) =
tcConfigB.embedSourceList <- tcConfigB.embedSourceList ++ file
member tcConfigB.AddEmbeddedResource filename =
tcConfigB.embedResources <- tcConfigB.embedResources ++ filename
member tcConfigB.AddCompilerToolsByPath (path) =
if not (tcConfigB.compilerToolPaths |> List.exists (fun text -> path = text)) then // NOTE: We keep same paths if range is different.
let compilerToolPath = tcConfigB.compilerToolPaths |> List.tryPick (fun text -> if text = path then Some text else None)
if compilerToolPath.IsNone then
tcConfigB.compilerToolPaths <- tcConfigB.compilerToolPaths ++ path
member tcConfigB.AddReferencedAssemblyByPath (m, path) =
if FileSystem.IsInvalidPathShim path then
warning(Error(FSComp.SR.buildInvalidAssemblyName(path), m))
elif not (tcConfigB.referencedDLLs |> List.exists (fun ar2 -> Range.equals m ar2.Range && path=ar2.Text)) then // NOTE: We keep same paths if range is different.
let projectReference = tcConfigB.projectReferences |> List.tryPick (fun pr -> if pr.FileName = path then Some pr else None)
tcConfigB.referencedDLLs <- tcConfigB.referencedDLLs ++ AssemblyReference(m, path, projectReference)
member tcConfigB.AddDependencyManagerText (packageManager: IDependencyManagerProvider, lt, m, path: string) =
tcConfigB.packageManagerLines <- PackageManagerLine.AddLineWithKey packageManager.Key lt path m tcConfigB.packageManagerLines
member tcConfigB.AddReferenceDirective (dependencyProvider: DependencyProvider, m, path: string, directive) =
let output = tcConfigB.outputDir |> Option.defaultValue ""
let reportError =
ResolvingErrorReport (fun errorType err msg ->
let error = err, msg
match errorType with
| ErrorReportType.Warning -> warning(Error(error, m))
| ErrorReportType.Error -> errorR(Error(error, m)))
let dm = dependencyProvider.TryFindDependencyManagerInPath(tcConfigB.compilerToolPaths, output , reportError, path)
match dm with
| _, dependencyManager when not(isNull dependencyManager) ->
if tcConfigB.langVersion.SupportsFeature(LanguageFeature.PackageManagement) then
tcConfigB.AddDependencyManagerText (dependencyManager, directive, m, path)
else
errorR(Error(FSComp.SR.packageManagementRequiresVFive(), m))
| _, _ when directive = Directive.Include ->
errorR(Error(FSComp.SR.poundiNotSupportedByRegisteredDependencyManagers(), m))
// #r "Assembly"
| path, _ ->
tcConfigB.AddReferencedAssemblyByPath (m, path)
member tcConfigB.RemoveReferencedAssemblyByPath (m, path) =
tcConfigB.referencedDLLs <- tcConfigB.referencedDLLs |> List.filter (fun ar -> not (Range.equals ar.Range m) || ar.Text <> path)
member tcConfigB.AddPathMapping (oldPrefix, newPrefix) =
tcConfigB.pathMap <- tcConfigB.pathMap |> PathMap.addMapping oldPrefix newPrefix
static member SplitCommandLineResourceInfo (ri: string) =
let p = ri.IndexOf ','
if p <> -1 then
let file = String.sub ri 0 p
let rest = String.sub ri (p+1) (String.length ri - p - 1)
let p = rest.IndexOf ','
if p <> -1 then
let name = String.sub rest 0 p+".resources"
let pubpri = String.sub rest (p+1) (rest.Length - p - 1)
if pubpri = "public" then file, name, ILResourceAccess.Public
elif pubpri = "private" then file, name, ILResourceAccess.Private
else error(Error(FSComp.SR.buildInvalidPrivacy pubpri, rangeStartup))
else
file, rest, ILResourceAccess.Public
else
ri, fileNameOfPath ri, ILResourceAccess.Public
//----------------------------------------------------------------------------
// TcConfig
//--------------------------------------------------------------------------
[<Sealed>]
/// This type is immutable and must be kept as such. Do not extract or mutate the underlying data except by cloning it.
type TcConfig private (data: TcConfigBuilder, validate: bool) =
// Validate the inputs - this helps ensure errors in options are shown in visual studio rather than only when built
// However we only validate a minimal number of options at the moment
do if validate then try data.version.GetVersionInfo(data.implicitIncludeDir) |> ignore with e -> errorR e
// clone the input builder to ensure nobody messes with it.
let data = { data with pause = data.pause }
let computeKnownDllReference libraryName =
let defaultCoreLibraryReference = AssemblyReference(range0, libraryName+".dll", None)
let nameOfDll(r: AssemblyReference) =
let filename = ComputeMakePathAbsolute data.implicitIncludeDir r.Text
if FileSystem.SafeExists filename then
r, Some filename
else
// If the file doesn't exist, let reference resolution logic report the error later...
defaultCoreLibraryReference, if Range.equals r.Range rangeStartup then Some(filename) else None
match data.referencedDLLs |> List.filter (fun assemblyReference -> assemblyReference.SimpleAssemblyNameIs libraryName) with
| [] -> defaultCoreLibraryReference, None
| [r]
| r :: _ -> nameOfDll r
// Look for an explicit reference to mscorlib/netstandard.dll or System.Runtime.dll and use that to compute clrRoot and targetFrameworkVersion
let primaryAssemblyReference, primaryAssemblyExplicitFilenameOpt = computeKnownDllReference(data.primaryAssembly.Name)
let fslibReference =
// Look for explicit FSharp.Core reference otherwise use version that was referenced by compiler
let dllReference, fileNameOpt = computeKnownDllReference getFSharpCoreLibraryName
match fileNameOpt with
| Some _ -> dllReference
| None -> AssemblyReference(range0, getDefaultFSharpCoreLocation, None)
// clrRoot: the location of the primary assembly (mscorlib.dll or netstandard.dll or System.Runtime.dll)
//
// targetFrameworkVersionValue: Normally just HighestInstalledNetFrameworkVersion()
//
// Note, when mscorlib.dll has been given explicitly the actual value of
// targetFrameworkVersion shouldn't matter since resolution has already happened.
// In those cases where it does matter (e.g. --noframework is not being used or we are processing further
// resolutions for a script) then it is correct to just use HighestInstalledNetFrameworkVersion().
let clrRootValue, targetFrameworkVersionValue =
match primaryAssemblyExplicitFilenameOpt with
| Some primaryAssemblyFilename ->
let filename = ComputeMakePathAbsolute data.implicitIncludeDir primaryAssemblyFilename
try
let clrRoot = Some(Path.GetDirectoryName(FileSystem.GetFullPathShim filename))
clrRoot, data.legacyReferenceResolver.HighestInstalledNetFrameworkVersion()
with e ->
// We no longer expect the above to fail but leaving this just in case
error(Error(FSComp.SR.buildErrorOpeningBinaryFile(filename, e.Message), rangeStartup))
| None ->
#if !ENABLE_MONO_SUPPORT
// TODO: we have to get msbuild out of this
if data.useSimpleResolution then
None, ""
else
#endif
None, data.legacyReferenceResolver.HighestInstalledNetFrameworkVersion()
member x.primaryAssembly = data.primaryAssembly
member x.noFeedback = data.noFeedback
member x.stackReserveSize = data.stackReserveSize
member x.implicitIncludeDir = data.implicitIncludeDir
member x.openDebugInformationForLaterStaticLinking = data.openDebugInformationForLaterStaticLinking
member x.fsharpBinariesDir = data.defaultFSharpBinariesDir
member x.compilingFslib = data.compilingFslib
member x.useIncrementalBuilder = data.useIncrementalBuilder
member x.includes = data.includes
member x.implicitOpens = data.implicitOpens
member x.useFsiAuxLib = data.useFsiAuxLib
member x.framework = data.framework
member x.implicitlyResolveAssemblies = data.implicitlyResolveAssemblies
member x.resolutionEnvironment = data.resolutionEnvironment
member x.light = data.light
member x.conditionalCompilationDefines = data.conditionalCompilationDefines
member x.loadedSources = data.loadedSources
member x.compilerToolPaths = data.compilerToolPaths
member x.referencedDLLs = data.referencedDLLs
member x.knownUnresolvedReferences = data.knownUnresolvedReferences
member x.clrRoot = clrRootValue
member x.reduceMemoryUsage = data.reduceMemoryUsage
member x.subsystemVersion = data.subsystemVersion
member x.useHighEntropyVA = data.useHighEntropyVA
member x.inputCodePage = data.inputCodePage
member x.embedResources = data.embedResources
member x.errorSeverityOptions = data.errorSeverityOptions
member x.mlCompatibility = data.mlCompatibility
member x.checkOverflow = data.checkOverflow
member x.showReferenceResolutions = data.showReferenceResolutions
member x.outputDir = data.outputDir
member x.outputFile = data.outputFile
member x.platform = data.platform
member x.prefer32Bit = data.prefer32Bit
member x.useSimpleResolution = data.useSimpleResolution
member x.target = data.target
member x.debuginfo = data.debuginfo
member x.testFlagEmitFeeFeeAs100001 = data.testFlagEmitFeeFeeAs100001
member x.dumpDebugInfo = data.dumpDebugInfo
member x.debugSymbolFile = data.debugSymbolFile
member x.typeCheckOnly = data.typeCheckOnly
member x.parseOnly = data.parseOnly
member x.importAllReferencesOnly = data.importAllReferencesOnly
member x.simulateException = data.simulateException
member x.printAst = data.printAst
member x.targetFrameworkVersion = targetFrameworkVersionValue
member x.tokenizeOnly = data.tokenizeOnly
member x.testInteractionParser = data.testInteractionParser
member x.reportNumDecls = data.reportNumDecls
member x.printSignature = data.printSignature
member x.printSignatureFile = data.printSignatureFile
member x.xmlDocOutputFile = data.xmlDocOutputFile
member x.stats = data.stats
member x.generateFilterBlocks = data.generateFilterBlocks
member x.signer = data.signer
member x.container = data.container
member x.delaysign = data.delaysign
member x.publicsign = data.publicsign
member x.version = data.version
member x.metadataVersion = data.metadataVersion
member x.standalone = data.standalone
member x.extraStaticLinkRoots = data.extraStaticLinkRoots
member x.noSignatureData = data.noSignatureData
member x.onlyEssentialOptimizationData = data.onlyEssentialOptimizationData
member x.useOptimizationDataFile = data.useOptimizationDataFile
member x.jitTracking = data.jitTracking
member x.portablePDB = data.portablePDB
member x.embeddedPDB = data.embeddedPDB
member x.embedAllSource = data.embedAllSource
member x.embedSourceList = data.embedSourceList
member x.sourceLink = data.sourceLink
member x.packageManagerLines = data.packageManagerLines
member x.ignoreSymbolStoreSequencePoints = data.ignoreSymbolStoreSequencePoints
member x.internConstantStrings = data.internConstantStrings
member x.extraOptimizationIterations = data.extraOptimizationIterations
member x.win32res = data.win32res
member x.win32manifest = data.win32manifest
member x.includewin32manifest = data.includewin32manifest
member x.linkResources = data.linkResources
member x.showFullPaths = data.showFullPaths
member x.errorStyle = data.errorStyle
member x.utf8output = data.utf8output
member x.flatErrors = data.flatErrors
member x.maxErrors = data.maxErrors
member x.baseAddress = data.baseAddress
member x.checksumAlgorithm = data.checksumAlgorithm
#if DEBUG
member x.showOptimizationData = data.showOptimizationData
#endif
member x.showTerms = data.showTerms
member x.writeTermsToFiles = data.writeTermsToFiles
member x.doDetuple = data.doDetuple
member x.doTLR = data.doTLR
member x.doFinalSimplify = data.doFinalSimplify
member x.optSettings = data.optSettings
member x.emitTailcalls = data.emitTailcalls
member x.deterministic = data.deterministic
member x.pathMap = data.pathMap
member x.langVersion = data.langVersion
member x.preferredUiLang = data.preferredUiLang
member x.lcid = data.lcid
member x.optsOn = data.optsOn
member x.productNameForBannerText = data.productNameForBannerText
member x.showBanner = data.showBanner
member x.showTimes = data.showTimes
member x.showLoadedAssemblies = data.showLoadedAssemblies
member x.continueAfterParseFailure = data.continueAfterParseFailure
#if !NO_EXTENSIONTYPING
member x.showExtensionTypeMessages = data.showExtensionTypeMessages
#endif
member x.pause = data.pause
member x.alwaysCallVirt = data.alwaysCallVirt
member x.noDebugData = data.noDebugData
member x.isInteractive = data.isInteractive
member x.isInvalidationSupported = data.isInvalidationSupported
member x.emitDebugInfoInQuotations = data.emitDebugInfoInQuotations
member x.copyFSharpCore = data.copyFSharpCore
member x.shadowCopyReferences = data.shadowCopyReferences
member x.useSdkRefs = data.useSdkRefs
member x.tryGetMetadataSnapshot = data.tryGetMetadataSnapshot
member x.internalTestSpanStackReferring = data.internalTestSpanStackReferring