WIP: test(vk): the brace check holds vk_internal.h's mkwvk functions inside mkwvk, compares each #if's branches and reads only tracked files #1960
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1960
Loading…
Reference in a new issue
No description provided.
Delete branch "d4nkn3ss/Longshot:fix/vk-braces-scope"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
tests/test_vk_braces.pycame in with #1949 (main's build break: a stray brace closednamespace mkwvkearly invk_replay.cpp). BeanBot's review of #1949 found four gaps in it, and #1949 merged before they were answered. This answers them:present_thread_drain(), which leavesswapchain_made_ready()outsidemkwvkand breaks the build the same way. Now every functionvk_internal.hdeclares innamespace mkwvk(203 of them) must be defined inside it, by name, in eachgpu/vksource that defines it.#if, so an extra brace in a Linux#elsepassed. Now every branch of an#ifmust change the depth as the first does (the namespaces still follow the first).#if 0inside a block comment no longer hides real code. A//comment continued by a backslash runs on to the next line, as C++ joins them.gpu/vk(or the tree when git can't say), never a symlink or a path outside the checkout, so a scratch header doesn't fail the suite.depth_skipis gone.On main: move
vk_replay.cpp's last} // namespace mkwvkto just afterpresent_thread_drain()(the build breaks) and runpython -I -B tests/test_vk_braces.py: it passes.Read first:
Scan(itsdirectiveandchar) andblank()intests/test_vk_braces.py.See #1949.
Testing
Tested:
python -I -B tests/test_vk_braces.py: passes on main @00e0dc93(548 sources, 203 functions). The same on Linux (Debian under WSL 2, Python 3), and throughtests/run_all.py.vk_replay.cpp(or a file added) and put back:present_thread_drain()line 7785: a '}' with nothing openpresent_thread_drain()line 6559: swapchain_made_ready() is defined outside namespace mkwvk}in the Linux#elseof the acquire timeoutline 5942: the last branch of the #if at line 5932 changes the depth by -1, its first by +0#ifdef X/#else(no#endif)1 brace(s) left open at the end, the comment's own*/blanked)//comment ending in a backslash, a}on the next linegpu/vk/zz_scratch.hholding}tests/test_vk_braces.pychanges, and no other check reads it. The rest of the suite runs as on main (miseisn't installed here; checks throughtests/run_all.py).Still to test: None
Measurements
Nothing to measure: a check only. It takes about 7 s through
run_allon this PC.Risks
None for players: only a check changes. Two separate
#ifdef Xand#ifndef Xblocks that each open a brace would both be counted and fail it. None exists now, and the failure names the line.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Recommendation: Request changes. The check catches the reported
vk_replay.cppregression, but it already misses a declaration invk_internal.hand can pass a broken Linux branch. File selection can also scan the wrong tree, and the new per-character scanner adds avoidable work to every full suite run.This gives contributors an earlier, game-free warning when a renderer function moves outside its namespace or a platform branch adds an unmatched brace. The reported examples show the benefit. Incomplete parsing and file selection can still miss build breaks or fail a valid checkout.
Does it help: Yes for the cases shown. The PR's comparison against
00e0dc93reports five improved outcomes: the balanced namespace move and the extra Linux brace now fail, while the block comment, continued line comment, and scratch header cases now pass. The original stray brace fails on both. The reported scan of 548 files and 203 names does not establish complete declaration coverage. The reported roughly 7 seconds throughrun_all.pyhas no paired base timing.Other systems: The diff changes one game-free Python check auto-discovered by
tests/run_all.pyand used by Forgejo and CircleCI. It can affect CI time and what contributors catch before building on Windows or Linux, including Steam Deck. It changes no game runtime, GPU path, player build step, save, audio, input, cache, or launcher behavior.Switches: None.
Reviewed:
67024c233fagainst00e0dc93a9: Read the full base-to-HEAD diff,tests/test_vk_braces.pyin full twice, the commit and trailers,AGENTS.md,CONTRIBUTING.md, the Forgejo template, anddocs/dev/standards.md. No review checklist file was present. Read the relevant suite discovery and subprocess code,vk_internal.hdeclarations, and the affected scope and call sites invk_replay.cpp,vk_vma.cpp,vk_main.cpp, andvk_texture.cpp. Skimmed CI configuration, the #1949 record, the current PR's results, generated shader headers, and translations. The remainder of the renderer and test runner was outside the read.; nothing run (a code review).Checked and fine:
git ls-files.Blocking (to change before merge)
vk_internal.hdeclaresdestroy_image_laterwithviews = {}andmemory = {}. The first{resets the pending declaration, sooursnever contains this name. Moving its definition invk_vma.cppoutsidemkwvkwould escape the new check. Keep balanced default expressions inside the function declarator until its closing)and cover this signature in a fixture.mkwvk. Aswapchain_made_ready()definition inside a nestednamespace detail { ... }withinmkwvkpasses even though it definesmkwvk::detail::swapchain_made_ready. The bare-name lookup also rejects an independent helper such as a file-localcompile_all(int). Track the full namespace and distinguish the declared function from unrelated overloads.}followed bynamespace mkwvk {both have net depth zero. The scanner passes while Linux sees a stray close. Check each arm from the depth at conditional entry, including the lowest depth it reaches.#elseomits the implicit empty arm. Putting the finalvk_replay.cppnamespace close under#ifdef _WIN32passes the check while Linux ends with the namespace open. Compare against a zero-delta arm when the conditional can select no explicit branch.bool swapchain_made_ready()in the Windows arm andbool unrelated()in the Linux arm, with the body after#endif. The regex picksunrelatedand misses the misplaced Windows definition. Keep branch-local scope and pending declarator state from#if, and check each branch through any shared function head or body./followed by a backslash-newline and then/ }forms a line comment in C++, but this scanner counts its}. A splice inside#elsecan likewise hide the branch boundary. Recognize splices before tokenizing comments, ordinary literals, and directives, while mapping diagnostics back to physical lines and preserving raw-string contents.cwd=ROOTstill lets Git inheritGIT_INDEX_FILE,GIT_DIR, andGIT_WORK_TREE. An alternate staging index that includesgpu/vk/zz_scratch.hcan therefore fail the check the PR says it fixes. A source archive unpacked under another Git worktree can also get an empty successful listing and miss the tree fallback. Clear Git's repository and index overrides, verify the discovered root, and report listing errors in a recognized checkout.gpu/vk/edenis replaced locally with a symlink to an in-tree scratch copy, its files pass both filters and are scanned. Check every component below the checkout root and prune symlinked directories and Windows junctions before walking the fallback tree.self.coderepeatedly copies the pending string on CPython, even inside scopes where the function recognizer immediately returns. The tracked ASTC shader header alone puts about 359 KB in one initializer. Buffer tokens or chunks and keep function-head text only where it can affect a scope decision.Waiting on the author (a run, a measurement or a decision; no edit does it)
run_all.pywithout its flags or results. Report the updated head'srun_all.py --strictresults and any matching base failures, and identify which scanner and file-selection cases ran under native Windows and Linux.Testing: Read-only review. No project code, builds, or tests were run. The author's mutation table is the available evidence for this PR. The Windows and Linux results recorded in #1949 apply to the earlier check. No head CI result was supplied.
Overlaps and merge order: #1949 introduced the check and is already in the base. No other overlap was found in the checkout or supplied discussion.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -63,3 +46,1 @@elif src.startswith("//", i):i = src.find("\n", i)i = n if i < 0 else iif src.startswith("//", i):A backslash-newline can join two slashes into a comment or join pieces of a directive. Recognize splices before lexing and retain physical line numbers.
@ -101,3 +175,4 @@return sorted(keep)def main():Keep the mutation cases as executable fixtures. The clean-tree run alone cannot tell if the new rejection rules are removed.
@ -101,0 +114,4 @@f[2], f[3] = 0, Falseelif word == "endif" and self.frames:f = self.frames.pop()if f[1] is not None and f[2] != f[1]:Compare the implicit empty arm when there is no
#else. Guarding the file's final namespace close with_WIN32currently passes.@ -101,0 +122,4 @@def char(self, number, ch):if ch not in "{};":self.code += chThe ASTC header puts about 359 KB in one initializer. This append repeatedly copies it even where only braces matter. Collect head text only where needed and buffer it in chunks.
@ -101,0 +126,4 @@returnstep = {"{": 1, "}": -1, ";": 0}[ch]if step and self.frames:self.frames[-1][2] += stepAn alternate arm can close below file scope and then reopen a brace to get back to zero. Check depth throughout each arm.
@ -101,0 +127,4 @@step = {"{": 1, "}": -1, ";": 0}[ch]if step and self.frames:self.frames[-1][2] += stepif self.following():Alternate arms skip scope validation but still write
self.code. With two platform signatures and one shared body, the Linux signature can hide a misplaced Windows definition.@ -101,0 +128,4 @@if step and self.frames:self.frames[-1][2] += stepif self.following():if ch == "{":destroy_image_laterhas= {}defaults invk_internal.h. The first initializer resets the declaration head, so a misplaced definition of this existing renderer function passes.@ -101,0 +154,4 @@if not m or "=" in head.split("(")[0] or m.group(2) in ("if", "for", "while", "switch", "return", "sizeof"):returnnames = [s[1] for s in self.stack] + [q for q in m.group(1).split("::") if q]into.append((m.group(2), number, "mkwvk" in names))A definition in a nested
mkwvk::detailnamespace can pass. Compare the full scope and distinguish unrelated same-name overloads.@ -101,0 +160,4 @@def sources():"""The repository's renderer sources: tracked files when git can say, else the tree; none outside the checkout"""try:listed = subprocess.run(["git", "ls-files", "-z", "--", "gpu/vk"], cwd=ROOT, capture_output=True, check=True).stdoutAn inherited Git index override or an enclosing repository can supply the wrong file list. Clear repository overrides and verify the Git root.
@ -101,0 +167,4 @@root = ROOT.resolve()keep = []for p in paths:if p.suffix not in SUFFIXES or p.is_symlink() or not p.is_file():An in-tree symlink in a parent directory passes both filters. Reject linked path components and prune links before traversing the fallback tree.
test(vk): the brace check holds vk_internal.h's mkwvk functions inside mkwvk, compares each #if's branches and reads only tracked filesto WIP: test(vk): the brace check holds vk_internal.h's mkwvk functions inside mkwvk, compares each #if's branches and reads only tracked filesBack to work in progress. The review is right on its points. Most of them (default arguments with braces, nested namespaces, an arm that dips below and comes back, an
#ifwith no#else, splices before lexing, Git's environment) need a hand-written C++ parser to get right, and every pass finds the next gap.The complete guard already exists: CI builds the renderer on Linux (
build-linux.yml,longshot_vk.so (build check)) and Windows. #1105's brace and the Linux link break #1961 just fixed both merged before those builds ran on their heads.So rather than grow this scanner, I'd keep
tests/test_vk_braces.pyas #1949 left it, a cheap tripwire for the one regression, and close this PR. Or, if maintainers want it, I'll replace both with a-fsyntax-onlycompile of the renderer sources, run where the Vulkan headers are found and skipped where they aren't. I'm waiting on that choice before doing more.Posted by an AI agent (Claude Code) for d4nkn3ss.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.