Carbon Language: An experimental successor to C++
Jon Ross-Perkins 6907870a18 Raw identifier syntax (#3797) | 1 day ago | |
---|---|---|
.devcontainer | 10 months ago | |
.github | 2 weeks ago | |
.vscode | 3 months ago | |
bazel | 1 week ago | |
common | 3 weeks ago | |
core | 1 week ago | |
docker | 1 year ago | |
docs | 1 month ago | |
examples | 1 week ago | |
explorer | 1 month ago | |
github_tools | 2 weeks ago | |
installers | 8 months ago | |
language_server | 2 months ago | |
migrate_cpp | 1 month ago | |
proposals | 1 day ago | |
scripts | 1 month ago | |
testing | 1 week ago | |
third_party | 1 month ago | |
toolchain | 1 day ago | |
utils | 3 months ago | |
.bazelignore | 3 months ago | |
.bazeliskrc | 1 month ago | |
.bazelrc | 3 months ago | |
.clang-format | 1 month ago | |
.clang-tidy | 1 month ago | |
.codespell_ignore | 4 weeks ago | |
.gdbinit | 2 years ago | |
.gitignore | 3 months ago | |
.pre-commit-config.yaml | 4 weeks ago | |
.prettierrc.yaml | 3 years ago | |
BUILD | 3 months ago | |
CODE_OF_CONDUCT.md | 4 months ago | |
CONTRIBUTING.md | 4 months ago | |
LICENSE | 3 years ago | |
MODULE.bazel | 1 month ago | |
MODULE.bazel.lock | 1 month ago | |
README.md | 1 month ago | |
SECURITY.md | 1 week ago | |
WORKSPACE | 4 months ago | |
bazel-execroot | 4 months ago | |
pyproject.toml | 3 years ago | |
setup.cfg | 2 years ago |
Why? | Goals | Status | Getting started | Join us
See our announcement video from CppNorth. Note that Carbon is not ready for use.
<img src="docs/images/quicksort_snippet.svg" align="right" width="575"
alt="Quicksort code in Carbon. Follow the link to read more.">
Fast and works with C++
Modern and evolving
Welcoming open-source community
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++:
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.
Carbon Language is currently an experimental project. There is no working compiler or toolchain. You can see the demo interpreter for Carbon on 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.
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.
C++ code like this:
<img src="docs/images/cpp_snippet.svg" width="600"
alt="A snippet of C++ code. Follow the link to read it.">
corresponds to this Carbon code:
<img src="docs/images/carbon_snippet.svg" width="600"
alt="A snippet of converted Carbon code. Follow the link to read it.">
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:
<img src="docs/images/mixed_snippet.svg" width="600"
alt="A snippet of mixed Carbon and C++ code. Follow the link to read it.">
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.
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.
Safety, and especially memory safety, remains a key challenge for C++ and something a successor language needs to address. Our initial priority and focus is on immediately addressing important, low-hanging fruit in the safety space:
Once we can migrate code into Carbon, we will have a simplified language with room in the design space to add any necessary annotations or features, and infrastructure like generics to support safer design patterns. Longer term, we will build on this to introduce a safe Carbon subset. This will be a large and complex undertaking, and won't be in the 0.1 design. Meanwhile, we are closely watching and learning from efforts to add memory safe semantics onto C++ such as Rust-inspired lifetime annotations.
To try out Carbon, you can use the Carbon explorer to interpret Carbon code and print its output. You can try it out immediately at compiler-explorer.com.
Because Carbon is an early, experimental project we don't yet have releases you can download and try out locally, you'll instead need to build any tools yourself from source. We expect to have packaged releases you can try out when we reach our 0.1 milestone.
If you do want to try out Carbon locally, you'll need to install our build dependencies (Bazel, Clang, LLD, libc++) and check out the Carbon repository, for example on Debian or Ubuntu:
# Update apt.
sudo apt update
# Install tools.
sudo apt install \
bazel \
clang \
libc++-dev \
libc++abi-dev \
lld
# Download Carbon's code.
$ git clone https://github.com/carbon-language/carbon-lang
$ cd carbon-lang
Then you can build and run the explorer:
# Build and run the explorer.
$ bazel run //explorer -- ./explorer/testdata/print/format_only.carbon
And you can try out our toolchain which has a very early-stage compiler for Carbon:
# Build and run the toolchain's help to get documentation on the command line.
$ bazel run //toolchain/driver:carbon -- help
For complete instructions, including installing dependencies on various different platforms, see our contribution tools documentation.
Learn more about the Carbon project:
Past Carbon focused talks from the community:
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.
You can also directly:
You can check out some
"good first issues",
or join the #contributing-help
channel on
Discord. See our full
CONTRIBUTING
documentation for more details.