Skip to content

cgen: preserve standalone poll and native-cache helpers - #32297

Merged
medvednikov merged 3 commits into
masterfrom
fix/native-cache-headerless-20261113
Nov 13, 2026
Merged

medvednikov merged 3 commits into
masterfrom
fix/native-cache-headerless-20261113

Conversation

@medvednikov

@medvednikov medvednikov commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

The shipped os poll header forced otherwise standalone programs into SDK-backed declarations, breaking poll bindings and cache reuse. The native-cache publication insert separately introduced headers into portable compiler snapshots.

Recognize these exact shipped interfaces and supply their standalone implementations in the generated preamble. Share cache-publication implementation with the SDK-backed header, preserving atomic hard-link publication and Linux RENAME_NOREPLACE fallback. No C headers are scanned or expanded by V.

Validation: poll coexistence and warm-cache regressions, mmap ownership, cache builtin reuse, full headerless compiler tests (including cross-target Clang checks), and full vself tests pass. The native publication tests and a headerless mock-Linux fallback/error-routing harness pass. The aggregate compiler-error suite passed 1,886 cases with one skip, and all 104 output fixtures completed without errors. Validation is limited to these and the focused checks above; the full compiler suite and paired instruction comparison remain incomplete. No test expectations are relaxed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T07:31:41.434130Z
We couldn’t complete this review. Comment @codex review to try again.
0e7a8ac Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@medvednikov medvednikov left a comment

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.

Reviewed d6fec3c4beb844d9e53307d066c02d26baaa6f2d for correctness. CI status and logs were excluded.

One C++ linkage issue in the new headerless native-cache helper is noted inline.

Rebuilt the candidate compiler and passed fd_set_poll_test.c.v and native_object_cache_noreplace_test.c.v on Linux. Native C probes also passed publication, no-replacement, fallback, and error-propagation checks. The SDK-backed include retains the original header's directory, so its relative implementation include resolves correctly.

For the C++ finding, a paired native test of the exact helper block links with the baseline SDK header, fails with the candidate's raw declarations, and links after adding C linkage to those two declarations. This is a reduced reproduction: the ordinary driver unit-test fixture selected SDK headers, and a full V driver C++ build was not completed.

Comment thread vlib/v/gen/c/bootstrap_runtime.v Outdated
Comment on lines +12 to +14
g.writeln('int link(char*, char*);')
g.writeln('#if defined(__linux__)')
g.writeln('long syscall(long, ...);')

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.

[P2] Preserve C linkage for the standalone libc prototypes

When a driver/compiler unit takes this headerless path with the C++ backend (-cc g++), these raw declarations acquire C++ linkage. The preceding headerless_libc_preamble does not declare either function, and collect_preserved_c_fns below suppresses their normal declarations through cpp_c_linkage. The embedded publication helper consequently refers to mangled link(char*, char*) and syscall(long, ...) symbols instead of libc's C symbols.

A native C++ comparison using this exact helper block links with the baseline SDK-backed header, fails on the candidate with those two undefined references, and links after adding extern "C" to just these declarations. This is a reduced helper reproduction, not a completed end-to-end V C++ build. Please emit these prototypes through g.cpp_c_linkage or an equivalent C-linkage guard.

@medvednikov medvednikov left a comment

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.

Re-reviewed d6fec3c4beb844d9e53307d066c02d26baaa6f2d, ignoring CI status and logs.

Two P2 issues remain:

  1. The existing C++ linkage finding is confirmed on an actual generated compiler translation unit. With this exact-head compiler, ./v -cc g++ -gc none -nocache -o compiler.c cmd/v selects the new headerless native-cache helper. G++ rejects the generated compiler because its raw syscall(long, ...) declaration has C++ linkage and conflicts with the later extern "C" declaration used by the gettid compatibility helper. The same generation and syntax check passes at the exact base. Wrapping only the two new libc prototypes in extern "C" in a scratch copy also makes the candidate pass. Please use g.cpp_c_linkage; the existing thread is #32297 (comment).
  2. The newly embedded implementation is missing from the compiler runtime-input fingerprint. The focused existing coverage test fails on the new embed, and runtime-reading backend consumers need this input in the cache salt. See the new inline finding.

Validation: rebuilt the exact candidate compiler; compared complete candidate/base generated cmd/v translation units with G++ 14.2.0 (-std=gnu++20 -fpermissive -w -fsyntax-only -x c++); ran test_module_cache_compiler_runtime_inputs_cover_compiler_embedded_files with the exact-head compiler and fallback disabled. The generated C++ was syntax-checked, not linked or executed. No stale cached binary reproduction is claimed.

g.writeln('long syscall(long, ...);')
g.writeln('#endif')
g.writeln('#endif')
g.write($embed_file('@VEXEROOT/vlib/v/driver/native_object_cache_impl.c').to_string())

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.

[P2] Fingerprint the newly embedded native-cache implementation

This new $embed_file target is absent from v3_cache_compiler_runtime_inputs in driver.v. That list contributes the running backend's external inputs to the cache salt for development/older-bootstrap consumers that read embedded files at runtime; changing this implementation would leave that part of the cache identity unchanged. Please add vlib/v/driver/native_object_cache_impl.c to the list alongside the other embedded runtime inputs. The existing focused test test_module_cache_compiler_runtime_inputs_cover_compiler_embedded_files reproducibly fails at cache_prune_test.v:206 on this exact head and names this new embed. Modern compiler self-builds that embed the bytes are separately covered by executable identity, but that does not cover the runtime-reading cases.

@medvednikov

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link
Copy Markdown
Member Author

CI-repair follow-up on current head 0e7a8ac82fac8bdbb6321b2c5a2a0aab5f9a73af (2026-11-13): both prior P2 code changes are visibly present: g.cpp_c_linkage wraps link/syscall, and native_object_cache_impl.c is in v3_cache_compiler_runtime_inputs. The new focused C++/cache regressions are present in the diff. I rechecked live PR head, the seven-file patch, and the review threads; the previous reviews tested the older d6fec3c head. Three GitHub compile/cold smoke checks are currently queued (not execution evidence), and branch-protection inspection returns 403.

Native validation still needed on this exact head before a compiler/runtime squash merge: ./v self; ./v fmt -verify for all touched V files; ./v -silent test vlib/v/gen/c/cpp_compat_test.v (including the new real C++ executable/link test); ./v -silent test vlib/v/driver/cache_prune_test.v (the previously failing runtime-input fingerprint invariant); then original headerless poll/cache replay and ./v -cc g++ -gc none -nocache -o compiler.c cmd/v followed by G++ syntax checking. Current PR body reports substantial V validation, but does not explicitly establish the two post-review regressions on the revised head. I cannot execute V locally (no checkout/compiler, github.com DNS unavailable). Keeping this open instead of treating queued checks or earlier-head native tests as verification. No tests or assertions should be suppressed.

@medvednikov
medvednikov merged commit 000de87 into master Nov 13, 2026
3 checks passed
@JalonSolov
JalonSolov deleted the fix/native-cache-headerless-20261113 branch November 13, 2026 12:27
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