11// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22
3- /// Loading initial context, reporting errors etc.
4- module internal Microsoft.FSharp.Compiler.Build
3+ /// Coordinating compiler operations - configuration, loading initial context, reporting errors etc.
4+ module internal Microsoft.FSharp.Compiler.CompileOps
55
66open System.Text
77open Internal.Utilities
@@ -37,19 +37,27 @@ module internal FullCompiler =
3737
3838#endif
3939
40+ //----------------------------------------------------------------------------
41+ // File names and known file suffixes
42+ //--------------------------------------------------------------------------
43+
4044/// Signature file suffixes
41- val sigSuffixes : string list
45+ val FSharpSigFileSuffixes : string list
4246
4347/// Implementation file suffixes
44- val implSuffixes : string list
48+ val FSharpImplFileSuffixes : string list
4549
4650/// Script file suffixes
47- val scriptSuffixes : string list
51+ val FSharpScriptFileSuffixes : string list
4852
4953val IsScript : string -> bool
5054
5155/// File suffixes where #light is the default
52- val lightSyntaxDefaultExtensions : string list
56+ val FSharpLightSyntaxFileSuffixes : string list
57+
58+
59+ /// Get the name used for FSharp.Core
60+ val GetFSharpCoreLibraryName : unit -> string
5361
5462//----------------------------------------------------------------------------
5563// Parsing inputs
@@ -61,22 +69,19 @@ val PrependPathToInput : Ast.Ident list -> Ast.ParsedInput -> Ast.ParsedInput
6169
6270val ParseInput : ( UnicodeLexing.Lexbuf -> Parser.token ) * ErrorLogger * UnicodeLexing.Lexbuf * string option * string * isLastCompiland : bool -> Ast.ParsedInput
6371
64-
65-
6672//----------------------------------------------------------------------------
67- // Errors
73+ // Error and warnings
6874//--------------------------------------------------------------------------
6975
7076/// Represents the style being used to format errros
7177type ErrorStyle =
7278 | DefaultErrors
7379 | EmacsErrors
7480 | TestErrors
75- | VSErrors
76-
81+ | VSErrors
7782
7883/// Get the location associated with an error
79- val RangeOfError : PhasedError -> range option
84+ val GetRangeOfError : PhasedError -> range option
8085
8186/// Get the number associated with an error
8287val GetErrorNumber : PhasedError -> int
@@ -93,67 +98,36 @@ val OutputErrorOrWarning : implicitIncludeDir:string * showFullPaths: bool * fla
9398/// Output extra context information for an error or warning to a buffer
9499val OutputErrorOrWarningContext : prefix : string -> fileLineFunction :( string -> int -> string ) -> StringBuilder -> PhasedError -> unit
95100
101+ [< RequireQualifiedAccess >]
96102type ErrorLocation =
97103 { Range : range
98104 File : string
99105 TextRepresentation : string
100106 IsEmpty : bool }
101107
108+ [<RequireQualifiedAccess>]
102109type CanonicalInformation =
103110 { ErrorNumber : int
104111 Subcategory : string
105112 TextRepresentation : string }
106113
114+ [<RequireQualifiedAccess>]
107115type DetailedIssueInfo =
108116 { Location : ErrorLocation option
109117 Canonical : CanonicalInformation
110118 Message : string }
111119
120+ [<RequireQualifiedAccess>]
112121type ErrorOrWarning =
113122 | Short of bool * string
114123 | Long of bool * DetailedIssueInfo
115124
116125val CollectErrorOrWarning : implicitIncludeDir : string * showFullPaths : bool * flattenErrors : bool * errorStyle : ErrorStyle * warning : bool * PhasedError -> seq < ErrorOrWarning >
117126
118127//----------------------------------------------------------------------------
119- // Options and configuration
128+ // Resolve assembly references
120129//--------------------------------------------------------------------------
121130
122- // For command - line options that can be suffixed with +/-
123- type OptionSwitch =
124- | On
125- | Off
126-
127- /// The spec value describes the action of the argument,
128- /// and whether it expects a following parameter.
129- type OptionSpec =
130- | OptionClear of bool ref
131- | OptionFloat of ( float -> unit )
132- | OptionInt of ( int -> unit )
133- | OptionSwitch of ( OptionSwitch -> unit )
134- | OptionIntList of ( int -> unit )
135- | OptionIntListSwitch of ( int -> OptionSwitch -> unit )
136- | OptionRest of ( string -> unit )
137- | OptionSet of bool ref
138- | OptionString of ( string -> unit )
139- | OptionStringList of ( string -> unit )
140- | OptionStringListSwitch of ( string -> OptionSwitch -> unit )
141- | OptionUnit of ( unit -> unit )
142- | OptionHelp of ( CompilerOptionBlock list -> unit ) // like OptionUnit, but given the "options"
143- | OptionGeneral of ( string list -> bool ) * ( string list -> string list ) // Applies? * (ApplyReturningResidualArgs)
144-
145- and CompilerOption =
146- /// CompilerOption(name, argumentDescriptionString, actionSpec, exceptionOpt, helpTextOpt
147- | CompilerOption of string * string * OptionSpec * Option < exn > * string option
148-
149- and CompilerOptionBlock =
150- | PublicOptions of string * CompilerOption list
151- | PrivateOptions of CompilerOption list
152-
153- val printCompilerOptionBlocks : CompilerOptionBlock list -> unit // for printing usage
154- val dumpCompilerOptionBlocks : CompilerOptionBlock list -> unit // for QA
155- val filterCompilerOptionBlock : ( CompilerOption -> bool ) -> CompilerOptionBlock -> CompilerOptionBlock
156-
157131exception AssemblyNotResolved of (* originalName *) string * range
158132exception FileNameNotResolved of (* filename *) string * (* description of searched locations *) string * range
159133exception DeprecatedCommandLineOptionFull of string * range
@@ -202,6 +176,10 @@ type ResolveAssemblyReferenceMode =
202176 | Speculative
203177 | ReportErrors
204178
179+ //----------------------------------------------------------------------------
180+ // TcConfig
181+ //--------------------------------------------------------------------------
182+
205183/// Represents the file or string used for the --version flag
206184type VersionFlag =
207185 | VersionString of string
@@ -501,12 +479,23 @@ type TcConfig =
501479
502480 static member Create : TcConfigBuilder * validate : bool -> TcConfig
503481
482+ /// Represents a computation to return a TcConfig. Normally this is just a constant immutable TcConfig ,
483+ /// but for F # Interactive it may be based on an underlying mutable TcConfigBuilder.
484+ [< Sealed >]
485+ type TcConfigProvider =
486+ /// Get a TcConfigProvider which will return only the exact TcConfig.
487+ static member Constant : TcConfig -> TcConfigProvider
488+
489+ /// Get a TcConfigProvider which will continue to respect changes in the underlying
490+ /// TcConfigBuilder rather than delivering snapshots.
491+ static member BasedOnMutableBuilder : TcConfigBuilder -> TcConfigProvider
504492
505493//----------------------------------------------------------------------------
506494// Tables of referenced DLLs
507495//--------------------------------------------------------------------------
508496
509497/// Represents a resolved imported binary
498+ [<RequireQualifiedAccess>]
510499type ImportedBinary =
511500 { FileName: string
512501 RawMetadata: ILModuleDef
@@ -519,6 +508,7 @@ type ImportedBinary =
519508 ILScopeRef: ILScopeRef }
520509
521510/// Represents a resolved imported assembly
511+ [<RequireQualifiedAccess>]
522512type ImportedAssembly =
523513 { ILScopeRef: ILScopeRef
524514 FSharpViewOfMetadata: CcuThunk
@@ -539,16 +529,6 @@ type TcAssemblyResolutions =
539529 static member BuildFromPriorResolutions : TcConfig * AssemblyResolution list * UnresolvedAssemblyReference list -> TcAssemblyResolutions
540530
541531
542- /// Represents a computation to return a TcConfig. Normally this is just a constant immutable TcConfig ,
543- /// but for F # Interactive it may be based on an underlying mutable TcConfigBuilder.
544- [< Sealed >]
545- type TcConfigProvider =
546- /// Get a TcConfigProvider which will return only the exact TcConfig.
547- static member Constant : TcConfig -> TcConfigProvider
548-
549- /// Get a TcConfigProvider which will continue to respect changes in the underlying
550- /// TcConfigBuilder rather than delivering snapshots.
551- static member BasedOnMutableBuilder : TcConfigBuilder -> TcConfigProvider
552532
553533/// Repreesnts a table of imported assemblies with their resolutions.
554534[< Sealed >]
@@ -610,8 +590,10 @@ val WriteSignatureData : TcConfig * TcGlobals * Tastops.Remap * CcuThunk * strin
610590val WriteOptimizationData : TcGlobals * string * CcuThunk * Optimizer.LazyModuleInfo -> ILResource
611591#endif
612592
613- /// Get the name used for FSharp.Core
614- val GetFSharpCoreLibraryName : unit -> string
593+
594+ //----------------------------------------------------------------------------
595+ // #r and other directives
596+ //--------------------------------------------------------------------------
615597
616598/// Process #r in F # Interactive.
617599/// Adds the reference to the tcImports and add the ccu to the type checking environment.
@@ -623,22 +605,30 @@ val ProcessMetaCommandsFromInput :
623605 ( 'T -> range * string -> 'T ) *
624606 ( 'T -> range * string -> unit ) -> TcConfigBuilder -> Ast.ParsedInput -> string -> 'T -> 'T
625607
608+ /// Process all the #r , #I etc. in an input
609+ val ApplyMetaCommandsFromInputToTcConfig : TcConfig -> ( Ast.ParsedInput * string ) -> TcConfig
610+
611+ /// Process the #nowarn in an input
612+ val ApplyNoWarnsToTcConfig : TcConfig -> ( Ast.ParsedInput * string ) -> TcConfig
613+
614+
615+ //----------------------------------------------------------------------------
616+ // Scoped pragmas
617+ //--------------------------------------------------------------------------
626618
627619/// Find the scoped #nowarn pragmas with their range information
628620val GetScopedPragmasForInput : Ast.ParsedInput -> ScopedPragma list
629621
630622/// Get an error logger that filters the reporting of warnings based on scoped pragma information
631623val GetErrorLoggerFilteringByScopedPragmas : checkFile : bool * ScopedPragma list * ErrorLogger -> ErrorLogger
632624
633- /// Process the #nowarn in an input
634- val ApplyNoWarnsToTcConfig : TcConfig -> ( Ast.ParsedInput * string ) -> TcConfig
635-
636- /// Process all the #r , #I etc. in an input
637- val ApplyMetaCommandsFromInputToTcConfig : TcConfig -> ( Ast.ParsedInput * string ) -> TcConfig
638-
639625/// This list is the default set of references for "non - project " files.
640626val DefaultBasicReferencesForOutOfProjectSources : string list
641627
628+ //----------------------------------------------------------------------------
629+ // Parsing
630+ //--------------------------------------------------------------------------
631+
642632/// Parse one input file
643633val ParseOneInputFile : TcConfig * Lexhelp.LexResourceManager * string list * string * isLastCompiland : bool * ErrorLogger * (* retryLocked *) bool -> ParsedInput option
644634
@@ -648,7 +638,7 @@ val ParseOneInputFile : TcConfig * Lexhelp.LexResourceManager * string list * st
648638
649639/// Get the initial type checking environment including the loading of mscorlib / System.Core , FSharp.Core
650640/// applying the InternalsVisibleTo in referenced assemblies and opening 'Checked' if requested.
651- val GetInitialTcEnv : string option -> range -> TcConfig -> TcImports -> TcGlobals -> TcEnv
641+ val GetInitialTcEnv : string option * range * TcConfig * TcImports * TcGlobals -> TcEnv
652642
653643[< Sealed >]
654644/// Represents the incremental type checking state for a set of inputs
@@ -691,38 +681,47 @@ val TypeCheckSingleInputAndFinishEventually :
691681 ( unit -> bool ) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * NameResolution.TcResultsSink * TcState * Ast.ParsedInput
692682 -> Eventually <( TcEnv * TopAttribs * Tast.TypedImplFile list ) * TcState >
693683
694- /// Parse and process a set of compiler options
695- val ParseCompilerOptions : ( string -> unit ) -> CompilerOptionBlock list -> string list -> unit
696-
697- /// Report a warning through the current error logger
698- val ReportWarning : int -> int list -> int list -> PhasedError -> bool
684+ /// Indicates if we should report a warning
685+ val ReportWarning : globalWarnLevel : int * specificWarnOff : int list * specificWarnOn : int list -> PhasedError -> bool
699686
700- /// Report a warning through the current error logger , but as an error
701- val ReportWarningAsError : int -> int list -> int list -> int list -> int list -> bool -> PhasedError -> bool
687+ /// Indicates if we should report a warning as an error
688+ val ReportWarningAsError : globalWarnLevel : int * specificWarnOff : int list * specificWarnOn : int list * specificWarnAsError : int list * specificWarnAsWarn : int list * globalWarnAsError : bool -> PhasedError -> bool
702689
703690//----------------------------------------------------------------------------
704691// #load closure
705692//--------------------------------------------------------------------------
706693
694+ [< RequireQualifiedAccess >]
707695type CodeContext =
708696 | Evaluation
709697 | Compilation
710698 | Editing
711699
700+ [<RequireQualifiedAccess>]
712701type LoadClosure =
713702 { /// The source files along with the ranges of the #load positions in each file.
714- SourceFiles: ( string * range list ) list
715- /// The resolved references along with the ranges of the #r positions in each file.
716- References: ( string * AssemblyResolution list ) list
717- /// The list of references that were not resolved during load closure. These may still be extension references.
718- UnresolvedReferences : UnresolvedAssemblyReference list
719- /// The list of all sources in the closure with inputs when available
720- Inputs: ( string * ParsedInput option ) list
721- /// The #nowarns
722- NoWarns: ( string * range list ) list
723- /// * Parse* errors seen while parsing root of closure
724- RootErrors : PhasedError list
725- /// * Parse* warnings seen while parsing root of closure
726- RootWarnings : PhasedError list }
703+ SourceFiles: ( string * range list ) list
704+
705+ /// The resolved references along with the ranges of the #r positions in each file.
706+ References: ( string * AssemblyResolution list ) list
707+
708+ /// The list of references that were not resolved during load closure. These may still be extension references.
709+ UnresolvedReferences : UnresolvedAssemblyReference list
710+
711+ /// The list of all sources in the closure with inputs when available
712+ Inputs: ( string * ParsedInput option ) list
713+
714+ /// The #nowarns
715+ NoWarns: ( string * range list ) list
716+
717+ /// * Parse* errors seen while parsing root of closure
718+ RootErrors : PhasedError list
719+
720+ /// * Parse* warnings seen while parsing root of closure
721+ RootWarnings : PhasedError list }
722+
723+ // Used from service.fs, when editing a script file
727724 static member ComputeClosureOfSourceText : filename : string * source : string * implicitDefines : CodeContext * lexResourceManager : Lexhelp.LexResourceManager -> LoadClosure
725+
726+ /// Used from fsi.fs and fsc.fs , for #load and command line. The resulting references are then added to a TcConfig.
728727 static member ComputeClosureOfSourceFiles : tcConfig : TcConfig * ( string * range ) list * implicitDefines : CodeContext * useDefaultScriptingReferences : bool * lexResourceManager : Lexhelp.LexResourceManager -> LoadClosure
0 commit comments