Circle
2023 - Sean Baxter - circlelang@gmail.com
Follow me on Twitter, @seanbax, for compiler updates.
Download the latest version: Build 200 for 64-bit Linux.
Circle is a new C++20 compiler. It's written from scratch and designed for easy extension.
New Circle is out!
New Circle is a major transformation of the Circle compiler, intended as a response to recent successor language announcements. It focuses on a novel fine-grained versioning mechanism that allows the compiler to fix defects and make the language safer and more productive while maintaining 100% compatibility with existing code assets.
New Circle is the richest C++ compiler yet. Try out:
- choice types,
- pattern matching,
- interfaces and impls,
- language type erasure,
- a-sexpressions for safer conversions,
- a modern declaration syntax with
fn
andvar
keywords to make clearer, less ambiguous declarations, - a simpler syntax for binary expressions, greatly reducing the likelihood of bugs caused by confusing operator precedences,
- a
forward
keyword to take the complexity and bugginess out of forwarding references, - safer initializer lists, which address ambiguities when calling std::initializerlist constructors and non-std::initializerlist constructors,
- lifting lambdas to pass overload sets as function arguments,
- nine kinds of template parameters to make templates far more comprehensive,
- reflection traits to access packs of information about class types, enum types, function types, class specializations, and so on,
- pack traits for pack-transforming algorithms, like sort, unique, count, erase, difference, intersection, and so on.
New Circle describes a path for evolving C++ to meet the needs of institutional users. The versioning mechanism that accommodated the development of the features above will also accommodate research into critically important areas like memory safety. Rather than insisting on a one-size-fit's-all approach to language development, project leads can opt into collections of features that best target their projects' needs.
GPU targets
Circle's main target is 64-bit Linux. Because all modern non-Microsoft operating systems use the same C++ ABI, it would be easy to bring Circle to these other platforms.
But Circle supports both major GPU targets as well:
- Circle supports GPU compute with a single-pass flavor of CUDA.
- Use libc and the C++ Standard Library in device code.
- Use reflection and if-target to programmatically define the best tuning for each PTX architecture.
- Circle supports shader programming by embedding GLSL 4.6 into C++ and emitting both SPIR-V (OpenGL and Vulkan) and DXIL (Direct3D 12) byte codes.
- Tag functions and objects with
spirv
attributes to target all 12 standard shader stages. - Use reflection and user-defined attributes to automatically generate interfaces to guide shader development.
- Write device-portable GPGPU code with Vulkan compute, using real pointers into physical storage buffers, a powerful feature only implemented by the Circle compiler.
- Tag functions and objects with
Circle is a heterogeneous compiler. In one translation unit, mix x64 code, CUDA code, and shader code. No tags are required. Only a single frontend pass is performed. This is the most seamless integration of CPU and GPU code of any programming language.
Using Circle
Download the latest version: Build 200 for 64-bit Linux.
Circle is best used locally, on any recent x86-64 Linux installation. You have two choices for C++ standard library:
- libstdc++ (gcc) is Circle's default standard library, and is the default on almost all Linux distributions. I like libstdc++-10.2.
- libc++ (LLVM) is supported by specifying
-stdlib=libc++
or specifying_LIBCPP_ABI_VERSION
as a command-line macro definitiono.
If you're on an incompatible distribution, or a different OS altogether, try running Circle through this Dockerfile.
Circle is also hosted on Compiler Explorer, so you can use it over the web.
Basic command-line options
--help
- list all command-line options.-c
- only compiles to an object file, without linking.-c -emit-llvm
- emit a binary LLVM IR bitcode file (.bc).-console
- print the output (if text) to the terminal. This is very useful when paired with -S or -S -emit-llvm.--cuda-path=<path>
- path to NVIDIA HPC SDK (for CUDA 12.0 or later). Alternatively, set the environment variableCUDA_PATH
. Eg,CUDA_PATH=/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0
.-dM
dump macros.-E
- only run the preprocessor.-fsyntax-only
- only run the preprocessor and parser.-ftime-report
- print a breakdown of compile times by category.-ftime-log=<path>
- log time reports to a single file. Useful for understanding compile times over an entire project.-g
- generate host debug info.-G
- generate device debug info.-M
- name a compile-time shared object library. This enables compile-time foreign function calls to compiled code.-no-demangle
prints mangled names in link errors.-P2128
- enable multi-dimensional subscript operator.-gpu
- When paired with-S
options, emit LLVM IR for GPU target modules.-O0
,-O1
,-O2
and-O3
- host code optimization levels.-OG0
,-OG1
,-OG2
and-OG3
- device code optimization levels.-S
- emit an ASM file (.s).-S -emit-llvm
- emit a human-readable LLVM IR file (.ll).-sm_XX
- generate code for one or more CUDA device architectures.-stdpar
- enable Accelerated Standard Parallelism for CUDA builds.-stat
reports on files opened and lines lexed.