v3: fix cmd/v compilation path - #27519
Conversation
- 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.
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
| 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");') |
There was a problem hiding this comment.
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 👍 / 👎.
| if ret_node.kind == .assoc { | ||
| g.gen_return_assoc(ret_node) | ||
| return |
There was a problem hiding this comment.
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 👍 / 👎.
| for candidate, _ in g.tc.fn_param_types { | ||
| if candidate.ends_with('.${short_method}') { | ||
| return candidate |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
cmd/v.v3.astpipeline now that v3 is flat-AST only.nonevalue instead ofOptional tmp = 0.v3 -prod ...with the flag before the input file and verify it uses optimizedcc -O2compilation.v3 -o file.c ...as C-only emission: writefile.cand skip C compiler invocation.Commits
c23542951v3: interface dispatch + self-hosting codegen fixesd9048e639more v1 fixes3fd290b4av3: remove old structured ast pathb9b66cef3more v11ccf48451v3: fix optional if expression temp inite04b9cfecv3: test prod flag before inputbe9535156v3: only emit C for .c outputTests
./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_onlycd 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.vstill reports unsupported generic diagnostics.