edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # av1splitdec: decode.rs module split (av1split D1-D21) |
| 2 | |
| 3 | Goal: mechanical module extraction of `crates/ec-av1/src/decode.rs` (61,650 lines) so that no |
| 4 | decode source file exceeds 5,000 lines (DONE.md / `lanes/av1split.plan.md` section 2), with no |
| 5 | behaviour change. |
| 6 | |
| 7 | Base: `main` @ 322837a2 (merged into the lane as c60b28ff). Gated head: `90a7b62f`. |
| 8 | Plan steps P0 (directory-aware source reader) was already on main (028fc46e), so the |
| 9 | `include_str!` scanners already read `decode/` as a directory. |
| 10 | |
| 11 | ## Steps |
| 12 | |
| 13 | | Step | What moved | File | |
| 14 | |---|---|---| |
| 15 | | D1 | `decode.rs` -> `decode/mod.rs` (git mv, 0 lines) | `decode/mod.rs` | |
| 16 | | D2 | `mod tests`, `mod tx4x8_table_tests`, `mod obmc_skip_chroma_tests` | `tests.rs`, `tx4x8_table_tests.rs`, `obmc_skip_chroma_tests.rs` | |
| 17 | | D3 | hit/census counter items (name-based) | `counters.rs` | |
| 18 | | D4 | `mod cdef_simd`, `mod deblock_simd` | `cdef_simd.rs`, `deblock_simd.rs` | |
| 19 | | D5 | `decode_inter_frame_tile*` | `frame_tile.rs` | |
| 20 | | D6 | `grid_stamp_rect`, `decode_inter_block8` | `inter_block8.rs` | |
| 21 | | D7 | `decode_inter_sub8_split4`, `decode_intra_sub8_leaf`, `decode_inter_sub8_rect2` | `sub8_inter.rs` | |
| 22 | | D8a | `decode_inter_block`: its intra `else` arm (~1,300 lines) extracted to `decode_inter_block_intra_arm`; the arm returns the locals the tail reads and `Ok(None)` for its early return | `inter_intra_arm.rs` | |
| 23 | | D8b | `decode_inter_block` (about 4,430 lines after D8a) | `inter_block.rs` | |
| 24 | | D9 | switchable interp / ref / OBMC / compound helpers | `inter_ctx.rs` | |
| 25 | | D10 | `decode_key_frame_tile*` region | `key_tile.rs` | |
| 26 | | D11 | `replay_*`, `cdef_band` | `replay.rs` | |
| 27 | | D12 | deblock filters, scratch, filter-replay capture | `deblock.rs` | |
| 28 | | D13 | block tx-size readers, inter shapes, edge params | `inter_shapes.rs` | |
| 29 | | D14 | CDEF constants and kernels | `cdef.rs` | |
| 30 | | D15 | sub-8x8 chroma leaves, split4, rect8 leaf | `leaf_sub8.rs` | |
| 31 | | D16 | 128-rect block, 8x8 leaf, sub-8 intra mode | `leaf8.rs` | |
| 32 | | D17 | intra mode/angle readers, CFL, plane reader, `decode_block` | `block.rs` | |
| 33 | | D18 | rect4 and 16-wide blocks | `rect4.rs` | |
| 34 | | D19 | rect intra/intrabc blocks, `decode_leaf_rect` | `rect.rs` | |
| 35 | | D20 | coefficient readers, `Neighbours`, filter-intra and palette | `coeffs.rs` | |
| 36 | | D20b | post-filter pipeline (CDEF / LR drivers, pipeline statics); not in the plan, added so `mod.rs` fits | `post_filter.rs` | |
| 37 | | D21 | final checks: lint cleanups (see below), all files under 5,000 lines | | |
| 38 | |
| 39 | The plan's base line ranges no longer matched after the first moves, so every step selected its |
| 40 | region by first and last item name. Each region was contiguous in the file at the time it moved. |
| 41 | |
| 42 | ## Line counts (`crates/ec-av1/src/decode/`, after D21) |
| 43 | |
| 44 | | File | Lines | |
| 45 | |---|---:| |
| 46 | | `rect.rs` | 4842 | |
| 47 | | `mod.rs` | 4767 | |
| 48 | | `coeffs.rs` | 4541 | |
| 49 | | `counters.rs` | 4460 | |
| 50 | | `inter_block.rs` | 4437 | |
| 51 | | `rect4.rs` | 3865 | |
| 52 | | `tests.rs` | 3828 | |
| 53 | | `frame_tile.rs` | 3658 | |
| 54 | | `block.rs` | 3587 | |
| 55 | | `key_tile.rs` | 3086 | |
| 56 | | `sub8_inter.rs` | 3043 | |
| 57 | | `leaf_sub8.rs` | 3040 | |
| 58 | | `inter_ctx.rs` | 2992 | |
| 59 | | `inter_block8.rs` | 2973 | |
| 60 | | `leaf8.rs` | 2087 | |
| 61 | | `inter_shapes.rs` | 1714 | |
| 62 | | `inter_intra_arm.rs` | 1359 | |
| 63 | | `deblock.rs` | 1024 | |
| 64 | | `post_filter.rs` | 825 | |
| 65 | | `replay.rs` | 596 | |
| 66 | | `deblock_simd.rs` | 438 | |
| 67 | | `cdef.rs` | 388 | |
| 68 | | `cdef_simd.rs` | 242 | |
| 69 | | `tx4x8_table_tests.rs` | 89 | |
| 70 | | `obmc_skip_chroma_tests.rs` | 27 | |
| 71 | |
| 72 | Largest: `rect.rs` 4,842, `mod.rs` 4,767. All under 5,000. `decode/` previously held one 61,650-line file. |
| 73 | |
| 74 | ## Non-mechanical changes (what is not a pure move) |
| 75 | |
| 76 | - Visibility only: moved items that the rest of the module uses became `pub(super)`, struct |
| 77 | fields and impl methods used across files became `pub(super)`, thread-local statics too. The |
| 78 | module `mod.rs` re-exports moved items with `pub use` / `pub(crate) use` (chosen to match the |
| 79 | widest visibility in each moved region), so `ec_av1::decode::*` paths are unchanged. |
| 80 | - D8a is the only change to code shape. The `else` arm body is unchanged apart from the |
| 81 | signature and 4-space dedent. Its early `return Ok(())` became `return Ok(None)` and the caller |
| 82 | does `return Ok(())` on `None`. Its outputs are returned in a tuple (`IntraArmOut`) and |
| 83 | destructured back into the caller's deferred locals. The arm reads the same values it read |
| 84 | inline: the locals it reads are passed by value or by `&mut` as before. `has_chroma`, |
| 85 | `is_inter` and `palette_record`'s incoming value were dropped because the arm never reads them |
| 86 | (its `palette_record` is always assigned before use). This is covered by the test gate below. |
| 87 | - Source-scan gates. Six gates in `decode/tests.rs`, `stream.rs` and `refusal_inventory.rs` read |
| 88 | decode source as text and match `\nfn name(` headers and function bodies. The split broke them |
| 89 | in three ways, all fixed without changing what they assert: |
| 90 | 1. `test_source::read_module` (the shared helper) rewrites column-0 `pub(super) fn ` headers to |
| 91 | `fn ` before the text is scanned, so the scanners see the same headers as on `main`. |
| 92 | 2. `decode/tests.rs` scope gate: the 1:4 test text can occur first in another file (concatenation |
| 93 | is in path order), so the gate now takes the first occurrence whose own function holds the |
| 94 | dispatch call; guard, test and dispatch must still share that function. |
| 95 | 3. `stream.rs` counts sites in `decode_inter_block` and `decode_inter_block_intra_arm` together, |
| 96 | since D8a moved some of those sites into the helper. |
| 97 | Also, `pub(super)` was reverted to plain `fn` for moved functions that no other decode file uses. |
| 98 | - Lint fixes made during D21: dangling doc blocks joined (6 places); the arm helper carries a |
| 99 | reasoned `#[allow(clippy::too_many_arguments, clippy::needless_late_init)]`. |
| 100 | |
| 101 | ## Verify |
| 102 | |
| 103 | - `scripts/remote-run.sh av1splitdec -- cargo check -p ec-av1 --tests` after every step: clean. |
| 104 | The only warnings are the ones main already has (12 lib, 11 lib-test); no new warnings. |
| 105 | - `cargo check --workspace --all-targets` (server): no errors (all ec_av1 path users still resolve). |
| 106 | - `cargo clippy -p ec-av1 --all-targets` diffed against a `main` worktree |
| 107 | (`~/.cache/wt/av1split-base`, detached at 322837a2): **no new clippy warnings**; 6 fewer |
| 108 | (`empty line after doc comment`). Clippy `-D warnings` is not clean on `main` either (322 |
| 109 | warnings there, 316 here), so that gate cannot pass on this crate as it stands. |
| 110 | - Test gate (ORCHESTRATION gate, on host b): |
| 111 | `EC_MEMGUARD_MAX=6G cargo test --release -p ec-av1 -- --test-threads=4`. |
| 112 | Required: 807 passed, 49 ignored, 0 failed. |
| 113 | |
| 114 | Run on host b, commit `90a7b62f` (the code under the gate): |
| 115 | `EC_MEMGUARD_MAX=6G cargo test --release -p ec-av1 -- --test-threads=4` -> |
| 116 | `test result: ok. 807 passed; 0 failed; 49 ignored; 0 measured` (lib, finished in 2897.70s), |
| 117 | plus a second binary `4 passed; 0 failed`. Required 807 passed, 49 ignored, 0 failed: met. |
| 118 | |
| 119 | An earlier gate on the pre-fix commit `fb7cec17` had 801 passed, 6 failed (source-scan gates, see below). |
| 120 | Those six now pass. |
| 121 | |
| 122 | ## Left |
| 123 | |
| 124 | - Out of scope for this lane (decode.rs only), still over 5,000 lines on `main`: |
| 125 | `stream.rs` (57,178), `encode.rs` (23,771), `tile.rs` (11,516), `qm.rs` (7,046), |
| 126 | `encoder.rs` (6,503), `cdf.rs` (5,519). `lanes/av1split.plan.md` sections 5c-5g cover them. |
| 127 | - `rustfmt --check` already fails on `main`'s `decode.rs`; the moved code is not reformatted. |