From 8546c2142739a7301af89e83a29123508a594bdd Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 11 Jun 2024 16:52:21 -0400 Subject: [PATCH] Remove `procedure_cache()` test capability from `Assembler` --- assembly/src/assembler/mod.rs | 6 --- .../assembler/module_graph/procedure_cache.rs | 6 --- assembly/src/assembler/tests.rs | 4 -- assembly/src/testing.rs | 38 ++----------------- 4 files changed, 3 insertions(+), 51 deletions(-) diff --git a/assembly/src/assembler/mod.rs b/assembly/src/assembler/mod.rs index 07f36ea68d..5deff97767 100644 --- a/assembly/src/assembler/mod.rs +++ b/assembly/src/assembler/mod.rs @@ -300,12 +300,6 @@ impl Assembler { self.allow_phantom_calls } - #[cfg(any(test, feature = "testing"))] - #[doc(hidden)] - pub fn procedure_cache(&self) -> &ProcedureCache { - &self.procedure_cache - } - #[cfg(any(test, feature = "testing"))] #[doc(hidden)] pub fn module_graph(&self) -> &ModuleGraph { diff --git a/assembly/src/assembler/module_graph/procedure_cache.rs b/assembly/src/assembler/module_graph/procedure_cache.rs index 3c3257ea50..cfe72437f6 100644 --- a/assembly/src/assembler/module_graph/procedure_cache.rs +++ b/assembly/src/assembler/module_graph/procedure_cache.rs @@ -143,12 +143,6 @@ impl ProcedureCache { self.by_mast_root.contains_key(hash) } - /// Returns an iterator over the non-empty entries in the cache - #[cfg(test)] - pub fn entries(&self) -> impl Iterator> + '_ { - self.cache.iter().flat_map(|m| m.iter().filter_map(|p| p.clone())) - } - /// Inserts the given [Procedure] into this cache, using the [GlobalProcedureIndex] as the /// cache key. /// diff --git a/assembly/src/assembler/tests.rs b/assembly/src/assembler/tests.rs index 384db5a785..3140363a18 100644 --- a/assembly/src/assembler/tests.rs +++ b/assembly/src/assembler/tests.rs @@ -70,10 +70,6 @@ fn nested_blocks() { // The expected `MastForest` for the program (that we will build by hand) let mut expected_mast_forest = MastForest::new(); - // the assembler should have a single kernel proc in its cache before the compilation of the - // source - assert_eq!(assembler.procedure_cache().len(), 1); - // fetch the kernel digest and store into a syscall block // // Note: this assumes the current internal implementation detail that `assembler.mast_forest` diff --git a/assembly/src/testing.rs b/assembly/src/testing.rs index 23a4ec4f16..e1e34d1a64 100644 --- a/assembly/src/testing.rs +++ b/assembly/src/testing.rs @@ -1,6 +1,6 @@ use crate::{ - assembler::{Assembler, AssemblyContext, ProcedureCache}, - ast::{Form, FullyQualifiedProcedureName, Module, ModuleKind}, + assembler::{Assembler, AssemblyContext}, + ast::{Form, Module, ModuleKind}, diagnostics::{ reporting::{set_hook, ReportHandlerOpts}, Report, SourceFile, @@ -13,10 +13,7 @@ use crate::diagnostics::reporting::set_panic_hook; use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}; use core::fmt; -use vm_core::{ - mast::{MastForest, Program}, - utils::DisplayHex, -}; +use vm_core::mast::{MastForest, Program}; /// Represents a pattern for matching text abstractly /// for use in asserting contents of complex diagnostics @@ -335,33 +332,4 @@ impl TestContext { }; self.assembler.assemble_module(module, options, &mut context, mast_forest) } - - /// Get a reference to the [ProcedureCache] of the [Assembler] constructed by this context. - pub fn procedure_cache(&self) -> &ProcedureCache { - self.assembler.procedure_cache() - } - - /// Display the MAST root associated with `name` in the procedure cache of the [Assembler] - /// constructed by this context. - /// - /// It is expected that the module containing `name` was previously compiled by the assembler, - /// and is thus in the cache. This function will panic if that is not the case. - pub fn display_digest_from_cache( - &self, - name: &FullyQualifiedProcedureName, - mast_forest: &MastForest, - ) -> impl fmt::Display { - self.procedure_cache() - .get_by_name(name) - .map(|p| p.mast_root(mast_forest)) - .map(DisplayDigest) - .unwrap_or_else(|| panic!("procedure '{}' is not in the procedure cache", name)) - } -} - -struct DisplayDigest(RpoDigest); -impl fmt::Display for DisplayDigest { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:#x}", DisplayHex(self.0.as_bytes().as_slice())) - } }