[src] Generate remaining native constant accessors - #26367
Conversation
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
There was a problem hiding this comment.
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 bepartial. - 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; }
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.
This comment has been minimized.
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
There was a problem hiding this comment.
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 (
!) onbgen.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");
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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
✅ 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 |
🔥 [CI Build #baa2c52] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 46 tests failed, 157 tests passed. Failures❌ cecil tests1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (MacCatalyst)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (macOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (tvOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)19 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)19 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ msbuild tests1 tests failed, 1 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests1 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download ❌ xtro tests1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
|
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:
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