Repository navigation
[tests] Detect and remove redundant OS version guards. - #26901
rolfbjarne wants to merge 2 commits into
Conversation
Scan platform implementation assemblies for SupportedOSPlatformGuard methods and properties, as well as the built-in OperatingSystem version checks. Compare constant versions with SdkVersions.GetMinVersion, normalizing omitted version components and skipping dynamic arguments or branches into argument sequences. Record the 52 existing failures across iOS, tvOS, macOS and Mac Catalyst using the standard Cecil known-failure mechanism. Add synthetic IL regression coverage for version boundaries, attributed getters, instance methods, platform aliases and control-flow exclusions, and document the check. Related to #4323. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d128a1b8-1056-457f-9a09-beb99c8a1575
Use the code paths already guaranteed by the minimum supported OS versions in CoreBluetooth, CoreImage, CoreVideo, MetricKit, MetalPerformanceShaders, VideoToolbox and certificate conversion. Preserve native object ownership and optional dictionary-value handling while removing the unreachable fallbacks and their obsolete private CoreVideo imports. Remove the now-unused Xcode 11, 12, 12.2 and 13 version guard properties and their cached state. Clear all 52 known failures from the Cecil OS platform guard check; rebuilt implementation assemblies for all four platforms have no remaining redundant guards. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d128a1b8-1056-457f-9a09-beb99c8a1575
There was a problem hiding this comment.
🟡 Changes recommended
The recognizer needs positive and negative fixture tests because the empty baseline cannot detect lost recognition.
1 open finding
What changed in this PR
Adds Cecil-based enforcement against redundant OS-version guards, following #4323’s testing approach rather than implementing linker optimization.
Changes:
- Detects guards at or below each platform’s minimum supported version.
- Removes obsolete fallback paths, guard properties, and private imports.
- Documents the detector and adds an empty known-failure baseline.
| File | Description |
|---|---|
| tests/cecil-tests/README.md | Documents detection scope and limitations. |
| tests/cecil-tests/OSPlatformGuardTest.KnownFailures.cs | Adds empty failure baseline. |
| tests/cecil-tests/OSPlatformGuardTest.cs | Adds redundant-guard detection. |
| src/VideoToolbox/VTVideoEncoder.cs | Removes guards while preserving optional values. |
| src/ObjCRuntime/SystemVersion.cs | Removes Xcode 11–13 guards and caches. |
| src/MetricKit/MXMetricPayload.cs | Removes legacy dictionary fallback. |
| src/MetricKit/MXMetric.cs | Removes legacy dictionary fallback. |
| src/MetricKit/MXMetaData.cs | Removes legacy fallback and warning suppressions. |
| src/MetalPerformanceShaders/MPSNNOptimizerStochasticGradientDescent.cs | Removes legacy initializer fallback. |
| src/Foundation/NSUrlSessionHandler.cs | Uses certificate-chain retrieval unconditionally. |
| src/CoreVideo/CVBuffer.cs | Removes obsolete imports and attachment fallbacks. |
| src/CoreImage/CIFilter.cs | Removes redundant filter availability checks. |
| src/CoreBluetooth/CBManager.cs | Uses static authorization directly. |
🧠 Review effort: Balanced
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #f6b3836] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 0 tests failed, 218 tests passed. Failures❌ windows tests🔥 Failed catastrophically on VSTS: test results - windows (no summary found). Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |

OS-version checks at or below our minimum supported versions always succeed, but their fallback paths still add unnecessary code and runtime checks. Add a Cecil test to prevent these redundant guards from accumulating in the platform implementation assemblies.
The check compares guarded versions with
SdkVersions.GetMinVersion, recognizingSupportedOSPlatformGuardattributes on methods and properties as well as the built-inOperatingSystem.Is*VersionAtLeastAPIs. It handles constant version arguments and skips dynamic arguments or branches into argument sequences.Remove all 52 existing failures by keeping the code paths guaranteed by the minimum OS versions. This also removes the unused Xcode 11-13 guard properties, cached state, and obsolete private CoreVideo imports, while preserving native ownership and optional dictionary-value handling. The known-failure baseline is now empty.
This implements the Cecil-test approach suggested in #4323, not a trimmer optimization. Inspection of the current dotnet/runtime ILLink sources found no equivalent deployment-target-based version folding, so the broader optimization remains outstanding.
Related to #4323.
Note
AI-generated with GitHub Copilot.
🤖 Pull request created by Copilot