Skip to content

v5.37.3: sub-phase 5B, Core Language Completion

Latest

Choose a tag to compare

@PanzerPeter PanzerPeter released this 08 Nov 16:42
· 11 commits to main since this release

Closes sub-phase 5B: Core Language Completion, built across v5.6.0 to v5.37.3.

Before 5B, closures over non-Copy values, borrowed iteration, generics nested in generics and half-precision arithmetic were rejected although the language reference describes them. They now compile and run, so code written the way the reference shows it works. This release also fixes a memory fault found in the closing audit: a chained read, store or method call through a borrow held in a struct field addressed the slot holding the borrow instead of the borrowed value.

What landed:

  • StringBuilder. The growable text type is renamed from String, so string and StringBuilder are no longer one letter apart.
  • Reading through a borrow. Built-in operators take borrowed operands, and method receivers dereference automatically.
  • Half precision. f16 and bf16 have scalar arithmetic, comparisons, math methods and .to_checked, each operation correctly rounded.
  • Generics. Self as a type, an enclosing type parameter inside Option<T> or Wrapper<T>, generic methods with the method turbofish, generic trait methods, supertraits, and operator traits on every type.
  • Declarable Copy, Clone, Debug, PartialEq and Hashable, with T: Copy and T: Clone bounds a generic body can use, including through references.
  • Closures. Capture by &, &mut and move, capture by value inferred from a move out of the capture, the Fn, FnMut and FnOnce call modes, inference, and closures that escape with their own environment. Borrowing closures can be stored in structs, tuples and arrays, and returned by combinators such as compose(f, g).
  • Function values. Instantiated generics and associated functions work as values, and any function value is a |> target or a >> operand.
  • Option and Result methods. .map, .map_err, .ok, .ok_or, the is_* family, and a diverging ?? fallback.
  • References in structs and enums. Fields and payloads hold borrows, Option<&T> included, and the checker tracks what each holder borrows.
  • Collections of owners. Vec, HashMap and BTreeMap own non-Copy elements: insertion moves, indexing names a place, lookup borrows.
  • Iteration. for x in &v yields &T and &mut v yields &mut T. Iterator adapters (.map, .filter, .enumerate) and ranges (0..n, .rev(), .step(n)) are values that bind, pass and return, and maps iterate in all three receiver modes.
  • Surface additions. Loop labels written 'outer:, @ on the multiplicative row, bitwise compound assignment, tuple element places, if val and while val, binding alternatives, nested payload patterns, @ bindings and array patterns in match, and .parse::<T>() on strings.
  • Ownership fixes found on the way. Pool-aware values release once per loop iteration, a &mut moves instead of copying, a break value carries its borrows, and a temporary struct releases the strings its construction allocated.

Known gaps are in docs/BUGS.md:

  • BUG-085, BUG-082 and BUG-077: a string buffer leaks when a struct is passed by value, when an enum owns it, or when a store through a borrow displaces it. The program stays correct and grows.
  • BUG-152: a method whose signature nests its own type in itself is refused at 128 levels.
  • BUG-138: a private function in an imported module is reachable by its bare name.
  • BUG-155: a panic inside the standard library or an imported module reports a position in the program's file.
  • BUG-027: a const generic parameter cannot be passed on to another generic call.

Next: sub-phase 5C, Standard Library & First Training Run (a prebuilt Linux neurc, hierarchical module namespaces, a standard library written in Neuro, @test, file and .safetensors I/O).

Per-version detail is in CHANGELOG.md.