codegen: sibling-module use-imports resolve under cxx-namespace mode (#38) - #42
Closed
shuaimu wants to merge 1 commit into
Closed
codegen: sibling-module use-imports resolve under cxx-namespace mode (#38)#42shuaimu wants to merge 1 commit into
shuaimu wants to merge 1 commit into
Conversation
Fixes #38 (together with the alias half below). In flat-export mode a sibling-module use-import emits 'import sib;' and drops the using -- correct there, since the sibling's names land at global scope. Under --cxx-namespace/--auto-namespace the sibling's names live in its OWN namespace, so the emitted 'seg::Item' path shapes and bare single-item imports both miss. At the sibling-import site, additionally emit: namespace <seg> = ::<sibling::ns>; (once per sibling module) [export ]using ::<sibling::ns>::<Item>; (single-item imports) Both land inside the wrapping namespace (they are not 'import' lines, so the module-import hoist leaves them in place); pub re-exports keep their export keyword. Real-world case: srpc.wire.serde (mako crates/srpc) -- 'use super::archive::{ReadArchive, WireError, ...}' path shapes and 'use super::varint::VARINT_BUF_LEN' bare references. 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 #38 (the sibling-import half; with #41's crate-root requalification the namespace mode becomes fully coherent).
In flat-export mode a sibling-module use-import emits
import sib;and drops theusing— correct there, since the sibling's names land at global scope. Under--cxx-namespace/--auto-namespacethe sibling's names live in its own namespace, so both emitted reference shapes miss: path-qualifiedseg::Item(nonamespace segexists in the consumer) and bare single-item imports (use super::varint::VARINT_BUF_LEN→ bareVARINT_BUF_LEN).Fix — at the sibling-import site, additionally emit:
Both land inside the wrapping namespace (not
importlines, so the module-import hoist leaves them in place);pub usere-exports keepexport.Real-world case:
srpc.wire.serde(makocrates/srpc) —use super::archive::{ReadArchive, WireError, WriteArchive}path shapes and theVARINT_BUF_LENbare reference. Verification against the full srpc chain is in flight on the merged stack (#41 + this + #42); will report in a comment.🤖 Generated with Claude Code
https://claude.ai/code/session_01N9DLY5SDRooowERihphNQ1