Skip to content

[tests] Detect and remove redundant OS version guards. - #26901

Open
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/cecil-protocol-validation
Open

rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/cecil-protocol-validation

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

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, recognizing SupportedOSPlatformGuard attributes on methods and properties as well as the built-in OperatingSystem.Is*VersionAtLeast APIs. 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

rolfbjarne and others added 2 commits October 16, 2026 19:25
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
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 16, 2026 17:26
Copilot AI balanced review requested due to automatic review settings October 16, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread tests/cecil-tests/OSPlatformGuardTest.cs
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: f6b3836a0a20780e3774dc1c470e86491f541e78 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [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
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 21 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: f6b3836a0a20780e3774dc1c470e86491f541e78 [PR build]

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants