Skip to content

v3: clean up transform helpers/inits; cmd/v: fix v3.v bootstrap dispatch on macOS - #28157

Merged
medvednikov merged 3 commits into
masterfrom
v3-transform-helper-cleanup
Aug 22, 2026
Merged

v3: clean up transform helpers/inits; cmd/v: fix v3.v bootstrap dispatch on macOS#28157
medvednikov merged 3 commits into
masterfrom
v3-transform-helper-cleanup

Conversation

@medvednikov

Copy link
Copy Markdown
Member

What

Two related changes that came out of resolving the XTODO markers in vlib/v3/transform/transform.v and then verifying self-host performance.

1. v3: transform helper/init cleanup (resolves the 3 XTODOs)

  • Remove the arr1/arr2/arr3/arr4 wrappers and node_kind_id, replacing every call site in the transform module with plain array literals ([a, b, ...]) and int(node.kind).
  • Drop the empty map[...]{} initializers from new_transformer_view — V auto-initializes those struct map fields, so only the AST/type-checker views, used_fns, and the pointer-backed lookup caches (which would otherwise be nil) need explicit values.
  • Keep the V3_STR_CAP experimental autostr-cap override (documented in fn.v) and replace the // XTODO is this needed marker with an explanatory comment.

2. cmd/v: route a bare v3.v bootstrap to the compat compiler on macOS

The macOS dispatch gates only recognized the v3 bootstrap by the literal path vlib/v3/v3.v. Building it as a bare v3.v from inside vlib/v3 (e.g. ../../v -prealloc -prod -o v3 v3.v) was treated as an ordinary .v build and delegated to the embedded V3 driver instead of the compatibility compiler (which then crashes and only survives via the auto-fallback retry). A shared is_macos_v3_compiler_bootstrap() helper now also resolves a file literally named v3.v through its real path, and both is_macos_v3_relevant_command and macos_v3_force_requested use it so they can't drift. The extra real-path lookup only runs for a v3.v target.

Verification

  • v fmt -verify clean on all changed files; v3 builds.

  • Transform unit tests (v test vlib/v3/transform/) pass 7/7.

  • New dispatcher test test_macos_v3_compiler_bootstrap_is_detected_from_any_cwd; before/after, the bare-v3.v invocation goes from "embedded V3 invoked → segfault → fallback" to a clean compat build.

  • No self-host performance regression (-prod, 5 runs each, baseline @ HEAD vs. this branch):

    metric baseline this PR
    transform, median 121.4 ms 118.6 ms
    transform, min 111.4 ms 109.3 ms
    transform RSS ~1.09 GB ~1.09 GB
    cgen, mean ~152.8 ms ~152.9 ms
    prod v3 binary size 14,096,904 B 14,096,904 B (byte-identical)

🤖 Generated with Claude Code

medvednikov and others added 2 commits August 22, 2026 11:01
…nsform

Resolve the three XTODO markers in vlib/v3/transform/transform.v:

- Drop the arr1/arr2/arr3/arr4 helper wrappers and node_kind_id in favor
  of plain array literals and int(node.kind) at every call site across the
  transform module.
- Remove the empty map initializers from new_transformer_view; V
  auto-initializes those struct map fields, so only the AST/type-checker
  views, used_fns, and the pointer-backed lookup caches need explicit
  values.
- Keep the V3_STR_CAP experimental autostr-cap override (documented in
  fn.v) and replace the "is this needed" marker with an explanatory
  comment.

No behavior change: transform unit tests pass and the v3 self-host
transform phase and peak RSS are unchanged (verified before/after), with a
byte-identical prod v3 binary.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The macOS dispatch gates only recognized the v3 bootstrap by the literal
path vlib/v3/v3.v, so building it as a bare `v3.v` from inside vlib/v3
(e.g. `../../v -prealloc -prod -o v3 v3.v`) was treated as an ordinary .v
build and delegated to the embedded V3 driver instead of the
compatibility compiler.

Add a shared is_macos_v3_compiler_bootstrap() helper that also resolves a
file literally named v3.v through its real path, and use it in both
is_macos_v3_relevant_command and macos_v3_force_requested so the two gates
cannot drift. The extra real-path lookup only runs for a v3.v target.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@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: 562f9f5c48

ℹ️ 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 cmd/v/macos_v3_test.v Outdated

// A bare `v3.v` invoked from inside vlib/v3 must resolve to the bootstrap so
// it builds with the compatibility compiler instead of the embedded V3 driver.
repo_root := os.dir(os.dir(os.real_path(@FILE)))

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 Ascend one more directory before testing the bare path

With this test located at cmd/v/macos_v3_test.v, two os.dir calls resolve repo_root to <repo>/cmd, so v3_dir becomes <repo>/cmd/vlib/v3. The existence guard is therefore false in a normal checkout, and the key bare and dotted assertions never run, allowing the exact bare-v3.v dispatch regression this test targets to pass unnoticed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch — the two os.dir calls resolved repo_root to <repo>/cmd, so the vlib/v3 existence guard was always false and the key assertions never ran.

Fixed in 3b22b60 by dropping the @FILE-relative guard entirely: the test now builds an isolated <tmp>/vlib/v3/v3.v (plus a sibling non-bootstrap v3.v) and chdirs into it, so the real-path resolution is exercised unconditionally regardless of where the test file lives. I also confirmed the test now fails on assert bare if the helper's real-path branch is removed, so the regression can no longer pass unnoticed.

The previous test derived the repo root with two os.dir calls from a file
at cmd/v/macos_v3_test.v, which resolves to <repo>/cmd, so the vlib/v3
existence guard was always false and the bare-`v3.v` assertions never ran.

Build an isolated <tmp>/vlib/v3/v3.v (and a sibling non-bootstrap v3.v)
instead, so the real-path resolution is exercised unconditionally
regardless of where the test file lives, and add the negative case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@medvednikov
medvednikov merged commit 4fbc55a into master Aug 22, 2026
53 of 78 checks passed
@JalonSolov
JalonSolov deleted the v3-transform-helper-cleanup branch August 24, 2026 19:15
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