Rust Guide
This document defines the rules for using Rust in the Wave project.
Rust is the implementation language used during the phase before Wave becomes self-hosted. Even after self-hosting is completed, this document remains valid as a reference; however, the actual implementation of the Wave compiler will no longer be written in Rust.
Rust Version & Edition
The Wave compiler must satisfy the following requirements:
- Only the Rust 2021 Edition is allowed.
- The code must be written with Rust version 1.56.0 as the baseline.
Dependence on newer features or experimental functionality is not permitted.
Naming Conventions
All naming conventions strictly follow the official Rust naming guidelines.
- Types:
PascalCase - Functions & variables:
snake_case - Constants:
SCREAMING_SNAKE_CASE - Modules & files:
snake_case
File and Module Size
If a single Rust source file exceeds 5,000 lines, it must be split into smaller modules.
Excessively large files significantly reduce maintainability and readability.
Type Inference
Rust’s type inference is allowed by default.
However, types must be explicitly declared in the following cases:
- When the type is not immediately obvious
- When type safety is critical in compiler logic
- When the intent could be misinterpreted during code review
Macro Usage Rules
User-defined macros are not allowed in the Wave compiler codebase.
The following Rust standard macros are allowed as exceptions:
println!format!- Other basic macros included in the Rust standard library
Excessive macro usage makes code harder to trace and should be especially avoided in compiler development.
Library Usage Rules
Development should primarily rely on the Rust standard library.
The following rules apply:
- Core functionality in the compiler frontend should be implemented directly whenever possible.
- When using external libraries, avoid relying on only a small subset of their features.
- s developed directly by the Rust Foundation (e.g.,
libc) may be used when absolutely necessary.
Unnecessary dependencies negatively impact the long-term maintainability of the Wave compiler.
Code Style
The default code style follows the K&R style.
Exceptions may be allowed when necessary for readability, such as when using the where keyword.
Commenting Rules
Functions that meet any of the following conditions must be documented with comments:
- The logic is not intuitive
- The function is closely tied to internal compiler behavior
- The function contains algorithms that are difficult to understand at a glance
All comments must be written in English.