Skip to content

Commit

Permalink
Merge pull request #764 from polyadic/net8.0
Browse files Browse the repository at this point in the history
Update SDK to .NET 8
  • Loading branch information
bash authored Nov 22, 2023
2 parents c55ff3b + 74385e6 commit 72c87a2
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- uses: actions/setup-dotnet@v3
name: Install Current .NET SDK
- name: Generate NuGet Packages
run: dotnet pack --configuration Release --output nupkg /p:FunckyBuildWithPreviewTargetFramework=false
run: dotnet pack --output nupkg
- uses: actions/upload-artifact@v3
if: success() && github.ref == 'refs/heads/main'
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-nightly-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
- uses: actions/setup-dotnet@v3
name: Install Current .NET SDK
- name: Pack Packages
run: dotnet pack Funcky/Funcky.csproj --configuration Release --output nupkg --version-suffix "nightly.$(git rev-parse --short "${{github.sha}}")" /p:GeneratePackageOnBuild=false
run: dotnet pack Funcky/Funcky.csproj --output nupkg --version-suffix "nightly.$(git rev-parse --short "${{github.sha}}")"
- name: Push Package
run: dotnet nuget push --source https://nuget.pkg.github.com/polyadic/index.json --api-key ${{secrets.GITHUB_TOKEN}} nupkg/Funcky.*.nupkg
3 changes: 0 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
<ItemGroup Label="Deterministic Builds and Source Link">
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All"/>
</ItemGroup>
<PropertyGroup>
<FunckyBuildWithPreviewTargetFramework Condition="'$(FunckyBuildWithPreviewTargetFramework)' == ''">true</FunckyBuildWithPreviewTargetFramework>
</PropertyGroup>
<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion FrameworkFeatureConstants.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<DefineConstants>$(DefineConstants);GENERIC_MATH;GENERIC_PARSEABLE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<DefineConstants>$(DefineConstants);RANDOM_SHUFFLE</DefineConstants>
<DefineConstants>$(DefineConstants);RANDOM_SHUFFLE;UTF8_SPAN_PARSEABLE</DefineConstants>
</PropertyGroup>
</Project>
7 changes: 2 additions & 5 deletions Funcky.Async/Funcky.Async.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(FunckyBuildWithPreviewTargetFramework)' == 'true'">net8.0;$(TargetFrameworks)</TargetFrameworks>
<TargetFrameworks>net8.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<Description>Extends Funcky with support for IAsyncEnumerable and Tasks.</Description>
Expand All @@ -20,9 +19,7 @@
<RootNamespace>Funcky</RootNamespace>
<DefineConstants>$(DefineConstants);CONTRACTS_FULL</DefineConstants>
</PropertyGroup>
<!-- The condition is a workaround for a weird error that we get in the .NET 8 SDK:
Unable to optimize assemblies for size: a valid runtime package was not found. -->
<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions Funcky.Test/Extensions/EnumerableExtensions/AnyOrElseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public void IsEmptyWhenBothEnumerablesAreEmpty()
[Fact]
public void IsSourceEnumerableWhenNonEmpty()
{
var source = Sequence.Return(1, 2, 3).EraseNonEnumeratedCount();
var source = Sequence.Return(1, 2, 3).PreventLinqOptimizations();
var fallback = Sequence.Return(4, 5, 6);
Assert.Equal(source, source.AnyOrElse(fallback));
}

[Fact]
public void IsFallbackEnumerableWhenSourceIsEmpty()
{
var source = Enumerable.Empty<int>().EraseNonEnumeratedCount();
var source = Enumerable.Empty<int>().PreventLinqOptimizations();
var fallback = Sequence.Return(1, 2, 3);
Assert.Equal(fallback, source.AnyOrElse(fallback));
}
Expand All @@ -36,7 +36,7 @@ public void SourceIsEnumeratedLazily()
[Fact]
public void FallbackIsEnumeratedLazily()
{
var source = Enumerable.Empty<int>().EraseNonEnumeratedCount();
var source = Enumerable.Empty<int>().PreventLinqOptimizations();
_ = source.AnyOrElse(new FailOnEnumerationSequence<int>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void GetNonEnumeratedCountOrNoneReturnsCountOnEnumerableRange()
[Property]
public Property GetNonEnumeratedCountOrNoneReturnsNoneForInstancesWithoutCount(List<int> list)
{
return list.EraseNonEnumeratedCount().GetNonEnumeratedCountOrNone()
return list.PreventLinqOptimizations().GetNonEnumeratedCountOrNone()
.Match(none: true, some: False)
.ToProperty();
}
Expand Down
15 changes: 13 additions & 2 deletions Funcky.Test/Extensions/EnumerableExtensions/MaterializeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,30 @@ public void MaterializeDoesNotEnumerateCollectionTypes()
[Fact]
public void MaterializeReturnsImmutableCollectionWhenEnumerated()
{
var sequence = Enumerable.Repeat("Hello world!", 3);
var sequence = Enumerable.Repeat("Hello world!", 3).PreventLinqOptimizations();

Assert.IsType<ImmutableList<string>>(sequence.Materialize());
}

[Fact]
public void MaterializeWithMaterializationReturnsCorrectCollectionWhenEnumerate()
{
var sequence = Enumerable.Repeat("Hello world!", 3);
var sequence = Enumerable.Repeat("Hello world!", 3).PreventLinqOptimizations();

Assert.IsType<HashSet<string>>(sequence.Materialize(ToHashSet));
}

#if NET8_0_OR_GREATER
// This is an optimization added in .NET 8
[Fact]
public void MaterializeDoesNotEnumerableEnumerableReturnedByRepeat()
{
var sequence = Enumerable.Repeat("Hello world!", 3);
var materialized = sequence.Materialize<string, IReadOnlyCollection<string>>(_ => throw new FailException("Materialization should never be called"));
Assert.Same(sequence, materialized);
}
#endif

[Fact]
public void MaterializeDoesNotEnumerateCollectionWhichImplementsICollectionOnly()
{
Expand Down
5 changes: 2 additions & 3 deletions Funcky.Test/TestUtils/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ namespace Funcky.Test.TestUtils;

internal static class EnumerableExtensions
{
internal static IEnumerable<TItem> EraseNonEnumeratedCount<TItem>(this IEnumerable<TItem> source)
/// <summary>Prevents LINQ from optimizing by hiding the underlying source enumerable.</summary>
internal static IEnumerable<TItem> PreventLinqOptimizations<TItem>(this IEnumerable<TItem> source)
{
// Having our own state machine erases the non enumerated count
// provided when using LINQ methods such as Select.
foreach (var element in source)
{
yield return element;
Expand Down
10 changes: 10 additions & 0 deletions Funcky/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Funcky.Extensions.EnumerableExtensions.Chunk``1(System.Collections.Generic.IEnumerable{``0},System.Int32)</Target>
<Left>lib/net5.0/Funcky.dll</Left>
<Right>lib/net6.0/Funcky.dll</Right>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if GENERIC_PARSEABLE
namespace Funcky.Extensions;

public static partial class ParseExtensions
{
#if GENERIC_PARSEABLE
public static Option<TParseable> ParseOrNone<TParseable>(this ReadOnlySpan<char> value, IFormatProvider? provider)
where TParseable : ISpanParsable<TParseable>
=> TParseable.TryParse(value, provider, out var result)
Expand All @@ -14,5 +14,13 @@ public static Option<TParseable> ParseOrNone<TParseable>(this string? value, IFo
=> TParseable.TryParse(value, provider, out var result)
? result
: Option<TParseable>.None;
}
#endif

#if UTF8_SPAN_PARSEABLE
public static Option<TParseable> ParseOrNone<TParseable>(this ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)
where TParseable : IUtf8SpanParsable<TParseable>
=> TParseable.TryParse(utf8Text, provider, out var result)
? result
: Option<TParseable>.None;
#endif
}
9 changes: 3 additions & 6 deletions Funcky/Funcky.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition="'$(FunckyBuildWithPreviewTargetFramework)' == 'true'">net8.0;$(TargetFrameworks)</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<Product>Funcky</Product>
Expand All @@ -19,7 +18,7 @@
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);CONTRACTS_FULL</DefineConstants>
<TargetFrameworkForPublicApiAnalyzers>net7.0</TargetFrameworkForPublicApiAnalyzers>
<TargetFrameworkForPublicApiAnalyzers>net8.0</TargetFrameworkForPublicApiAnalyzers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="all" Condition="'$(TargetFramework)' == '$(TargetFrameworkForPublicApiAnalyzers)'" />
Expand All @@ -39,9 +38,7 @@
<AdditionalFiles Include="PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI.Unshipped.txt" />
</ItemGroup>
<!-- The condition is a workaround for a weird error that we get in the .NET 8 SDK:
Unable to optimize assemblies for size: a valid runtime package was not found. -->
<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
Expand Down
34 changes: 34 additions & 0 deletions Funcky/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,44 @@ Funcky.Monads.Result<TValidResult>.OrElse(Funcky.Monads.Result<TValidResult> fal
Funcky.Monads.Result<TValidResult>.OrElse(System.Func<System.Exception!, Funcky.Monads.Result<TValidResult>>! fallback) -> Funcky.Monads.Result<TValidResult>
Funcky.UpCast<TResult>
static Funcky.Extensions.EnumeratorExtensions.MoveNextOrNone<T>(this System.Collections.Generic.IEnumerator<T>! enumerator) -> Funcky.Monads.Option<T>
static Funcky.Extensions.ParseExtensions.ParseByteOrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<byte>
static Funcky.Extensions.ParseExtensions.ParseByteOrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<byte>
static Funcky.Extensions.ParseExtensions.ParseByteOrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<byte>
static Funcky.Extensions.ParseExtensions.ParseDecimalOrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<decimal>
static Funcky.Extensions.ParseExtensions.ParseDecimalOrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<decimal>
static Funcky.Extensions.ParseExtensions.ParseDecimalOrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<decimal>
static Funcky.Extensions.ParseExtensions.ParseDoubleOrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<double>
static Funcky.Extensions.ParseExtensions.ParseDoubleOrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<double>
static Funcky.Extensions.ParseExtensions.ParseDoubleOrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<double>
static Funcky.Extensions.ParseExtensions.ParseInt16OrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<short>
static Funcky.Extensions.ParseExtensions.ParseInt16OrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<short>
static Funcky.Extensions.ParseExtensions.ParseInt16OrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<short>
static Funcky.Extensions.ParseExtensions.ParseInt32OrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<int>
static Funcky.Extensions.ParseExtensions.ParseInt32OrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<int>
static Funcky.Extensions.ParseExtensions.ParseInt32OrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<int>
static Funcky.Extensions.ParseExtensions.ParseInt64OrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<long>
static Funcky.Extensions.ParseExtensions.ParseInt64OrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<long>
static Funcky.Extensions.ParseExtensions.ParseInt64OrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<long>
static Funcky.Extensions.ParseExtensions.ParseNumberOrNone<TNumber>(this string! value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<TNumber>
static Funcky.Extensions.ParseExtensions.ParseNumberOrNone<TNumber>(this System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<TNumber>
static Funcky.Extensions.ParseExtensions.ParseOrNone<TParseable>(this string? value, System.IFormatProvider? provider) -> Funcky.Monads.Option<TParseable>
static Funcky.Extensions.ParseExtensions.ParseOrNone<TParseable>(this System.ReadOnlySpan<char> value, System.IFormatProvider? provider) -> Funcky.Monads.Option<TParseable>
static Funcky.Extensions.ParseExtensions.ParseOrNone<TParseable>(this System.ReadOnlySpan<byte> utf8Text, System.IFormatProvider? provider) -> Funcky.Monads.Option<TParseable>
static Funcky.Extensions.ParseExtensions.ParseSByteOrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<sbyte>
static Funcky.Extensions.ParseExtensions.ParseSByteOrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<sbyte>
static Funcky.Extensions.ParseExtensions.ParseSByteOrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<sbyte>
static Funcky.Extensions.ParseExtensions.ParseSingleOrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<float>
static Funcky.Extensions.ParseExtensions.ParseSingleOrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<float>
static Funcky.Extensions.ParseExtensions.ParseSingleOrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<float>
static Funcky.Extensions.ParseExtensions.ParseUInt16OrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<ushort>
static Funcky.Extensions.ParseExtensions.ParseUInt16OrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<ushort>
static Funcky.Extensions.ParseExtensions.ParseUInt16OrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<ushort>
static Funcky.Extensions.ParseExtensions.ParseUInt32OrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<uint>
static Funcky.Extensions.ParseExtensions.ParseUInt32OrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<uint>
static Funcky.Extensions.ParseExtensions.ParseUInt32OrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<uint>
static Funcky.Extensions.ParseExtensions.ParseUInt64OrNone(this System.ReadOnlySpan<byte> candidate, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<ulong>
static Funcky.Extensions.ParseExtensions.ParseUInt64OrNone(this System.ReadOnlySpan<byte> candidate, System.IFormatProvider? provider) -> Funcky.Monads.Option<ulong>
static Funcky.Extensions.ParseExtensions.ParseUInt64OrNone(this System.ReadOnlySpan<byte> candidate) -> Funcky.Monads.Option<ulong>
static Funcky.Extensions.StringExtensions.Chunk(this string! source, int size) -> System.Collections.Generic.IEnumerable<string!>!
static Funcky.Extensions.StringExtensions.SlidingWindow(this string! source, int width) -> System.Collections.Generic.IEnumerable<string!>!
static Funcky.UpCast<TResult>.From<T>(System.Lazy<T>! lazy) -> System.Lazy<TResult>!
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-preview.5.23303.2",
"version": "8.0.100",
"rollForward": "feature"
}
}

0 comments on commit 72c87a2

Please sign in to comment.