Repository navigation
Conversation
Quest-Claim: 5a395c3ef305109e
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
A Rust name C++ reserves (holding `__`, or `_` and a capital) drops its leading `_`s and keeps one `_` per run, so `__all__` is `all_`. A clash steps with `_` then `2` rather than stacking underscores, so `delete` beside `delete_` is `delete_2`. Namespace names now resolve through `named` over every C name, apart from each other and the runtime's. The strict C++ build turns on `-Wreserved-identifier` and pins the names still made of C names to the new c-reserved-names quest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging this PR will regress 2 benchmarks1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the quest
quest/m1/ffi-export/cpp-reserved-names.md, planned in kixel-ai/rust2#870 and added as a follow-up by kixel-ai/rust2#925.Summary
No name the C++ generator makes from a Rust name is one C++ reserves for the implementation ([lex.name]: one holding
__anywhere, or starting with_and a capital). The strict C++ build now runs with-Wreserved-identifier.cpp::escapedrops a reserved name's leading_s and keeps one_of each run, then escapes the result as any other name. So the api fixture's__all__isapi::all_(was__all___), serde's derived__deserializerparameter in moq isdeserializer(was__deserializer_), and_BoolisBool. A lowercase_xis left alone, since C++ reserves it only in the global namespace, which holds no API name._until free, so the generator's own escapes made__:delete__,new___,default__, the==operanda__, and a parameterc_by__past the header's locals. A clash now takes astep:_, or2after a trailing_. Sodeletebesidedelete_isdelete_2, andapast the arenaa_isa_2. This applies tonamed,parameter, and a macro family's escape (unix_isunix_2).Header::nameescaped each C name alone, so two C names escaping alike (__all__andall_, or alreadydeleteanddelete_at namespace scope) would have declared one C++ name twice. It now looks up a map thatnamedbuilds over every C name the ABI declares, kept apart from each other and fromrt.hpp's names. This neededAbi::without_jni, which every language but Kotlin uses, to keep its claims' names (it dropped them).cpp_strictinffi/tests/fixtures.rs) adds-Wreserved-identifieras a warning and requires the reserved names it reports to be exactlyRESERVED_FROM_C. Those are the 13 names made of C names, which the new follow-up removes, after which the list and the-Wno-errorgo.Decisions
The user was away, so I made these calls myself. Each is open to review.
_and joins with_, soapi_Status_(apart from the runtime's status) givesapi_Status__eq,API_STATUS__MOVED, and C++'sStatus__debug. A Rust_deprecatedgivesapi__deprecated. Removing them renames C symbols (in clash cases only; none of moq's) and changes C's naming scheme, which is beyond this [S] C++ quest. The new quest owns it, with aMaintainer:decision on renaming those symbols.-Werrorwould need the C header fixed first, and leaving the flag off would let C++'s own reserved names come back.2after a trailing_(delete_2,new_2,a_2), rather than appending a letter or counting from the start. Every name escapes the same way, so a stable suffix keeps the rule simple, and2reads as "the second". A third clash givesx_2_. trailing-underscore-names, which gives every language C++'s rule, should take this step too._s and collapses runs, as the Plan recommended. The Plan's other option, a trailing_"where that clears the reservation", never applies: appending keeps a reserved name reserved.rt.hpp's names (detail,result,future, ...). A Rust item named like one of them would otherwise have shadowed it. No current crate does, and the api and moq surfaces show no such rename.Validation
just cipasses.ffi/src/cpp.rs:no_name_is_reserved: every identifier of up to five of_,a,A,1, plus keyword and macro families, escapes (and as a parameter) to an unreserved name. One scope of all 1,300 of them is named distinct and unreserved.the_namespace_keeps_escapes_apart: runsheaderson thewithout_jniABI over free functions__all__,all_,all,delete, anddelete_, and checks each C++ function calls its own C one. With thewithout_jniclaims fix reverted, it fails (ns___all__ is not all_2).reserved_names_escape_unreserved, plus the updated expectations of the existing naming tests.-Wreserved-identifierreported 26 distinct names. After, it reports exactly the 13 inRESERVED_FROM_C, all from the C header or made of a C name.tests/api.cppcallsapi::all_(1) == 3andapi::_deprecated(1) == 2.__all__,all_,all,a__b(__x, x_),struct _Bool, andEscaped::{delete, delete_}: exported, its glue built, and a C++ program compiled with Clang 23 at-Wall -Wextra -Wshadow -Wreserved-identifier. Every reserved-identifier warning comes fromresv.h(the C header), none from a.hpp. The program callsall_2,all_,all,a_b(x, x_),delete_2,delete_, andBool, and each returns its own Rust function's value. The first run of this check is what found the droppedwithout_jniclaims.just ffi surface: the api fixture'scpp.hppchanges only in the renames above. moq's changes in one parameter (__deserializer_→deserializer).Public API
Breaking, hence the
!, for C++ only:__, or starting with_and a capital, has a new C++ name (__all__→all_,_Bool→Bool)._2where it took__(delete__→delete_2, a parameterc_by_→c_by_2,default__→default_2).mux_container_ts_Mpegts::deserialize's parameter isdeserializer. A parameter name is no break for a caller.To migrate, use the renamed member the binding's API lock reports.
Caused by
No single PR. Reserved Rust names have passed through since the C++ generator began. kixel-ai/rust2#923 escaped them by appending
_, which keeps them reserved. kixel-ai/rust2#914 madenamedstack_s past a clash, asparameteralready did. Found by a person in the kixel-ai/rust2#925 audit.Overlap
kixel-ai/rust2#919 (ffi-apart) rewrites the same branch of
cpp::escapeto escape every system header macro, withabi::unmacroedappending_s per family (unix__,__GNUC____). Whichever lands second merges the other. The merge should keep this PR's two rules: reserved names unreserve first, and no step makes__. That meansunmacroed's count for C++ should step asstepdoes.Follow-ups
quest/m1/ffi-export/c-reserved-names.md[M]: the C header declares no name C or C++ reserves, nor does C++ make one from a C name, andRESERVED_FROM_Cgoes. Open decision: whether C symbols holding__today (api_Status__eq) may be renamed, a break for a C caller of a clashing name. I recommend yes, since none of moq's symbols hold one.Models
Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)