Skip to content

Commit ab3676e

Browse files
gHashTagDmitrii Vasilevgithub-actions[bot]SSD DDDclaude
authored
fix(codegen): emit type aliases as comments in gen-verilog (not invalid params) (#1025)
* trigger: force railway redeploy for direct access Refs #1025 * Update NotebookLM sync status [skip ci] Refs #1025 * Update NotebookLM sync status [skip ci] Refs #1025 * fix(codegen): emit type aliases as comments in gen-verilog (not invalid params) gen_verilog_const emitted `const GF16 = u16;` / `const TernaryWord = [N]u8;` as invalid `parameter [31:0] GF16 = u16;` (non-numeric RHS, uncompilable). Verilog has no typedef -> emit a comment. Guard excludes `{...}` initializers so array-LUT consts ([32]u16{0x..}) are not misclassified. Verified regen-vs-regen on master: zero regressions; type-alias error class removed. Closes #1027 Refs #979 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Dmitrii Vasilev <admin@t27.ai> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: SSD DDD <ssdm4@MacBook-Pro.local> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent d9b76c5 commit ab3676e

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

bootstrap/src/compiler.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,6 +3906,24 @@ impl VerilogCodegen {
39063906
return;
39073907
}
39083908

3909+
// Type alias (e.g. `const GF16 = u16;`, `const TernaryWord = [N]u8;`).
3910+
// Verilog has no typedef and the alias carries no runtime value, so emitting it
3911+
// as `parameter [31:0] GF16 = u16;` is invalid (non-numeric RHS). Emit a comment.
3912+
if node.children.len() == 1 && node.children[0].kind == NodeKind::ExprIdentifier {
3913+
let target = &node.children[0].name;
3914+
// A pure type (alias). NOT a value: array literals like `[32]u16{0x..}` carry
3915+
// a `{...}` initializer and are LUT constants, not type aliases — exclude those.
3916+
let looks_like_type = !target.contains('{')
3917+
&& (target.starts_with('[')
3918+
|| target.chars().next().map(|c| c.is_uppercase()).unwrap_or(false)
3919+
|| matches!(target.as_str(),
3920+
"u8"|"u16"|"u32"|"u64"|"usize"|"i8"|"i16"|"i32"|"i64"|"bool"|"trit"|"f32"|"f64"));
3921+
if looks_like_type {
3922+
self.write_line(&format!("// type alias: {} = {} (no Verilog typedef)", node.name, target));
3923+
return;
3924+
}
3925+
}
3926+
39093927
// Determine if this is an array constant (LUT)
39103928
let is_array = !node.extra_size.is_empty();
39113929

docs/NOW.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Last updated: 2026-06-01
44

5+
## fix-gen-verilog-typealias -- type aliases emitted as comments, not invalid params (Closes #1027 Refs #979)
6+
7+
- **WHERE** (codegen): `bootstrap/gen_verilog.t27` / `bootstrap/gen_verilog_const` were emitting `const GF16 = u16;` and `const TernaryWord = [N]u8;` as `parameter [31:0] GF16 = u16;` -- a non-numeric RHS that does not compile in any Verilog flavor. Verilog has no typedef construct, so the codegen now emits these as line comments (`// type alias: GF16 = u16`). The detection guard explicitly excludes `{...}` array initializers so array-LUT consts (e.g. `[32]u16{0x..}` exp/mantissa LUTs) keep their existing correct emission path. Verified regen-vs-regen on master: zero regressions, the type-alias-as-parameter error class is gone.
8+
- **Why**: this was a silent codegen bug -- any spec that introduced a type alias produced uncompilable Verilog, but the failure surfaced only at the downstream Yosys/iverilog parse step rather than at codegen time, so it was misattributed for several waves. Fixing it at emission keeps the spec authoring contract (type aliases are legal in t27c) while honoring Verilog's lack of typedef. L6 untouched (gf16 SSOT and conformance JSON unchanged). Closes #1027. Refs #979.
9+
- **Anchor**: phi^2 + phi^-2 = 3
10+
511
## formats-catalog-ssot-77-polyglot -- Universal Numeric Format Catalog SSOT + 16-language codegen (Closes #1029)
612

713
- **WHERE** (numeric specs + bootstrap codegen + derived artefacts): new `specs/numeric/formats_catalog.t27` is the single source of truth for 77 numeric formats across 13 clusters (GoldenFloat 16, IEEE 754 binary 5, IEEE 754 decimal 3, ML low-precision 7, Posit/unum III 8, OCP MX 3, LNS 4, Historical Vendor 10, Integer/Fixed 8, Theoretical 4, Compression 4, Extended float 3, QuantTuned 2). t27c parse: clean (60 KB AST, exit 0). The spec uses only constructs t27c supports today (const + fn + module); per-format records live in a canonical CATALOG: line-comment block until t27c gains struct literals. new `tools/gen_formats_catalog.py` is the bootstrap codegen in the style of `bootstrap/t27c.py`, with 16 language emitters: originally Markdown, JSON, Python (dataclass), Rust (struct + const array), C (typedef + extern array), TypeScript (interface + export const); extended in this PR with Go (struct + slice), Zig (struct + const), Swift (struct + let), Java (Java-8 POJO with static final List, not record so it builds on javac 11), Kotlin (data class + listOf), C++17 (std::array + string_view), Verilog (.vh localparam bit-width header, strings omitted), Haskell (data record + list), OCaml (type record + list), Julia (struct + const tuple). All 16 artefacts in `gen/numeric/` contain exactly 77 records and pass ASCII + banned-word audit. Smoke-tested where toolchains available in the sandbox: gcc -c (C), g++ -c -std=c++17 (C++17, after one `}}};` -> `}};` fix), javac (Java POJO), python3 -c import (Python), JSON schema validation.

0 commit comments

Comments
 (0)