Resolver: Arc<dyn Fn> with a non-breaking impl Fn constructor - #15
Closed
mwaddip wants to merge 3 commits into
Closed
Resolver: Arc<dyn Fn> with a non-breaking impl Fn constructor#15mwaddip wants to merge 3 commits into
mwaddip wants to merge 3 commits into
Conversation
…upport The Resolver type was defined as a bare function pointer (fn(&Digest32) -> Node), which cannot capture state. This makes it impossible to implement VersionedAVLStorage with a real storage backend — the resolver needs to load nodes from a database, but a function pointer cannot hold a database reference. Changed to Arc<dyn Fn(&Digest32) -> Node + Send + Sync> which allows closures that capture storage handles. Arc (not Box) because AVLTree derives Clone. Send + Sync for thread safety with concurrent readers. All 22 existing tests pass unchanged (modulo wrapping bare functions in Arc::new). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
28862a1 changed Resolver from a plain fn pointer to Arc<dyn Fn> for the persistence backend, which broke every caller written against the old signature (sigma-rust's interpreter passes bare closures at 13 sites). Take `impl Fn(&Digest32) -> Node + Send + Sync + 'static` and wrap it in the Arc inside the constructor: fn-pointer-era callers compile unchanged, capturing closures (the persistence resolver) pass straight in without their own Arc::new. Callers holding a prebuilt Resolver construct the struct literally — `resolver` is a pub field. Internal call sites (prover test + tests/common) updated to drop the now-redundant Arc::new. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… Arc resolvers a4a2aa7 changed new() to take impl Fn, which fixed bare-closure callers (ergotree-interpreter's 13 sites) but BREAKS callers holding a pre-built Resolver (Arc<dyn Fn>): Arc<dyn Fn> does not implement Fn, so the node's persistence-backend resolvers are rejected with E0277. Introduce IntoResolver, implemented for both F: Fn(...) (Arc-wrapped here) and Resolver (passed through, no re-wrap), and take impl IntoResolver in new(). The two impls don't overlap precisely because Arc<dyn Fn> isn't Fn. Serves the interpreter and the node from one constructor; the internal bare-closure call sites are unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Superseded by #16. #15 carried the |
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.
Replaces #10. That PR was opened from
mwaddip:mainand, as the fork'smainadvanced, accreted commits belonging to #11/#13/#14; this is a self-contained 2-commit branch offmain.Changes the
Resolvertype from a barefnpointer toArc<dyn Fn(&Digest32) -> Node + Send + Sync>, so persistence/storage backends can hold captured state.To keep it non-breaking,
AVLTree::newnow acceptsimpl Fn(&Digest32) -> Node + Send + Sync + 'staticand wraps it in theArcinternally — callers written against the old fn-pointer signature (e.g. ergotree-interpreter's 13 bare-closure sites) compile unchanged. Callers holding a prebuiltResolverconstruct the struct literally (resolveris pub).All crate tests pass.