Skip to content

Compiler style guide

Note

This style guide is only for the developers of the compiler and other official projects. For the I-Language style guide see ILEP 008.

All code

Comments

Comments should always be written in the third person when describing an action, e.g. # Removes the old files instead of # Remove the old files.

Rust code

Generally just refer to the official rust style guide. There are some exceptions you should follow though.

Code groups

Groups start with a three line header like this:

Rust
1
2
3
///////////
// TITLE //
///////////

Where the top and bottom lines are as long as the middle one. The title should be in SCREAMING_SNAKE_CASE.

There should always be two blank lines above, but not below a group header.

The groups should be in the following order

  1. Header with copyright notice (without a header)
  2. Global attributes (#![...])
  3. Imports
  4. Constants
  5. Statics
  6. type statements
  7. Trait definitions
  8. Type definitions with trait implementations in this order (without own headers)
  9. Implementation without a trait
  10. Trait implementations with traits from the same library
  11. Trait implementations with traits from libraries in the same project
  12. Trait implementations with traits from the standard library
  13. Trait implementations with traits from other dependencies
  14. Helper functions
  15. The main function/the most important function (e.g. the lex function in the lexer, the parse function in the parser, etc.)

Dependencies

Always prefer core over std. Try to use functionality from the standard library instead of adding new dependencies if it doesn't add to much complexity.

Mutable statics

Use mutable statics only when it's the only reasonable option available. Mutable statics' names should be in SCREAMING_SNAKE_CASE, even though they behave more like variables to make other people irritated.

Sorting imports

Sort imports in the following order

  1. core and std imports
  2. self, super and crate imports
  3. Imports from other crates in the same project
  4. Imports from other libraries
  5. Conditional imports (#[cfg(...)])

There should be one blank line in between import groups. For sorting imports within groups, refer to the official style guide.


Last update: 2025-03-23