Skip to content

[src] Generate remaining native constant accessors - #26367

Merged
rolfbjarne merged 14 commits into
mainfrom
dev/rolf/dev-rolf-generate-remaining-constants
Aug 4, 2026
Merged

rolfbjarne merged 14 commits into
mainfrom
dev/rolf/dev-rolf-generate-remaining-constants

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Express native constants for CFDictionary, CMTime, CMTimeRange, and cohesive analogous APIs as binding [Field] declarations instead of handwritten symbol-loading code.

Extend bgen with narrowly scoped support for:

  • Native symbol addresses without pointer dereferencing.
  • Named partial struct extensions.
  • Required and optional unmanaged struct constants.

Preserve existing API shape, platform availability, nullability, mutability, and missing-symbol behavior. Add focused bgen and static-initialization regression coverage.

🤖 Pull request created by Copilot

Add opt-in support for partial structs, symbol-address fields, and default values for missing struct symbols.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6df2b2e1-3751-40b2-9815-036801d4959d
Allow field-only binding interfaces to generate members into an existing partial struct with a different API-definition name, and register the new field metadata for copied attribute assemblies.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6df2b2e1-3751-40b2-9815-036801d4959d
Apply DefaultValueOnMissingSymbol before direct lookup of the existing CMTime and AVCaptureWhiteBalanceGains special cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6df2b2e1-3751-40b2-9815-036801d4959d
Move Core Foundation callback addresses and cohesive native struct/string constants into binding definitions while preserving existing public fields, private setters, optional-symbol fallback, and platform availability.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6df2b2e1-3751-40b2-9815-036801d4959d
Copilot AI review requested due to automatic review settings July 30, 2026 11:24
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner July 30, 2026 11:24

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.

Pull request overview

This PR migrates several handwritten native-constant loaders (CFDictionary/CFArray callbacks, CoreMedia/CoreVideo/CoreGraphics/CoreAnimation/UIKit/MPS constants, etc.) to bgen-generated [Field] accessors, and extends bgen to support (1) symbol-address loading, (2) generating partial structs, and (3) optional struct constants with missing-symbol fallbacks. This fits the codebase’s long-term direction of consolidating bindings into generator-driven patterns while keeping manually implemented types as the public surface.

Changes:

  • Extend bgen to generate partial structs ([Partial (IsStruct = true, Name = ...)]), support symbol-address loading ([SymbolAddress]), and support optional unmanaged struct constants ([DefaultValueOnMissingSymbol]).
  • Replace multiple handwritten constant accessors with [Field] declarations in binding definition files and adjust the corresponding manually implemented types to be partial.
  • Add targeted regression coverage in bgen tests and cecil static-initialization tests.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/cecil-tests/Test.cs Updates the audited backing-field assignment whitelist to match moved constant initialization.
tests/bgen/tests/native-field-generation.cs Adds a bgen input fixture covering partial struct extension + symbol address + optional struct constants.
tests/bgen/BGenTests.cs Adds a regression test asserting the generated output for the new native field generation scenarios.
src/Vision/VNUtils.cs Removes handwritten symbol-loading for VNNormalizedIdentityRect in favor of generated [Field].
src/vision.cs Adds [Field] binding for VNUtils.NormalizedIdentityRect.
src/UIKit/UITypes.cs Makes UIPointerAccessoryPosition partial and removes handwritten field loaders.
src/UIKit/UIListSeparatorConfiguration.cs Deletes handwritten lazy loader for AutomaticInsets (migrated to [Field]).
src/uikit.cs Adds [Field] bindings for UIListSeparatorConfiguration.AutomaticInsets and UIPointerAccessoryPosition struct constants via partial struct extension.
src/MetalPerformanceShaders/MPSKernel.cs Removes handwritten loader for MPSRectNoClip constant.
src/metalperformanceshaders.cs Adds [Field] binding for MPSKernel.RectNoClip with missing-symbol defaulting.
src/frameworks.sources Removes the deleted UIListSeparatorConfiguration.cs from the UIKit source list.
src/CoreVideo/CVTime.cs Makes CVTime partial and removes handwritten loaders for ZeroTime / IndefiniteTime.
src/corevideo.cs Adds [Field] bindings for CVTime struct constants via partial struct extension.
src/CoreMedia/CoreMedia.cs Makes CMTimeRange partial; moves constant initialization into field initializers; removes handwritten symbol-loading cctor.
src/CoreMedia/CMTime.cs Removes handwritten symbol-loading cctor; replaces with field initializers backed by generated internal [Field] accessors.
src/coremedia.cs Adds partial-struct field interfaces for CMTime and CMTimeRange constants/keys (internal underscore-prefixed accessors).
src/CoreGraphics/CGRect.cs Makes CGRect partial and removes handwritten Null / Infinite loaders.
src/coregraphics.cs Adds partial-struct [Field] bindings for CGRect.Null and CGRect.Infinite.
src/CoreFoundation/CFDictionary.cs Converts callbacks loading to generated internal [Field] symbol-address accessors; removes handwritten cctor.
src/CoreFoundation/CFArray.cs Converts callbacks pointer loading to generated internal [Field] symbol-address accessor.
src/corefoundation.cs Adds internal [Field] symbol-address accessors for CFArray/CFDictionary callback tables.
src/CoreAnimation/CAFrameRateRange.cs Makes CAFrameRateRange partial and removes handwritten Default loader.
src/coreanimation.cs Adds partial-struct [Field] binding for CAFrameRateRange.Default.
src/bgen/Generator.cs Implements the new bgen behaviors: named partial struct generation + symbol-address loading + value-type field generation and missing-symbol defaulting.
src/bgen/Attributes.cs Extends PartialAttribute (IsStruct/Name) and adds new attributes: SymbolAddressAttribute, DefaultValueOnMissingSymbolAttribute.
src/bgen/AttributeManager.cs Registers the new attributes so bgen can resolve them from API definition assemblies.
Comments suppressed due to low confidence (1)

src/coregraphics.cs:17

  • 🤖 ❌ error Binding definition — Same as CGRect.Null: this used to return an empty CGRect if the native symbol couldn't be resolved. Add [DefaultValueOnMissingSymbol] so missing symbol handling doesn't turn into an unsafe dereference/crash in the generated accessor.
		/// <summary>Gets an infinitely large rectangle.</summary>
		[Field ("CGRectInfinite", "CoreGraphics")]
		CGRect Infinite { get; }

Comment thread src/bgen/Generator.cs Resolved
Comment thread src/coregraphics.cs Resolved
Comment thread src/vision.cs Resolved
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Comment thread src/bgen/Generator.cs Resolved
Comment thread src/bgen/Generator.cs Resolved
Comment thread src/coregraphics.cs Resolved
Comment thread src/coregraphics.cs Resolved
Always load generated value-type fields through Dlfcn.GetStruct and keep public struct APIs in their manual definitions, forwarding to internal generated helper classes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 80ff2496-65d4-4c7f-932a-2bb664a7fe75
@vs-mobiletools-engineering-service2

This comment has been minimized.

Comment thread src/bgen/Attributes.cs Resolved
Move symbol-address generation to a FieldAttribute property and report BI1125 when it is used on a non-IntPtr field.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 80ff2496-65d4-4c7f-932a-2bb664a7fe75

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.

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • src/Resources.Designer.cs: Generated file
Comments suppressed due to low confidence (1)

tests/bgen/BGenTests.cs:1642

  • ❌ Avoid the null-forgiving operator (!) on bgen.TmpDirectory (it’s disallowed in this repo’s nullable patterns, and it can mask a real null bug in the test harness). Capture the value once with an explicit null-check / throw and reuse it for both Path.Combine calls.
			var structFile = Path.Combine (bgen.TmpDirectory!, "NativeFieldGeneration", "NativeStructFields.g.cs");

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Resolve generator error code conflicts by preserving upstream BI1125-BI1127 and assigning the symbol-address validation BI1128.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 80ff2496-65d4-4c7f-932a-2bb664a7fe75
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

⚠️ AppSizeTest expected files changed ⚠️

The AppSizeTest detected changes in the expected app size files.

To update the expected files, add a comment with the following command:

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/8f51d9375f6adaaa5159f5e5c4b1769b
Updated files
  • iOS-MonoVM-interpreter-preservedapis.txt
  • iOS-MonoVM-preservedapis.txt
  • iOS-MonoVM-size.txt
  • MacCatalyst-MonoVM-interpreter-preservedapis.txt
  • MacCatalyst-MonoVM-preservedapis.txt
  • MacOSX-CoreCLR-Interpreter-size.txt
  • MacOSX-CoreCLR-Interpreter-TrimmableStatic-size.txt
  • TVOS-MonoVM-interpreter-preservedapis.txt
  • TVOS-MonoVM-preservedapis.txt

Pipeline on Agent
Hash: baa2c52e8d48c5599cb796f375205bd25a399bad [PR build]

@rolfbjarne
rolfbjarne enabled auto-merge (squash) August 3, 2026 17:16
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@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: 871b5d754138c999eb1bc65469382534f3eab256 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #871b5d7] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 203 tests passed 🎉

Tests counts

✅ 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. 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 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 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 Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ 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

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 871b5d754138c999eb1bc65469382534f3eab256 [PR build]

@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Aug 4, 2026
@rolfbjarne
rolfbjarne merged commit b7caf07 into main Aug 4, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/dev-rolf-generate-remaining-constants branch August 4, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants