[pr-refactor] SAFETY comments on the remaining unsafe blocks in darner-core and darner-loader #314
Loading…
Reference in a new issue
No description provided.
Delete branch "elgibbone/safety-comments-non-gpu"
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?
What it changes
// SAFETY:comment.Adds the five missing
// SAFETY:comments (darner-core folders.rs; darner-loader callhook.rs tests, console_insn.rs, heap_sites.rs) and turns on#![warn(clippy::undocumented_unsafe_blocks)]in darner-core and darner-loader, so a new unsafe block without one is reported. No code changes behaviour: console_insn.rs and heap_sites.rs only move a comment next to its block (oneelse ifbecameelse { if }for that).The first version also put a copy of
main's comment on theremove_varindarner-shader/src/emit/wave64_tests.rs. As lewis499 found, that comment claims every reader ofDARNER_THREAD_TICKETholdsONE_AT_A_TIME, which is not true, so8ed8039takes it out again: this PR no longer touches darner-shader. The race itself is onmainand has its own PR, #386.How it was tested
8ed8039cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo xtask policy: 555 files okcargo test --workspace --locked --no-fail-fast: darner-core 31 passed; darner-loader 92 passed, plus its integration tests (load_probe, title_dlls) passed; darner-hle, darner-formats, darner-game and the darner app passed.host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end,watch::tests::ask_once_by_res_splits_reservations_without_refusals); in an earlier run a third,watch::watch_pipe_epoch_tests::ask_once_delta_reask_direct_carves_refreshes_and_updates_page_epochs, failed instead. The watch_pipe_epoch test passes run alone (5 of 5 on this branch, 5 of 5 onmain); I did not rerun the other two alone. They look like tests that fail under the load of the parallel run. This PR does not touch darner-gpu.oracle64::legacy_mul_forms_are_exactwas still running after 15 minutes in a debug build). One failure,emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders("DXIL validation failed: Not all elements of output SV_Depth were written"), fails the same way onmain(f3840d7, 3 of 3); this PR no longer touches darner-shader.emit::wave64_testspassed.cargo xtask policyin full;cargo test --workspacewith the gaps above.oracle64::legacy_mul_forms_are_exactand the crates and doc tests after darner-shader did not finish.Checklist
main.docs/asset-policy.md.Checked for overlap
DARNER_THREAD_TICKETrace that the review found.Document remaining unsafe blocks in core, loader and shaderto [pr-refactor] SAFETY comments on the remaining unsafe blocks in darner-core, darner-loader and a shader testIndependent Windows build, gate, and code-read review of
66df156078b6(full head66df156078b6f85ac153e3e9ed60755bfebc809f), based onmainf3840d73d3504c30218debfbc8795b9225447317. Not run in-game.Environment
x86_64-pc-windows-msvc), MSVC 19.44.35230.Measured results
cargo clippy --workspace --all-targets --locked -- -D warnings): PASS.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS.cargo xtask policy: PASS (asset policy: 555 files ok).cargo test --locked -p darner-core: PASS (31 passed; 0 failed; 0 ignored).cargo test --locked -p darner-loader --lib: PASS (92 passed; 0 failed; 0 ignored).cargo test --locked -p darner-shader --lib emit::wave64_tests::the_console_threads_of_a_two_dimensional_group_are_each_given_once: PASS (1 passed; 0 failed; 0 ignored; 573 filtered out).cargo test --locked -p darner-shader --lib emit::wave64_tests: PASS (48 passed; 0 failed; 1 ignored; 525 filtered out).cargo test --workspace --locked) was not run; focused affected-crate tests were run instead.Code-read audit
clippy::undocumented_unsafe_blockslints are active in the intended core and loader crates, and both workspace Clippy gates pass. The folder setup comment matchesapply's documented before-threads precondition (crates/darner-core/src/folders.rs:73-94); the loader comments were checked against the generated Win64 call/entry test routines, the owned line passed tozero_through_fault, and the protected code/table writes (crates/darner-loader/src/callhook.rs:289-326,console_insn.rs:651-667,heap_sites.rs:1606-1624).DARNER_THREAD_TICKETholdsONE_AT_A_TIME(crates/darner-shader/src/emit/wave64_tests.rs:1540-1546), butlanes_past_32_take_the_high_dword_of_a_mask_held_as_a_numberlowers a 64-thread wave64 program at host width 32 without acquiring that lock (wave64_tests.rs:773-775). That lowering can reachticket_on()whengroup > wave(crates/darner-shader/src/emit/lower.rs:1653-1656), so it can observe the temporary"0"set bylower_with(false)while the other test is compiling. The full wave64 test run passed here, but the stated synchronization invariant does not hold and the output remains schedule-dependent. Synchronize every translation path that can read the switch or replace the process-environment toggle with a test-only override.Verdict: CHANGES NEEDED.
AI-assisted: yes (GitHub Copilot, Auto mode).
Thanks @lewis499, you're right: the comment claimed an invariant that does not hold, so it is gone. Pushed
8ed8039, which drops the copied// SAFETY:line onremove_varinwave64_tests.rs. With it this PR no longer touches darner-shader at all; the comment onset_varjust above ismain's and stays as it is.One correction on the reader:
lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_numberlowers a wave64 program at host width 32, solowertakes thewave == 32 && x.native.wave64branch (crates/darner-shader/src/emit/lower.rs:1641) and never callsticket_on(). The test that does reach it without the lock isfolded_tests::two_dimensional_groups_of_several_host_waves_give_every_console_thread_once(a wave32 program in a 32 x 2 group,lower.rs:1653-1656). That race is onmainalready and is not this PR's change, so it has its own PR: #386.Windows results on
8ed8039: both clippy gates clean,cargo xtask policy555 files ok, darner-core and darner-loader tests pass. The workspace run has failures in darner-gpu, which this PR does not touch (the one I reran alone passed 5 of 5) and one in darner-shader that fails the same way onmain; the details are in the updated description.[pr-refactor] SAFETY comments on the remaining unsafe blocks in darner-core, darner-loader and a shader testto [pr-refactor] SAFETY comments on the remaining unsafe blocks in darner-core and darner-loaderView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.