Deduplicate polyfill type forwarding via centralized PolyfillTypeForwarders.cs#8596
Deduplicate polyfill type forwarding via centralized PolyfillTypeForwarders.cs#8596Copilot wants to merge 2 commits into
PolyfillTypeForwarders.cs#8596Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
PolyfillTypeForwarders.cs
There was a problem hiding this comment.
Pull request overview
This PR refactors the src/Polyfills area by consolidating assembly-level TypeForwardedTo declarations into a single, centralized file (PolyfillTypeForwarders.cs). This reduces duplicated conditional forwarding blocks across many individual polyfill implementations while preserving the existing conditional behavior for when polyfills vs. BCL types are used.
Changes:
- Added
src/Polyfills/PolyfillTypeForwarders.csto centralize allTypeForwardedToassembly attributes (guarded by the same TFMs/preprocessor symbols). - Removed per-file
#else/#elif NETCOREAPPforwarding-only blocks from affected polyfill files, leaving the polyfill implementations unchanged. - Standardized forwarding declarations to use fully-qualified
System.Runtime.CompilerServices.TypeForwardedTo(...).
Show a summary per file
| File | Description |
|---|---|
| src/Polyfills/PolyfillTypeForwarders.cs | New centralized location for assembly-level type forwarders (NETCOREAPP + NET10_0_OR_GREATER guards). |
| src/Polyfills/UnreachableException.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/UnconditionalSuppressMessageAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/StackTraceHiddenAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/RequiredMemberAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/Range.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/PlatformAttributes.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/NullableAttribtues.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/ModuleInitializerAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/IsExternalInit.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized (also eliminates the short-form attribute usage). |
| src/Polyfills/InterpolatedStringHandlerAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/InterpolatedStringHandlerArgumentAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/Index.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/ExperimentalAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/DynamicallyAccessedMemberTypes.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/DynamicallyAccessedMembersAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/CompilerLoweringPreserveAttribute.cs | Removed per-file forwarding branch; forwarding now centralized under NET10_0_OR_GREATER. |
| src/Polyfills/CompilerFeatureRequiredAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
| src/Polyfills/CallerArgumentExpressionAttribute.cs | Removed per-file NETCOREAPP forwarding branch; forwarding now centralized. |
Copilot's findings
- Files reviewed: 19/19 changed files
- Comments generated: 0
| #if NETCOREAPP | ||
| [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.CallerArgumentExpressionAttribute))] |
There was a problem hiding this comment.
This shouldn't be done this way.
Each polyfill knows exactly the TFM it's polyfilling for and should do the forwarding under #else.
Even all current polyfills are under #if !NETCOREAPP, that's just a coincidence. Also it's much easier to see the type forwarding in the same file that implements the polyfill, so I can easily see that no polyfill is missing type forwarding.
|
Rejecting |
Polyfill files in
src/Polyfillsrepeated identical#else/#elif NETCOREAPPforwarding patterns with only forwarded types differing. This change consolidates forwarding declarations into one file while keeping existing conditional behavior and polyfill implementations intact.Centralized forwarders
src/Polyfills/PolyfillTypeForwarders.csas the single location for assembly-levelTypeForwardedTodeclarations.#if NETCOREAPPfor runtime-provided types#if NET10_0_OR_GREATERforCompilerLoweringPreserveAttributeRemoved duplicated per-file forwarding blocks
#else/#elif NETCOREAPPbranches from affected polyfill source files.Consistency cleanup
System.Runtime.CompilerServices.TypeForwardedTo(...)uniformly (eliminates mixed short/fully-qualified forms such asIsExternalInit’s previous short form).