== Clone of https://github.com/carbon-language/carbon-lang.git ==

Jon Ross-Perkins e343ea593c Add macro for postfix operators. (#3504) 2 năm trước cách đây
.devcontainer 7d817c857a Remove obsolete TAG arg for devcontainer (#2974) 2 năm trước cách đây
.github 226b653e11 Fix tests.yaml to execute tests when there's a mix of code and ignored files. (#3472) 2 năm trước cách đây
.vscode 553ee84fdb Recommend GH MD preview for mermaid support (#1240) 4 năm trước cách đây
bazel 23a02ac0d9 Update cc_toolchain configuration to be compatible with bazel 7. (#3496) 2 năm trước cách đây
common bd0ef62a8f Fix clang-tidy issues in common and testing (#3470) 2 năm trước cách đây
docker 47f28b361f Updated docker tagging to match correct ubuntu version (#2440) 3 năm trước cách đây
docs 4605b1d3e1 Style note for explicit constructors. (#3457) 2 năm trước cách đây
explorer ef0fa81a58 Upgrade clang-format version (#3471) 2 năm trước cách đây
github_tools 5a098089c5 Upgrade to latest rules_python. (#3423) 2 năm trước cách đây
installers 605763d62d Add lint fixes to the buildifier setup. (#3109) 2 năm trước cách đây
language_server fe6f7b4330 Rename `Name` -> `IdentifierName` given that we have several other kinds of parse nodes that represent names. (#3453) 2 năm trước cách đây
migrate_cpp 01e12111a8 Auto-update pre-commit repositories and fix. (#3427) 2 năm trước cách đây
proposals 01e12111a8 Auto-update pre-commit repositories and fix. (#3427) 2 năm trước cách đây
scripts 437b5e60d6 Add Linux AArch64 Bazel support and simplify. (#3422) 2 năm trước cách đây
testing ef0fa81a58 Upgrade clang-format version (#3471) 2 năm trước cách đây
third_party 605763d62d Add lint fixes to the buildifier setup. (#3109) 2 năm trước cách đây
toolchain e343ea593c Add macro for postfix operators. (#3504) 2 năm trước cách đây
utils 8c28a0494e Add size="small" to test targets where advised (#3326) 2 năm trước cách đây
.bazelignore fbb0aa729b Update LLVM and switch to upstreamed Bazel BUILD. (#838) 4 năm trước cách đây
.bazeliskrc dd26ea6a15 Update Bazel & protobufs, then narrow warnings to Carbon. (#2500) 3 năm trước cách đây
.bazelrc 23a02ac0d9 Update cc_toolchain configuration to be compatible with bazel 7. (#3496) 2 năm trước cách đây
.clang-format 29b6399e4f Modify EnumBase to better support the namespacing of toolchain (#3156) 2 năm trước cách đây
.clang-tidy 7fe8bb308b Clean up clang-tidy issues in explorer. (#2621) 3 năm trước cách đây
.codespell_ignore 4619ffa874 Update pre-commit (#2919) 2 năm trước cách đây
.gdbinit dcc694c2e0 Auto-enable pretty-printing of libcxx in gdb. (#679) 4 năm trước cách đây
.gitignore 8e8041ab1a Improved Error Handling in `remap_file` Function and Added `.DS_Store` to `.gitignore (#3195) 2 năm trước cách đây
.pre-commit-config.yaml ef0fa81a58 Upgrade clang-format version (#3471) 2 năm trước cách đây
.prettierrc.yaml a768b0ee19 Adjust copyrights based on carbon-project-tools/#3 (#171) 5 năm trước cách đây
BUILD d550256c93 Delete the website and references (#782) 4 năm trước cách đây
CODE_OF_CONDUCT.md e8f0866b2f Introduce a new Conduct team (#2922) 2 năm trước cách đây
CONTRIBUTING.md 8990ccd05a Add a "How to say things" section to CONTRIBUTING (#2715) 3 năm trước cách đây
LICENSE 7e81d1c213 Fix typo 'langauge'. 5 năm trước cách đây
README.md 70161c7c1d Update C++Now talks with video links (#3158) 2 năm trước cách đây
WORKSPACE 23a02ac0d9 Update cc_toolchain configuration to be compatible with bazel 7. (#3496) 2 năm trước cách đây
bazel-execroot e440b07eb3 Improve correctness of our Clang tooling infrastructure. (#392) 5 năm trước cách đây
compile_flags.txt 4d522c8e90 Finish making clang-tidy (mostly) work (again) and run -fix (#2312) 3 năm trước cách đây
pyproject.toml a768b0ee19 Adjust copyrights based on carbon-project-tools/#3 (#171) 5 năm trước cách đây
setup.cfg 24bea76c3e Move mypy config to setup.cfg (#1239) 4 năm trước cách đây

README.md

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.

<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++

  • Performance matching C++ using LLVM, with low-level access to bits and addresses
  • Interoperate with your existing C++ code, from inheritance to templates
  • Fast and scalable builds that work with your existing C++ build systems

Modern and evolving

  • Solid language foundations that are easy to learn, especially if you have used C++
  • Easy, tool-based upgrades between Carbon versions
  • Safer fundamentals, and an incremental path towards a memory-safe subset

Welcoming open-source community

  • Clear goals and priorities with robust governance
  • Community that works to be welcoming, inclusive, and friendly
  • Batteries-included approach: compiler, libraries, docs, tools, package manager, and more

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:

  • Performance matching C++, an essential property for our developers.
  • Seamless, bidirectional interoperability with C++, such that a library anywhere in an existing C++ stack can adopt Carbon without porting the rest.
  • A gentle learning curve with reasonable familiarity for C++ developers.
  • Comparable expressivity and support for existing software's design and architecture.
  • Scalable migration, with some level of source-to-source translation for idiomatic C++ code.

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++:

  • JavaScript → TypeScript
  • Java → Kotlin
  • C++ → Carbon

Language Goals

We are designing Carbon to support:

  • Performance-critical software
  • Software and language evolution
  • Code that is easy to read, understand, and write
  • Practical safety and testing mechanisms
  • Fast and scalable development
  • Modern OS platforms, hardware architectures, and environments
  • Interoperability with and migration from existing C++ code

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. 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:

  • The strategy of the Carbon Language and project.
  • An open-source project structure, governance model, and evolution process.
  • Critical and foundational aspects of the language design informed by our experience with C++ and the most difficult challenges we anticipate. This includes designs for:
    • Generics
    • Class types
    • Inheritance
    • Operator overloading
    • Lexical and syntactic structure
    • Code organization and modular structure
  • A prototype interpreter demo that can both run isolated examples and gives a detailed analysis of the specific semantic model and abstract machine of Carbon. We call this the Carbon Explorer.

If you're interested in contributing, we would love help completing the 0.1 language designs, and completing the Carbon Explorer implementation of this design. We are also currently working to get more broad feedback and participation from the C++ community. Beyond that, we plan to prioritize C++ interoperability and a realistic toolchain that implements the 0.1 language and can be used to evaluate 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.

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.

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:

  • Generic definitions are fully type-checked, removing the need to instantiate to check for errors and giving greater confidence in code.
    • Avoids the compile-time cost of re-checking the definition for every instantiation.
    • When using a definition-checked generic, usage error messages are clearer, directly showing which requirements are not met.
  • Enables automatic, opt-in type erasure and dynamic dispatch without a separate implementation. This can reduce the binary size and enables constructs like heterogeneous containers.
  • Strong, checked interfaces mean fewer accidental dependencies on implementation details and a clearer contract for consumers.

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. Our initial priority and focus is on immediately addressing important, low-hanging fruit in the safety space:

  • Tracking uninitialized states better, increased enforcement of initialization, and systematically providing hardening against initialization bugs when desired.
  • Designing fundamental APIs and idioms to support dynamic bounds checks in debug and hardened builds.
  • Having a default debug build mode that is both cheaper and more comprehensive than existing C++ build modes even when combined with Address Sanitizer.

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.

Getting started

As there is no compiler yet, 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.

To build the Carbon explorer yourself, you'll need to install dependencies (Bazel, Clang, libc++), and then you can run:

# Download Carbon's code.
$ git clone https://github.com/carbon-language/carbon-lang
$ cd carbon-lang

# Build and run the explorer.
$ bazel run //explorer -- ./explorer/testdata/print/format_only.carbon

For complete instructions, including installing dependencies, see our contribution tools documentation.

Learn more about the Carbon project:

Conference talks

Past Carbon focused talks from the community:

2022

2023

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-help channel on Discord. See our full CONTRIBUTING documentation for more details.