Cangjie Release Notes
0. Version Introduction
This version is the first LTS version of the Cangjie programming language (for details about the definition and maintenance period of the LTS version, see Cangjie Community Version Lifecycle Management Regulations). The version number is Cangjie 1.0.0. This version provides the capabilities required for Cangjie application development, including the compiler, runtime, standard library, and toolchain. Developers are encouraged to use this version. If you have any questions, feel free to post issues in the Cangjie community. We will address them promptly.
1. Language Features
Features
- Support basic identifiers and basic program structures such as loops and conditional branches.
- Support basic data types such as integer, floating-point number, Boolean, character, string, tuple, array, interval, Unit, and Nothing.
- Support custom data types struct, class, and enum, as well as interface, which is used to abstractly describe external functionalities.
- Support type aliases, so that users can describe the same type in different scenarios.
- Support defining ordinary functions, operator overloading functions, const functions, lambda expressions, and higher-order nested functions. In addition, mut functions can be defined in struct. Support function overloading. When calling a function, you can use syntax sugars such as trailing closures and flow expressions.
- Support pattern matching expressions, which can be used to match enum constructors, Option type deconstruction, and downward data type conversion.
- Support defining generic user-defined types and functions and adding constraints to generic types.
- Support the extend declaration, which extends new functionalities for existing types. The extend declaration can contain functions and properties and provide specialization capabilities for generic types.
- Support compiling code by package. Users can organize modules based on the structure of packages and their subpackages, and provide modifiers with different visibility scopes for declarations in packages.
- Support exception handling and provide two basic exception classes: Exception and Error.
- Support concise concurrency syntax: spawn expression.
- Support cross-language interoperability with C.
- Support reflection and provide a reflection library. Users can call any function with reflection information through the reflection library interface.
- Provide metaprogramming capabilities based on lexical macros and support code transformation during compilation. Developers can use macros to compile Cangjie code generation templates or define their own DSL grammars.
- For more features, see [Development Guide](https://cangjie-lang.cn/en/docs?url=%2F0.53.13%2Fuser_manual%2Fsource_en%2Ffirst_understanding%2Fbasic.html).
2. Compilers
Cangjie compilers enable compilation with the Cangjie language. They are implemented in the frontend and backend. The backend is developed based on the LLVM.
Features
- Provide different optimization capabilities such as
O0~O2,Os, andOzto meet different requirements.O2provides features such as function inlining, constant propagation, and virtual function call optimization. For details, see Cangjie Compilation Options. - Provide various compiler security checks to improve application quality: Array out-of-bounds check (Try-Best) Integer arithmetic overflow check (Try-Best) Shift overflow check (Try-Best) Division-by-zero check (Try-Best) Dead code check (Try-Best) Uninitialized variable check
- Support Cangjie
GC: The Cangjie backend based on theLLVMsupports the Cangjie language, including operations likeRewriteStatePoint. This feature is applicable to Cangjie active variable analysis. The main implementation passes areCJRewriteStatepointandCJGCLiveAnalysis. - To achieve better performance, Cangjie adds optimization passes based on the
LLVM, as shown in the following table.
| Pass Name | Optimization Option | On | Description |
|---|---|---|---|
| CJIRVerifier | cj-ir-verifier | O0~On | Ensures that the intermediate representations (IRs) generated by the frontend comply with the Cangjie specifications. |
| InsertCJTBAA | insert-cj-tbaa | O0~On | Inserts Cangjie TBAA metadata into load, store, memcpy, and barrier to help compilers optimize memory access. |
| CJFillMetadata | cj-fill-metadata | O0~On | Fills TypeInfo and reflection information. |
| CJRuntimeLowering | cj-runtime-lowering | O0~On | Lowers intrinsics generated by the Cangjie frontend to runtime functions. |
| CJSpecificOpt | cj-specific-opt | O0~On | Enables Cangjie-specific backend optimizations. 1. Stack allocation optimization: Eliminates unused memory allocation. 2. Memory operation optimization: Simplifies address translation and inline memset. 3. Math function optimization: Specially processes the pow function. 4. Security check: Checks stacks to be inserted and resets floating-point status. |
| CJBarrierOpt | cj-barrier-opt | O2~On | Optimizes write barriers and eliminates the overhead of useless write barriers. |
| CJRewriteStatepoint | cj-rewrite-statepoint | O0~On | Constructs statepoints for call/invoke instructions. In this way, IRs explicitly reflect the relocation operations that may be required by Cangjie GC during execution. |
| CJSimpleOpt | cj-simple-opt | O2 | Enables a series of optimizations applicable to Cangjie. 1. Return value optimization: Eliminates unnecessary copy when a structure is returned. 2. Floating-point-to-integer conversion optimization: Simplifies the overflow check process. 3. Mutex optimization: Adds atomic operations on the fast path. 4. Integer comparison optimization: Simplifies comparison by using symbolic information. 5. Array size optimization: Replaces the constant array size. |
| CJSimpleRangeAnalysisPass | cj-simple-range-analysis | O2 | Performs simple range analysis on integers and floating-point numbers and optimizes the control flow graph (CFG) based on the analysis result. |
| CJLoopFloatOpt | cj-loop-float-opt | O2 | Optimizes top-level loops that only involve simple floating-point calculations. It improves performance by converting floating-point calculations to integer calculations. |
| CJRSSCEPass | cj-rssce | O2 | Eliminates redundant stack structure copies through memory definition range analysis and alias analysis. |
| CJDevirtualOpt | cj-devirtual-opt | O2 | Optimizes virtual function calls to direct calls. |
| CJBarrierSplit | cj-barrier-split | O2 | Splits and optimizes barrier instructions to eliminate useless barriers. |
| CJPartialEscapeAnalysis | cj-pea | O1~On | Optimizes escape analysis. |
| CJGenericIntrinsicOpt | cj-generic-intrinsic-opt | O0~On | Optimizes Cangjie generic intrinsics. |
| CJBarrierLowering | cj-barrier-lowering | O0 | Lowers barrier instructions. |
3. Runtime
As one of the core components of Cangjie, the Cangjie runtime is designed for high-performance and lightweight purposes in all scenarios.
Features
| Feature | Description |
|---|---|
| Memory management | The automatic memory management module uses a low-latency full-concurrency memory sorting algorithm. The core objective is to lower service latency and memory overhead, helping developers focus on services. |
| Thread management | The thread management module provides a more lightweight and elastic thread management solution to better cope with various concurrency scenarios. |
| Exception management | In Cangjie, exceptions are classified into Exception and Error based on severity. The Error class describes internal errors and resource exhaustion errors of the Cangjie runtime. In most cases, an application does not throw this type of error. If an internal error occurs, the application can only notify the user to safely terminate the application as soon as possible. The Exception class describes exceptions caused by logic or I/O errors of the application runtime, for example, out-of-bounds arrays or attempts to open a non-existent file. Such exceptions need to be captured and processed in the application. |
| Stack Unwinding | Cangjie applies stack unwinding based on the frame pointer. That is, the rbp register is used to save the stack frame address, and the rsp register is used to save the stack top pointer. During procedure calls, the address of the previous stack frame is saved to the stack. |
| Package management | Cangjie packages can be loaded by package and the reflection feature is supported. |
| Object model | Includes Cangjie object metadata, member information, method information, and method tables. |
| Cross-language call | Foreign function interfaces (FFIs) are used to implement function calls and data exchange between Cangjie and C or ArkTs. |
| DFX | Provides functionalities such as log printing, CPU collection, and heap snapshot file export, and supports runtime status monitoring and troubleshooting. |
4. Standard Library
Cangjie provides a broad range of standard library capabilities, such as collection, timer, I/O, and file processing. For details, see the following table. For details about APIs, see API Reference.
Features
| Package | Description |
|---|---|
| std.core | Provides fundamental APIs for Cangjie programming. This is the core package of the standard library. |
| std.argopt | Provides capabilities for parsing parameter names and values from command line parameter strings. |
| std.ast | Contains the syntax parser of Cangjie source code and Cangjie syntax tree nodes, and provides syntax parsing functions. |
| std.binary | Provides APIs for converting between Cangjie data types and binary byte sequences. |
| std.collection | Provides efficient implementations of commonly used data structures, definitions of related abstract APIs, and functions in the collection type. |
| std.collection.concurrent | Provides implementations of the concurrency-safe collection types. |
| std.console | Provides methods for interaction with standard input, standard output, and standard errors. |
| std.convert | Provides a series of Convert functions for converting strings into specific types. |
| std.crypto | Provides common APIs for symmetric encryption and decryption as well as common APIs for digest algorithms. |
| std.database.sql | Provides APIs for Cangjie to access databases. |
| std.deriving | Provides a method for automatically generating API implementations based on the fields and properties of classes, structures, and enum types. |
| std.env | Provides information and functionalities related to the current process, including environment variables, command line parameters, standard streams, and exit programs. Provides methods for interaction with standard input, standard output, and standard errors. |
| std.fs | Provides some operation functions for files, directories, paths, and file metadata. |
| std.io | Allows programs to exchange data with external devices. |
| std.math | Provides functionalities including common mathematical operations, constant definition, and floating-point number processing. |
| std.math.numeric | Extends the expressible range of basic types. |
| std.net | Provides functionalities including starting the socket server, connecting to the socket server, sending data, and receiving data, and supports data structures related to IP addresses, IP prefixes (also known as IP subnets), and socket addresses. These are for network communications. |
| std.objectpool | Caches and reuses objects. |
| std.overflow | Processes overflows in integer operations. |
| std.posix | Adapts to POSIX system APIs. |
| std.process | Provides process operation APIs, including process creation, standard flow obtainment, process waiting, and process information query. |
| std.random | Generates pseudo random numbers. |
| std.reflect | Supports reflection, allowing programs to obtain the type information of various instances during runtime and perform various read, write, and call operations. |
| std.regex | Analyzes and processes text using regular expressions and supports search, segmentation, replacement, and verification. |
| std.runtime | Interacts with the runtime environment of a program. It provides a series of functions and variables for controlling, managing, and monitoring the execution of the program. |
| std.sort | Provides sorting functions for the array type. |
| std.sync | Provides capabilities related to concurrent programming. |
| std.time | Provides time-related types, including date and time, time interval, monotonic time, and time zone, and supports calculation and comparison. |
| std.unicode | Processes characters according to Unicode. |
| std.unittest | Compiles unit test code for Cangjie projects. It provides basic functionalities including code writing, running, and debugging, and some advanced functionalities for experienced users. |
5. Toolchain
1 IDE Plug-ins
Features
- Support Cangjie language services, including code highlighting, automatic completion, jump-to definition, reference search, error diagnosis, selection and highlighting, floating prompt, definition search, renaming, outline view, breadcrumb navigation, and type hierarchy.
- Support creating a Cangjie project.
- Support compiling a Cangjie project.
- Support debugging services, including breakpoint debugging, debugging information viewing, program control, expression evaluation, and reverse debugging.
- Support Cangjie code formatting.
2 cjpm
Features
cjpm is a build tool for compiling a Cangjie project. This tool is implemented using the Cangjie language and provides capabilities such as project creation, compilation, operation, and unit test. The project supports automatic dependency analysis of multiple modules to complete sequential build. Its design aims to simplify the workflow, improve multi-platform development efficiency, and provide highly customizable configuration options.
cjpm provides the following functionalities:
- Create a Cangjie module.
- Check dependencies and output the package dependency topology sequence.
- Print package dependencies.
- Compile a Cangjie program.
- Run executable products.
- Compile and execute test cases.
- Compile and execute performance test cases.
- Clear compilation products.
- Install or uninstall module executable products.
- Provide the command extension mechanism.
- Provide the build script capability.
cjpm provides a cjpm.toml configuration file in the root directory of a module. Users can configure the entire module by editing the file. The main configuration items include basic module information, transparent transmission, dependency module information, command profile information, platform isolation, and workspace information.
3 cjdb
Features
cjdb is a Cangjie program command-line debugger developed based on lldb for Cangjie developers:
cjdb provides the following functionalities:
- Use the debugger to launch a target program.
- Set source/function/conditional breakpoints.
- Set observation points.
- Run programs.
- Enter and exit from functions, perform single-stepping, and resume execution.
- View and modify variables.
- Calculate expressions.
- View Cangjie threads.
4 cjfmt
Features
cjfmt is an automatic code formatter developed based on Cangjie Coding Style.
cjfmt provides the following functionalities:
- Format files.
- Format directories.
- Format fragments.
- Customize the formatting style through a configuration file.
5 cjlint
Features
cjlint is a static check tool developed based on Cangjie Coding Style. It can identify code that does not comply with the Cangjie Coding Style, helping developers detect vulnerabilities in code and write Cangjie code that meets the Clean Source standards.
You can use the -f option of this tool to specify the check directory and the -r option to specify the format of the scan report to be generated. Currently, the json and csv formats are supported. Currently, rule-level alarm masking and source code comment alarm masking are also supported.
6 cjcov
Features
cjcov is a coverage statistics tool designed to generate coverage reports for Cangjie applications.
7 cjprof
Features
cjprof is a performance analysis tool of Cangjie. It supports the following functionalities (only in Linux):
- Sample the CPU hotspot functions of Cangjie applications and export the sampling data.
- Analyze the sampling data of hotspot functions and generate a CPU hotspot function statistics report or flame graph.
- Export the heap memory of Cangjie applications, analyze the heap memory, and generate an analysis report.
8 cjtrace-recover
Features
cjtrace-recover is a Cangjie tool for restoring abnormal stack information.
If developers enable appearance obfuscation when compiling a Cangjie application and the application encounters a problem during runtime, the stack information in the thrown exception is also obfuscated. As a result, it is difficult for developers to locate the cause of the problem. With cjtrace-recover, developers can restore the obfuscated stack information to better locate and rectify the problem. Specifically, cjtrace-recover can restore the following two types of stack information:
- Obfuscated function names
- Obfuscated path names