Skip to content

C++ Interop: API importing and semantics#6358

Merged
bricknerb merged 15 commits intocarbon-language:trunkfrom
bricknerb:interop2
Mar 2, 2026
Merged

C++ Interop: API importing and semantics#6358
bricknerb merged 15 commits intocarbon-language:trunkfrom
bricknerb:interop2

Conversation

@bricknerb
Copy link
Copy Markdown
Contributor

@bricknerb bricknerb commented Nov 12, 2025

This proposal defines the concrete technical mechanisms for C++
interoperability. It specifies the precise syntax and semantics for importing
C++ APIs. This includes the import Cpp library "..." and implicitly importing
C++ built-in entities, and the establishment of the Cpp package as the
dedicated namespace for all imported entities.

This PR also includes high level language C++ Interop design and the basics of importing C++ APIs and function calling.
Leaving plenty of TODOs to make it easier to fill in more details in followups.

Part of #4666.

This includes high level design ideas and the basics of importing C++ APIs and function calling.
Leaving plenty of TODOs to make it easier to fill in more details in followups.
@github-actions github-actions Bot added the documentation An issue or proposed change to our documentation label Nov 12, 2025
@bricknerb bricknerb marked this pull request as ready for review November 12, 2025 15:04
@bricknerb bricknerb requested a review from a team as a code owner November 12, 2025 15:04
@bricknerb bricknerb requested review from jonmeow and removed request for a team November 12, 2025 15:04
Copy link
Copy Markdown
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an important distinction of implementation versus design... Where you talk about a specific implementation requirement using Clang, I think that's a toolchain design detail. That'd suggest to me that the details are more appropriate for toolchain/docs (implementation) than docs/design (language design).

That is, for our implementation, we have chosen to use Clang and we're making implementation trade-offs based on that. However, if someone chose to build their own Carbon compiler, they should have freedom to choose a C++ compiler that suited them so long as it fit the higher-level language needs.

Also for language design, I think we typically want proposals first, then language design changes (or, put the language design change in with the proposal). But I'm just going to swap myself out for review with zygoloid since that's more of a leads choice, and he's also familiar with what's being done here.

@jonmeow jonmeow requested review from jonmeow and zygoloid and removed request for jonmeow November 12, 2025 17:01
Copy link
Copy Markdown
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just highlighting a few things from a read-through, but trying not to get into many details because of the mix of design and implementation here.

Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
@bricknerb
Copy link
Copy Markdown
Contributor Author

I think there's an important distinction of implementation versus design... Where you talk about a specific implementation requirement using Clang, I think that's a toolchain design detail. That'd suggest to me that the details are more appropriate for toolchain/docs (implementation) than docs/design (language design).

That is, for our implementation, we have chosen to use Clang and we're making implementation trade-offs based on that. However, if someone chose to build their own Carbon compiler, they should have freedom to choose a C++ compiler that suited them so long as it fit the higher-level language needs.

Also for language design, I think we typically want proposals first, then language design changes (or, put the language design change in with the proposal). But I'm just going to swap myself out for review with zygoloid since that's more of a leads choice, and he's also familiar with what's being done here.

Thanks Jon!
I've edited this to focus on language design, removing implementation specific parts including the entire TODO section for thunks.

@bricknerb
Copy link
Copy Markdown
Contributor Author

I think there's an important distinction of implementation versus design... Where you talk about a specific implementation requirement using Clang, I think that's a toolchain design detail. That'd suggest to me that the details are more appropriate for toolchain/docs (implementation) than docs/design (language design).
That is, for our implementation, we have chosen to use Clang and we're making implementation trade-offs based on that. However, if someone chose to build their own Carbon compiler, they should have freedom to choose a C++ compiler that suited them so long as it fit the higher-level language needs.
Also for language design, I think we typically want proposals first, then language design changes (or, put the language design change in with the proposal). But I'm just going to swap myself out for review with zygoloid since that's more of a leads choice, and he's also familiar with what's being done here.

Thanks Jon! I've edited this to focus on language design, removing implementation specific parts including the entire TODO section for thunks.

Waiting for @zygoloid review.

Copy link
Copy Markdown
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable, but I think there are details here that haven't been through the proposal process, so it'd make sense to add a little pro forma /proposals/p6358.md here and treat this as a proposal so we can give it the weight of being an approved design change.

Comment thread docs/design/interoperability/README.md
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
Comment thread docs/design/interoperability/README.md Outdated
@bricknerb bricknerb requested a review from a team as a code owner November 17, 2025 12:29
@bricknerb bricknerb requested review from chandlerc and removed request for a team November 17, 2025 12:29
@bricknerb
Copy link
Copy Markdown
Contributor Author

This seems reasonable, but I think there are details here that haven't been through the proposal process, so it'd make sense to add a little pro forma /proposals/p6358.md here and treat this as a proposal so we can give it the weight of being an approved design change.

I've created a proposal, which assumes the proposal #6254 is accepted.

@bricknerb bricknerb requested a review from zygoloid November 17, 2025 12:30
@bricknerb bricknerb added proposal A proposal proposal rfc Proposal with request-for-comment sent out labels Nov 17, 2025
@bricknerb bricknerb changed the title C++ Interop design details - the basics C++ Interop: API importing and semantics Nov 17, 2025
@bricknerb
Copy link
Copy Markdown
Contributor Author

This seems reasonable, but I think there are details here that haven't been through the proposal process, so it'd make sense to add a little pro forma /proposals/p6358.md here and treat this as a proposal so we can give it the weight of being an approved design change.

I've created a proposal, which assumes the proposal #6254 is accepted.

I've removed the dependency on #6254.
@zygoloid, PTAL.

@github-actions
Copy link
Copy Markdown

We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please comment or remove the inactive label.

This PR is labeled inactive because the last activity was over 90 days ago. This PR will be closed and archived after 14 additional days without activity.

@github-actions github-actions Bot added the inactive Issues and PRs which have been inactive for at least 90 days. label Feb 25, 2026
@zygoloid zygoloid removed the inactive Issues and PRs which have been inactive for at least 90 days. label Feb 25, 2026
Copy link
Copy Markdown
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a couple of minor edits.

Comment thread docs/design/interoperability/README.md Outdated
Comment thread proposals/p6358.md Outdated
Copy link
Copy Markdown
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG to me as well with the suggestions from @zygoloid

Let us know if we should merge those and land this or you want to!

bricknerb and others added 2 commits March 2, 2026 14:53
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
@bricknerb bricknerb enabled auto-merge March 2, 2026 13:54
@bricknerb
Copy link
Copy Markdown
Contributor Author

Thanks!
Committed the suggestions.

Comment thread proposals/p6358.md
bricknerb and others added 2 commits March 2, 2026 14:58
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
Removed a long line of text in the rationale section.
Comment thread proposals/p6358.md
## Rationale

01234567890123456789012345678901234567890123456789012345678901234567890123456789
- [Code that is easy to read, understand, and write](/docs/project/goals.md#code-that-is-easy-to-read-understand-and-write)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
- [Code that is easy to read, understand, and write](/docs/project/goals.md#code-that-is-easy-to-read-understand-and-write)
- **Explicitness and Clarity:** The `import Cpp library "..."` directives

Copy link
Copy Markdown
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bricknerb bricknerb added this pull request to the merge queue Mar 2, 2026
Merged via the queue into carbon-language:trunk with commit 9ff6b0a Mar 2, 2026
8 checks passed
@bricknerb bricknerb deleted the interop2 branch March 2, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation An issue or proposed change to our documentation proposal rfc Proposal with request-for-comment sent out proposal A proposal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants