Repository navigation
fix(scoring)!: describe matched entities without copying them - #264
Merged
Merged
Conversation
Constraint analysis stored every matched entity as a type-erased copy,
`Arc::new(entity.clone())` inside `EntityRef`, so that `as_entity::<T>()`
could downcast it later. Nothing outside two tests ever read that copy:
equality, hashing and display used only the type name and `Debug`
rendering. The copy was the only reason explanation needed `Clone`, it put
an `Arc` behind a rule that forbids one, and it cost an allocation and a
deep clone per entity per match on every analysis call.
`EntityRef` is now just `{ type_name, display }`, built from any
`T: Debug + ?Sized`. With the copy gone, no scoring stream needs `Clone` on
an entity type: the `Clone` bound is removed from all 130 entity type
parameters across the stream builders, joins, groups, complements,
projections and terminals, and the scoring crate compiles without it. Generic
scoring code therefore cannot clone an entity; a `.clone()` on one no longer
compiles. Collector payloads keep their own contract (`CollectedVec::to_vec`
still asks for `T: Clone` when called).
Tests: matches justify `Debug`-only entities (the grouped analysis fixtures
no longer derive `Clone`), and an `EntityRef` describes a borrowed,
non-`'static` entity. The type-erasure exception for `EntityRef` payloads is
removed from AGENTS.md, which now states that scoring streams do not require
`Clone` on entities.
BREAKING CHANGE: Constraint analysis describes entities by type name and `Debug` rendering only. `EntityRef::as_entity` and `EntityRef::with_display` are removed and `EntityRef::new` takes any `T: Debug + ?Sized`; read the entity from your solution instead of from the match. Grouped and complemented constraints, which now report their matches (#261), require `Debug` on their entities like every other constraint. `SharedOperatorBuilder::with_explainer` and `OperatorScorerSet::score_for` are removed. Scoring streams no longer require `Clone` on entity types.
blackopsrepl
force-pushed
the
fix/entity-ref-without-copy
branch
from
November 14, 2026 08:43
5012784 to
821a841
Compare
Collaborator
Author
Zero-regression gate —
|
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.
What
EntityRef, the entity entry in constraint analysis, no longer keeps a copy of the entity. It is now{ type_name, display }: the entity's type name andDebugrendering, taken when a match is explained.Why
Arc::new(entity.clone())behind adyn Any, there only soas_entity::<T>()could downcast it.Cloneon entities.Arcbehind a rule that forbidsArc, and cost an allocation plus a deep clone per entity per match on every analysis call.Result
Cloneon an entity type. The bound is gone from all 130 entity type parameters, and the scoring crate compiles without it. Generic scoring code can no longer clone an entity: a.clone()on one does not compile.Debug, works for borrowed, non-'statictypes, and allocates no entity copies.CollectedVec::to_veckeeps its ownT: Clonerequirement, asked for only when that method is called.Breaking
EntityRef::as_entityandEntityRef::with_displayare removed, andEntityRef::newtakes anyT: Debug + ?Sized. Read the entity from your solution instead of from the match. The commit carries theBREAKING CHANGEfooter, so the next release is 0.28.0 and its changelog says so.Verification
Debug-only, and a new test explains a borrowed, non-'staticentity.make pre-releaseandmake examplespass.public-api.txtis blessed.EntityReftype-erasure exception and states that scoring streams do not requireCloneon entities.docs/constraints.mdanddocs/extend-scoring.mdare updated.