-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Composable foreign call handlers #6857
Conversation
Peak Memory Sample
|
Compilation Sample
|
16ffefd
to
17fda21
Compare
Changes to Brillig bytecode sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Changes to number of Brillig opcodes executed
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
If I'm understanding things correctly, DefaultForeignCallExecutor
used to have three internal executors and it would try them one after the other. Now in this PR they are layered on top of each other, so the effect is the same... except that we end up without duplicated code.
That's right, the Then the With layering there is a chance to combine layers differently, and also to remove duplication by passing around builder functions. There is more reliance on the In the next extension we could add something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, I really like the removal of duplication between test and default executors.
Description
Problem*
Followup for #6849
Summary*
Adds a
foreign_calls::layer::Layer
construct which is used to composeForeignCallExecutor
instances.DefaultForeignCallExecutor
,DebugForeignCallExecutor
andTestForeignCallExecutor
are reimplemented with this layering.The
DefaultForeignCallExecutor
allows us to inject a base layer, which theTestForeignCallExecutor
uses to change the behaviour when nothing handles the call; this way we can reuse the default composition without having to repeat the logic in the test, similar to how theDefaultDebugForeignCallExecutor
did it earlier.Follow up for this would be:
DefaultForeignCallExecutor
optional, so that during normal execution no contract can install a mock and then handle foreign calls that should hit URLs. ADisabledMockForeignCallExecutor
has been added in this PR, but it's unused. (I'm not sure this is a legit concern, but I didn't see any reason it wouldn't work).run_test
accept a generic function to create aForeignCallExecutor
on top of theUnhandled
base handler, instead of explicitly creating aDefaultForeignCallExecutor
, so that we don't depend onRPCForeignCallExecutor
in the tests, and then we can compile them to Wasm. feat!:nargo::ops::test::run_test
generic inForeignCallExecutor
#6858Additional Context
It's a breaking change because it changes the return type of
DefaultForeignCallHandler::new
, although the way it's called is the same for now.Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.