10. Programming language

10.1. Compiler

The certified libraries are being built with the safety qualified Ferrocene compiler. The compiler is qualified for the same safety standards as the certified libraries, see Ferrocene Evaluation Plan.

The Ferrocene compiler uses Rust as defined by the Ferrocene language specification.

The Ferrocene compiler performs thorough control flow and data flow analysis. The data flow analysis is usually referred to as “Borrow Checker” and is one of the central features of Rust. One example for the outstanding control flow analysis is that rustc detects when some variants of an enum are not handled and throws a hard error.

10.2. Rust

Characteristics of Rust:

  • strong typing and assertions

  • memory safety

  • well suited to structured and defensive programming

  • support for modular design

  • all items within a module are private by default and must be made public explicitly

  • no support for goto jumps, except in inline assembly

  • complex return types, therefore the use of out parameters is not common

  • explicit type conversions (.into or as), except for convenience (e.g. & &mut T to &T) or method dispatch

  • all fields and methods of a data structure are private by default and must be made public explicitly

  • functions in Rust can only be called through one interface (i.e. no overloading)

  • Usage of raw pointers is discouraged and limited in safe Rust

  • Functions with many parameters are discouraged (clippy::too_many_arguments)

Rust is well matched to the needs of the certified Rust libraries.

10.3. Heap allocations

The core library does not use heap allocations which is enforced by core being no_std and not specifying extern alloc.

The alloc library defines interfaces, data structures and functions that use heap allocations. But no allocator implementation is supplied, but must be supplied by the user.

The std library supplies allocator implementations, but std is currently out of scope of the certification.

10.4. Recursion limit

10.4.1. Compile-time

By default, the Rust compiler has a recursion limit of 128 for compile-time operations such as macro expansion and automatic dereferencing, to limit the maximum source code complexity. This can be configured with the recursion_limit attribute.

10.4.2. Runtime

Rust does not enforce a runtime recursion limit, so it is the user’s responsibility to enforce limits in line with appropriate safety standards as part of their coding standards.

To support users there are a few lints that catch common problems related to recursion, e.g.:

Note that the recursion_depth_exceeding_limit lint is not related to runtime recursion, but compile time recursion.