Skip to content

optimize v3 ownership checking - #27708

Merged
medvednikov merged 3 commits into
masterfrom
agent/optimize-v3-checker
Jul 8, 2026
Merged

medvednikov merged 3 commits into
masterfrom
agent/optimize-v3-checker

Conversation

@medvednikov

Copy link
Copy Markdown
Member

Summary

  • enables parallel semantic checking for ownership-enabled V3 compiles by forking and merging ownership state
  • reduces ownership pre-scan work by using top-level indexes, reusable function scan items, void-return skips, and cheaper marker lookups
  • preserves statement-level ownership effects in the parallel checker path and adds a fast path for discarded array element methods

Why

Compiling ripgrep_v with -prod -ownership spent around 2.9s in the V3 checker. The main cost was ownership collection/pre-scan plus serialized semantic checking. This change keeps ownership diagnostics intact while allowing the checker to use the existing parallel function-body scheduler.

Validation

  • ./v -g -keepc -o ./vnew cmd/v
  • ./vnew fmt -w vlib/v3/types/checker.v vlib/v3/types/checker_ownership_d_ownership.v vlib/v3/types/checker_parallel.v
  • ./vnew -silent test vlib/v3/tests/review_ownership_pr_regressions_test.v
  • direct ownership regression for discarded arr.first() moving arr[0]
  • ./vnew -prod -ownership -o /tmp/rg_v_prod_opt /Users/alexander/code/ripgrep_v/main.v reached check (parallel) 996.13 ms on the final code

Broader V3 suites were not clean in this worktree before this PR: vlib/v3/tests/type_checker_errors_test.v still has bad_multi_return_match_tail_return compiling successfully even with -no-parallel, and a heavy veb ownership case was killed by the OS during earlier validation.

@medvednikov
medvednikov marked this pull request as ready for review July 8, 2026 21:37

@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: 5cd5065419

ℹ️ 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 on lines +481 to +483
$if ownership ? {
w.ownership_fork_for_parallel_check(tc)
}

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 Isolate signature maps before ownership workers

Cloning only the ownership state here is not enough once -d ownership is allowed to use the pthread checker: while checking function bodies, ownership_fn_value_name_from_expr() can call ownership_register_fn_literal_signature(), which mutates fn_ret_types/fn_param_types through register_fn_signature(). Those maps are still shared by the shallow-copied TypeChecker, so non-Windows builds with enough functions to enter the parallel path and function literals in checked bodies can race on shared map writes or leave nondeterministic/lost synthetic signatures; the worker needs private/merged signature maps or ownership should remain serial for that path.

Useful? React with πŸ‘Β / πŸ‘Ž.

@medvednikov
medvednikov force-pushed the master branch 2 times, most recently from ec6ffa6 to bf0fdff Compare July 8, 2026 22:07

@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: ef66989a7b

ℹ️ 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/types/checker_parallel.v Outdated
if tc.pending_ierror_errors.len > 0 {
tc.collect_selected_file_called_fns()
}
tc.filter_pending_ierror_errors()

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 Re-sort diagnostics after filtering pending IError errors

When diagnostic_files is set and any invalid-IError-return candidates are pending, filter_pending_ierror_errors() appends the selected candidates to tc.errors after run_parallel_check() has already sorted and deduped the worker errors. In parallel chunks (and even the serial fallback through this path), those appended diagnostics can be left out of source order or duplicated; the previous flow sorted again after filtering, so this path should do the same after line 82 when pending errors may have been added.

Useful? React with πŸ‘Β / πŸ‘Ž.

@medvednikov
medvednikov merged commit 43f1e57 into master Jul 8, 2026
0 of 2 checks passed
rilaaax pushed a commit to rilaaax/v that referenced this pull request Jul 9, 2026
@JalonSolov
JalonSolov deleted the agent/optimize-v3-checker branch July 28, 2026 01:18
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