Skip to content

Refactor: var consistency, guard ordering, and other style improvements#118

Merged
Tyrrrz merged 13 commits intoprimefrom
copilot/refactor-consistency-in-codebase
Apr 17, 2026
Merged

Refactor: var consistency, guard ordering, and other style improvements#118
Tyrrrz merged 13 commits intoprimefrom
copilot/refactor-consistency-in-codebase

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

  • PolyShim/Net50/Interlocked.cs — replace explicit-type int/long current/original with var + initializers
  • PolyShim/Net60/Random.cs — replace ulong ulongRand; with var ulongRand = 0UL;
  • PolyShim/NetCore20/File.cs — replace int charsRead; (×2) with var charsRead = 0;
  • PolyShim/NetCore30/RandomNumberGenerator.cs — replace uint result; with var result = 0U;
  • PolyShim.Tests/Net50/InterlockedTests.cs — replace uint ui, long l, ulong ul with var + casts
  • PolyShim/NetCore10/Task.cs — replace Timer? timer = null; and CancellationTokenRegistration registration = default; with var forms; use new(...) for Timer assignment
  • PolyShim/Net90/Lock.csreturn new Scope(this); (×2) → return new(this);
  • PolyShim/NetCore10/AggregateException.csreturn new AggregateException(...)return new(...)
  • PolyShim/Net80/TimeProvider.csreturn new DateTimeOffset(...) and _timer = new Timer(...) → target-typed new
  • PolyShim/Net70/Stopwatch.csreturn new TimeSpan(...) (×3) → return new(...)
  • PolyShim/Net50/IntPtr.csresult = new IntPtr(...) (×2) → result = new(...)
  • PolyShim/Net50/UIntPtr.csresult = new UIntPtr(...) (×2) → result = new(...)
  • PolyShim/Net70/IntPtr.csresult = new IntPtr(...) (×2) → result = new(...)
  • PolyShim/Net70/UIntPtr.csresult = new UIntPtr(...) (×2) → result = new(...)
  • PolyShim/NetCore10/Version.csresult = new Version(input);result = new(input);
  • PolyShim/Net60/Random.csnew Random()new()
  • PolyShim.Tests/NetCore21/SpanTests.csSpan<byte> ... = [...]var ... = (Span<byte>)[...]
  • PolyShim.Tests/NetCore21/ReadOnlySpanTests.csReadOnlySpan<byte> ... = [...]var ... = (ReadOnlySpan<byte>)[...]
  • PolyShim.Tests/NetCore21/MemoryTests.csMemory<byte> ... = new byte[]var ... = (Memory<byte>)new byte[]
  • PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.csReadOnlyMemory<byte> ... = new byte[]var ... = (ReadOnlyMemory<byte>)new byte[]
  • PolyShim.Tests/NetCore21/MemoryExtensionsTests.csSpan/Memory explicit typesvar + cast
  • PolyShim.Tests/Net80/RandomTests.csReadOnlySpan<int>/Span<int>var + cast
  • PolyShim.Tests/Net90/FileTests.csReadOnlySpan/Memoryvar + cast

Copilot AI and others added 2 commits April 17, 2026 09:44
…arget-typed new

Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/9380a44e-217f-4733-8885-0bf8cbd4c74a

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 17, 2026

@copilot resolve the merge conflicts in this pull request

@@ -1,4 +1,5 @@
#if FEATURE_TASK
// ValueTask is provided via the System.Threading.Tasks.Extensions NuGet package when available.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Replace this and other similar comments with just:

// Can be provided natively or by a compatibility package

@copilot

Comment thread PolyShim/NetCore21/Span.cs Outdated
public Span(T[]? array)
: this(array, 0, array?.Length ?? 0) { }

// Unsafe code is required for the pointer-accepting constructor.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Remove periods from one-line comments similar to this one @copilot

Comment thread PolyShim/NetCore30/Process.cs Outdated
internal static class MemberPolyfills_NetCore30_Process
{
// Both process and management features are required for process tree support.
#if FEATURE_PROCESS && FEATURE_MANAGEMENT
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The process guard should be file-wide since it applies to everything in this file @copilot

@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 17, 2026

@copilot retry

@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 17, 2026

@copilot merge in latest prime, re-check added/modified files, and then retry whatever you failed to do last time.

Copilot AI and others added 2 commits April 17, 2026 16:53
…sistency-in-codebase

# Conflicts:
#	PolyShim/NetCore21/ManualResetValueTaskSourceCore.cs

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot merge in latest prime, re-check added/modified files, and then retry whatever you failed to do last time.

Done in 9b87704:

  • Merged latest prime (resolved conflict in ManualResetValueTaskSourceCore.cs by taking prime's version)
  • Replaced all // ValueTask/IValueTaskSource is provided via... comments with // Can be provided natively or by a compatibility package across 7 files
  • Removed trailing periods from all one-line explanatory comments I had added
  • Made #if FEATURE_PROCESS && FEATURE_MANAGEMENT a file-wide nested guard in NetCore30/Process.cs

@Tyrrrz Tyrrrz marked this pull request as ready for review April 17, 2026 17:10
Copilot AI review requested due to automatic review settings April 17, 2026 17:10
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 17, 2026

@copilot can you debug the build error?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR applies repository-wide style/consistency refactors across PolyShim polyfill sources and tests, primarily standardizing var usage, adding clarifying feature-guard comments, and adopting target-typed new where applicable.

Changes:

  • Standardize locals to var with explicit initializers/casts (including tests for Span/Memory and numeric literals).
  • Add/adjust feature-guard ordering and explanatory comments around FEATURE_TASK and related polyfill conditions.
  • Replace explicit constructor calls with target-typed new for consistency.

Reviewed changes

Copilot reviewed 62 out of 62 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
PolyShim/NetCore30/Timer.cs Removes FEATURE_ASYNCINTERFACES guard from DisposeAsync (now unconditional).
PolyShim/NetCore30/TextWriter.cs Wraps async dispose support under FEATURE_TASK; removes inner async-interface guard.
PolyShim/NetCore30/TaskAsyncEnumerableExtensions.cs Adds explanatory comment before FEATURE_TASK guard.
PolyShim/NetCore30/Stream.cs Wraps async dispose support under FEATURE_TASK; removes inner async-interface guard.
PolyShim/NetCore30/RandomNumberGenerator.cs Switches explicit uint local to var with initializer.
PolyShim/NetCore30/Process.cs Reorders/adjusts feature guards (FEATURE_PROCESS, FEATURE_MANAGEMENT).
PolyShim/NetCore30/IAsyncEnumerable.cs Adds explanatory comment before FEATURE_TASK guard.
PolyShim/NetCore30/IAsyncDisposable.cs Adds explanatory comment before FEATURE_TASK guard.
PolyShim/NetCore30/ConfiguredCancelableAsyncEnumerable.cs Adds explanatory comment before FEATURE_TASK guard.
PolyShim/NetCore30/AsyncIteratorMethodBuilder.cs Adds explanatory comment before FEATURE_TASK guard.
PolyShim/NetCore21/ValueTaskSourceStatus.cs Adds comment clarifying native vs package availability.
PolyShim/NetCore21/ValueTaskSourceOnCompletedFlags.cs Adds comment clarifying native vs package availability.
PolyShim/NetCore21/ValueTaskAwaiter.cs Adds comment clarifying native vs package availability.
PolyShim/NetCore21/ValueTask.cs Adds comment clarifying native vs package availability.
PolyShim/NetCore21/TextWriter.cs Adds comment before FEATURE_TASK-guarded async members.
PolyShim/NetCore21/TextReader.cs Adds comment before FEATURE_TASK-guarded async members.
PolyShim/NetCore21/Stream.cs Adds comments before FEATURE_TASK-guarded async members.
PolyShim/NetCore21/Span.cs Adds comment before ALLOW_UNSAFE_BLOCKS guarded constructor.
PolyShim/NetCore21/IValueTaskSource.cs Adds comment clarifying native vs package availability.
PolyShim/NetCore21/ConfiguredValueTaskAwaitable.cs Adds comment clarifying native vs package availability; uses target-typed new.
PolyShim/NetCore21/AsyncValueTaskMethodBuilder.cs Adds comment clarifying native vs package availability.
PolyShim/NetCore20/Task.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/NetCore20/File.cs Adds comment before FEATURE_TASK async members; switches int locals to var init.
PolyShim/NetCore10/Version.cs Uses target-typed new in TryParse.
PolyShim/NetCore10/TaskCompletionSource.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/NetCore10/Task.cs Moves FEATURE_TASK under TFM guard; uses var + target-typed new in Delay impl.
PolyShim/NetCore10/SemaphoreSlim.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/NetCore10/ParallelOptions.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/NetCore10/AggregateException.cs Uses target-typed new in Flatten.
PolyShim/Net90/Task.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net90/Lock.cs Uses target-typed new for Scope construction.
PolyShim/Net90/File.cs Adds comment before FEATURE_TASK async members.
PolyShim/Net80/TimeProvider.cs Uses target-typed new; changes async dispose guard to FEATURE_TASK.
PolyShim/Net80/TextWriter.cs Adds comment before FEATURE_TASK async members.
PolyShim/Net80/Parallel.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net80/ITimer.cs Changes async-disposable base-interface guard to FEATURE_TASK; adds comment.
PolyShim/Net80/CancellationTokenSource.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net70/UIntPtr.cs Uses target-typed new in TryParse.
PolyShim/Net70/TextReader.cs Adds comment before FEATURE_TASK async members.
PolyShim/Net70/Stream.cs Adds comments before FEATURE_TASK async members.
PolyShim/Net70/Stopwatch.cs Uses target-typed new for TimeSpan construction.
PolyShim/Net70/IntPtr.cs Uses target-typed new in TryParse.
PolyShim/Net70/File.cs Adds comment before FEATURE_TASK async members.
PolyShim/Net60/Task.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net60/Random.cs Switches explicit ulong local to var init; uses new() for Random.
PolyShim/Net60/Parallel.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net50/UIntPtr.cs Uses target-typed new in TryParse.
PolyShim/Net50/TaskCompletionSourceOfT.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net50/TaskCompletionSource.cs Moves FEATURE_TASK under TFM guard; adds explanatory comment.
PolyShim/Net50/Process.cs Adds FEATURE_TASK-guard comment for async members.
PolyShim/Net50/Interlocked.cs Switches explicit locals to var + initializer; adds unsafe-guard comments.
PolyShim/Net50/IntPtr.cs Uses target-typed new in TryParse.
PolyShim/Net50/HttpContent.cs Moves FEATURE_HTTPCLIENT under TFM guard; adds FEATURE_TASK-guard comment.
PolyShim/Net50/HttpClient.cs Moves FEATURE_HTTPCLIENT under TFM guard; adds FEATURE_TASK-guard comment.
PolyShim.Tests/NetCore21/SpanTests.cs Converts explicit Span locals to var + cast for collection expressions/stackalloc.
PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs Converts explicit ReadOnlySpan/Span locals to var + cast.
PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs Converts explicit ReadOnlyMemory/Memory locals to var + cast.
PolyShim.Tests/NetCore21/MemoryTests.cs Converts explicit Memory locals to var + cast.
PolyShim.Tests/NetCore21/MemoryExtensionsTests.cs Converts explicit Span/Memory locals to var + cast.
PolyShim.Tests/Net90/FileTests.cs Converts explicit ReadOnlySpan/ReadOnlyMemory locals to var + cast.
PolyShim.Tests/Net80/RandomTests.cs Converts explicit Span/ReadOnlySpan locals to var + cast.
PolyShim.Tests/Net50/InterlockedTests.cs Converts explicit numeric locals to var with casts for literal typing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PolyShim/NetCore30/Timer.cs
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot can you debug the build error?

Fixed in 0086dd7. Two issues:

  1. NetCore30/Timer.cs — CS0246 ValueTask not found: Commit 223d83c removed the #if FEATURE_ASYNCINTERFACES guard from DisposeAsync(). On TFMs where FEATURE_TASK is not set (e.g. old netstandard), neither the native ValueTask nor its polyfill is available. Restored the guard as #if FEATURE_TASK (matching the pattern used in Stream.cs, TextWriter.cs, and ITimer.cs).

  2. Net80/ITimer.cs — whitespace format error: The comment before #if FEATURE_TASK in the interface base list had 4 leading spaces that dotnet format rejected. Fixed by running dotnet format.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 87.75510% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (b0eb67b) to head (6b30dd3).
⚠️ Report is 1 commits behind head on prime.

Files with missing lines Patch % Lines
PolyShim/Net70/Stopwatch.cs 0.00% 3 Missing ⚠️
PolyShim/Net50/IntPtr.cs 0.00% 2 Missing ⚠️
PolyShim/Net50/UIntPtr.cs 0.00% 2 Missing ⚠️
PolyShim/Net80/TimeProvider.cs 0.00% 2 Missing ⚠️
PolyShim/Net70/IntPtr.cs 50.00% 1 Missing ⚠️
PolyShim/Net70/UIntPtr.cs 50.00% 1 Missing ⚠️
PolyShim/NetCore20/File.cs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #118      +/-   ##
==========================================
- Coverage   90.83%   90.72%   -0.11%     
==========================================
  Files         285      286       +1     
  Lines        4962     4982      +20     
  Branches      404      406       +2     
==========================================
+ Hits         4507     4520      +13     
- Misses        365      370       +5     
- Partials       90       92       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants