Skip to content

v3: fix cmd/v compilation path - #27519

Merged
medvednikov merged 21 commits into
masterfrom
codex/v3-cmd-v-compilation-fixes
Jun 21, 2026
Merged

v3: fix cmd/v compilation path#27519
medvednikov merged 21 commits into
masterfrom
codex/v3-cmd-v-compilation-fixes

Conversation

@medvednikov

@medvednikov medvednikov commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix v3 parser/type-checker/transform/codegen paths needed for compiling more of cmd/v.
  • Extend v3 C backend handling around interfaces, structs, options/results, and generated C names.
  • Remove the obsolete structured v3.ast pipeline now that v3 is flat-AST only.
  • Fix optional-valued if-expression temps so C codegen emits a typed optional none value instead of Optional tmp = 0.
  • Cover v3 -prod ... with the flag before the input file and verify it uses optimized cc -O2 compilation.
  • Treat v3 -o file.c ... as C-only emission: write file.c and skip C compiler invocation.

Commits

  • c23542951 v3: interface dispatch + self-hosting codegen fixes
  • d9048e639 more v1 fixes
  • 3fd290b4a v3: remove old structured ast path
  • b9b66cef3 more v1
  • 1ccf48451 v3: fix optional if expression temp init
  • e04b9cfec v3: test prod flag before input
  • be9535156 v3: only emit C for .c output

Tests

  • ./vnew fmt -w vlib/v3/gen/c/names.v
  • ./vnew check-md vlib/v3/README.md
  • ./vnew -silent vlib/v3/tests/c_global_static_codegen_test.v
  • ./vnew -silent vlib/v3/tests/ssa_builder_parity_test.v
  • ./vnew -silent vlib/v3/tests/option_arg_codegen_test.v
  • ./vnew -silent vlib/v3/tests/prod_flag_test.v
  • ./vnew -silent vlib/v3/tests/c_output_only_test.v
  • ./vnew -o /tmp/v3_prod_flag_test vlib/v3/v3.v && /tmp/v3_prod_flag_test -prod vlib/v3/tests/hello.v -o /tmp/v3_prod_hello && /tmp/v3_prod_hello
  • ./vnew -o /tmp/v3_c_only_smoke vlib/v3/v3.v && rm -f /tmp/v3_smoke_only /tmp/v3_smoke_only.c && /tmp/v3_c_only_smoke -o /tmp/v3_smoke_only.c vlib/v3/tests/hello.v; test -f /tmp/v3_smoke_only.c && test ! -e /tmp/v3_smoke_only
  • cd vlib/v3 && ../../vnew -gc none -prod -o v3 v3.v && ./v3 -parallel-transform -parallel -o v4 v3.v && ./v4 -o v5 v3.v && ./v5 -o v6 v3.v
  • ./vnew -silent test vlib/v3/ - 17 passed, 1 failed: vlib/v3/tests/generics_test.v still reports unsupported generic diagnostics.

- Implement interface method dispatch (switch-on-_typ): boxed value carries
  _typ/_object; per-interface implementer ids; abstract-method dispatch fns;
  markused reachability for implementers; module init() calls in _vinit.
- Fix interface method param parsing (named params like `seed_data []u32`).
- Use abstract-method set for type-implements-interface checks.
- Apply nested struct field defaults in struct literals (e.g. min_len=999999).
- Emit &Struct{} global initializers as inline memdup heap allocations.
- Preserve &&/|| short-circuit when a right operand lowers to pending stmts
  (wrap in a statement-expression block).
- Emit @[if flag ?] functions as no-op stubs when the flag is off.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9b66cef34

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/transform/transform.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ccf484514

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/gen/c/cleanc.v
Comment thread vlib/v3/parser/parser.v
Comment thread vlib/v3/transform/array.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be9535156a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/parser/parser.v

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be227276fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/gen/c/fn.v

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68172247d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/gen/c/cleanc.v Outdated
Comment thread vlib/v3/transform/transform.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f379d3f234

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/transform/interface.v
Comment thread vlib/v3/parser/parser.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9f4757e71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/parser/parser.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4daa4ce4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/gen/c/cleanc.v Outdated
Comment thread vlib/v3/transform/for.v

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 343ea6e25c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/parser/parser.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a200a779b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/parser/parser.v

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9579f5e12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/gen/c/stmt.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a344e62843

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v3/gen/c/fn.v
g.writeln('\t\tif (!v3_same_exe) {')
g.writeln('\t\t\tFILE* v3_in = fopen(v3_src, "rb");')
g.writeln('\t\t\tif (v3_in != NULL) {')
g.writeln('\t\t\t\tFILE* v3_out = fopen(v3_vexe_target, "wb");')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid overwriting the checkout compiler for VEXE

When a v3-built cmd/v is executed with VEXE unset, v3_vexe_target is computed as ${root}/<argv0 basename> and this wb open truncates that path. Running a self-hosted compiler from /tmp/v therefore overwrites ${VEXEROOT}/v before setting the env var, leaving the repo's bootstrap compiler replaced. Set VEXE to the running executable or copy to a safe cache path instead of writing into the source root.

Useful? React with 👍 / 👎.

Comment thread vlib/v3/gen/c/stmt.v
Comment on lines +378 to +380
if ret_node.kind == .assoc {
g.gen_return_assoc(ret_node)
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run defers before assoc returns

When a function has pending defers and returns an assoc expression such as return Foo{base | x: 1}, this early path calls gen_return_assoc, which emits return tmp; itself; because gen_all_defers() is below and never reached, both block defers and defer(fn) callbacks registered before the return are skipped. Cache the assoc result and then run defers before returning, like the generic return path.

Useful? React with 👍 / 👎.

Comment thread vlib/v3/gen/c/fn.v
Comment on lines +1119 to +1121
for candidate, _ in g.tc.fn_param_types {
if candidate.ends_with('.${short_method}') {
return candidate

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require exact enum type for custom str methods

For a qualified enum such as a.Color, this suffix search treats any *.Color.str as proof that a.Color has a custom str; if only b.Color.str exists, the caller suppresses the built-in enum formatting path and falls through to emit a__Color__str, which is undefined. Only accept the exact resolved enum method name instead of matching by the short enum name.

Useful? React with 👍 / 👎.

@medvednikov
medvednikov merged commit 8520724 into master Jun 21, 2026
77 of 83 checks passed
@JalonSolov
JalonSolov deleted the codex/v3-cmd-v-compilation-fixes branch July 28, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant