Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fsharp/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ type TcConfigBuilder =
internalTestSpanStackReferring = false
noConditionalErasure = false
pathMap = PathMap.empty
langVersion = LanguageVersion("default")
langVersion = LanguageVersion.Default
implicitIncludeDir = implicitIncludeDir
defaultFSharpBinariesDir = defaultFSharpBinariesDir
reduceMemoryUsage = reduceMemoryUsage
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/ErrorLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ let deprecatedOperator m = deprecatedWithError (FSComp.SR.elDeprecatedOperator()

let mlCompatWarning s m = warning(UserCompilerMessage(FSComp.SR.mlCompatMessage s, 62, m))

let mlCompatError s m = errorR(UserCompilerMessage(FSComp.SR.mlCompatError s, 62, m))

let suppressErrorReporting f =
let errorLogger = CompileThreadStatic.ErrorLogger
try
Expand Down
4 changes: 3 additions & 1 deletion src/fsharp/ErrorLogger.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ val libraryOnlyWarning: m:range -> unit

val deprecatedOperator: m:range -> unit

val mlCompatWarning: s:String -> m:range -> unit
val mlCompatWarning: s:string -> m:range -> unit

val mlCompatError: s:string -> m:range -> unit

val suppressErrorReporting: f:(unit -> 'a) -> 'a

Expand Down
11 changes: 11 additions & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ tupleRequiredInAbstractMethod,"\nA tuple type is required for one or more argume
224,buildOptionRequiresParameter,"Option requires parameter: %s"
225,buildCouldNotFindSourceFile,"Source file '%s' could not be found"
226,buildInvalidSourceFileExtension,"The file extension of '%s' is not recognized. Source files must have extension .fs, .fsi, .fsx, .fsscript, .ml or .mli."
226,buildInvalidSourceFileExtensionUpdated,"The file extension of '%s' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript"
226,buildInvalidSourceFileExtensionML,"The file extension of '%s' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'."
227,buildCouldNotResolveAssembly,"Could not resolve assembly '%s'"
228,buildCouldNotResolveAssemblyRequiredByFile,"Could not resolve assembly '%s' required by '%s'"
229,buildErrorOpeningBinaryFile,"Error opening binary file '%s': %s"
Expand Down Expand Up @@ -1078,13 +1080,21 @@ parsNonAtomicType,"The use of the type syntax 'int C' and 'C <int>' is not perm
#1203 - used for error in FSharp.Core CompilerMessage message
#1204 - used for error in FSharp.Core CompilerMessage message
mlCompatMessage,"This construct is for ML compatibility. %s. You can disable this warning by using '--mlcompatibility' or '--nowarn:62'."
mlCompatError,"This construct is deprecated. %s. You can enable this feature by using '--langversion:5.0' and '--mlcompatibility'."
mlCompatKeyword,"In previous versions of F# '%s' was a reserved keyword but the use of this keyword is now deprecated"
mlCompatLightOffNoLongerSupported,"The use of '#light \"off\"' or '#indent \"off\"' was deprecated in F# 2.0 and is no longer supported"
mlCompatSigColonNoLongerSupported,"The use of 'module M: sig ... end ' was deprecated in F# 2.0 and is no longer supported. Change the ':' to an '=' and remove the 'sig' and 'end' and use indentation instead"
mlCompatSigEndNoLongerSupported,"The use of 'module M = sig ... end ' was deprecated in F# 2.0 and is no longer supported. Remove the 'sig' and 'end' and use indentation instead"
mlCompatMultiPrefixTyparsNoLongerSupported,"The use of multiple parenthesized type parameters before a generic type name such as '(int, int) Map' was deprecated in F# 2.0 and is no longer supported"
mlCompatStructEndNoLongerSupported,"The use of 'module M = struct ... end ' was deprecated in F# 2.0 and is no longer supported. Remove the 'struct' and 'end' and use indentation instead"
#1205,chkDuplicateInherittedVirtualMethod,"Duplicate virtual methods. There are multiple virtual methods named '%s' with the same signature in the parent (inherited) type. This may be a result of instantiating the parent type."
1206,ilFieldDoesNotHaveValidOffsetForStructureLayout,"The type '%s' has been marked as having an Explicit layout, but the field '%s' has not been marked with the 'FieldOffset' attribute"
1207,tcInterfacesShouldUseInheritNotInterface,"Interfaces inherited by other interfaces should be declared using 'inherit ...' instead of 'interface ...'"
1208,parsInvalidPrefixOperator,"Invalid prefix operator"
1208,parsInvalidPrefixOperatorDefinition,"Invalid operator definition. Prefix operator definitions must use a valid prefix operator name."
buildCompilingExtensionIsForML,"The file extensions '.ml' and '.mli' are for ML compatibility"
lexIndentOffForML,"Consider using a file with extension '.ml' or '.mli' instead"
lexIfOCaml,"IF-FSHARP/IF-CAML regions are no longer supported"
1209,activePatternIdentIsNotFunctionTyped,"Active pattern '%s' is not a function"
1210,activePatternChoiceHasFreeTypars,"Active pattern '%s' has a result type containing type variables that are not determined by the input. The common cause is a when a result case is not mentioned, e.g. 'let (|A|B|) (x:int) = A x'. This can be fixed with a type constraint, e.g. 'let (|A|B|) (x:int) : Choice<int,unit> = A x'"
1211,ilFieldHasOffsetForSequentialLayout,"The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)"
Expand Down Expand Up @@ -1237,6 +1247,7 @@ featureRefCellNotationInformationals,"informational messages related to referenc
featureDiscardUseValue,"discard pattern in use binding"
featureNonVariablePatternsToRightOfAsPatterns,"non-variable patterns to the right of 'as' patterns"
featureAttributesToRightOfModuleKeyword,"attributes to the right of the 'module' keyword"
featureMLCompatRevisions,"ML compatibility revisions"
3090,tcIfThenElseMayNotBeUsedWithinQueries,"An if/then/else expression may not be used within queries. Consider using either an if/then expression, or use a sequence expression instead."
3091,ilxgenUnexpectedArgumentToMethodHandleOfDuringCodegen,"Invalid argument to 'methodhandleof' during codegen"
3092,etProvidedTypeReferenceMissingArgument,"A reference to a provided type was missing a value for the static parameter '%s'. You may need to recompile one or more referenced assemblies."
Expand Down
23 changes: 20 additions & 3 deletions src/fsharp/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ type LanguageFeature =
| UseBindingValueDiscard
| NonVariablePatternsToRightOfAsPatterns
| AttributesToRightOfModuleKeyword
| MLCompatRevisions

/// LanguageVersion management
type LanguageVersion (specifiedVersionAsString) =
type LanguageVersion (versionText) =

// When we increment language versions here preview is higher than current RTM version
static let languageVersion46 = 4.6m
Expand Down Expand Up @@ -95,10 +96,13 @@ type LanguageVersion (specifiedVersionAsString) =
LanguageFeature.UseBindingValueDiscard, previewVersion
LanguageFeature.NonVariablePatternsToRightOfAsPatterns, previewVersion
LanguageFeature.AttributesToRightOfModuleKeyword, previewVersion
LanguageFeature.MLCompatRevisions,previewVersion
]

static let defaultLanguageVersion = LanguageVersion("default")

let specified =
match specifiedVersionAsString with
match versionText with
| "?" -> 0m
| "preview" -> previewVersion
| "default" -> defaultVersion
Expand All @@ -123,7 +127,7 @@ type LanguageVersion (specifiedVersionAsString) =

/// Has preview been explicitly specified
member _.IsExplicitlySpecifiedAs50OrBefore() =
match specifiedVersionAsString with
match versionText with
| "4.6" -> true
| "4.7" -> true
| "5.0" -> true
Expand All @@ -149,6 +153,9 @@ type LanguageVersion (specifiedVersionAsString) =
sprintf "%M%s" v (if v = defaultVersion then " (Default)" else "")
|]

/// Get the text used to specify the version
member _.VersionText = versionText

/// Get the specified LanguageVersion
member _.SpecifiedVersion = specified

Expand Down Expand Up @@ -186,9 +193,19 @@ type LanguageVersion (specifiedVersionAsString) =
| LanguageFeature.UseBindingValueDiscard -> FSComp.SR.featureDiscardUseValue()
| LanguageFeature.NonVariablePatternsToRightOfAsPatterns -> FSComp.SR.featureNonVariablePatternsToRightOfAsPatterns()
| LanguageFeature.AttributesToRightOfModuleKeyword -> FSComp.SR.featureAttributesToRightOfModuleKeyword()
| LanguageFeature.MLCompatRevisions -> FSComp.SR.featureMLCompatRevisions()

/// Get a version string associated with the given feature.
member _.GetFeatureVersionString feature =
match features.TryGetValue feature with
| true, v -> versionToString v
| _ -> invalidArg "feature" "Internal error: Unable to find feature."

override x.Equals(yobj: obj) =
match yobj with
| :? LanguageVersion as y -> x.SpecifiedVersion = y.SpecifiedVersion
| _ -> false

override x.GetHashCode() = hash x.SpecifiedVersion

static member Default = defaultLanguageVersion
6 changes: 6 additions & 0 deletions src/fsharp/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type LanguageFeature =
| UseBindingValueDiscard
| NonVariablePatternsToRightOfAsPatterns
| AttributesToRightOfModuleKeyword
| MLCompatRevisions

/// LanguageVersion management
type LanguageVersion =
Expand Down Expand Up @@ -62,6 +63,9 @@ type LanguageVersion =
/// Get the specified LanguageVersion
member SpecifiedVersion: decimal

/// Get the text used to specify the version, several of which may map to the same version
member VersionText: string

/// Get the specified LanguageVersion as a string
member SpecifiedVersionString: string

Expand All @@ -70,3 +74,5 @@ type LanguageVersion =

/// Get a version string associated with the given feature.
member GetFeatureVersionString: feature: LanguageFeature -> string

static member Default: LanguageVersion
15 changes: 11 additions & 4 deletions src/fsharp/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open FSharp.Compiler.CompilerDiagnostics
open FSharp.Compiler.CompilerImports
open FSharp.Compiler.Diagnostics
open FSharp.Compiler.ErrorLogger
open FSharp.Compiler.Features
open FSharp.Compiler.IO
open FSharp.Compiler.Lexhelp
open FSharp.Compiler.NameResolution
Expand Down Expand Up @@ -269,7 +270,10 @@ let ParseInput (lexer, errorLogger: ErrorLogger, lexbuf: UnicodeLexing.Lexbuf, d
try
let input =
if mlCompatSuffixes |> List.exists (FileSystemUtils.checkSuffix lower) then
mlCompatWarning (FSComp.SR.buildCompilingExtensionIsForML()) rangeStartup
if lexbuf.SupportsFeature LanguageFeature.MLCompatRevisions then
errorR(Error(FSComp.SR.buildInvalidSourceFileExtensionML filename, rangeStartup))
else
mlCompatWarning (FSComp.SR.buildCompilingExtensionIsForML()) rangeStartup

// Call the appropriate parser - for signature files or implementation files
if FSharpImplFileSuffixes |> List.exists (FileSystemUtils.checkSuffix lower) then
Expand All @@ -279,7 +283,11 @@ let ParseInput (lexer, errorLogger: ErrorLogger, lexbuf: UnicodeLexing.Lexbuf, d
let intfs = Parser.signatureFile lexer lexbuf
PostParseModuleSpecs (defaultNamespace, filename, isLastCompiland, intfs)
else
delayLogger.Error(Error(FSComp.SR.buildInvalidSourceFileExtension filename, rangeStartup))
if lexbuf.SupportsFeature LanguageFeature.MLCompatRevisions then
error(Error(FSComp.SR.buildInvalidSourceFileExtensionUpdated filename, rangeStartup))
else
error(Error(FSComp.SR.buildInvalidSourceFileExtension filename, rangeStartup))


scopedPragmas <- GetScopedPragmasForInput input
input
Expand Down Expand Up @@ -416,8 +424,7 @@ let parseInputFileAux (tcConfig: TcConfig, lexResourceManager, conditionalCompil
use reader = fileStream.GetReader(tcConfig.inputCodePage, retryLocked)

// Set up the LexBuffer for the file
let checkLanguageFeatureErrorRecover = ErrorLogger.checkLanguageFeatureErrorRecover tcConfig.langVersion
let lexbuf = UnicodeLexing.StreamReaderAsLexbuf(not tcConfig.compilingFslib, tcConfig.langVersion.SupportsFeature, checkLanguageFeatureErrorRecover, reader)
let lexbuf = UnicodeLexing.StreamReaderAsLexbuf(not tcConfig.compilingFslib, tcConfig.langVersion, reader)

// Parse the file drawing tokens from the lexbuf
ParseOneInputLexbuf(tcConfig, lexResourceManager, conditionalCompilationDefines, lexbuf, filename, isLastCompiland, errorLogger)
Expand Down
12 changes: 4 additions & 8 deletions src/fsharp/ParseHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ and LexCont = LexerContinuation
// Parse IL assembly code
//------------------------------------------------------------------------

let ParseAssemblyCodeInstructions s reportLibraryOnlyFeatures (isFeatureSupported: LanguageFeature -> bool) checkLanguageFeatureErrorRecover m : IL.ILInstr[] =
let ParseAssemblyCodeInstructions s reportLibraryOnlyFeatures langVersion m : IL.ILInstr[] =
#if NO_INLINE_IL_PARSER
ignore s
ignore isFeatureSupported
Expand All @@ -231,26 +231,22 @@ let ParseAssemblyCodeInstructions s reportLibraryOnlyFeatures (isFeatureSupporte
try
AsciiParser.ilInstrs
AsciiLexer.token
(StringAsLexbuf(reportLibraryOnlyFeatures, isFeatureSupported, checkLanguageFeatureErrorRecover, s))
(StringAsLexbuf(reportLibraryOnlyFeatures, langVersion, s))
with _ ->
errorR(Error(FSComp.SR.astParseEmbeddedILError(), m)); [||]
#endif

let ParseAssemblyCodeType s reportLibraryOnlyFeatures (isFeatureSupported: LanguageFeature -> bool) (checkLanguageFeatureErrorRecover: LanguageFeature -> range -> unit) m =
let ParseAssemblyCodeType s reportLibraryOnlyFeatures langVersion m =
ignore s
ignore isFeatureSupported
ignore checkLanguageFeatureErrorRecover

#if NO_INLINE_IL_PARSER
errorR(Error((193, "Inline IL not valid in a hosted environment"), m))
IL.PrimaryAssemblyILGlobals.typ_Object
#else
let isFeatureSupported (_featureId:LanguageFeature) = true
let checkLanguageFeatureErrorRecover (_featureId:LanguageFeature) _range = ()
try
AsciiParser.ilType
AsciiLexer.token
(StringAsLexbuf(reportLibraryOnlyFeatures, isFeatureSupported, checkLanguageFeatureErrorRecover, s))
(StringAsLexbuf(reportLibraryOnlyFeatures, langVersion, s))
with RecoverableParseError ->
errorR(Error(FSComp.SR.astParseEmbeddedILTypeError(), m));
IL.PrimaryAssemblyILGlobals.typ_Object
Expand Down
5 changes: 3 additions & 2 deletions src/fsharp/ParseHelpers.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module internal FSharp.Compiler.ParseHelpers

open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.Features
open FSharp.Compiler.Text
open FSharp.Compiler.Xml
open Internal.Utilities.Text.Lexing
Expand Down Expand Up @@ -108,6 +109,6 @@ type LexerContinuation =

and LexCont = LexerContinuation

val ParseAssemblyCodeInstructions: s:string -> reportLibraryOnlyFeatures: bool -> isFeatureSupported:(Features.LanguageFeature -> bool) -> checkLanguageFeatureErrorRecover:(Features.LanguageFeature -> range -> unit) -> m:range -> ILInstr[]
val ParseAssemblyCodeInstructions: s:string -> reportLibraryOnlyFeatures: bool -> langVersion: LanguageVersion -> m:range -> ILInstr[]

val ParseAssemblyCodeType: s:string -> reportLibraryOnlyFeatures: bool -> isFeatureSupported:(Features.LanguageFeature -> bool) -> checkLanguageFeatureErrorRecover:(Features.LanguageFeature -> range -> unit) -> m:range -> ILType
val ParseAssemblyCodeType: s:string -> reportLibraryOnlyFeatures: bool -> langVersion: LanguageVersion -> m:range -> ILType
4 changes: 1 addition & 3 deletions src/fsharp/ScriptClosure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ module ScriptPreprocessClosure =
| CodeContext.Compilation -> ["COMPILED"]
| CodeContext.Editing -> "EDITING" :: (if IsScript filename then ["INTERACTIVE"] else ["COMPILED"])

let isFeatureSupported featureId = tcConfig.langVersion.SupportsFeature featureId
let checkLanguageFeatureErrorRecover = ErrorLogger.checkLanguageFeatureErrorRecover tcConfig.langVersion
let lexbuf = UnicodeLexing.SourceTextAsLexbuf(true, isFeatureSupported, checkLanguageFeatureErrorRecover, sourceText)
let lexbuf = UnicodeLexing.SourceTextAsLexbuf(true, tcConfig.langVersion, sourceText)

let isLastCompiland = (IsScript filename), tcConfig.target.IsExe // The root compiland is last in the list of compilands.
ParseOneInputLexbuf (tcConfig, lexResourceManager, defines, lexbuf, filename, isLastCompiland, errorLogger)
Expand Down
16 changes: 8 additions & 8 deletions src/fsharp/UnicodeLexing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ open Internal.Utilities.Text.Lexing

type Lexbuf = LexBuffer<char>

let StringAsLexbuf (reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, s: string) =
LexBuffer<char>.FromChars (reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, s.ToCharArray())
let StringAsLexbuf (reportLibraryOnlyFeatures, langVersion, s: string) =
LexBuffer<char>.FromChars (reportLibraryOnlyFeatures, langVersion, s.ToCharArray())

let FunctionAsLexbuf (reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, bufferFiller) =
LexBuffer<char>.FromFunction(reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, bufferFiller)
let FunctionAsLexbuf (reportLibraryOnlyFeatures, langVersion, bufferFiller) =
LexBuffer<char>.FromFunction(reportLibraryOnlyFeatures, langVersion, bufferFiller)

let SourceTextAsLexbuf (reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, sourceText) =
LexBuffer<char>.FromSourceText(reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, sourceText)
let SourceTextAsLexbuf (reportLibraryOnlyFeatures, langVersion, sourceText) =
LexBuffer<char>.FromSourceText(reportLibraryOnlyFeatures, langVersion, sourceText)

let StreamReaderAsLexbuf (reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, reader: StreamReader) =
let StreamReaderAsLexbuf (reportLibraryOnlyFeatures, langVersion, reader: StreamReader) =
let mutable isFinished = false
FunctionAsLexbuf (reportLibraryOnlyFeatures, supportsFeature, checkLanguageFeatureErrorRecover, fun (chars, start, length) ->
FunctionAsLexbuf (reportLibraryOnlyFeatures, langVersion, fun (chars, start, length) ->
if isFinished then 0
else
let nBytesRead = reader.Read(chars, start, length)
Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/UnicodeLexing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ open Internal.Utilities.Text.Lexing

type Lexbuf = LexBuffer<char>

val internal StringAsLexbuf: reportLibraryOnlyFeatures: bool * (LanguageFeature -> bool) * (LanguageFeature -> range -> unit) * string -> Lexbuf
val internal StringAsLexbuf: reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * string -> Lexbuf

val public FunctionAsLexbuf: reportLibraryOnlyFeatures: bool * (LanguageFeature -> bool) * (LanguageFeature -> range -> unit) * (char [] * int * int -> int) -> Lexbuf
val public FunctionAsLexbuf: reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * (char [] * int * int -> int) -> Lexbuf

val public SourceTextAsLexbuf: reportLibraryOnlyFeatures: bool * (LanguageFeature -> bool) * (LanguageFeature -> range -> unit) * ISourceText -> Lexbuf
val public SourceTextAsLexbuf: reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * ISourceText -> Lexbuf

/// Will not dispose of the stream reader.
val public StreamReaderAsLexbuf: reportLibraryOnlyFeatures: bool * (LanguageFeature -> bool) * (LanguageFeature -> range -> unit) * StreamReader -> Lexbuf
val public StreamReaderAsLexbuf: reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * StreamReader -> Lexbuf
Loading