Skip to content

Torvik v1.2.0 — Ættir, Pattern Matching, and a Compiler That Warns You

Choose a tag to compare

@torvik-lang torvik-lang released this 11 Jul 15:17
· 136 commits to main since this release
Immutable release. Only release title and notes can be modified.
f9c66a6

v1.2.0 is a language-ergonomics and tooling release — the biggest addition to Torvik's surface since 1.0, with no breaking changes. Verified green on Linux and Windows: three-generation self-hosting fixpoints on both platforms and a 94-case end-to-end suite.

Update with:

rune update

aett — enumerations, the Torvik way

The runes of the futhark are grouped into families called ættir — and now, so are your named values. An aett is Torvik's enumeration:

aett Status { Pending, Active, Closed }

set s: Status = Status::Pending;
echo!(s);           // 0 — variants are i64 ordinals, in declaration order
echo!(typeof(s));   // Status

Variants are accessed with :: and behave like integers everywhere — print, compare, store in lists, pass to functions — while the aett name works as a type annotation for variables, parameters, and return types. Unknown variants, duplicate declarations, and X::Y on a non-aett are all clean located errors (an unknown variant even lists the real ones).

when — pattern matching with exhaustiveness

df describe(s: Status) -> str {
    when s {
        Status::Pending => return "waiting";
        Status::Active  => return "live";
        Status::Closed  => return "done";
    }
    return "";
}

Arms use => with a single statement or a block, and fallback => as the default (Torvik has no else — consistency kept). The headline: a when over an aett with no fallback is checked for exhaustiveness. Miss a variant and the compile error names exactly what's uncovered — so adding a variant to an aett later instantly surfaces every when in your codebase that needs updating. Integer-literal patterns (negatives included) work too, with a required fallback.

A warnings system that never cries wolf

The compiler now warns — never fails — on legal-but-suspicious code, with the same line-and-caret rendering as errors:

  • Unused variables, including write-only bindings that are assigned but never read. Prefix a name with _ to mark a deliberate discard.
  • Unreachable code after return / break / continue / halt / exit — with the halt(...); return x; all-paths-return idiom sensibly exempt.
  • A deprecation channel, so future removals warn at every call site (nothing is deprecated today).

Warnings render before errors, so an "unreachable code" note can explain the "must return a value" error it caused. Suppress globally with torvc --no-warn (-q implies it), or per file with directives at the top: !@NO_WARN; for everything, stackable !@ALLOW[category]; for one category. A typo'd directive is a clean compile error, not a silent no-op. Proof it works: enabling the system on the compiler's own source found and removed four dead variables in torvc and rune.

Result types, completed

The consumer side (is_ok, unwrap, unwrap_or, err_msg, err_code, try_readfile, try_toint, try_tofloat) has been in the runtime for a while. v1.2.0 adds the producer side — ok(value) and err(msg) / err(code, msg) — so your own functions can return result<i64>, result<str>, or result<f64>:

df safe_div(a: i64, b: i64) -> result<i64> {
    check b == 0 { return err("division by zero"); }
    return ok(a / b);
}

Standard library: grown, and now properly versioned

  • New core builtin find(s, sub) — the byte index of a substring, -1 when absent. contains told you whether; find tells you where.
  • New module std::path — path_base, path_dir, path_ext, path_join, with both / and \ recognized on input.
  • std::list gains in-place sort / sort_str (stable insertion sort), reverse_list, and index_of / index_of_str; std::math gains sign and isqrt; std::strings gains count_str, reverse_str, and capitalize.
  • Independent std versioning. The standard library now carries its own semver, decoupled from the compiler's: additive growth bumps its minor, breaking changes bump its major. torvc --version and rune version report it, and a project can require a minimum with std = "1.1.0" in torvik.rune — a too-old installation is a clean build error pointing at rune update. This release demonstrates the policy: std moves to 1.1.0, fully backward compatible.

Sharper diagnostics

  • Version-string-looking literals get a real error. 0.1.0 is not a number (a float has one decimal point), but it previously produced a confusing cascade of parse errors. Now it's one clean located error with the fix: quote it as a string.

Tooling & platform

  • Windows .tv file-type & icon integration — the installer registers the .tv extension with a friendly name and the Torvik file icon (per-user, no admin needed; no open-command is hijacked — source files belong to your editor). rune uninstall removes the registration.
  • The end-to-end suite grows to 94 cases (aett/when, results, find, std growth, the warnings system and its directives, the std version gate, and the malformed-literal diagnostic all covered).

Roadmap notes

task (async) headlines v1.3.0. Official macOS support remains on the future list, waiting on real Apple hardware for credible testing.

Full details in CHANGELOG.md.

Full Changelog: v1.1.3...v1.2.0