Cangjie Programming Language White Paper

Author: Cangjie Language Team, Compilers & Programming Languages Lab, Huawei Technologies Co., Ltd.

With the advent of the Internet of Everything (IoE) and intelligent era, the form of software will change greatly. On the one hand, mobile applications and mobile Internet are still driving innovations in human-machine interaction, device collaboration, intelligence, and security. On the other hand, AI is also driving software to evolve towards intelligence and device-edge-cloud synergy. The development of application software in new technologies and scenarios poses new requirements and challenges to programming languages.

The Cangjie programming language is a modern programming language oriented to all-scenario application development. It provides developers with friendly development experience and excellent program performance through integration of modern language features, comprehensive compilation optimization, runtime implementation, and out-of-the-box IDE toolchain support. The specific features are as follows:

  • Efficient programming: For application development, the Cangjie language is easy to learn and use, which reduces the entry threshold and workload of developers during development and supports various common development paradigms and programming modes, so that developers can express various service logics in a simple and efficient manner. The Cangjie language is a multi-paradigm programming language that supports multiple paradigms such as functional paradigm, imperative paradigm, and object-oriented paradigm, and features such as value types, classes and interfaces, generics, algebraic data types, pattern matching, and higher-order functions. In addition, the Cangjie language supports type inference, which reduces the workload of type annotation for developers. The Cangjie language has a series of concise and efficient syntax, which reduces redundant writing and improves development efficiency. Various syntax sugar and macros built in the Cangjie language help developers quickly develop domain-specific languages (DSLs) to build domain abstractions.

  • Secure and reliable: As a modern programming language, the Cangjie language pursues real-time coding security. The static type system and automatic memory management are used to ensure programs' type security and memory security such as null safety. In addition, the Cangjie language provides various runtime checks, including array index out-of-bounds check, type conversion check, value calculation overflow check, and character string encoding validity check, to detect errors during program running in a timely manner. In addition, code scanning tools, obfuscation tools, and sterilizers are used to further support cross-language interoperability security and code asset protection.

  • Easy concurrency: Concurrent and asynchronous programming can effectively improve processor utilization and ensure program response speed in interactive applications, which is an indispensable capability in application development. The Cangjie language implements lightweight user-level threads and concurrent object libraries, making efficient concurrency easy. The Cangjie language uses the user-level thread model. Each Cangjie thread is an extremely lightweight execution entity and has an independent execution context but shared memory. For developers, the use of user-level threads is the same as that of traditional system threads, and no extra workload is brought. From the perspective of the runtime state, thread management is completed by the runtime and does not depend on thread management of the operating system. Therefore, operations such as threads' creation, scheduling, and destruction are more efficient, and resource usage of user-level threads is less than that of system threads. To avoid data competition, the Cangjie language provides a concurrent object library. The methods of concurrent objects are thread-safe. Therefore, calling these methods in multiple threads is the same as serial programming. Developers for application logic do not need to pay attention to concurrency management. For some core libraries, the Cangjie language also provides lock-free or fine-grained lock algorithm implementations to further reduce thread blocking and improve concurrency.

  • Excellent performance: The Cangjie compiler and runtime optimize the compilation of the full stack, including the high-level compilation optimization (such as semantic-aware loop optimization and semantic-aware back-end collaboration optimization) based on the Cangjie HighLevel IR (CHIR) for the compiler front-end, compilation optimization (such as SLP vectorization, Intrinsic optimization, InlineCache, interprocedural pointer optimization, and Barrier optimization) for the compiler back-end, and runtime optimization (such as lightweight lock, distributed marking, and concurrent Tracing optimization). The series of optimizations enable the Cangjie language to fully utilize the processor capability and provide excellent performance support for applications. In addition, the Cangjie language implements native lightweight design for the runtime. By modular and layered design of the runtime, the Cangjie common object models and the common basic components of the runtime are defined. Based on the common object models, basic capabilities such as memory management, stack return, exception handling, and cross-language calling during runtime are implemented, the redundant object design between multiple capabilities is greatly reduced, and the volume during runtime is reduced. In addition, the technology of loading packages by demands is used to reduce the memory overhead of redundant packages for starting Cangjie applications. Therefore, for resource-sensitive devices, less resources are occupied and the support is more user-friendly.

In addition, the Cangjie language supports a series of tool chains for application development, including language services (highlighting and association), debugging (cross-language debugging and thread-level visualized debugging), static checks, performance analysis, package management, document generation, mock tools, test frameworks, coverage tools, fuzz tools, and intelligent auxiliary programming tools, further improving software development experience and efficiency. The following describes the main features of the Cangjie language from the preceding aspects, helping readers quickly understand the positioning and main technical features of the Cangjie language.