Skip to content

refactor: one copy of each byte, GUID, JSON-id, geometry and storey helper, and one ArcWall scan per file - #1136

Merged
DrunkOnJava merged 14 commits into
mainfrom
refactor/one-copy-of-each-helper
Oct 30, 2026
Merged

DrunkOnJava merged 14 commits into
mainfrom
refactor/one-copy-of-each-helper

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

The audit's helper refactor (Griffin, 2026-10-30, "One copy of each helper"): copied helpers become one shared copy each, little-endian reads go through le_bytes where the conversion is exactly equivalent, and the partition ArcWall scan runs once per file instead of up to four times. Nothing an export writes should change; Measure checks that.

Changes

  • le_bytes: about 117 of 227 inline from_le_bytes reads now use le_bytes, which gains i32_at and u16_units. The rest are left because their failure semantics differ: Result errors with specific messages, InstanceField::Bytes fallbacks in walker.rs, cursor take(n)? reads, fixed-size arrays that cannot fail, and src/bin. A raw-indexed read behind an explicit bounds check becomes ? only where that check makes the new None arm unreachable. Messages from anyhow errors are kept word for word.
  • find_subslice: one copy, memchr, with the empty-needle guard kept. It replaces two wrappers and one scalar loop.
  • GUID: one guid_string, now used by three readers. One IFC GlobalId alphabet. derive_default_ifc_guid calls compress_ifc_guid.
  • src/native_json.rs (research): element_id, element_id_i64, finite_triple and agree, shared by twelve native_* and partition modules. Variants with different semantics stay.
  • src/vector_math.rs (private): sub, dot, cross, distance and polygon_area_xy. Expressions are token-identical to the copies they replace. from_decoded::polygon_area_sqft keeps its public path. The three point-in-polygon copies and the signed areas differ and stay.
  • Storeys: one elevation_storey_name.
  • ArcWall scan: memoised on RevitFile per release and WalkerLimits (memoised_arc_wall_scan). The production walk, the partition assembler and both IFC-export sites share it. The public scan_partition_arc_walls_with_limits keeps its signature.
  • changelog.d/changed/arc-wall-scan-memo.md.

No public signature changes. fuzz/ and rvt-probes call public items only.

Testing

Found, not changed

partition_scanner.rs:239/449 can index buf[offset + 3] past the end when a tag matches in a buffer's last three bytes. That is a panic on hostile input, so it will be fixed in its own PR rather than in a behaviour-preserving refactor.

Breaking changes

None.

Related issues

None.

…nd quantise helpers

dot, sub and cross move from ifc/body_geometry and native_parametric_surface, distance from native_symbol_cuts and native_parametric_mesh, and the shoelace area from geometry/recovery and ifc/from_decoded into the private vector_math module, with the expressions unchanged. polygon_area_sqft keeps its public path and calls the shared function. quantise is shared from partition_element_records.
native_index reads native_extensible_storage::guid_string instead of its own copy. The 22-digit alphabet is one constant in revit_global_ids, and derive_default_ifc_guid calls compress_ifc_guid, which computes the same string.
partition_level_records and partition_ifc_export_overrides use the memchr-backed copy in partition_element_records. All three returned None for an empty needle or a haystack shorter than the needle and the first match otherwise.
partition_arc_walls names a storey through element_record_storeys::elevation_storey_name instead of its own identical format.
…elpers

native_json holds element_id (u64 and signed forms), finite_triple and agree, read by native_column_joins, native_connectors, native_element_types, native_mullion_hosts, native_rendered_content, native_stairs, native_symbol_cuts, native_wall_types and native_walls. The readers that differ stay in place: native_walls' triple (no finiteness check), native_stairs' element_id (as_u64), native_family_forms' Option argument and native_saved_mesh's Result point.
…imits

The production walk, the partition MVP and the IFC export (twice) each ran scan_partition_arc_walls_with_limits over every Partitions stream. RevitFile now memoises the scan under its release and WalkerLimits, as it does the walk; the public function returns a copy of the memoised scan and the four internal readers share it.
… le_bytes

The partition readers, compression and basic_file_info read integers, floats and UTF-16 units at an offset with the same bounds as before and through the one le_bytes module. le_bytes gains i32_at and u16_units for the reads the existing helpers did not cover.
… index and document readers

The reads that were bounds-checked by a get or an ensure! before an infallible try_into now use u16_at and u32_at with the same error text, and the UTF-16 unit decodes use u16_units. The walker, ElemTable, partitions and ArcWall trailer readers take the same helpers where the surrounding function already returned None on a short buffer.
…roof_slopes read ElementIds through native_json
…ported

Four calls already on main read crate::le_bytes::*_at in files this branch now imports le_bytes into, which the workspace's unused_qualifications lint (an error under -D warnings) rejects.
DrunkOnJava added a commit that referenced this pull request Oct 30, 2026
…a buffer whose last tag is followed by a zero (#1137)

## Summary

`research::partition_scanner::scan_partition_buffer` looped offsets up
to `len - 3` and then checked the two bytes after a matching tag. A tag
in the last three bytes followed by a zero byte therefore read
`buf[len]` and panicked. The loop now ends at `len - 4`, and no output
changes.

## Motivation

The helper-refactor review (#1136) found this; that PR left it alone
because it was behaviour-preserving. Parsing paths take untrusted input
and must not panic (CLAUDE.md). No fuzz target reaches this function.

## Changes

- `src/partition_scanner.rs`: `let last = buf.len() - 4;`. The function
already returns early for buffers under 4 bytes, so this cannot
underflow. A candidate needs the tag and the two zero bytes after it, so
no offset that could yield one is skipped.
- `tests/fuzz_regressions.rs` (hardening, run in CI): replays buffers of
4 to 11 bytes that end with an ArcWall tag (`0x0191`) followed by a
zero, on a supported release (2023). Before the fix each one panics, and
the test asserts none does.

## Testing

CI runs the hardening class. The fix is in a research module and changes
no export (`scan_partition_buffer` serves probes, tests and the
ElemTable passthrough).

## Breaking changes

None.

## Related issues

Refs #1136.

@DrunkOnJava DrunkOnJava left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer self-review. GitHub does not let a PR's author approve it, so this review stands in for an approval. A side agent wrote the commits, and I reviewed them as a reviewer would.

  • Read conversions: a raw read became ? only where a bounds check already in place makes the new None arm unreachable. Sites whose failure semantics differ stay inline: Result errors with messages, InstanceField::Bytes fallbacks and cursor reads. anyhow messages are unchanged.
  • find_subslice: keeps its empty-needle guard; memchr returns Some(0) for an empty needle, and the guard keeps None.
  • vector_math and native_json: expressions are token-identical to the copies they replace. Variants that differ stay put: the signed areas, the three point-in-polygon tests and pipe_axes' d*d distance.
  • ArcWall memo: keyed by release and WalkerLimits, so callers passing different limits never share a result. The handle is immutable, so nothing invalidates it. The public scan_partition_arc_walls_with_limits is unchanged.
  • CI fix: the branch's new use crate::le_bytes; imports made four existing crate::le_bytes:: paths fail unused_qualifications, and ac976268 fixed them before the first CI run.
  • Verified: CI passed. Measure is byte-identical on all 32 models; the description explains the office's base-side outage and the cross-check that covers it.
  • Found and fixed separately: the scanner's past-the-end read is #1137, already merged.

Ready to land.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 30, 2026 10:35
@DrunkOnJava
DrunkOnJava merged commit f07614f into main Oct 30, 2026
28 checks passed
@DrunkOnJava
DrunkOnJava deleted the refactor/one-copy-of-each-helper branch October 30, 2026 10:42
DrunkOnJava added a commit that referenced this pull request Oct 30, 2026
## Summary

Moves the 75 research modules from `src/` into `src/research/`, declared
as plain modules in `src/research.rs` instead of one `#[path]` attribute
each. Module paths (`crate::partition_schema_mvp`, `rvt::research::*`)
do not change, so this is a pure move: 75 R100 renames plus five edited
files.

Stacked on #1136 (its commits show here until it lands; this PR stays a
draft until then and takes an update-branch merge, so only the move
remains).

## Motivation

The second of the four repository-audit refactors Griffin chose on
2026-10-30. The research readers sat beside the stable modules, so
nothing in the tree said which files are outside the semver promise
(`RELEASE.md`, "What 1.0 keeps stable").

## Changes

- `src/<m>.rs` → `src/research/<m>.rs` for every module
`src/research.rs` declares (75, including `native_json` from #1136,
which is `pub(crate)`).
- `src/research.rs`: the `#[path]` lines go.
- Current-state mentions of the moved paths: `docs/support-matrix.json`
evidence (15), `probes/examples/probe_re207_element_parameters.rs`,
`tools/re/element_parameters_vs_ifc.py`, and CONTRIBUTING's probe step
(a new research reader goes in `src/research/`). Reports, dated notes
and the changelog keep the paths they were written with.

Checked before pushing: no moved file declares a child module or uses
`include_str!`/`include_bytes!`/`include!` with a relative path (both
would resolve differently one directory down); the crate's `include`
allowlist is `/src/**/*.rs`, so packaging is unchanged.

## Testing

Unit tests are banned in this repository. No local builds on this
machine: CI is the compile gate. Exports must be byte-identical; a
Measure run on the head confirms it before this leaves draft.

## Audit-honesty checklist

- [x] Docs name the new paths; no capability changes
- [x] No user-visible change, so no changelog fragment
- [x] No emojis, private paths or internal jargon

## Legal and contribution hygiene

- [x] Apache-2.0
- [x] No Autodesk proprietary content

## Breaking changes

None: module paths are unchanged.
DrunkOnJava added a commit that referenced this pull request Oct 30, 2026
…sibility (#1141)

## Summary

Splits `src/research/partition_schema_mvp.rs` (12,553 lines) into 19
child modules by responsibility, under
`src/research/partition_schema_mvp/`. The parent keeps the module doc,
`PartitionSchemaMvp`, the `recover_partition_schema_mvp` orchestrator
and the helpers every responsibility shares, and re-exports each child
with `pub use <child>::*`, so every `partition_schema_mvp::<item>` path
used in `src/`, `tests/`, `probes/` and `docs/` resolves as before. It
is a pure move: bodies, doc comments, attributes and the relative order
of items are unchanged.

Stacked on #1136 and #1139, both of which have since landed on main
(squash commits f07614f and 580982d); this branch merged main, so only
the split remains in the diff. It stays a draft until a Measure run on
the head confirms the move is byte-identical.

## Motivation

One of the repository-audit refactors Griffin chose on 2026-10-30: one
12.5k-line file held 175 constants and about 200 functions for a dozen
unrelated responsibilities.

## Changes

- `partition_schema_mvp.rs` (1,130 lines): module doc, imports,
`PartitionSchemaMvp`, `recover_partition_schema_mvp`,
`element_record_decoded`, `element_record_bbox`, `record_references`,
`element_source_stream`, `partition_streams_largest_first`,
`rect_openings_from_partitions`, and the `mod` / `pub use` lines.
- `fields` (933): all 175 constants.
- `types` (961), `parameters` (282): type picks and names, system
families, type functions; named parameters, `IsExternal`, phases
created, serial numbers.
- `openings` (765), `curtain` (399), `materials` (704), `layers` (292).
- `walls` (728), `wall_joins` (453).
- `stairs` (730), `stair_bodies` (1,111), `framing` (509), `mep` (750),
`rooms` (289).
- `slabs` (592), `roofs` (862), `levels` (511).
- `records` (495), `records_2023` (325): category and instance
selection, host binding, design-option and nesting filters; the Revit
2023 record path.

The only edits to moved text:

- `pub(super)` on the 148 private top-level items that left the parent
(the file has no private struct fields or methods).
- `fields.rs` has no `use super::*;`, since none of its constants names
anything outside it. Five of its doc links named a function that now
lives in another child, so they read `[`super::system_family`]`,
`[`super::attach_is_external`]`, `[`super::bind_opening_hosts`]`,
`[`super::roof_slope_edge_fields`]` and
`[`super::roof_slope_plate_offset_field`]`.
- The imports only one child uses moved into it (`le_bytes` into
`curtain` and `openings`, `partition_arc_walls` / `PartitionArcWall`
into `levels`, `NameBucket` / `classify_name` into `materials`,
`FRAC_PI_4` into `walls`), so the parent has no unused import.

Checked before pushing: every original non-blank line appears in the new
files the same number of times, except the added `pub(super)` tokens,
the `mod` / `pub use` / `use super::*;` / child `//!` lines, the five
doc links and the moved imports; `rustfmt +stable --edition 2024
--check` passes on the parent and every child, and rustfmt's own changes
(29 signatures rewrapped by the longer visibility prefix) differ from
the unformatted output only in whitespace and trailing commas. Every
`partition_schema_mvp::<name>` that code outside the module uses
(`src/`, `tests/`, `probes/`, `fuzz/`, `tools/`) names a `pub` item; the
non-`pub` names that remain are prose in docs and reports, as before.

## Testing

Unit tests are banned in this repository. No local builds on this
machine: CI is the compile gate.

- [ ] `tools/check-local.sh` passes: not run here (no local
compilation); `CI passed` is the gate
- [ ] Verified end to end on real Revit files: a Measure run on the head
must show byte-identical IFC hashes (`-f base=main -f nordic=true -f
r2025=true`) before this leaves draft
- [x] Does not touch the IFC exporter's behaviour; the witness verdicts
need no refresh
- [x] Not a performance change

## Audit-honesty checklist

- [x] Docs name no moved line numbers: `docs/support-matrix.json` cites
`partition_schema_mvp::<item>` module paths, which still resolve
- [x] No user-visible change, so no changelog fragment
- [x] No new limitation
- [x] No emojis, private paths or internal jargon

## Legal and contribution hygiene

- [x] Apache-2.0
- [x] No Autodesk proprietary content
- [x] No new test fixtures

## Breaking changes

None: the module's public items keep their paths.
Repository owner deleted a comment from chatgpt-codex-connector Bot Oct 31, 2026
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