codegen: cxx-namespace wrap re-qualifies crate-root item self-references (#37) - #41
Closed
shuaimu wants to merge 1 commit into
Closed
codegen: cxx-namespace wrap re-qualifies crate-root item self-references (#37)#41shuaimu wants to merge 1 commit into
shuaimu wants to merge 1 commit into
Conversation
Fixes #37. The expression emitters conservatively global-qualify crate-local free-fn/const references as `::<item>` — correct in the legacy flat-export mode where crate items land at global scope, but once `--cxx-namespace`/`--auto-namespace` wraps the module purview those references look in the (now-empty) global namespace and miss: namespace srpc::wire::varint { export size_t dump64(...) { auto n = ::val_size(val); ... } } error: no member named 'val_size' in the global namespace This is the same gap wrap_module_purview_in_crate_namespace closes for the dep pipeline with its Rule 4; the CLI namespace wrap had no requalification pass at all. Close it with the same mechanics at the wrap-close: every declared crate-root item name (C++-escaped to match emission, sorted for deterministic output) is rewritten `::<item>` -> `::<ns>::<item>` by the boundary-aware requalify_crate_root_symbol, which leaves `x::item`, `.item(`, `>::item`, and already-qualified `::<ns>::item` untouched and cannot double-prefix (single pass, never re-scans its output). Verified: bin unit suite 1910/1910; e2e_basic 31/31 incl. the new test_cxx_namespace_requalifies_crate_root_item_refs regression; guard/runtime/trait/parity-matrix integration suites green; parity_test_verification 43/43. (either_parity_harness fails identically on clean main in this environment — pre-existing.) Real-world case: the srpc crate (mako repo) — namespace-mode srpc.wire.varint and srpc.wire.archive now compile under clang 22. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
Full-stack verification: with #41 + #42 + #43 + #45 merged locally (verify-stack), the srpc crate (mako |
This was referenced Jul 29, 2026
Owner
Author
|
Closing — PRs should not have been opened without explicit instruction. The fix remains on this branch for review whenever wanted. |
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.
Fixes #37.
The expression emitters conservatively global-qualify crate-local free-fn/const references as
::<item>— correct in legacy flat-export mode, but under--cxx-namespace/--auto-namespacethose refs look in the (now-empty) global namespace and miss. This is the same gapwrap_module_purview_in_crate_namespacecloses for the dep pipeline with its Rule 4; the CLI namespace wrap had no requalification pass.Fix: at the wrap-close, rewrite
::<item>→::<ns>::<item>for every declared crate-root item name (C++-escaped, sorted for determinism) using the existing boundary-awarerequalify_crate_root_symbol(leavesx::item,.item(,>::item, already-qualified forms untouched; single pass, cannot double-prefix).Verification:
e2e_basic31/31 incl. new regressiontest_cxx_namespace_requalifies_crate_root_item_refsparity_test_verification43/43either_parity_harnessfails identically on cleanmainin this environment (pre-existing, not touched)Real-world case: the srpc crate (mako repo,
crates/srpc) —--auto-namespaceoutput forsrpc.wire.varint(::val_size/::buf_sizeself-refs) andsrpc.wire.archivenow compiles under clang 22 / C++23 modules.🤖 Generated with Claude Code
https://claude.ai/code/session_01N9DLY5SDRooowERihphNQ1