Scalar layout definitions and ABI design—sounds routine, right? Except this time, our Cx language backend takes a significant leap forward. The Phase 8 Round 1 commit introduces the first formal ABI groundwork focusing on scalar layout and ABI documentation, assigning a solid design-first methodology.
Scalar Layout and the ABI Document
The latest commit lands on submain, adding 134 lines across two files, most notably docs/backend/cx_abi_v0.1.md. This document is where the scalar layout for Cx's integer types (t8, t16, t32, t64, t128), f64, and bool is locked. Details like size, alignment, representation, and how they map to Cranelift types are stipulated.
The alignment model follows natural alignment principles, meaning each type aligns according to its size. For example, t8 aligns to 1, t16 to 2, and t32 to 4. This choice simplifies the design for x86-64 and mirrors what typical C compilers produce. Right now, there are no packed or special alignment modes.
There's one crucial thing: i128 is emulated using two i64 values instead of having native support, as it would in LLVM. Not a hurdle for correctness but a known performance consideration.
On the coding side, we see new size_bytes() and align_bytes() methods added to IrType in src/ir/types.rs. Seven unit tests, each focusing on different scalar types, now ensure that sizes and alignments are correctly handled. These are strictly Rust-level tests—not touching the main testing matrix, which sits impeccably at 72/72.
Design-First Mentality
This phase marks a shift to documenting before implementing—a design-first mantra. The ABI document locks some scalar layout decisions with accompanying tests, marking them as LOCKED, whereas OPEN marks those awaiting further exploration.
Among the interesting OPEN topics:
- TBool Representation involves complexities with its three-state value (true/false/unknown) handling across function calls.
- String Layout in JIT Mode and Struct Layout require alignment and padding rules that need drafting.
- Array and Enum Layout are potential upcoming challenges.
- Copy Parameter Convention remains undecided for call handling.
This approach sets a clear path and helps prevent technical debt accruing from hasty, undocumented choices.
The Submain Gap
Despite putting substantial work into submain, the main branch hasn't seen these fruits yet. Now stacking up to thirteen commits including the multi-file import pipeline—critical for the 0.1 release—plus bug fixes and additional tests, submain is becoming the storehouse of progress. The import pipeline is particularly vital and ready but sits awaiting integration.
What's Next?
With the scalar layout solidified, the focus shifts toward more nuanced decisions like struct layout and TBool representation, mostly because these elements already have a presence in the frontend. However, the need to merge submain to main grows pressing, especially with pending tasks like the test runner and assert infrastructure still blocking essentials for the 0.1 release. Similarly, the error model (Result) is crucial yet stalled.
Steps from here involve wrapping up the backend tasks and addressing these blockers, possibly setting the stage for the next major release.
Follow the Cx language project:
- Website: cx-lang.com
- GitHub: github.com/COMMENTERTHE9/Cx_lang
- Dev.to: dev.to/commenterthe9
- Bluesky: thecomment.bsky.social
- Twitter/X: @commenterthe9
Originally published at https://cx-lang.com/blog/2026-03-27
Top comments (0)