Rust
HIR projection. The package product path compiles this through Cargo.
Part of the HIR lane. Every panel below is compiler output.
How to read it#
Close to one-for-one with the source. That is the point of this emitter: generated Rust is meant to be read and reviewed, so it keeps the shape of the Faber it came from rather than expanding into something unrecognisable.
Measured support#
| Capable | Analyzable | Coverage |
|---|---|---|
| 570 | 573 | 99% |
From the target matrix: how many corpus exempla lower to this target. Coverage is not a quality score — an emitter can lower a term and still erase a distinction.
Not fully supported#
Terms the matrix records as partial, planned, or unsupported for this target. A term here is a measured gap, not an omission.
| Category | Terms |
|---|---|
| Operators — application lane | ↦ |
Typed tensors#
Builds two shaped matrices, multiplies them, and reduces the product to a scalar. Exercises shape-bearing types and a reduction.
Faber source
faber convert --to en — English reader surfacemain {
let list<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
let list<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
let tf32[2, 3] a ← flat_a ↦ tensor<f32, [2, 3]>
let tf32[3, 4] b ← flat_b ↦ tensor<f32, [3, 4]>
let tf32[2, 4] product ← a.matmul(b)
let f32 mean ← product.mean()
print mean
}faber convert --to la — canonical Faberincipit {
sit lista<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
sit lista<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
sit tf32[2, 3] a ← flat_a ↦ tensor<f32, [2, 3]>
sit tf32[3, 4] b ← flat_b ↦ tensor<f32, [3, 4]>
sit tf32[2, 4] product ← a.matmul(b)
sit f32 mean ← product.media()
nota mean
}faber convert --to th-TH — Thaiเริ่ม {
กำหนด รายการ<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
กำหนด รายการ<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
กำหนด tf32[2, 3] a ← flat_a ↦ เทนเซอร์<f32, [2, 3]>
กำหนด tf32[3, 4] b ← flat_b ↦ เทนเซอร์<f32, [3, 4]>
กำหนด tf32[2, 4] product ← a.คูณเมทริกซ์(b)
กำหนด f32 mean ← product.ค่าเฉลี่ย()
บันทึก mean
}faber convert --to zh-Hans — Simplified Chinese入口 {
设 列表<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
设 列表<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
设 tf32[2, 3] a ← flat_a ↦ 张量<f32, [2, 3]>
设 tf32[3, 4] b ← flat_b ↦ 张量<f32, [3, 4]>
设 tf32[2, 4] product ← a.矩阵乘法(b)
设 f32 mean ← product.均值()
显示 mean
}faber convert --to zh-Hant — Traditional Chinese入口 {
設為 列表<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
設為 列表<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
設為 tf32[2, 3] a ← flat_a ↦ 張量<f32, [2, 3]>
設為 tf32[3, 4] b ← flat_b ↦ 張量<f32, [3, 4]>
設為 tf32[2, 4] product ← a.矩陣乘法(b)
設為 f32 mean ← product.平均值()
註記 mean
}faber convert --to vi — Vietnamesebắt_đầu {
đặt danh_sách<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
đặt danh_sách<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
đặt tf32[2, 3] a ← flat_a ↦ ten_xo<f32, [2, 3]>
đặt tf32[3, 4] b ← flat_b ↦ ten_xo<f32, [3, 4]>
đặt tf32[2, 4] product ← a.nhân_ma_trận(b)
đặt f32 mean ← product.trung_bình()
ghi_chú mean
}faber convert --to ar — Arabicبداية {
ليكن قائمة<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
ليكن قائمة<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
ليكن tf32[2, 3] a ← flat_a ↦ موتر<f32, [2, 3]>
ليكن tf32[3, 4] b ← flat_b ↦ موتر<f32, [3, 4]>
ليكن tf32[2, 4] product ← a.ضرب_المصفوفات(b)
ليكن f32 mean ← product.المتوسط()
اعرض mean
}faber convert --to hi — Hindiआरंभ {
बैठा सूची<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
बैठा सूची<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
बैठा tf32[2, 3] a ← flat_a ↦ टेंसर<f32, [2, 3]>
बैठा tf32[3, 4] b ← flat_b ↦ टेंसर<f32, [3, 4]>
बैठा tf32[2, 4] product ← a.आव्यूह_गुणन(b)
बैठा f32 mean ← product.माध्य()
दिखाओ mean
}Rust — 9 lines in, 19 out (2.1×)
// Generated by radix - do not edit
// Requires the faber language-runtime crate (add to Cargo.toml):
// faber = { path = "../faber" } # adjust path for your layout
// Recorded suppressions: identifier/literal fidelity, plan-directed
// casts and parameter passing, library-shaped artifact items.
#![allow(non_camel_case_types, non_snake_case, dead_code, clippy::unreadable_literal, clippy::cast_lossless, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss, clippy::cast_precision_loss, clippy::needless_pass_by_value)]
fn main() {
faber::trap::exit_on_trap();
let _stdout_flush_guard = faber::stdout::FlushOnDrop;
let l_flat_a: Vec<f32> = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
let l_flat_b: Vec<f32> = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0];
let l_a: faber::Tensor<f32> /* tensor<f32, [2, 3]> */ = { let t0 = l_flat_a.clone(); ({ let f0 = t0; let f0_n = f0.len(); match faber::Tensor::<f32>::structa(f0, &[2, 3]) { Ok(value) => value, Err(_) => faber::tensor::conversion_count_mismatch(&[2, 3], f0_n) } }) };
let l_b: faber::Tensor<f32> /* tensor<f32, [3, 4]> */ = { let t1 = l_flat_b.clone(); ({ let f0 = t1; let f0_n = f0.len(); match faber::Tensor::<f32>::structa(f0, &[3, 4]) { Ok(value) => value, Err(_) => faber::tensor::conversion_count_mismatch(&[3, 4], f0_n) } }) };
let l_product: faber::Tensor<f32> /* tensor<f32, [2, 4]> */ = faber::trap::ok_static({ let t2 = &l_a; t2.matmul_parallel_float(&(l_b)) });
let l_mean: f32 = { let t3 = &l_product; let c0_flat = faber::trap::ok_static(t3.planata()); let c0: f32 = c0_flat.iter().map(|x| *x as f32).sum(); c0 / t3.element_count() as f32 };
faber::stdout::println(format_args!("{}", faber::display::fractus(l_mean)));
}The error channel#
A function that may fail, and a caller that catches. Shows how the ⇥ channel becomes each target's own error idiom.
Faber source
faber convert --to en — English reader surfacefn divide(int a, int b) → int ⇥ string {
if b ≡ 0 {
throw "division by zero"
}
return a / b
}
main {
do {
print divide(10, 2)
}
catch err {
warn err
}
}faber convert --to la — canonical Faberfunctio divide(numerus a, numerus b) → numerus ⇥ textus {
si b ≡ 0 {
iace "division by zero"
}
redde a / b
}
incipit {
fac {
nota divide(10, 2)
}
cape err {
mone err
}
}faber convert --to th-TH — Thaiฟังก์ชัน divide(จํานวน a, จํานวน b) → จํานวน ⇥ ข้อความ {
ถ้า b ≡ 0 {
โยน "division by zero"
}
คืน a / b
}
เริ่ม {
ทำ {
บันทึก divide(10, 2)
}
จับ err {
เตือน err
}
}faber convert --to zh-Hans — Simplified Chinese函数 divide(整数 a, 整数 b) → 整数 ⇥ 文本 {
如果 b ≡ 0 {
抛错 "division by zero"
}
返回 a / b
}
入口 {
执行 {
显示 divide(10, 2)
}
捕获 err {
警告 err
}
}faber convert --to zh-Hant — Traditional Chinese函式 divide(整數 a, 整數 b) → 整數 ⇥ 文字 {
若 b ≡ 0 {
拋出 "division by zero"
}
傳回 a / b
}
入口 {
執行 {
註記 divide(10, 2)
}
捕捉 err {
警告 err
}
}faber convert --to vi — Vietnamesehàm divide(số a, số b) → số ⇥ văn_bản {
nếu b ≡ 0 {
ném "division by zero"
}
trả a / b
}
bắt_đầu {
làm {
ghi_chú divide(10, 2)
}
bắt err {
cảnh_báo err
}
}faber convert --to ar — Arabicدالة divide(عدد a, عدد b) → عدد ⇥ نص {
إذا b ≡ 0 {
ارم "division by zero"
}
أعد a / b
}
بداية {
افعل {
اعرض divide(10, 2)
}
التقط err {
نبه err
}
}faber convert --to hi — Hindiफलन divide(संख्या a, संख्या b) → संख्या ⇥ पाठ {
यदि b ≡ 0 {
इधरफेंको "division by zero"
}
लौटाओ a / b
}
आरंभ {
करो {
दिखाओ divide(10, 2)
}
पकड़ो err {
चेताओ err
}
}Rust — 13 lines in, 26 out (2.0×)
// Generated by radix - do not edit
// Requires the faber language-runtime crate (add to Cargo.toml):
// faber = { path = "../faber" } # adjust path for your layout
// Recorded suppressions: identifier/literal fidelity, plan-directed
// casts and parameter passing, library-shaped artifact items.
#![allow(non_camel_case_types, non_snake_case, dead_code, clippy::unreadable_literal, clippy::cast_lossless, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss, clippy::cast_precision_loss, clippy::needless_pass_by_value)]
fn divide(p_a: i64, p_b: i64) -> Result<i64, String> {
if p_b == 0 {
return Err(String::from("division by zero"));
}
Ok(faber::exact::store::<i64>(faber::exact::div(p_a as i128, p_b as i128), "return"))
}
fn main() {
faber::trap::exit_on_trap();
let _stdout_flush_guard = faber::stdout::FlushOnDrop;
match 'fac_result: {
faber::stdout::println(format_args!("{}", match divide(10, 2) { Ok(fac_value) => fac_value, Err(fac_err) => break 'fac_result Err(fac_err) }));
Ok::<(), String>(())
} { Ok(()) => {}, Err(err) => {
let l_err = err;
faber::stdout::eprintln(format_args!("{l_err}"));
} }
}Collections and iteration#
A list folded to a total with for from. The plainest possible read on how loops lower.
Faber source
fn sum(list<int> numeri) → int {
mut int total ← 0
for from numeri let n {
total ← total + n
}
return total
}
main {
let list<int> valores ← [1, 2, 3, 4, 5]
print sum(valores)
}Rust — 12 lines in, 23 out (1.9×)
// Generated by radix - do not edit
// Requires the faber language-runtime crate (add to Cargo.toml):
// faber = { path = "../faber" } # adjust path for your layout
// Recorded suppressions: identifier/literal fidelity, plan-directed
// casts and parameter passing, library-shaped artifact items.
#![allow(non_camel_case_types, non_snake_case, dead_code, clippy::unreadable_literal, clippy::cast_lossless, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss, clippy::cast_precision_loss, clippy::needless_pass_by_value)]
fn sum(p_numeri: &[i64]) -> i64 {
let mut l_total: i64 = 0;
for i0 in p_numeri {
let l_n = i0.clone();
l_total = faber::exact::store::<i64>(faber::exact::add(l_total as i128, l_n as i128), "assignment to `total`");
}
l_total
}
fn main() {
faber::trap::exit_on_trap();
let _stdout_flush_guard = faber::stdout::FlushOnDrop;
let l_valores: Vec<i64> = vec![1, 2, 3, 4, 5];
faber::stdout::println(format_args!("{}", sum(&l_valores)));
}---