Skip to content

Commit

Permalink
First pass F# 9 support and nullness (#308)
Browse files Browse the repository at this point in the history
* First pass F# 9 support

* Add Nullable and changes to compensate

* Keep fantomas from having a stroke

* support fable

* Update ValueOption/Option CE for F# 9 nullness

* Fix fable

* Format the world

* fix devcontainer

* Add ValueOption tests for fable
  • Loading branch information
TheAngryByrd authored Feb 16, 2025
1 parent e72eff3 commit 57fb06c
Show file tree
Hide file tree
Showing 43 changed files with 338 additions and 451 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "8.0.3",
"version": "9.0.2",
"commands": [
"paket"
],
Expand All @@ -17,7 +17,7 @@
"rollForward": false
},
"fantomas": {
"version": "6.3.16",
"version": "7.0.0",
"commands": [
"fantomas"
],
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"ghcr.io/devcontainers-contrib/features/starship:1": {},
// https://github.com/devcontainers/features/blob/main/src/dotnet/README.md
"ghcr.io/devcontainers/features/dotnet:2": {
"version": "8.0",
"additionalVersions": "7.0,6.0"
"version": "9.0",
"additionalVersions": "8.0"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "18"
Expand Down
2 changes: 1 addition & 1 deletion .fantomasignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
AssemblyInfo.fs
tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/Main.fs
tests/FsToolkit.ErrorHandling.Tests/Main.fs
tests/FsToolkit.ErrorHandling.Tests/Main.fs
9 changes: 7 additions & 2 deletions .paket/Paket.Restore.targets
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,15 @@
<Splits>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',').Length)</Splits>
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
<Reference>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[2])</Reference>
<AllPrivateAssets>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4])</AllPrivateAssets>
<CopyLocal Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 6">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5])</CopyLocal>
<OmitContent Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 7">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[6])</OmitContent>
<ImportTargets Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 8">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[7])</ImportTargets>
<Aliases Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 9">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[8])</Aliases>
</PaketReferencesFileLinesInfo>
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
<PackageReference Condition=" '$(ManagePackageVersionsCentrally)' != 'true' Or '%(PaketReferencesFileLinesInfo.Reference)' == 'Direct' " Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version Condition=" '$(ManagePackageVersionsCentrally)' != 'true' ">%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
<PrivateAssets Condition=" ('%(PaketReferencesFileLinesInfo.AllPrivateAssets)' == 'true') Or ('$(PackAsTool)' == 'true') ">All</PrivateAssets>
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.CopyLocal) == 'false' or %(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'exclude'">runtime</ExcludeAssets>
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.OmitContent) == 'true'">$(ExcludeAssets);contentFiles</ExcludeAssets>
Expand All @@ -252,6 +253,10 @@
<AllowExplicitVersion>true</AllowExplicitVersion>

</PackageReference>

<PackageVersion Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
</PackageVersion>
</ItemGroup>

<PropertyGroup>
Expand Down
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"editor.inlayHints.enabled": "off",
"FSharp.enableMSBuildProjectGraph": true,
"editor.formatOnSave": true,
"[fsharp]": {
"editor.formatOnSave": true,
},
"FSharp.notifications.trace": false,
"FSharp.notifications.traceNamespaces": [
"BoundModel.TypeCheck",
"BackgroundCompiler."
],
"FSharp.fsac.parallelReferenceResolution": false,
"FSharp.enableAnalyzers": true,
"FSharp.analyzersPath": ["packages/analyzers"]
}
"FSharp.analyzersPath": [
"packages/analyzers"
]
}
12 changes: 11 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<Project>
<PropertyGroup>
<DisableCheckingDuplicateNuGetItems>true</DisableCheckingDuplicateNuGetItems>
<NoWarn>$(NoWarn);FS2003; NU1903; NU1904</NoWarn>
<NoWarn>$(NoWarn);FS2003;NU1903;NU1904;FS0057</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<!--
Changing the LangVersion based on TFM because F# 9 brings in new features that older SDK's can't support.
See https://github.com/dotnet/fsharp/issues/14313 for an example.
To keep this library as backward compatible as possible we're setting the LangVersion to 8.0 by default.
Then, we're assuming if you're building for net9.0 you're using F# 9 Language features.
-->
<LangVersion>8.0</LangVersion>
<LangVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0</LangVersion>
<Nullable Condition="'$(TargetFramework)' == 'net9.0'">enable</Nullable>
<PaketPropsVersion>6.0.0</PaketPropsVersion> <!-- Hack to prevent paket from restoring when it should not -->
</PropertyGroup>
</Project>
13 changes: 10 additions & 3 deletions Directory.Solution.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<Project>
<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences">
<Exec Command="dotnet tool restore" StandardOutputImportance="High"
StandardErrorImportance="High" />
<PropertyGroup>
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)-$(OS)</_DotnetToolRestoreOutputFile>
</PropertyGroup>

<Target Name="ToolRestore" BeforeTargets="Restore;CollectPackageReferences;PaketRestore" Inputs="$(_DotnetToolManifestFile)" Outputs="$(_DotnetToolRestoreOutputFile)">
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
</Target>
</Project>
7 changes: 2 additions & 5 deletions benchmarks/benchmarks.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<PropertyGroup>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -14,9 +13,6 @@
<IsPackable>false</IsPackable>
<NoWarn>FS1204;FS3501;FS3511</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Tailcalls>true</Tailcalls>
</PropertyGroup>
<ItemGroup>
<Compile Include="SeqTests.fs" />
<Compile Include="ApplicativeTests.fs" />
Expand All @@ -28,7 +24,8 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\FsToolkit.ErrorHandling.JobResult\FsToolkit.ErrorHandling.JobResult.fsproj" />
<ProjectReference
Include="..\src\FsToolkit.ErrorHandling.JobResult\FsToolkit.ErrorHandling.JobResult.fsproj" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
6 changes: 3 additions & 3 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ let formatCode _ =
Trace.traceErrorfn "Errors while formatting all files: %A" result.Messages

let analyze _ =
let analyzerPaths = !! "packages/analyzers/**/analyzers/dotnet/fs"
let analyzerPaths = !!"packages/analyzers/**/analyzers/dotnet/fs"

let createArgsForProject (project: string) analyzerPaths =
let projectName = Path.GetFileNameWithoutExtension project
Expand All @@ -162,7 +162,7 @@ let analyze _ =
]
|> String.concat " "

!! "src/**/*.fsproj"
!!"src/**/*.fsproj"
|> Seq.iter (fun fsproj ->
let result =
createArgsForProject fsproj analyzerPaths
Expand All @@ -187,7 +187,7 @@ let checkFormatCode _ =


let clean _ =
!! "bin"
!!"bin"
++ "benchmarks/**/bin"
++ "src/**/bin"
++ "tests/**/bin"
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"version": "9.0.100",
"rollForward": "latestMinor"
}
}
4 changes: 1 addition & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
</PropertyGroup>

<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<NoWarn>FS2003</NoWarn>
<NoWarn>$(NoWarn);FS2003</NoWarn>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<TargetFrameworks>netstandard2.1;netstandard2.0;net9.0</TargetFrameworks>

<DebugType>portable</DebugType>
</PropertyGroup>
<!-- Add source files to "fable" folder in Nuget package -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ module CancellableTaskResultCE =
sm.ResumptionDynamicInfo.ResumptionData
:?> ICriticalNotifyCompletion

assert not (isNull awaiter)

MethodBuilder.AwaitUnsafeOnCompleted(
&sm.Data.MethodBuilder,
&awaiter,
Expand Down Expand Up @@ -99,7 +97,7 @@ module CancellableTaskResultCE =
(MoveNextMethodImpl<_>(fun sm ->
//-- RESUMABLE CODE START
__resumeAt sm.ResumptionPoint
let mutable __stack_exn: Exception = null
let mutable __stack_exn: ExceptionNull = null

try
let __stack_code_fin = code.Invoke(&sm)
Expand Down Expand Up @@ -181,7 +179,7 @@ module CancellableTaskResultCE =
(MoveNextMethodImpl<_>(fun sm ->
//-- RESUMABLE CODE START
__resumeAt sm.ResumptionPoint
let mutable __stack_exn: Exception = null
let mutable __stack_exn: ExceptionNull = null

try
let __stack_code_fin = code.Invoke(&sm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module CancellableTaskValidationCE =
(MoveNextMethodImpl<_>(fun sm ->
//-- RESUMABLE CODE START
__resumeAt sm.ResumptionPoint
let mutable __stack_exn: Exception = null
let mutable __stack_exn: ExceptionNull = null

try
let __stack_code_fin = code.Invoke(&sm)
Expand Down Expand Up @@ -236,10 +236,8 @@ module AsyncExtensions =
this.ReturnFrom(Async.AwaitCancellableTask t)

member inline this.Bind
([<InlineIfLambda>] t: CancellableTask, [<InlineIfLambda>] binder: (unit -> Async<'U>)) : Async<
'U
>
=
([<InlineIfLambda>] t: CancellableTask, [<InlineIfLambda>] binder: (unit -> Async<'U>))
: Async<'U> =
this.Bind(Async.AwaitCancellableTask t, binder)

member inline this.ReturnFrom([<InlineIfLambda>] t: CancellableTask) : Async<unit> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>preview</LangVersion>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1;net9.0</TargetFrameworks>

<DebugType>portable</DebugType>
<NoWarn>FS3511;FS3513</NoWarn>
<NoWarn>$(NoWarn);FS3511;FS3513</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="CancellableTaskResultBuilderBase.fs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net9.0</TargetFrameworks>
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/FsToolkit.ErrorHandling.JobResult/JobOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module JobOptionCE =
type JobOptionBuilder() =

member inline _.Return(value: 'T) : Job<_ option> =
option.Return value
Some value
|> job.Return

member inline _.ReturnFrom(jobResult: Job<_ option>) : Job<_ option> = jobResult

member inline _.Zero() : Job<_ option> =
option.Zero()
Some()
|> job.Return

member inline _.Bind
Expand Down Expand Up @@ -70,7 +70,7 @@ module JobOptionCE =
Job.tryFinallyFunDelay computation compensation

member inline _.Using
(resource: 'T :> IDisposable, [<InlineIfLambda>] binder: 'T -> Job<_ option>)
(resource: 'T :> IDisposableNull, [<InlineIfLambda>] binder: 'T -> Job<_ option>)
: Job<_ option> =
job.Using(resource, binder)

Expand Down
20 changes: 6 additions & 14 deletions src/FsToolkit.ErrorHandling.JobResult/JobResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,8 @@ module JobResultCE =
Job.tryWithDelay computation handler

member inline _.TryFinally
(computation: Job<Result<'T, 'TError>>, [<InlineIfLambda>] compensation: unit -> unit) : Job<
Result<
'T,
'TError
>
>
=
(computation: Job<Result<'T, 'TError>>, [<InlineIfLambda>] compensation: unit -> unit)
: Job<Result<'T, 'TError>> =
Job.tryFinallyFun computation compensation

member inline _.TryFinally
Expand All @@ -75,13 +70,10 @@ module JobResultCE =
Job.tryFinallyFunDelay computation compensation

member inline _.Using
(resource: 'T :> IDisposable, [<InlineIfLambda>] binder: 'T -> Job<Result<'U, 'TError>>) : Job<
Result<
'U,
'TError
>
>
=
(
resource: 'T :> IDisposableNull,
[<InlineIfLambda>] binder: 'T -> Job<Result<'U, 'TError>>
) : Job<Result<'U, 'TError>> =
job.Using(resource, binder)

member this.While
Expand Down
8 changes: 3 additions & 5 deletions src/FsToolkit.ErrorHandling/AsyncOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module AsyncOptionCE =
member inline _.ReturnFrom(value: Async<'value option>) : Async<'value option> = value

member inline _.Zero() : Async<unit option> =
option.Zero()
Some()
|> async.Return

member inline _.Bind
Expand Down Expand Up @@ -43,10 +43,8 @@ module AsyncOptionCE =
async.TryFinally(computation, compensation)
#if !FABLE_COMPILER
member inline _.TryFinallyAsync
(computation: Async<'value option>, [<InlineIfLambda>] compensation: unit -> ValueTask) : Async<
'value option
>
=
(computation: Async<'value option>, [<InlineIfLambda>] compensation: unit -> ValueTask)
: Async<'value option> =
let compensation =
async {
let vTask = compensation ()
Expand Down
9 changes: 2 additions & 7 deletions src/FsToolkit.ErrorHandling/AsyncResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ module AsyncResultCE =
async.TryWith(computation, handler)

member inline _.TryFinally
(computation: Async<Result<'ok, 'error>>, [<InlineIfLambda>] compensation: unit -> unit) : Async<
Result<
'ok,
'error
>
>
=
(computation: Async<Result<'ok, 'error>>, [<InlineIfLambda>] compensation: unit -> unit)
: Async<Result<'ok, 'error>> =
async.TryFinally(computation, compensation)
#if !FABLE_COMPILER
member inline _.TryFinallyAsync
Expand Down
Loading

0 comments on commit 57fb06c

Please sign in to comment.