Scanner/wrapper cleanups: sort spans, anchor struct, quote macro#6
Merged
Conversation
span_index_for_offset (binary search) and ExecReader::find_span assume the code spans are ascending and non-overlapping, but the PE/ELF/Mach wrappers emitted them in section/segment order. Real binaries are conventionally VA-ascending, but a crafted or unusual image with out-of-order executable regions could mis-resolve offsets. Sort code_spans by mapped.start at construction in all three wrappers; add a fixture test enforcing the invariant.
The unified scan path threaded the anchor as four separate parameters (bytes/len/offset/jumps), giving 9-11-arg functions. Introduce an AnchorPlan struct (already a coherent unit, and the fields of PatternPlan/PreparedPattern) and pass &AnchorPlan through the scan strategies instead. Pure refactor; the matches/finds cross-check proptests and fixture tests confirm no behavior change.
pattern! built a Rust source string ("&[...]") and re-parsed it, and compile_error
did the same with manual escaping. Build the output TokenStream directly with
quote/proc-macro2 instead (one quoted Atom expression per atom, integer args as
suffixed literals). Behavior is unchanged; the macro_smoke tests still match the
runtime parser output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three remaining review cleanups, each its own commit. All preserve matching semantics —
the matches/finds cross-check proptests and fixture tests are the net.
Commits
span_index_for_offset(binary search) andExecReader::find_spanassume code spans are ascending and non-overlapping, but the PE/ELF/Mach wrappers emitted
them in section/segment order. Real binaries are conventionally VA-ascending, but a crafted
or unusual image with out-of-order executable regions could mis-resolve offsets. Sort
code_spansbymapped.startat construction in all three wrappers; add a fixture testenforcing the invariant.
four separate params (bytes/len/offset/jumps), giving 9–11-arg functions. Introduce an
AnchorPlanstruct (the fields ofPatternPlan/PreparedPattern) and pass&AnchorPlanthrough the scan strategies instead. Pure refactor.
pattern!built a Rust source string ("&[...]") andre-parsed it (and
compile_errordid the same with manual escaping). Build the outputTokenStreamdirectly withquote/proc-macro2(one quotedAtomper atom, integer argsas suffixed literals). Adds the two standard proc-macro deps to the macros crate only.
Verification
cargo test --workspace --all-targets --all-features,cargo test --workspace --doc,cargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::all, andcargo fmt --all -- --checkall pass.