From 6d462596b081181ba1dc1bb8964d72c8066058d2 Mon Sep 17 00:00:00 2001 From: antono2 Date: Sat, 5 Sep 2026 06:45:42 +0200 Subject: [PATCH 1/3] cgen: preserve declarations used through aliases --- vlib/v/checker/checker.v | 2 +- vlib/v/gen/c/cgen.v | 35 +++++++++++++++++-- .../v/gen/c/testdata/alias_c_struct_field.out | 1 + vlib/v/gen/c/testdata/alias_c_struct_field.vv | 12 +++++++ .../gen/c/testdata/alias_of_explicit_enum.out | 1 + .../gen/c/testdata/alias_of_explicit_enum.vv | 15 ++++++++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 vlib/v/gen/c/testdata/alias_c_struct_field.out create mode 100644 vlib/v/gen/c/testdata/alias_c_struct_field.vv create mode 100644 vlib/v/gen/c/testdata/alias_of_explicit_enum.out create mode 100644 vlib/v/gen/c/testdata/alias_of_explicit_enum.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index d141d4e4102274..66e06bd4aa6499 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3137,7 +3137,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { } } field_name := node.field_name - mut sym := c.table.sym(typ) + mut sym := c.table.final_sym(typ) mut final_sym := c.table.final_sym(typ) if (typ.has_flag(.variadic) || final_sym.kind == .array_fixed) && field_name == 'len' { node.typ = ast.int_type diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 783bafca4fa016..209c213061fca3 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -9500,6 +9500,26 @@ fn (mut g Gen) debugger_stmt(node ast.DebuggerStmt) { g.write('}') } +fn (g &Gen) is_enum_type_used(enum_typ ast.Type) bool { + if !g.pref.skip_unused || enum_typ.idx() in g.table.used_features.used_syms { + return true + } + for sym in g.table.type_symbols { + if sym.kind != .alias || sym.idx !in g.table.used_features.used_syms { + continue + } + match sym.info { + ast.Alias { + if g.table.final_sym(sym.info.parent_type).idx == enum_typ.idx() { + return true + } + } + else {} + } + } + return false +} + fn (mut g Gen) enum_decl(node ast.EnumDecl) { enum_name := util.no_dots(node.name) is_flag := node.is_flag @@ -9530,10 +9550,19 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) { } // Explicit-size enums are emitted as typedef + defines, so all C compilers // (including tinyc) respect the selected storage size. - if g.is_cc_msvc || node.typ != ast.int_type { + mut needs_define_style := g.is_cc_msvc || node.typ != ast.int_type + if !needs_define_style { + for field in node.fields { + if field.has_expr && g.expr_string(field.expr).contains('v__') { + needs_define_style = true + break + } + } + } + if needs_define_style { mut last_value := '0' enum_typ_name := g.table.get_type_name(node.typ) - if g.pref.skip_unused && node.enum_typ !in g.table.used_features.used_syms { + if !g.is_enum_type_used(node.enum_typ) { return } g.enum_typedefs.writeln('') @@ -9556,7 +9585,7 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) { } return } - if g.pref.skip_unused && node.enum_typ !in g.table.used_features.used_syms { + if !g.is_enum_type_used(node.enum_typ) { return } g.enum_typedefs.writeln('') diff --git a/vlib/v/gen/c/testdata/alias_c_struct_field.out b/vlib/v/gen/c/testdata/alias_c_struct_field.out new file mode 100644 index 00000000000000..d81cc0710eb6cf --- /dev/null +++ b/vlib/v/gen/c/testdata/alias_c_struct_field.out @@ -0,0 +1 @@ +42 diff --git a/vlib/v/gen/c/testdata/alias_c_struct_field.vv b/vlib/v/gen/c/testdata/alias_c_struct_field.vv new file mode 100644 index 00000000000000..dbcece9bd42bbb --- /dev/null +++ b/vlib/v/gen/c/testdata/alias_c_struct_field.vv @@ -0,0 +1,12 @@ +struct C.NativeConfig { + value int +} + +type NativeConfig = C.NativeConfig + +fn main() { + config := NativeConfig{ + value: 42 + } + println(config.value) +} diff --git a/vlib/v/gen/c/testdata/alias_of_explicit_enum.out b/vlib/v/gen/c/testdata/alias_of_explicit_enum.out new file mode 100644 index 00000000000000..573541ac9702dd --- /dev/null +++ b/vlib/v/gen/c/testdata/alias_of_explicit_enum.out @@ -0,0 +1 @@ +0 diff --git a/vlib/v/gen/c/testdata/alias_of_explicit_enum.vv b/vlib/v/gen/c/testdata/alias_of_explicit_enum.vv new file mode 100644 index 00000000000000..16a596efc8cfe6 --- /dev/null +++ b/vlib/v/gen/c/testdata/alias_of_explicit_enum.vv @@ -0,0 +1,15 @@ +enum RasterizationMode as u32 { + default = 0 + max_enum = max_int +} + +type RasterizationModeExt = RasterizationMode + +struct Config { + mode RasterizationModeExt +} + +fn main() { + config := Config{} + println(u32(config.mode)) +} From 9714710ab04074223183a2304d30af86eb669dd2 Mon Sep 17 00:00:00 2001 From: antono3 <324856971+antono3@users.noreply.github.com> Date: Mon, 7 Sep 2026 09:10:59 +0200 Subject: [PATCH 2/3] ci: add temporary PR 28368 review workflow --- .github/workflows/codex_review_ci.yml | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/codex_review_ci.yml diff --git a/.github/workflows/codex_review_ci.yml b/.github/workflows/codex_review_ci.yml new file mode 100644 index 00000000000000..e1db10d22e0101 --- /dev/null +++ b/.github/workflows/codex_review_ci.yml @@ -0,0 +1,30 @@ +name: Codex PR review + +on: + push: + branches: + - 'codex/review-pr-28368' + workflow_dispatch: + +permissions: + contents: read + +jobs: + review-pr-28368: + runs-on: ubuntu-24.04 + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - name: Build V + run: make -j4 + - name: Run new fixtures with supported C compilers + run: | + set -euo pipefail + for cc in tcc gcc clang; do + test "$(./v -cc "$cc" run vlib/v/gen/c/testdata/alias_c_struct_field.vv)" = '42' + test "$(./v -cc "$cc" run vlib/v/gen/c/testdata/alias_of_explicit_enum.vv)" = '0' + done + - name: Run C-output regression suite + run: ./v test vlib/v/gen/c/coutput_test.v + - name: Run checker tests + run: ./v test vlib/v/checker From c23bd27671442586a3e4c2a1f71f039c385ea301 Mon Sep 17 00:00:00 2001 From: antono3 <324856971+antono3@users.noreply.github.com> Date: Mon, 7 Sep 2026 09:20:33 +0200 Subject: [PATCH 3/3] ci: exercise PR 28368 through compatibility compiler --- .github/workflows/codex_review_ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codex_review_ci.yml b/.github/workflows/codex_review_ci.yml index e1db10d22e0101..f2f2f6558d08c1 100644 --- a/.github/workflows/codex_review_ci.yml +++ b/.github/workflows/codex_review_ci.yml @@ -21,10 +21,10 @@ jobs: run: | set -euo pipefail for cc in tcc gcc clang; do - test "$(./v -cc "$cc" run vlib/v/gen/c/testdata/alias_c_struct_field.vv)" = '42' - test "$(./v -cc "$cc" run vlib/v/gen/c/testdata/alias_of_explicit_enum.vv)" = '0' + test "$(./v1_fallback -cc "$cc" run vlib/v/gen/c/testdata/alias_c_struct_field.vv)" = '42' + test "$(./v1_fallback -cc "$cc" run vlib/v/gen/c/testdata/alias_of_explicit_enum.vv)" = '0' done - name: Run C-output regression suite - run: ./v test vlib/v/gen/c/coutput_test.v + run: ./v1_fallback vlib/v/gen/c/coutput_test.v - name: Run checker tests - run: ./v test vlib/v/checker + run: ./v1_fallback test vlib/v/checker