vx-lang / vx-lang/Vx

comptime · phase 2: structs in the evaluator

Open
#573 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Phase 2 of compile-time values, after #562 (fixed-size arrays of scalars).

Scope

A struct as a compile-time value: build one, read a field, write a field.

In scope

  • A struct variant in Value (src/hir/env.rs), holding the field names and their values.
  • Construction from a struct literal, S { f : 1, g : 2 }.
  • Field read, s.f.
  • Field write, s.f = v.
  • Fields may hold anything the evaluator already holds, so a struct with an array field and
    an array of structs both follow from this plus #562.

Deferred

  • Methods on the struct. A method call is not evaluated at all today (#560), so nothing here
    depends on it and nothing here fixes it.
  • Enums and their variants.

What exists now

eval_expr (src/hir/stmt.rs) has no arm for a struct literal or for field access, and
eval_statement and check_assign_stmt only handle an identifier or an index on the left of
an assignment. A s.f = v therefore falls through both.

The rule this has to keep

The same one #562 established. A field write the evaluator cannot carry out drops the whole
struct rather than leaving the old field values readable. check_assign_stmt already has a
place_root helper that walks a place expression down to the variable it writes through;
extending it to cover a field access is how a s.f = v and a s.a[i] = v reach the right
variable.

Two related holes are worth reading before starting, because both were wrong values rather
than missing ones: #558 and #569.

Tests to add

  • Construct, field read, field write, each with a false assert so the fixture can go red.
  • A field write the evaluator cannot compute, checked with a pair of contradictory asserts
    that are both expected to be accepted. That pair is the oracle for "the evaluator holds no
    value here".
  • A struct holding an array, and an array holding structs, once #562 has landed.

Related: #562, #558, #560, #569.

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 with src/hir/env.rs, src/hir/stmt.rs, eval_expr, eval_statement, and check_assign_stmt, including its place_root helper. Read #562, #558, and #569 before adding coverage for struct construction, field reads and writes, and unsupported writes. Done means the requested false-assert fixtures expose each behavior, including contradictory asserts for dropped values and nested struct/array cases after #562.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.