Judgment codegen_expr_into
judgment_fn! {
fn codegen_expr_into(
global: CodegenGlobal,
cfn: CodegenFn,
scope: CodegenScope,
target: MiniRustLocal,
expr: Expr,
) => (CodeBlock, CodegenGlobal, CodegenFn) {
/* rules omitted */
}
}
Source: crates/formality-rust/src/codegen/mod.rs:221
The number on each rule’s conclusion is positive coverage; the number on each premise is negative coverage. Click a number to browse the tests.
parenthesized| Line | Coverage | Source |
|---|---|---|
| 232 | ✗ | (codegen_expr_into(global, cfn, scope, target, expr) => (code, global, cfn)) |
| ──────── ("parenthesized") | ||
| 234 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Parens(expr)) => (code, global, cfn)) |
multiplication| Line | Coverage | Source |
|---|---|---|
| 238 | N/A | (let expr = Expr::BinOp { lhs: lhs.clone(), op: BinOpKind::Mul, rhs: rhs.clone() }) |
| 239 | ✗ | (codegen_expr_into(global, cfn, scope, target, expr) => (code, global, cfn)) |
| ──────── ("multiplication") | ||
| 241 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Mul { lhs, rhs }) => (code, global, cfn)) |
literal| Line | Coverage | Source |
|---|---|---|
| 245 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("literal") | ||
| 247 | ✗ | (codegen_expr_into(global, cfn, scope, target, literal@Literal { value: _ , ty: _ }) => ( code.assign(target, constant(literal)), global, cfn, )) |
fn-as-value| Line | Coverage | Source |
|---|---|---|
| 256 | ✗ | (if scope.lookup_var(id).is_err()) |
| 257 | ✗ | (if cfn.crates.fn_named(id).is_ok()) |
| 258 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("fn-as-value") | ||
| 260 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Place(PlaceExpr::Var(id))) => ( code.assign(target, unit_value()), global, cfn, )) |
place| Line | Coverage | Source |
|---|---|---|
| 268 | ✗ | (resolve_place(cfn, scope, place_expr) => typed) |
| 269 | ✗ | (let source = typed_place_to_minirust(cfn, scope, &typed)?) |
| 270 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("place") | ||
| 272 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Place(place_expr)) => ( code.assign(target, load(source)), global, cfn, )) |
true| Line | Coverage | Source |
|---|---|---|
| 280 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("true") | ||
| 282 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::True) => ( code.assign(target, bool_constant(true)), global, cfn, )) |
false| Line | Coverage | Source |
|---|---|---|
| 290 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("false") | ||
| 292 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::False) => ( code.assign(target, bool_constant(false)), global, cfn, )) |
assign| Line | Coverage | Source |
|---|---|---|
| 300 | ✗ | (resolve_place(cfn, scope, place) => typed_dest) |
| 301 | ✗ | (let dest = typed_place_to_minirust(cfn, scope, &typed_dest)?) |
| 302 | ✗ | (type_expr(cfn, scope, rhs) => rhs_ty) |
| 303 | ✗ | (let (rhs_temp, cfn) = cfn.alloc_temp(rhs_ty)?) |
| 304 | ✗ | (codegen_expr_into(global, cfn, scope, rhs_temp, rhs) => (code, global, cfn)) |
| ──────── ("assign") | ||
| 306 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Assign { place, expr: rhs }) => ( code .assign(dest, load(rhs_temp)) .assign(target, unit_value()), global, cfn, )) |
assign-op| Line | Coverage | Source |
|---|---|---|
| 316 | ✗ | (resolve_place(cfn, scope, place) => typed_dest) |
| 317 | ✗ | (let dest = typed_place_to_minirust(cfn, scope, &typed_dest)?) |
| 318 | ✗ | (type_expr(cfn, scope, rhs) => rhs_ty) |
| 319 | ✗ | (let (rhs_temp, cfn) = cfn.alloc_temp(rhs_ty)?) |
| 320 | ✗ | (codegen_expr_into(global, cfn, scope, rhs_temp, rhs) => (code, global, cfn)) |
| ──────── ("assign-op") | ||
| 322 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::AssignOp { place, op, rhs }) => ( code .assign(dest, binop(op, load(dest), load(rhs_temp))) .assign(target, unit_value()), global, cfn, )) |
turbofish| Line | Coverage | Source |
|---|---|---|
| 334 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("turbofish") | ||
| 336 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Turbofish { .. }) => ( code.assign(target, unit_value()), global, cfn, )) |
call| Line | Coverage | Source |
|---|---|---|
| 347 | ✗ | (type_expr(cfn, scope, callee) => callee_ty) |
| 348 | ✗ | (resolve_rigid(cfn, scope, callee_ty) => RigidTy { name: RigidName::FnDef(fn_id), parameters }) |
| 349 | N/A | (let (fn_name, global) = global.ensure_fn(MonoKey::new(fn_id, parameters))) |
| 351 | ✗ | (let (callee_temp, cfn) = cfn.alloc_temp(&callee_ty)?) |
| 352 | ✗ | (codegen_expr_into(global, cfn, scope, callee_temp, callee) => (code, global, cfn)) |
| 354 | ✗ | (let (temps, cfn) = alloc_temps_for_args(cfn, scope, args)?) |
| 355 | ✗ | (for_all(i in 0..args.len()) with(code, global, cfn) (codegen_expr_into(global, cfn, scope, &temps[i], &args[i]) => (arg_code, global, cfn)) (let (code, cfn) = cfn.append_from(code, arg_code))) |
| 359 | ✗ | (let (code, cfn) = cfn.call(code, fn_name, temps, target)?) |
| ──────── ("call") | ||
| 361 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Call { callee, args }) => (code, global, cfn)) |
ref| Line | Coverage | Source |
|---|---|---|
| 365 | ✗ | (resolve_place(cfn, scope, place) => typed) |
| 366 | ✗ | (let mr_place = typed_place_to_minirust(cfn, scope, typed)?) |
| 367 | ✗ | (let ref_value = addr_of(cfn, mr_place, kind, &typed.ty)?) |
| 368 | N/A | (let code = cfn.fresh_code_block()) |
| ──────── ("ref") | ||
| 370 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Ref { kind, lt: _, place }) => ( code.assign(target, ref_value), global, cfn, )) |
struct| Line | Coverage | Source |
|---|---|---|
| 378 | ✗ | (let fields = resolve_struct_fields(cfn, adt_id, turbofish)?) |
| 379 | ✗ | (let (temps, cfn) = alloc_temps_for_fields(cfn, fields)?) |
| 380 | N/A | (let code = cfn.fresh_code_block()) |
| 381 | ✗ | (for_all(field_expr in field_exprs) with(code, global, cfn) (let (_, temp) = fields .iter() .zip(temps.iter()) .find(|(field, _)| field.name == field_expr.name) .ok_or_else(|| anyhow::anyhow!("unknown field {:?}", field_expr.name))?) (codegen_expr_into(global, cfn, scope, temp, &field_expr.value) => (field_code, global, cfn)) (let (code, cfn) = cfn.append_from(code, field_code))) |
| 389 | ✗ | (let struct_value = tuple_value(&temps, adt_id, turbofish, &cfn)?) |
| ──────── ("struct") | ||
| 391 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::Struct { field_exprs, adt_id, turbofish }) => ( code.assign(target, struct_value), global, cfn, )) |
binop| Line | Coverage | Source |
|---|---|---|
| 398 | ✗ | (type_expr(cfn, scope, lhs) => lhs_ty) |
| 399 | ✗ | (let (lhs_temp, cfn) = cfn.alloc_temp(&lhs_ty)?) |
| 400 | ✗ | (codegen_expr_into(global, cfn, scope, lhs_temp, lhs) => (code, global, cfn)) |
| 401 | ✗ | (type_expr(cfn, scope, rhs) => rhs_ty) |
| 402 | ✗ | (let (rhs_temp, cfn) = cfn.alloc_temp(&rhs_ty)?) |
| 403 | ✗ | (codegen_expr_into(global, cfn, scope, rhs_temp, rhs) => (rhs_code, global, cfn)) |
| 404 | N/A | (let (code, cfn) = cfn.append_from(code, rhs_code)) |
| ──────── ("binop") | ||
| 406 | ✗ | (codegen_expr_into(global, cfn, scope, target, Expr::BinOp { lhs, op, rhs }) => ( code.assign(target, binop(op, load(lhs_temp), load(rhs_temp))), global, cfn, )) |