vx-lang / vx-lang/Vx

flat codegen: lower the remaining declined expression constructs (calls, match, arrays, logical ops)

Open
#239 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

codegen enhancement
Dominant language
Rust
Stars
14
Forks
2
Avg merge
12h 42m
Merged PRs (30d)
61

Description

Umbrella for widening the flat path (src/hir/flatten.rs) to lower the expression constructs it currently declines entirely (falls back to the AST path). These are the last non-scalar/non-tensor gaps in lower_expr; each is independent and can be split into its own PR/issue. Named here so the coercion follow-up (below) has a home.

Current decline points (the other => … catch-all in lower_expr, surfaced by VX_FLAT_DBG=1):

  • Method calls (Expr::MethodCall, except with_memory which is transparent, line ~624). Needs the receiver-GID + method-name resolution the frozen registry already exposes (registry.methods, hiraditya/Vx.1#218), receiver lowering, and monomorph handling. Overlaps the stdlib-method surface.
  • Closure / function-pointer calls (Expr::Closure, Expr::IndirectCall). The AST models a closure as an !llvm.struct<(ptr, ptr)> fat pointer and calls via func.call_indirect (codegen/lower/expr.rs ~2095–2320). Largest item.
  • Value-producing match (Expr::Match in expression/tail position). lower_match is statement-form only today (#227); a value form stores each arm's result into a slot (like the value-if, hiraditya/Vx.1#201). Overlaps data-carrying enums (#233) for payload binds, but a value-match over payload-free enums is tractable now.
  • Array literals (Expr::Array as a value; today only accepted as the shape arg of Tensor<T>([…]), line ~1102).
  • Logical ops (Expr::LogicalOp — short-circuit && / ||). The AST lowers these to control flow; the flat path can emit the same cf.cond_br skeleton it already uses for if.

Note: the intrinsic calls (dot/sum/max/min, Tensor<T>(…), print/print!) are already lowered — they are not in this list; their arguments are tensors/dims, not scalars needing coercion.

Coercion follow-up (why this is filed now). hiraditya/Vx#238 materialized implicit coercions at every is_assignable site the flat path reaches. The sites it doesn't reach are exactly the call-argument / match-arm / array-element positions inside these declined constructs. So once a construct here is lowered, add a Lowerer::coerce_val(v, target) at its value positions (a one-liner each) — that closes hiraditya/Vx#238's residue for it. No separate coercion issue is needed; it rides on each construct's lowering.

Acceptance (per construct). The construct lowers through the flat path with JIT parity vs --legacy-codegen; full-corpus flat-vs-AST parity holds; coercion added at its value positions.

Part of the flat-codegen convergence (#200/#201).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/hir/flatten.rs at lower_expr and inspect the listed decline points, then compare the relevant AST lowering in codegen/lower/expr.rs and the frozen registry methods. Choose one construct, implement its flat-path lowering and coercion at its value positions, and verify JIT parity with --legacy-codegen plus full-corpus flat-vs-AST parity.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.