Repository navigation
Avoid copying the prompt name before a parse error needs it - #21
Merged
Merged
Conversation
Keep frontmatter ownership in parse_source and borrow its name only when body parsing fails. Let parse_body borrow the split source and return sections, with shared body text retained in an Arc. Closes cppalliance#20.
Member
|
This still leaves a body copy in the failure path, |
Contributor
Author
|
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.
Why
The parser copied the frontmatter name as soon as frontmatter parsing succeeded, but used that copy only if body parsing failed. On a successful parse, we cloned the name and then threw the copy away.
This is a minor cleanup, but it illustrates the ownership issue discussed in Slack: a copy can work around an ownership constraint that we can instead remove by changing where the value is owned.
Plan
parse_sourcewhile the body is parsed.parse_bodyborrow the split source and return sections, rather than consume the frontmatter and construct the whole prompt.frontmatter.name()inside the error closure, and assemble the prompt only after body parsing succeeds.Arc<str>in the split source so sections can retain shared ownership without copying the body text.Arc::cloneshares the allocation; it does not clone the text.Error facts, file names, source locations, and parsing order remain unchanged. This does not remove every allocation from error handling or introduce a new lint.
Validation
Passed locally:
cargo test --locked -p runvil-prompt --all-features: 233 tests.cargo test --locked -p build-xtask: 204 passed, 21 ignored.cargo fmt --all --checkandgit diff --check.CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features.RUSTDOCFLAGS="-D warnings": workspace/all features, default-featurerunvil-engine, and default-featurerunvil.node --test tools/docs-claims.mjs: 3 tests.The fallback
cargo test --locked --workspace --all-featuresrun failed atlifecycle::the_fixture_is_loaded_invoked_unloaded_once_and_closedin the Plugin test fixture, on the assertion that the dynamic library is closed. That test also failed in isolation on this macOS machine. Its code is outside this change; the cause has not been established, and the full workspace suite is not claimed as passing.The prescribed
nextest, custom Dylint, and facade API checks were not run locally:cargo-nextest,cargo-dylint, and the pinnednightly-2026-09-05toolchain are not installed. CI results should be checked before merging.Follow-up
Once the Engine stabilizes, review
cloneandto_ownedcalls across the crates for similar patterns. Restructure ownership first where practical; when a copy really is needed to resolve a borrow conflict, explain the conflict. A broader audit, lint evaluation, or improved borrow-checker guidance is separate work—not something this PR claims to solve. Decision pages are unchanged because this is an internal refactor, not a change to a caller-visible decision.Closes #20.
Summary by CodeRabbit
Bug Fixes