Skip to content

Commit 9877cfe

Browse files
authored
Faster equality in generic contexts (#16615)
1 parent b9519e7 commit 9877cfe

File tree

21 files changed

+836
-76
lines changed

21 files changed

+836
-76
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ stages:
794794
condition: always()
795795

796796
# Test trimming on Windows
797-
- job: Build_And_Test_Trimming_Windows
797+
- job: Build_And_Test_AOT_Windows
798798
pool:
799799
name: $(DncEngPublicBuildPool)
800800
demands: ImageOverride -equals $(WindowsMachineQueueName)
@@ -825,9 +825,9 @@ stages:
825825
env:
826826
NativeToolsOnMachine: true
827827
displayName: Initial build and prepare packages.
828-
- script: $(Build.SourcesDirectory)/tests/AheadOfTime/Trimming/check.cmd
828+
- script: $(Build.SourcesDirectory)/tests/AheadOfTime/check.cmd
829829
displayName: Build, trim, publish and check the state of the trimmed app.
830-
workingDirectory: $(Build.SourcesDirectory)/tests/AheadOfTime/Trimming
830+
workingDirectory: $(Build.SourcesDirectory)/tests/AheadOfTime
831831
- task: PublishPipelineArtifact@1
832832
displayName: Publish Trim Tests Logs
833833
inputs:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
### Added
22

33
* Minor tweaks to inline specifications to support Visibility PR ([PR #15484](https://github.com/dotnet/fsharp/pull/15484), [#PR 16427](https://github.com/dotnet/fsharp/pull/15484)
4+
* Optimize equality in generic contexts. ([PR #16615](https://github.com/dotnet/fsharp/pull/16615))
45

56
### Fixed
7+
68
* Preserve original stack traces in resumable state machines generated code if available. ([PR #16568](https://github.com/dotnet/fsharp/pull/16568))

eng/Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ try {
680680
}
681681

682682
if ($testAOT) {
683-
Push-Location "$RepoRoot\tests\AheadOfTime\Trimming"
683+
Push-Location "$RepoRoot\tests\AheadOfTime"
684684
./check.cmd
685685
Pop-Location
686686
}

src/FSharp.Core/prim-types.fs

Lines changed: 190 additions & 62 deletions
Large diffs are not rendered by default.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<LangVersion>preview</LangVersion>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
</PropertyGroup>
9+
10+
<PropertyGroup>
11+
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
12+
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
13+
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
14+
<PublishTrimmed>true</PublishTrimmed>
15+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
16+
</PropertyGroup>
17+
18+
<PropertyGroup>
19+
<DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Release/net8.0/fsc.dll</DotnetFscCompilerPath>
20+
<Fsc_DotNET_DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Release/net8.0/fsc.dll</Fsc_DotNET_DotnetFscCompilerPath>
21+
<FSharpPreferNetFrameworkTools>False</FSharpPreferNetFrameworkTools>
22+
<FSharpPrefer64BitTools>True</FSharpPrefer64BitTools>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<Compile Include="Program.fs" />
27+
</ItemGroup>
28+
29+
<Import Project="$(MSBuildThisFileDirectory)../../../eng/Versions.props" />
30+
31+
<ItemGroup>
32+
<PackageReference Include="FSharp.Core" Version="$(FSharpCorePreviewPackageVersionValue)"/>
33+
</ItemGroup>
34+
35+
</Project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
open System.Collections.Generic
2+
open NonStructuralComparison
3+
4+
let failures = HashSet<string>()
5+
6+
let reportFailure (s: string) =
7+
stderr.Write " NO: "
8+
stderr.WriteLine s
9+
failures.Add s |> ignore
10+
11+
let test testName x y =
12+
let result = HashIdentity.Structural.Equals(x, y)
13+
if result = false
14+
then
15+
stderr.WriteLine($"\n***** {testName}: Expected: 'true' Result: '{result}' = FAIL\n");
16+
reportFailure testName
17+
18+
module BasicTypes =
19+
test "test000" true true
20+
test "test001" 1y 1y
21+
test "test002" 1uy 1uy
22+
test "test003" 1s 1s
23+
test "test004" 1us 1us
24+
test "test005" 1 1
25+
test "test006" 1u 1u
26+
test "test007" 1L 1L
27+
test "test008" 1UL 1UL
28+
test "test009" (nativeint 1) (nativeint 1)
29+
test "test010" (unativeint 1) (unativeint 1)
30+
test "test011" 'a' 'a'
31+
test "test012" "a" "a"
32+
test "test013" 1m 1m
33+
test "test014" 1.0 1.0
34+
test "test015" 1.0f 1.0f
35+
36+
module Arrays =
37+
test "test100" [|1|] [|1|]
38+
test "test101" [|1L|] [|1L|]
39+
test "test102" [|1uy|] [|1uy|]
40+
test "test103" [|box 1|] [|box 1|]
41+
42+
module Structs =
43+
test "test200" struct (1, 1) struct (1, 1)
44+
test "test201" struct (1, 1, 1) struct (1, 1, 1)
45+
test "test202" struct (1, 1, 1, 1) struct (1, 1, 1, 1)
46+
test "test203" struct (1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1)
47+
test "test204" struct (1, 1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1, 1)
48+
test "test205" struct (1, 1, 1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1, 1, 1)
49+
test "test206" struct (1, 1, 1, 1, 1, 1, 1, 1) struct (1, 1, 1, 1, 1, 1, 1, 1)
50+
51+
module OptionsAndCo =
52+
open System
53+
54+
test "test301" (Some 1) (Some 1)
55+
test "test302" (ValueSome 1) (ValueSome 1)
56+
test "test303" (Ok 1) (Ok 1)
57+
test "test304" (Nullable 1) (Nullable 1)
58+
59+
module Enums =
60+
open System
61+
62+
type SomeEnum =
63+
| Case0 = 0
64+
| Case1 = 1
65+
66+
test "test401" (enum<SomeEnum>(1)) (enum<SomeEnum>(1))
67+
test "test402" (enum<DayOfWeek>(1)) (enum<DayOfWeek>(1))
68+
69+
[<EntryPoint>]
70+
let main _ =
71+
match failures with
72+
| set when set.Count = 0 ->
73+
stdout.WriteLine "All tests passed"
74+
exit 0
75+
| _ ->
76+
stdout.WriteLine "Some tests failed"
77+
exit 1
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Write-Host "Publish and Execute: net8.0 - Equality"
2+
3+
$build_output = dotnet publish -restore -c release -f:net8.0 $(Join-Path $PSScriptRoot Equality.fsproj)
4+
5+
# Checking that the build succeeded
6+
if ($LASTEXITCODE -ne 0)
7+
{
8+
Write-Error "Build failed with exit code ${LASTEXITCODE}"
9+
Write-Error "${build_output}" -ErrorAction Stop
10+
}
11+
12+
$process = Start-Process `
13+
-FilePath $(Join-Path $PSScriptRoot bin\release\net8.0\win-x64\publish\Equality.exe) `
14+
-Wait `
15+
-NoNewWindow `
16+
-PassThru `
17+
-RedirectStandardOutput $(Join-Path $PSScriptRoot output.txt)
18+
19+
$output = Get-Content $(Join-Path $PSScriptRoot output.txt)
20+
21+
# Checking that it is actually running.
22+
if ($LASTEXITCODE -ne 0)
23+
{
24+
Write-Error "Test failed with exit code ${LASTEXITCODE}" -ErrorAction Stop
25+
}
26+
27+
# Checking that the output is as expected.
28+
$expected = "All tests passed"
29+
if ($output -ne $expected)
30+
{
31+
Write-Error "Test failed with unexpected output:`nExpected:`n`t${expected}`nActual`n`t${output}" -ErrorAction Stop
32+
}

tests/AheadOfTime/Trimming/check.cmd

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/AheadOfTime/Trimming/check.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function CheckTrim($root, $tfm, $outputfile, $expected_len) {
3939
# error NETSDK1124: Trimming assemblies requires .NET Core 3.0 or higher.
4040

4141
# Check net7.0 trimmed assemblies
42-
CheckTrim -root "SelfContained_Trimming_Test" -tfm "net8.0" -outputfile "FSharp.Core.dll" -expected_len 287232
42+
CheckTrim -root "SelfContained_Trimming_Test" -tfm "net8.0" -outputfile "FSharp.Core.dll" -expected_len 284160
4343

4444
# Check net8.0 trimmed assemblies
45-
CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8820736
45+
CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8817152

tests/AheadOfTime/check.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Trimming\check.ps1""""
3+
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Equality\check.ps1""""

0 commit comments

Comments
 (0)