Include the Carbon package name in the exported C++ namespace. (#7935)

When exporting `X` from Carbon package `Foo`, expose it to C++ with
fully-qualified name `Carbon::Foo::X`, not simply `Carbon::X`. This
ensures that C++ mangled names properly distinguish between same-named
Carbon entities in different packages.

Name *lookup* into `Carbon::` still uses the same rules as before: it
finds what a `package.` lookup would find in Carbon. So `X` is named
from C++ as `Carbon::X` still, and a lookup for `Carbon::Foo` fails,
even though `X`'s "true name" is now `Carbon::Foo::X`.

Assisted-by: Gemini via Antigravity
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-15 20:26:05 +00:00
1 parent d87891f3a6
commit 09b79784dc
35 files changed
+440 -262

No files matched your search

@@ -352,12 +352,12 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress uwtable
// CHECK:STDOUT: define linkonce_odr dso_local void @_Z2G1v() #1 comdat {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_ZN6CarbonL1FEv()
// CHECK:STDOUT: call void @_ZN6Carbon4MainL1FEv()
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
// CHECK:STDOUT: define internal void @_ZN6CarbonL1FEv() #2 {
// CHECK:STDOUT: define internal void @_ZN6Carbon4MainL1FEv() #2 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF__carbon_thunk.Main()
// CHECK:STDOUT: ret void
@@ -424,12 +424,12 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress uwtable
// CHECK:STDOUT: define linkonce_odr dso_local void @_Z8CallBasev() #1 comdat {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_ZN6CarbonL4baseEv()
// CHECK:STDOUT: call void @_ZN6Carbon4MainL4baseEv()
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
// CHECK:STDOUT: define internal void @_ZN6CarbonL4baseEv() #2 {
// CHECK:STDOUT: define internal void @_ZN6Carbon4MainL4baseEv() #2 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_Cbase__carbon_thunk.Main()
// CHECK:STDOUT: ret void