Skip to content

Commit

Permalink
Make rustc/linter v1.78.0 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sword-Smith committed May 6, 2024
1 parent 05256ee commit c3e7f28
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 64 deletions.
2 changes: 1 addition & 1 deletion tasm-lib/src/arithmetic/u64/decr_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod tests {
use crate::test_helpers::test_rust_equivalence_given_input_values_deprecated;
use crate::test_helpers::test_rust_equivalence_multiple_deprecated;
use crate::traits::basic_snippet::BasicSnippet;
use crate::traits::deprecated_snippet::DeprecatedSnippetWrapper;
use crate::traits::deprecated_snippet::tests::DeprecatedSnippetWrapper;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion tasm-lib/src/arithmetic/u64/safe_mul_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod tests {
use crate::test_helpers::test_rust_equivalence_given_input_values_deprecated;
use crate::test_helpers::test_rust_equivalence_multiple_deprecated;
use crate::traits::basic_snippet::BasicSnippet;
use crate::traits::deprecated_snippet::DeprecatedSnippetWrapper;
use crate::traits::deprecated_snippet::tests::DeprecatedSnippetWrapper;

use super::*;

Expand Down
119 changes: 57 additions & 62 deletions tasm-lib/src/traits/deprecated_snippet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

use anyhow::Result;
use triton_vm::instruction::LabelledInstruction;
Expand All @@ -14,13 +12,10 @@ use crate::execute_test;
use crate::execute_with_terminal_state;
use crate::library::Library;
use crate::snippet_bencher::BenchmarkResult;
use crate::test_helpers::test_rust_equivalence_given_execution_state_deprecated;
use crate::InitVmState;
use crate::VmHasher;
use crate::DIGEST_LENGTH;

use super::basic_snippet::BasicSnippet;
use super::rust_shadow::RustShadow;

pub trait DeprecatedSnippet {
/// The name of a Snippet
Expand Down Expand Up @@ -193,61 +188,6 @@ pub trait DeprecatedSnippet {
}
}

#[cfg(test)]
pub(crate) struct DeprecatedSnippetWrapper<S: DeprecatedSnippet> {
pub(crate) deprecated_snippet: S,
}

#[cfg(test)]
impl<S: DeprecatedSnippet> DeprecatedSnippetWrapper<S> {
pub(crate) fn new(deprecated_snippet: S) -> Self {
Self { deprecated_snippet }
}
}

#[cfg(test)]
impl<S: DeprecatedSnippet + Clone + 'static> RustShadow for DeprecatedSnippetWrapper<S> {
fn inner(&self) -> Rc<RefCell<dyn BasicSnippet>> {
Rc::new(RefCell::new(self.deprecated_snippet.clone()))
}

fn rust_shadow_wrapper(
&self,
stdin: &[BFieldElement],
nondeterminism: &NonDeterminism,
stack: &mut Vec<BFieldElement>,
memory: &mut HashMap<BFieldElement, BFieldElement>,
_sponge: &mut Option<VmHasher>,
) -> Vec<BFieldElement> {
let mut stack_copy = stack.to_vec();
self.deprecated_snippet.rust_shadowing(
&mut stack_copy,
stdin.to_vec(),
nondeterminism.individual_tokens.clone(),
memory,
);
*stack = stack_copy;
vec![]
}

fn test(&self) {
let mut execution_states = self.deprecated_snippet.gen_input_states();

let snippet = &self.deprecated_snippet;

for execution_state in execution_states.iter_mut() {
test_rust_equivalence_given_execution_state_deprecated(
snippet,
execution_state.clone(),
);
}
}

fn bench(&self) {
todo!()
}
}

impl<S: DeprecatedSnippet> BasicSnippet for S {
fn inputs(&self) -> Vec<(DataType, String)> {
// Notice that the deprecated snippet trait has its input and output
Expand Down Expand Up @@ -303,15 +243,70 @@ impl<S: DeprecatedSnippet> BasicSnippet for S {
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
pub(crate) mod tests {
use std::{cell::RefCell, rc::Rc, str::FromStr};

use itertools::Itertools;

use crate::arithmetic;
use crate::test_helpers::test_rust_equivalence_given_execution_state_deprecated;
use crate::traits::rust_shadow::RustShadow;
use crate::VmHasher;

use super::*;

pub(crate) struct DeprecatedSnippetWrapper<S: DeprecatedSnippet> {
pub(crate) deprecated_snippet: S,
}

impl<S: DeprecatedSnippet> DeprecatedSnippetWrapper<S> {
pub(crate) fn new(deprecated_snippet: S) -> Self {
Self { deprecated_snippet }
}
}

impl<S: DeprecatedSnippet + Clone + 'static> RustShadow for DeprecatedSnippetWrapper<S> {
fn inner(&self) -> Rc<RefCell<dyn BasicSnippet>> {
Rc::new(RefCell::new(self.deprecated_snippet.clone()))
}

fn rust_shadow_wrapper(
&self,
stdin: &[BFieldElement],
nondeterminism: &NonDeterminism,
stack: &mut Vec<BFieldElement>,
memory: &mut HashMap<BFieldElement, BFieldElement>,
_sponge: &mut Option<VmHasher>,
) -> Vec<BFieldElement> {
let mut stack_copy = stack.to_vec();
self.deprecated_snippet.rust_shadowing(
&mut stack_copy,
stdin.to_vec(),
nondeterminism.individual_tokens.clone(),
memory,
);
*stack = stack_copy;
vec![]
}

fn test(&self) {
let mut execution_states = self.deprecated_snippet.gen_input_states();

let snippet = &self.deprecated_snippet;

for execution_state in execution_states.iter_mut() {
test_rust_equivalence_given_execution_state_deprecated(
snippet,
execution_state.clone(),
);
}
}

fn bench(&self) {
todo!()
}
}

#[test]
fn can_return_code() {
let mut empty_library = Library::new();
Expand Down

0 comments on commit c3e7f28

Please sign in to comment.