From 38c70f5a56c27ce3cbfe34528f908a6a9bdd6ff3 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 15 Nov 2024 14:19:54 +0200 Subject: [PATCH] feature: introduce `Host::advice_provider*` to access host's advice provider --- .../integration/operations/decorators/mod.rs | 10 +++++++ processor/src/host/mod.rs | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/miden/tests/integration/operations/decorators/mod.rs b/miden/tests/integration/operations/decorators/mod.rs index 9e4a17f35..d5bee4820 100644 --- a/miden/tests/integration/operations/decorators/mod.rs +++ b/miden/tests/integration/operations/decorators/mod.rs @@ -31,6 +31,16 @@ impl Default for TestHost { } impl Host for TestHost { + type AdviceProvider = A; + + fn advice_provider(&self) -> &Self::AdviceProvider { + &self.adv_provider + } + + fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider { + &mut self.adv_provider + } + fn get_advice( &mut self, process: ProcessState, diff --git a/processor/src/host/mod.rs b/processor/src/host/mod.rs index 0a5b7c65b..384e79ec2 100644 --- a/processor/src/host/mod.rs +++ b/processor/src/host/mod.rs @@ -31,9 +31,17 @@ pub use mast_forest_store::{MastForestStore, MemMastForestStore}; /// state of the VM ([ProcessState]), which it can use to extract the data required to fulfill the /// request. pub trait Host { + type AdviceProvider: AdviceProvider; + // REQUIRED METHODS // -------------------------------------------------------------------------------------------- + /// Returns a reference to the advice provider. + fn advice_provider(&self) -> &Self::AdviceProvider; + + /// Returns a mutable reference to the advice provider. + fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider; + /// Returns the requested advice, specified by [AdviceExtractor], from the host to the VM. fn get_advice( &mut self, @@ -174,6 +182,16 @@ impl Host for &mut H where H: Host, { + type AdviceProvider = H::AdviceProvider; + + fn advice_provider(&self) -> &Self::AdviceProvider { + H::advice_provider(self) + } + + fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider { + H::advice_provider_mut(self) + } + fn get_advice( &mut self, process: ProcessState, @@ -333,6 +351,16 @@ impl Host for DefaultHost where A: AdviceProvider, { + type AdviceProvider = A; + + fn advice_provider(&self) -> &Self::AdviceProvider { + &self.adv_provider + } + + fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider { + &mut self.adv_provider + } + fn get_advice( &mut self, process: ProcessState,