Skip to content

Commit

Permalink
Move #if NET directives forward (#75500)
Browse files Browse the repository at this point in the history
* Move `#if NET` directives forward

* Update .NET version in a comment
  • Loading branch information
jjonescz authored Oct 17, 2024
1 parent e114b11 commit b05d623
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/contributing/Target Framework Strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ When the .NET SDK RTMs and Roslyn adopts it all occurrences of `$(NetRoslynNext)
- Might need updating `MicrosoftNetCompilersToolsetVersion` in `eng\Versions.props` to consume latest compiler features.
- Change `$(NetRoslynNext)` references to `$(NetRoslyn)` in project files.
- Update TFMs in code/scripts/pipelines (search for the old `netX.0` and replace with the new `netY.0`).
- Replace `#if NET7_0_OR_GREATER` corresponding to the no longer used TFM (`net7.0` in this example) with the lowest used TFM (e.g., `net8.0`: `#if NET8_0_OR_GREATER`) and similarly the negated variant `#if !NET7_0_OR_GREATER` with `#if !NET8_0_OR_GREATER`. See https://github.com/dotnet/roslyn/issues/75453#issuecomment-2405500584.
- Check that the same number of tests still run in CI (they are not unintentionally filtered out by TFM).
- Try an official build, a VS insertion.
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Hashing/XxHash128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static bool TryHash(ReadOnlySpan<byte> source, Span<byte> destination, ou
return false;
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>Computes the XXH128 hash of the provided data.</summary>
/// <param name="source">The data to hash.</param>
/// <param name="seed">The seed value for this hash computation. The default is zero.</param>
Expand Down Expand Up @@ -204,7 +204,7 @@ private Hash128 GetCurrentHashAsHash128()
return current;
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>Gets the current computed hash value without modifying accumulated state.</summary>
/// <returns>The hash value for the data already provided.</returns>
// [CLSCompliant(false)]
Expand Down
18 changes: 9 additions & 9 deletions src/Compilers/Core/Portable/Hashing/XxHashShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
Expand Down Expand Up @@ -342,7 +342,7 @@ public static void CopyAccumulators(ref State state, ulong* accumulators)
{
fixed (ulong* stateAccumulators = state.Accumulators)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated)
{
Vector256.Store(Vector256.Load(stateAccumulators), accumulators);
Expand Down Expand Up @@ -399,7 +399,7 @@ public static void DigestLong(ref State state, ulong* accumulators, byte* secret
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InitializeAccumulators(ulong* accumulators)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated)
{
Vector256.Store(Vector256.Create(Prime32_3, Prime64_1, Prime64_2, Prime64_3), accumulators);
Expand Down Expand Up @@ -488,7 +488,7 @@ public static void DeriveSecretFromSeed(byte* destinationSecret, ulong seed)
{
fixed (byte* defaultSecret = &MemoryMarshal.GetReference(DefaultSecret))
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated && BitConverter.IsLittleEndian)
{
Vector256<ulong> seedVec = Vector256.Create(seed, 0u - seed, seed, 0u - seed);
Expand Down Expand Up @@ -524,7 +524,7 @@ private static void Accumulate(ulong* accumulators, byte* source, byte* secret,
byte* secretForAccumulate = secret;
byte* secretForScramble = secret + (SecretLengthBytes - StripeLengthBytes);

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated && BitConverter.IsLittleEndian)
{
Vector256<ulong> acc1 = Vector256.Load(accumulators);
Expand Down Expand Up @@ -629,7 +629,7 @@ public static void Accumulate512(ulong* accumulators, byte* source, byte* secret
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Accumulate512Inlined(ulong* accumulators, byte* source, byte* secret)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated && BitConverter.IsLittleEndian)
{
for (int i = 0; i < AccumulatorCount / Vector256<ulong>.Count; i++)
Expand Down Expand Up @@ -668,7 +668,7 @@ private static void Accumulate512Inlined(ulong* accumulators, byte* source, byte
}
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<ulong> Accumulate256(Vector256<ulong> accVec, byte* source, Vector256<uint> secret)
{
Expand Down Expand Up @@ -723,7 +723,7 @@ private static Vector128<ulong> MultiplyWideningLower(Vector128<uint> source)

private static void ScrambleAccumulators(ulong* accumulators, byte* secret)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated && BitConverter.IsLittleEndian)
{
for (int i = 0; i < AccumulatorCount / Vector256<ulong>.Count; i++)
Expand Down Expand Up @@ -761,7 +761,7 @@ private static void ScrambleAccumulators(ulong* accumulators, byte* secret)
}
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector256<ulong> ScrambleAccumulator256(Vector256<ulong> accVec, Vector256<ulong> secret)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copied from:
// https://github.com/dotnet/runtime/blob/fdd104ec5e1d0d2aa24a6723995a98d0124f724b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CompilerFeatureRequiredAttribute.cs

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

using System.Runtime.CompilerServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> sou
return source.OrderByDescending(Comparer<T>.Create(compare));
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
public static IOrderedEnumerable<T> Order<T>(IEnumerable<T> source) where T : IComparable<T>
#else
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) where T : IComparable<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copied from:
// https://github.com/dotnet/runtime/blob/fdd104ec5e1d0d2aa24a6723995a98d0124f724b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RequiredMemberAttribute.cs

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

using System.Runtime.CompilerServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copied from:
// https://github.com/dotnet/runtime/blob/fdd104ec5e1d0d2aa24a6723995a98d0124f724b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/SetsRequiredMembersAttribute.cs

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ internal static class TextReaderExtensions
/// </summary>
public static async Task<string?> TryReadLineOrReturnNullIfCancelledAsync(this TextReader streamReader, CancellationToken cancellationToken)
{
// If we're on .NET Core 7.0 the implementation is easy, but on older versions we don't have the helper and since we also don't have
// If we're on .NET Core 8.0 the implementation is easy, but on older versions we don't have the helper and since we also don't have
// Microsoft.VisualStudio.Threading's WithCancellation helper we have to inline the same approach.

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

try
{
Expand Down
6 changes: 3 additions & 3 deletions src/Workspaces/CoreTest/XxHash128Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Hash_OneShot_Expected()
Assert.Equal(expectedHash128, ReadHashBigEndian(XxHash128.Hash(input, test.Seed)));
Assert.Equal(expectedHash128, ReadHashBigEndian(XxHash128.Hash((ReadOnlySpan<byte>)input, test.Seed)));

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
// Validate `XxHash128.HashToUInt128`
Assert.Equal(new UInt128(test.HashHigh, test.HashLow), XxHash128.HashToUInt128(input, test.Seed));
#endif
Expand Down Expand Up @@ -115,7 +115,7 @@ public void Hash_Streaming_Expected()

// Validate that the hash we get from doing a one-shot of all the data up to this point
// matches the incremental hash for the data appended until now.
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
Assert.Equal(XxHash128.HashToUInt128(asciiBytes.AsSpan(0, processed), test.Seed), hash.GetCurrentHashAsUInt128());
#endif
Assert.True(hash.TryGetCurrentHash(destination, out int bytesWritten));
Expand All @@ -125,7 +125,7 @@ public void Hash_Streaming_Expected()
}

// Validate the final hash code.
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
Assert.Equal(new UInt128(test.HashHigh, test.HashLow), hash.GetCurrentHashAsUInt128());
#endif
Array.Clear(destination, 0, destination.Length);
Expand Down

0 comments on commit b05d623

Please sign in to comment.