Skip to content

codegen: sibling-module use-imports resolve under cxx-namespace mode (#38) - #42

Closed
shuaimu wants to merge 1 commit into
mainfrom
fix-38-sibling-imports-namespace-mode
Closed

codegen: sibling-module use-imports resolve under cxx-namespace mode (#38)#42
shuaimu wants to merge 1 commit into
mainfrom
fix-38-sibling-imports-namespace-mode

Conversation

@shuaimu

@shuaimu shuaimu commented Jul 28, 2026

Copy link
Copy Markdown
Owner

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 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 both emitted reference shapes miss: path-qualified seg::Item (no namespace seg exists in the consumer) and bare single-item imports (use super::varint::VARINT_BUF_LEN → bare VARINT_BUF_LEN).

Fix — 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 (not import lines, so the module-import hoist leaves them in place); pub use re-exports keep export.

Real-world case: srpc.wire.serde (mako crates/srpc) — use super::archive::{ReadArchive, WireError, WriteArchive} path shapes and the VARINT_BUF_LEN bare 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

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>
@shuaimu

shuaimu commented Jul 29, 2026

Copy link
Copy Markdown
Owner Author

Full-stack verification: with #41 + #42 + #43 + #45 merged locally (verify-stack), the srpc crate (mako crates/srpc) transpiles --crate --auto-namespace with 0 errors and all six emitted modules compile under clang 22 / C++23 modules: srpc.wire.{varint,archive,frame,serde}, srpc.wire, srpc — 6/6. (Issue #44 was sidestepped srpc-side by moving the varint API to idiomatic slice params.)

@shuaimu

shuaimu commented Jul 29, 2026

Copy link
Copy Markdown
Owner Author

Closing — PRs should not have been opened without explicit instruction. The fix remains on this branch for review whenever wanted.

@shuaimu shuaimu closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crate mode: cross-module use-imports not resolved in emitted references

1 participant