Support CARBON_KIND with Any types (#6828)
This uses the
CARBON_KIND_ANY(AnyImportRef, auto import_ref):syntax that seemed to be favored on Discord.This converted uses in the
sem_irdirectory to show it works initially, then addedcheckfor full coverage plus validating theSemIR::namespace discard.Note in inst_namer.cpp, AnyBindingPattern includes FormBindingPattern which wasn’t previously handled.
I’m disabling clang-format because I think it formats with readability issues, e.g.:
#define CARBON_KIND_ANY_EXPAND_AnyBinding(X, SEP) \ X(::Carbon::SemIR::AliasBinding) \ SEP X(::Carbon::SemIR::FormBinding) SEP X(::Carbon::SemIR::RefBinding) \ SEP X(::Carbon::SemIR::SymbolicBinding) \ SEP X(::Carbon::SemIR::ValueBinding)Since
SEPis typically a comma, it’s also a nuisance to treat as an argument toX(which could get better results).Assisted-by: Google Antigravity with Gemini 3 Flash
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
Carbon Language:
An experimental successor to C++
Why? | Goals | Status | Getting started | Join us
See our announcement video from CppNorth. Note that Carbon is not ready for use.
Fast and works with C++
Modern and evolving
Welcoming open-source community
Why build Carbon?
C++ remains the dominant programming language for performance-critical software, with massive and growing codebases and investments. However, it is struggling to improve and meet developers’ needs, as outlined above, in no small part due to accumulating decades of technical debt. Incrementally improving C++ is extremely difficult, both due to the technical debt itself and challenges with its evolution process. The best way to address these problems is to avoid inheriting the legacy of C or C++ directly, and instead start with solid language foundations like modern generics system, modular code organization, and consistent, simple syntax.
Existing modern languages already provide an excellent developer experience: Go, Swift, Kotlin, Rust, and many more. Developers that can use one of these existing languages should. Unfortunately, the designs of these languages present significant barriers to adoption and migration from C++. These barriers range from changes in the idiomatic design of software to performance overhead.
Carbon is fundamentally a successor language approach, rather than an attempt to incrementally evolve C++. It is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers. A successor language for C++ requires:
With this approach, we can build on top of C++’s existing ecosystem, and bring along existing investments, codebases, and developer populations. There are a few languages that have followed this model for other ecosystems, and Carbon aims to fill an analogous role for C++:
Language Goals
We are designing Carbon to support:
While many languages share subsets of these goals, what distinguishes Carbon is their combination.
We also have explicit non-goals for Carbon, notably including:
Our detailed goals document fleshes out these ideas and provides a deeper view into our goals for the Carbon project and language.
Project status
Carbon Language is currently an experimental project. We are hard at work on a toolchain implementation with compiler and linker. You can try out the current state at compiler-explorer.com.
We want to better understand whether we can build a language that meets our successor language criteria, and whether the resulting language can gather a critical mass of interest within the larger C++ industry and community.
Currently, we have fleshed out several core aspects of both Carbon the project and the language:
If you’re interested in contributing, we’re currently focused on developing the Carbon toolchain until it can support Carbon ↔ C++ interop. Beyond that, we plan to continue developing the design and toolchain until we can ship the 0.1 language and support evaluating Carbon in more detail.
You can see our full roadmap for more details.
Carbon and C++
If you’re already a C++ developer, Carbon should have a gentle learning curve. It is built out of a consistent set of language constructs that should feel familiar and be easy to read and understand.
The Carbon code here is hypothetical and meant to show the look and feel of the language.
C++ code like this:
corresponds to this Carbon code:
You can call Carbon from C++ without overhead and the other way around. This means you migrate a single C++ library to Carbon within an application, or write new Carbon on top of your existing C++ investment. For example:
Read more about C++ interop in Carbon.
Beyond interoperability between Carbon and C++, we’re also planning to support migration tools that will mechanically translate idiomatic C++ code into Carbon code to help you switch an existing C++ codebase to Carbon.
Generics
Carbon provides a modern generics system with checked definitions, while still supporting opt-in templates for seamless C++ interop. Checked generics provide several advantages compared to C++ templates:
Without sacrificing these advantages, Carbon generics support specialization, ensuring it can fully address performance-critical use cases of C++ templates. For more details about Carbon’s generics, see their design.
In addition to easy and powerful interop with C++, Carbon templates can be constrained and incrementally migrated to checked generics at a fine granularity and with a smooth evolutionary path.
Memory safety
Safety, and especially memory safety, remains a key challenge for C++ and something a successor language needs to address.
We plan to support a two step migration process:
We also want to address important, low-hanging fruit in the safety space immediately when migrating into Carbon:
unsafesyntax.For more details, see our safety design.
Getting started
To try out Carbon immediately in your browser, you can use the toolchain at: carbon.compiler-explorer.com.
We are developing a traditional toolchain for Carbon that can compile and link programs. However, Carbon is still an early, experimental project, and so we only have very experimental nightly releases of the Carbon toolchain available to download, and only on limited platforms. If you are using a recent Ubuntu Linux or similar (Debian, WSL, etc.), you can try these out by going to our releases page and download the latest nightly toolchain tar file:
carbon_toolchain-0.0.0-0.nightly.YYYY.MM.DD.tar.gz. Then you can try it out:As a reminder, the toolchain is still very early and many things don’t yet work. Please hold off on filing lots of bugs: we know many parts of this don’t work yet or may not work on all systems. We expect to have releases that are much more robust and reliable that you can try out when we reach our 0.1 milestone.
If you want to build Carbon’s toolchain yourself or are thinking about contributing fixes or improvements to Carbon, you’ll need to install our build dependencies (Clang, LLD, libc++) and check out the Carbon repository. For example, on Debian or Ubuntu:
Then you can try out our toolchain which has a very early-stage compiler for Carbon:
For complete instructions, including installing dependencies on various different platforms, see our contribution tools documentation.
Learn more about the Carbon project:
Conference talks
Carbon focused talks from the community:
2026
2025
2024
2023
2022
Other videos
We additionally have toolchain videos.
Join us
We’d love to have folks join us and contribute to the project. Carbon is committed to a welcoming and inclusive environment where everyone can contribute.
Contributing
You can also directly:
You can check out some “good first issues”, or join the
#contributing-helpchannel on Discord. See our fullCONTRIBUTINGdocumentation for more details.