Release of the programming language Rust 1.59 with support for assembler inserts

The general-purpose programming language Rust 1.59, founded by the Mozilla project but now developed under the auspices of the independent non-profit organization Rust Foundation, has been released. The language focuses on memory safety and provides the means to achieve high job parallelism while avoiding the use of a garbage collector and runtime (runtime is reduced to basic initialization and maintenance of the standard library).

Rust's memory handling methods save the developer from errors when manipulating pointers and protect against problems that arise due to low-level memory handling, such as accessing a memory area after it has been freed, dereferencing null pointers, buffer overruns, etc. To distribute libraries, provide builds and manage dependencies, the project develops the Cargo package manager. The crates.io repository is supported for hosting libraries.

Memory safety is provided in Rust at compile time through reference checking, keeping track of object ownership, keeping track of object lifetimes (scopes), and assessing the correctness of memory access during code execution. Rust also provides protection against integer overflows, requires mandatory initialization of variable values ​​before use, handles errors better in the standard library, applies the concept of immutable references and variables by default, offers strong static typing to minimize logical errors.

Main innovations:

  • The ability to use assembler inserts, which are in demand in applications that need to control execution at a low level or be able to use specialized machine instructions, is provided. Asm inserts are added using macros "asm!" and "global_asm!" using string formatting syntax for naming registers, similar to that used in string substitutions in Rust. The compiler supports assembler instructions for the x86, x86-64, ARM, AArch64, and RISC-V architectures. Paste example: use std::arch::asm; // Multiply x by 6 using shifts and adds let mut x: u64 = 4; unsafe { asm!( "mov {tmp}, {x}", "shl {tmp}, 1", "shl {x}, 2", "add {x}, {tmp}", x = inout(reg ) x, tmp = out(reg) _, ); } assert_eq!(x, 4 * 6);
  • Added support for destructured (parallel) assignments, in which several traits, slices or structures are specified on the left side of the expression. For example: let (a, b, c, d, e); (a, b) = (1, 2); [c, .., d, _] = [1, 2, 3, 4, 5]; Struct { e, .. } = Struct { e: 5, f: 3 }; assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]);
  • Provided the ability to specify default values ​​for const generics: struct ArrayStorage {arr: [T; N], } impl ArrayStorage { fn new(a: T, b: T) -> ArrayStorage { ArrayStorage { arr: [a, b], } } }
  • The Cargo package manager provides warnings about the use of invalid constructs in dependencies that are processed due to errors in the compiler (for example, due to an error, fields of packed structures in safe blocks were allowed to be borrowed). Support for such constructs will be dropped in a future version of Rust.
  • cargo and rustc have the ability to generate executable files stripped of debug data (strip = "debuginfo") and symbols (strip = "symbols") without the need to call a separate utility. The cleanup setting is implemented through the "strip" parameter in Cargo.toml: [profile.release] strip = "debuginfo", "symbols"
  • By default, incremental compilation is disabled. The cause is cited as a temporary workaround for a bug in the compiler that causes crashes and deserialization errors. The bug fix has already been prepared and will be part of the next release. To return incremental compilation, you can use the RUSTC_FORCE_INCREMENTAL=1 environment variable.
  • A new portion of the API has been moved to the category of stable, including the methods and implementations of traits have been stabilized:
    • std::thread::available_parallelism
    • Result::copied
    • Result::cloned
    • arch::asm!
    • arch::global_asm!
    • ops::ControlFlow::is_break
    • ops::ControlFlow::is_continue
    • TryFrom for u8
    • char::TryFromCharError (Clone, Debug, Display, PartialEq, Copy, Eq, Error)
    • iter::zip
    • NonZeroU8::is_power_of_two
    • NonZeroU16::is_power_of_two
    • NonZeroU32::is_power_of_two
    • NonZeroU64::is_power_of_two
    • NonZeroU128::is_power_of_two
    • DoubleEndedIterator for ToLowercase structure
    • DoubleEndedIterator for ToUppercase structure
    • TryFrom<&mut [T]> for [T; N]
    • UnwindSafe for the Once structure
    • RefUnwindSafe for Once
    • compiler built-in armv8 neon support functions for aarch64
  • The "const" attribute, which determines the possibility of using it in any context instead of constants, is used in functions:
    • mem::MaybeUninit::as_ptr
    • mem::MaybeUninit::assume_init
    • mem::MaybeUninit::assume_init_ref
    • ffi::CStr::from_bytes_with_nul_unchecked

Source: opennet.ru

Add a comment