Skip to content
Draft
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
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Allow `let!`, `use!`, `and!` type annotations without requiring parentheses (([PR #18508](https://github.com/dotnet/fsharp/pull/18508) and [PR #18682](https://github.com/dotnet/fsharp/pull/18682)))
* Exception names are now validated for illegal characters using the same mechanism as types/modules/namespaces ([Issue #18763](https://github.com/dotnet/fsharp/issues/18763))
* Support tail calls in computation expressions ([PR #18804](https://github.com/dotnet/fsharp/pull/18804))
* Add `--disableLanguageFeature` CLI switch and MSBuild property to selectively disable specific F# language features on a per-project basis. ([PR #TBD](https://github.com/dotnet/fsharp/pull/TBD))

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ type TcConfigBuilder =

mutable langVersion: LanguageVersion

mutable disabledLanguageFeatures: Set<LanguageFeature>

mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option

mutable exiter: Exiter
Expand Down Expand Up @@ -836,6 +838,7 @@ type TcConfigBuilder =
pathMap = PathMap.empty
applyLineDirectives = true
langVersion = LanguageVersion.Default
disabledLanguageFeatures = Set.empty
implicitIncludeDir = implicitIncludeDir
defaultFSharpBinariesDir = defaultFSharpBinariesDir
reduceMemoryUsage = reduceMemoryUsage
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ type TcConfigBuilder =

mutable langVersion: LanguageVersion

mutable disabledLanguageFeatures: Set<LanguageFeature>

mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option

mutable exiter: Exiter
Expand Down
19 changes: 18 additions & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,28 @@ let languageFlags tcConfigB =
CompilerOption(
"langversion",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still did not update any help tests which is for sure wrong and is a hint of you not running any tests at all, neither build.
Do not do that, follow repo level coding instructions for building code and running tests.
Also run tests you have added at least, on top of the help tests.

@copilot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated help baseline in commit 7c0dc12. Help tests now pass. Running targeted tests for disableLanguageFeature still shows "key not present in dictionary" errors that need debugging.

tagLangVersionValues,
OptionString(fun switch -> tcConfigB.langVersion <- setLanguageVersion switch),
OptionString(fun switch ->
let newVersion = setLanguageVersion switch
// Preserve disabled features when updating version
tcConfigB.langVersion <- newVersion.WithDisabledFeatures(Set.toArray tcConfigB.disabledLanguageFeatures)),
None,
Some(FSComp.SR.optsSetLangVersion ())
)

// -disableLanguageFeature:<string> Disable a specific language feature by name (repeatable)
CompilerOption(
"disableLanguageFeature",
tagString,
OptionStringList(fun featureName ->
match LanguageVersion.TryParseFeature(featureName) with
| Some feature ->
tcConfigB.disabledLanguageFeatures <- Set.add feature tcConfigB.disabledLanguageFeatures
tcConfigB.langVersion <- tcConfigB.langVersion.WithDisabledFeatures(Set.toArray tcConfigB.disabledLanguageFeatures)
| None -> error (Error(FSComp.SR.optsUnrecognizedLanguageFeature featureName, rangeCmdArgs))),
None,
Some(FSComp.SR.optsDisableLanguageFeature ())
)

CompilerOption(
"checked",
tagNone,
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,8 @@ optsCheckNulls,"Enable nullness declarations and checks (%s by default)"
fSharpBannerVersion,"%s for F# %s"
optsGetLangVersions,"Display the allowed values for language version."
optsSetLangVersion,"Specify language version such as 'latest' or 'preview'."
optsDisableLanguageFeature,"Disable a specific language feature by name."
3879,optsUnrecognizedLanguageFeature,"Unrecognized language feature name: '%s'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'."
optsSupportedLangVersions,"Supported language versions:"
optsStrictIndentation,"Override indentation rules implied by the language version (%s by default)"
nativeResourceFormatError,"Stream does not begin with a null resource and is not in '.RES' format."
Expand Down
33 changes: 29 additions & 4 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type LanguageFeature =
| ReturnFromFinal

/// LanguageVersion management
type LanguageVersion(versionText) =
type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) =

// When we increment language versions here preview is higher than current RTM version
static let languageVersion46 = 4.6m
Expand Down Expand Up @@ -279,11 +279,19 @@ type LanguageVersion(versionText) =

let specifiedString = versionToString specified

let disabledFeatures: LanguageFeature array = defaultArg disabledFeaturesArray [||]

/// Check if this feature is supported by the selected langversion
member _.SupportsFeature featureId =
match features.TryGetValue featureId with
| true, v -> v <= specified
| false, _ -> false
if Array.contains featureId disabledFeatures then
false
else
match features.TryGetValue featureId with
| true, v -> v <= specified
| false, _ -> false

/// Create a new LanguageVersion with updated disabled features
member _.WithDisabledFeatures(disabled: LanguageFeature array) = LanguageVersion(versionText, disabled)

/// Has preview been explicitly specified
member _.IsExplicitlySpecifiedAs50OrBefore() =
Expand Down Expand Up @@ -422,6 +430,23 @@ type LanguageVersion(versionText) =
| true, v -> versionToString v
| _ -> invalidArg "feature" "Internal error: Unable to find feature."

/// Try to parse a feature name string to a LanguageFeature option using reflection
static member TryParseFeature(featureName: string) =
let normalized = featureName.Trim()

Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(
typeof<LanguageFeature>,
System.Reflection.BindingFlags.Public
||| System.Reflection.BindingFlags.NonPublic
)
|> Array.tryFind (fun case -> System.String.Equals(case.Name, normalized, System.StringComparison.OrdinalIgnoreCase))
|> Option.bind (fun case ->
let union = Microsoft.FSharp.Reflection.FSharpValue.MakeUnion(case, [||])

match box union with
| null -> None
| obj -> Some(obj :?> LanguageFeature))

override x.Equals(yobj: obj) =
match yobj with
| :? LanguageVersion as y -> x.SpecifiedVersion = y.SpecifiedVersion
Expand Down
8 changes: 7 additions & 1 deletion src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type LanguageFeature =
type LanguageVersion =

/// Create a LanguageVersion management object
new: string -> LanguageVersion
new: string * ?disabledFeaturesArray: LanguageFeature array -> LanguageVersion

/// Get the list of valid versions
static member ContainsVersion: string -> bool
Expand All @@ -115,6 +115,9 @@ type LanguageVersion =
/// Does the selected LanguageVersion support the specified feature
member SupportsFeature: LanguageFeature -> bool

/// Create a new LanguageVersion with updated disabled features
member WithDisabledFeatures: LanguageFeature array -> LanguageVersion

/// Get the list of valid versions
static member ValidVersions: string[]

Expand All @@ -136,4 +139,7 @@ type LanguageVersion =
/// Get a version string associated with the given feature.
static member GetFeatureVersionString: feature: LanguageFeature -> string

/// Try to parse a feature name string to a LanguageFeature option
static member TryParseFeature: featureName: string -> LanguageFeature option

static member Default: LanguageVersion
10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading