Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring langversion options in FSC #13785

Closed
wants to merge 3 commits into from
Closed
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
54 changes: 30 additions & 24 deletions src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ let ParseCompilerOptions (collectOtherArgument: string -> unit, blocks: Compiler

// 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]

let mutable opt = s

if opt = "" then
()
Expand All @@ -283,9 +282,13 @@ let ParseCompilerOptions (collectOtherArgument: string -> unit, blocks: Compiler
else
opt <- ""

// grab the option token
let opts = opt.Split([| ':' |])
let token = opts[0]

// get the argument string
let optArgs = if opts.Length > 1 then String.Join(":", opts[1..]) else ""
opt, optArgs
opt, token, optArgs

let getOptionArg compilerOption (argString: string) =
if argString = "" then
Expand Down Expand Up @@ -352,7 +355,7 @@ let ParseCompilerOptions (collectOtherArgument: string -> unit, blocks: Compiler

processArg (responseFileOptions @ t)
| opt :: t ->
let optToken, argString = parseOption opt
let option, optToken, argString = parseOption opt

let reportDeprecatedOption errOpt =
match errOpt with
Expand All @@ -361,7 +364,7 @@ let ParseCompilerOptions (collectOtherArgument: string -> unit, blocks: Compiler

let rec attempt l =
match l with
| CompilerOption (s, _, OptionConsoleOnly f, d, _) :: _ when optToken = s && argString = "" ->
| CompilerOption (s, _, OptionConsoleOnly f, d, _) :: _ when option = s ->
reportDeprecatedOption d
f blocks
t
Expand Down Expand Up @@ -710,7 +713,7 @@ let tagAlgorithm = "{SHA1|SHA256}"
let tagInt = "<n>"
let tagPathMap = "<path=sourcePath;...>"
let tagNone = ""
let tagLangVersionValues = "{?|version|latest|preview}"
let tagLangVersionValues = "{version|latest|preview}"

// PrintOptionInfo
//----------------
Expand Down Expand Up @@ -1104,23 +1107,16 @@ let mlCompatibilityFlag (tcConfigB: TcConfigBuilder) =
Some(FSComp.SR.optsMlcompatibility ())
)

/// LanguageVersion management
let setLanguageVersion specifiedVersion =

let dumpAllowedValues () =
printfn "%s" (FSComp.SR.optsSupportedLangVersions ())

for v in LanguageVersion.ValidOptions do
printfn "%s" v

for v in LanguageVersion.ValidVersions do
printfn "%s" v

exit 0
let GetLanguageVersions () =
seq {
FSComp.SR.optsSupportedLangVersions ()
yield! LanguageVersion.ValidOptions
yield! LanguageVersion.ValidVersions
}
|> String.concat Environment.NewLine

if specifiedVersion = "?" then
dumpAllowedValues ()
elif specifiedVersion.ToUpperInvariant() = "PREVIEW" then
let setLanguageVersion (specifiedVersion: string) =
if specifiedVersion.ToUpperInvariant() = "PREVIEW" then
()
elif not (LanguageVersion.ContainsVersion specifiedVersion) then
error (Error(FSComp.SR.optsUnrecognizedLanguageVersion specifiedVersion, rangeCmdArgs))
Expand All @@ -1130,6 +1126,16 @@ let setLanguageVersion specifiedVersion =
let languageFlags tcConfigB =
[
// -langversion:? Display the allowed values for language version
CompilerOption(
"langversion:?",
tagNone,
OptionConsoleOnly(fun _ ->
Console.Write(GetLanguageVersions())
exit 0),
None,
Some(FSComp.SR.optsGetLangVersions ())
)

// -langversion:<string> Specify language version such as
// 'default' (latest major version), or
// 'latest' (latest version, including minor versions),
Expand All @@ -1140,7 +1146,7 @@ let languageFlags tcConfigB =
tagLangVersionValues,
OptionString(fun switch -> tcConfigB.langVersion <- setLanguageVersion (switch)),
None,
Some(FSComp.SR.optsLangVersion ())
Some(FSComp.SR.optsSetLangVersion ())
)

CompilerOption(
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Driver/CompilerOptions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ val GetHelpFsc: tcConfigB: TcConfigBuilder -> blocks: CompilerOptionBlock list -

val GetVersion: tcConfigB: TcConfigBuilder -> string

val GetLanguageVersions: unit -> string

val GetCoreFscCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list

val GetCoreFsiCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,8 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
3353,chkFeatureNotSupportedInLibrary,"Feature '%s' requires the F# library for language version %s or greater."
3360,parsEqualsMissingInTypeDefinition,"Unexpected token in type definition. Expected '=' after the type '%s'."
useSdkRefs,"Use reference assemblies for .NET framework references when available (Enabled by default)."
optsLangVersion,"Display the allowed values for language version, specify language version such as 'latest' or 'preview'"
optsGetLangVersions,"Display the allowed values for language version."
optsSetLangVersion,"Specify language version such as 'latest' or 'preview'."
optsSupportedLangVersions,"Supported language versions:"
nativeResourceFormatError,"Stream does not begin with a null resource and is not in '.RES' format."
nativeResourceHeaderMalformed,"Resource header beginning at offset %s is malformed."
Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@
<target state="new">Compress interface and optimization data files</target>
<note />
</trans-unit>
<trans-unit id="optsGetLangVersions">
<source>Display the allowed values for language version.</source>
<target state="new">Display the allowed values for language version.</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="translated">Neplatné použití generování referenčního sestavení, nepoužívejte --staticlink ani --refonly a --refout společně.</target>
Expand All @@ -487,11 +492,6 @@
<target state="translated">Neplatná cesta k referenčnímu sestavení</target>
<note />
</trans-unit>
<trans-unit id="optsLangVersion">
<source>Display the allowed values for language version, specify language version such as 'latest' or 'preview'</source>
<target state="translated">Zobrazte si povolené hodnoty verze jazyka a pak zadejte požadovanou verzi, například latest nebo preview.</target>
<note />
</trans-unit>
<trans-unit id="optsOptimizationData">
<source>Specify included optimization information, the default is file. Important for distributed libraries.</source>
<target state="new">Specify included optimization information, the default is file. Important for distributed libraries.</target>
Expand All @@ -517,6 +517,11 @@
<target state="new">Disable implicit generation of constructs using reflection</target>
<note />
</trans-unit>
<trans-unit id="optsSetLangVersion">
<source>Specify language version such as 'latest' or 'preview'.</source>
<target state="new">Specify language version such as 'latest' or 'preview'.</target>
<note />
</trans-unit>
<trans-unit id="optsSignatureData">
<source>Include F# interface information, the default is file. Essential for distributing libraries.</source>
<target state="new">Include F# interface information, the default is file. Essential for distributing libraries.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@
<target state="new">Compress interface and optimization data files</target>
<note />
</trans-unit>
<trans-unit id="optsGetLangVersions">
<source>Display the allowed values for language version.</source>
<target state="new">Display the allowed values for language version.</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="translated">Ungültige Verwendung der Ausgabe einer Referenzassembly. Verwenden Sie nicht "--staticlink" oder "--refonly" und "--refout" zusammen.</target>
Expand All @@ -487,11 +492,6 @@
<target state="translated">Ungültiger Referenzassemblypfad"</target>
<note />
</trans-unit>
<trans-unit id="optsLangVersion">
<source>Display the allowed values for language version, specify language version such as 'latest' or 'preview'</source>
<target state="translated">Zeigen Sie die zulässigen Werte für die Sprachversion an. Geben Sie die Sprachversion als "latest" oder "preview" an.</target>
<note />
</trans-unit>
<trans-unit id="optsOptimizationData">
<source>Specify included optimization information, the default is file. Important for distributed libraries.</source>
<target state="new">Specify included optimization information, the default is file. Important for distributed libraries.</target>
Expand All @@ -517,6 +517,11 @@
<target state="new">Disable implicit generation of constructs using reflection</target>
<note />
</trans-unit>
<trans-unit id="optsSetLangVersion">
<source>Specify language version such as 'latest' or 'preview'.</source>
<target state="new">Specify language version such as 'latest' or 'preview'.</target>
<note />
</trans-unit>
<trans-unit id="optsSignatureData">
<source>Include F# interface information, the default is file. Essential for distributing libraries.</source>
<target state="new">Include F# interface information, the default is file. Essential for distributing libraries.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@
<target state="new">Compress interface and optimization data files</target>
<note />
</trans-unit>
<trans-unit id="optsGetLangVersions">
<source>Display the allowed values for language version.</source>
<target state="new">Display the allowed values for language version.</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="translated">Uso no válido de emitir un ensamblado de referencia, no use "--staticlink', or '--refonly' and '--refout" de forma conjunta.</target>
Expand All @@ -487,11 +492,6 @@
<target state="translated">Ruta de acceso de ensamblado de referencia no válida</target>
<note />
</trans-unit>
<trans-unit id="optsLangVersion">
<source>Display the allowed values for language version, specify language version such as 'latest' or 'preview'</source>
<target state="translated">Mostrar los valores permitidos para la versión de idioma, especificar la versión de idioma como "latest" "preview"</target>
<note />
</trans-unit>
<trans-unit id="optsOptimizationData">
<source>Specify included optimization information, the default is file. Important for distributed libraries.</source>
<target state="new">Specify included optimization information, the default is file. Important for distributed libraries.</target>
Expand All @@ -517,6 +517,11 @@
<target state="new">Disable implicit generation of constructs using reflection</target>
<note />
</trans-unit>
<trans-unit id="optsSetLangVersion">
<source>Specify language version such as 'latest' or 'preview'.</source>
<target state="new">Specify language version such as 'latest' or 'preview'.</target>
<note />
</trans-unit>
<trans-unit id="optsSignatureData">
<source>Include F# interface information, the default is file. Essential for distributing libraries.</source>
<target state="new">Include F# interface information, the default is file. Essential for distributing libraries.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@
<target state="new">Compress interface and optimization data files</target>
<note />
</trans-unit>
<trans-unit id="optsGetLangVersions">
<source>Display the allowed values for language version.</source>
<target state="new">Display the allowed values for language version.</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="translated">Utilisation non valide de l’émission d’un assembly de référence. N’utilisez pas '--staticlink' ni '--refonly' et '--refout' ensemble.</target>
Expand All @@ -487,11 +492,6 @@
<target state="translated">Chemin d'assemblage de référence non valide'</target>
<note />
</trans-unit>
<trans-unit id="optsLangVersion">
<source>Display the allowed values for language version, specify language version such as 'latest' or 'preview'</source>
<target state="translated">Afficher les valeurs autorisées pour la version du langage, spécifier la version du langage comme 'dernière' ou 'préversion'</target>
<note />
</trans-unit>
<trans-unit id="optsOptimizationData">
<source>Specify included optimization information, the default is file. Important for distributed libraries.</source>
<target state="new">Specify included optimization information, the default is file. Important for distributed libraries.</target>
Expand All @@ -517,6 +517,11 @@
<target state="new">Disable implicit generation of constructs using reflection</target>
<note />
</trans-unit>
<trans-unit id="optsSetLangVersion">
<source>Specify language version such as 'latest' or 'preview'.</source>
<target state="new">Specify language version such as 'latest' or 'preview'.</target>
<note />
</trans-unit>
<trans-unit id="optsSignatureData">
<source>Include F# interface information, the default is file. Essential for distributing libraries.</source>
<target state="new">Include F# interface information, the default is file. Essential for distributing libraries.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@
<target state="new">Compress interface and optimization data files</target>
<note />
</trans-unit>
<trans-unit id="optsGetLangVersions">
<source>Display the allowed values for language version.</source>
<target state="new">Display the allowed values for language version.</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="translated">Utilizzo non valido della creazione di un assembly di riferimento. Non usare insieme '--staticlink' o '--refonly' e '--refout'.</target>
Expand All @@ -487,11 +492,6 @@
<target state="translated">Percorso assembly di riferimento non valido'</target>
<note />
</trans-unit>
<trans-unit id="optsLangVersion">
<source>Display the allowed values for language version, specify language version such as 'latest' or 'preview'</source>
<target state="translated">Visualizza i valori consentiti per la versione del linguaggio. Specificare la versione del linguaggio, ad esempio 'latest' o 'preview'</target>
<note />
</trans-unit>
<trans-unit id="optsOptimizationData">
<source>Specify included optimization information, the default is file. Important for distributed libraries.</source>
<target state="new">Specify included optimization information, the default is file. Important for distributed libraries.</target>
Expand All @@ -517,6 +517,11 @@
<target state="new">Disable implicit generation of constructs using reflection</target>
<note />
</trans-unit>
<trans-unit id="optsSetLangVersion">
<source>Specify language version such as 'latest' or 'preview'.</source>
<target state="new">Specify language version such as 'latest' or 'preview'.</target>
<note />
</trans-unit>
<trans-unit id="optsSignatureData">
<source>Include F# interface information, the default is file. Essential for distributing libraries.</source>
<target state="new">Include F# interface information, the default is file. Essential for distributing libraries.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/xlf/FSComp.txt.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@
<target state="new">Compress interface and optimization data files</target>
<note />
</trans-unit>
<trans-unit id="optsGetLangVersions">
<source>Display the allowed values for language version.</source>
<target state="new">Display the allowed values for language version.</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="translated">参照アセンブリの生成の使用が無効です。'--staticlink'、または '--refonly' と '--refout' を同時に使用しないでください。</target>
Expand All @@ -487,11 +492,6 @@
<target state="translated">参照アセンブリ パスが無効です'</target>
<note />
</trans-unit>
<trans-unit id="optsLangVersion">
<source>Display the allowed values for language version, specify language version such as 'latest' or 'preview'</source>
<target state="translated">言語バージョンで許可された値を表示し、'最新' や 'プレビュー' などの言語バージョンを指定する</target>
<note />
</trans-unit>
<trans-unit id="optsOptimizationData">
<source>Specify included optimization information, the default is file. Important for distributed libraries.</source>
<target state="new">Specify included optimization information, the default is file. Important for distributed libraries.</target>
Expand All @@ -517,6 +517,11 @@
<target state="new">Disable implicit generation of constructs using reflection</target>
<note />
</trans-unit>
<trans-unit id="optsSetLangVersion">
<source>Specify language version such as 'latest' or 'preview'.</source>
<target state="new">Specify language version such as 'latest' or 'preview'.</target>
<note />
</trans-unit>
<trans-unit id="optsSignatureData">
<source>Include F# interface information, the default is file. Essential for distributing libraries.</source>
<target state="new">Include F# interface information, the default is file. Essential for distributing libraries.</target>
Expand Down
Loading