Commit 1f438e8
committed
fix(ssa): autobox values stored into
`Type::Any` lowers to `HirType::I64` because the slot is meant to
hold a `*mut DynamicBoxRepr` (the runtime tagged-box used for
type-erased storage and FFI). The runtime already exposes
`zyntax_box_i32`, `_i64`, `_f32`, `_f64`, `_bool`; the LLVM and
Cranelift backends already emit calls to them when an extern
parameter is declared `DynamicBox`. The struct literal lowering
just wasn't using them — it tried to raw-store the value into the
i64 slot, which crashed the LLVM backend at `Cannot select: i64 =
bitcast Constant:i32<42>` whenever the value's HIR type wasn't
already i64-shaped.
Now: in `TypedExpression::Struct` lowering (both value-type and
`@reference` paths), every field marked `Type::Any` in the
declaring class's `TypeDefinition` gets its value routed through
`zyntax_box_X` before the `InsertValue` / `Store`. Values that
are already i64-shaped (`I64`, `U64`, any `Ptr`) pass through
unchanged — the slot just holds them as the raw pointer / 64-bit
value. Unsupported value types fall through to the prior
behaviour (which we'll formalise as the unbox-on-read path lands).
Test: `struct Box { value: Any }` followed by `Box { value: 42 }`,
`Box { value: 3.14 }`, `Box { value: <ptr> }` — all now compile
and execute cleanly via the LLVM tier. Previously the i32 case
crashed at codegen, the f64 case silently mis-stored the bit
pattern, and the pointer case worked by accident.
Existing kernels unaffected — none of them use `Any` fields, so
the autobox helper is a no-op for them. 248 compiler tests + all
embed tests pass; clippy clean.
Followup: insert matching unbox calls on `Type::Any` field reads
when the use-site has a known target type. Without that, reading
`b.value` returns the raw box pointer (i64) and the user has to
manually call `zyntax_box_get_X` — which works but isn't
ergonomic.Type::Any struct fields1 parent d9e1180 commit 1f438e8
1 file changed
Lines changed: 83 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4912 | 4912 | | |
4913 | 4913 | | |
4914 | 4914 | | |
| 4915 | + | |
4915 | 4916 | | |
4916 | | - | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
| 4923 | + | |
4917 | 4924 | | |
4918 | 4925 | | |
4919 | 4926 | | |
| |||
4972 | 4979 | | |
4973 | 4980 | | |
4974 | 4981 | | |
| 4982 | + | |
| 4983 | + | |
| 4984 | + | |
| 4985 | + | |
| 4986 | + | |
| 4987 | + | |
| 4988 | + | |
| 4989 | + | |
| 4990 | + | |
| 4991 | + | |
4975 | 4992 | | |
4976 | 4993 | | |
4977 | 4994 | | |
4978 | 4995 | | |
4979 | 4996 | | |
4980 | | - | |
| 4997 | + | |
| 4998 | + | |
| 4999 | + | |
| 5000 | + | |
| 5001 | + | |
| 5002 | + | |
4981 | 5003 | | |
4982 | 5004 | | |
4983 | 5005 | | |
| |||
7400 | 7422 | | |
7401 | 7423 | | |
7402 | 7424 | | |
| 7425 | + | |
| 7426 | + | |
| 7427 | + | |
| 7428 | + | |
| 7429 | + | |
| 7430 | + | |
| 7431 | + | |
| 7432 | + | |
| 7433 | + | |
| 7434 | + | |
| 7435 | + | |
| 7436 | + | |
| 7437 | + | |
| 7438 | + | |
| 7439 | + | |
| 7440 | + | |
| 7441 | + | |
| 7442 | + | |
| 7443 | + | |
| 7444 | + | |
| 7445 | + | |
| 7446 | + | |
| 7447 | + | |
| 7448 | + | |
| 7449 | + | |
| 7450 | + | |
| 7451 | + | |
| 7452 | + | |
| 7453 | + | |
| 7454 | + | |
| 7455 | + | |
| 7456 | + | |
| 7457 | + | |
| 7458 | + | |
| 7459 | + | |
| 7460 | + | |
| 7461 | + | |
| 7462 | + | |
| 7463 | + | |
| 7464 | + | |
| 7465 | + | |
| 7466 | + | |
| 7467 | + | |
| 7468 | + | |
| 7469 | + | |
| 7470 | + | |
| 7471 | + | |
| 7472 | + | |
| 7473 | + | |
| 7474 | + | |
| 7475 | + | |
| 7476 | + | |
| 7477 | + | |
| 7478 | + | |
| 7479 | + | |
| 7480 | + | |
| 7481 | + | |
| 7482 | + | |
| 7483 | + | |
7403 | 7484 | | |
7404 | 7485 | | |
7405 | 7486 | | |
| |||
0 commit comments