Skip to content

Commit

Permalink
Remove procedure_cache() test capability from Assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Jun 11, 2024
1 parent df8709b commit 8546c21
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 51 deletions.
6 changes: 0 additions & 6 deletions assembly/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions assembly/src/assembler/module_graph/procedure_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = Arc<Procedure>> + '_ {
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.
///
Expand Down
4 changes: 0 additions & 4 deletions assembly/src/assembler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
38 changes: 3 additions & 35 deletions assembly/src/testing.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()))
}
}

0 comments on commit 8546c21

Please sign in to comment.