-
Notifications
You must be signed in to change notification settings - Fork 480
Add Public API for NameMap Inspection #1800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Public API for NameMap Inspection #1800
Conversation
Thanks for opening a PR and looking into this! Making public APIs for |
Yeah, that sounds promising. It's been a pain for multiple users to map back the enum name manually, so I decided to publish what we figured out would solve our issues for now. I am available to contribute to this work stream if needed, happy to help :) |
Will keep the PR open just in case anyone else wants to apply this patch to their forks. Feel free to turn it into a Draft (and eventually close it), I don't have permission to do it |
@0xLucasMarcal I'm going to go ahead and close this since I don't think this PR is something being considered for merging, and I worry someone might take it being open as such. Folks should still be able to find the PR when closed (or references to it). |
@thomasvl Sounds good! |
@allevato @thomasvl I haven't had the time yet to take a closer look at the recent changes, but does the new nameMap bytecode include public access to it? If you don't have, with a bit of context, I can help contribute to that :) Also, I noticed the compiler having a hard time running type-check on the initializers of the new NameMap, for all of our protos it took more than 500ms to run type-check on (swiftc 6.1.2) |
No change in APIs, just changes to the internals.
Can you do a sample .proto that shows this? That's sorta a surprise since I don't think we're leaning on overloads much. |
Add Public API for NameMap Inspection
Summary
This PR addresses the long-standing TODO in
NameMap.swift
by implementing a comprehensive public API that allows external code to inspect the name-mapping metadata stored in_NameMap
instances. Previously, this valuable data was only accessible internally, limiting tooling and debugging capabilities.Problem
The existing TODO noted:
This limitation prevented users from:
Solution
Core API
Added a new public API that provides clean, type-safe access to name mapping information:
Type-Safe Field Identification
Added
RawRepresentable
overloads to eliminate magic numbers and provide type safety:Usage Examples
Basic Field Inspection
Type-Safe Field Access
Field Enumeration
Key Features
RawRepresentable
overloads eliminate magic numbersSendable
conformance for modern concurrency.same
,.standard
,.unique
,.aliased
)Compatibility
This is a purely additive change with no breaking changes:
_NameMap
implementation is unchangedNameDescription
enum cases or orderingTesting
Added comprehensive test suite (
Test_NameMap_PublicAPI.swift
) covering:RawRepresentable
overloads with bothInt
andInt32
All tests pass: 12/12 ✅
Use Cases Enabled
Trade-offs Considered
Int
andInt32
overloads for maximum compatibilityFiles Changed
Sources/SwiftProtobuf/NameMap.swift
- Core API implementationTests/SwiftProtobufTests/Test_NameMap_PublicAPI.swift
- Comprehensive test suiteTotal additions: ~150 lines of production code + ~240 lines of tests