chore(execution-engine): remove unnecessary value_to_pos logic (#527)

remove unncessary value_to_pos logic
This commit is contained in:
Mike Voronov 2023-03-16 21:12:43 +03:00 committed by GitHub
parent f1975becb3
commit 93c54431b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 50 deletions

View File

@ -20,12 +20,9 @@ use crate::ExecutionError;
use crate::JValue;
use crate::UncatchableError;
use air_interpreter_data::TracePos;
use air_trace_handler::merger::ValueSource;
use air_trace_handler::TraceHandler;
use std::collections::HashMap;
/// Streams are CRDT-like append only data structures. They are guaranteed to have the same order
/// of values on each peer.
#[derive(Debug, Default, Clone)]
@ -38,10 +35,6 @@ pub struct Stream {
/// Count of values from previous data.
previous_gens_count: usize,
/// This map is intended to support canonicalized stream creation, such streams has
/// corresponding value positions in a data and this field are used to create such streams.
values_by_pos: HashMap<TracePos, StreamValueLocation>,
}
impl Stream {
@ -56,20 +49,15 @@ impl Stream {
Self {
values: vec![vec![]; overall_count],
previous_gens_count: previous_count,
values_by_pos: HashMap::new(),
}
}
// streams created with this ctor assumed to have only one generation,
// for streams that have values in
pub(crate) fn from_value(value: ValueAggregate) -> Self {
let values_by_pos = maplit::hashmap! {
value.trace_pos => StreamValueLocation::new(0, 0),
};
Self {
values: vec![vec![value]],
previous_gens_count: 0,
values_by_pos,
}
}
@ -95,12 +83,7 @@ impl Stream {
.into());
}
let values = &mut self.values[generation_number];
self.values_by_pos.insert(
value.trace_pos,
StreamValueLocation::new(generation_number, values.len()),
);
values.push(value);
self.values[generation_number].push(value);
Ok(generation_number as u32)
}
@ -175,16 +158,6 @@ impl Stream {
Some(JValue::Array(jvalue_array))
}
#[allow(dead_code)]
pub(crate) fn get_value_by_pos(&self, position: TracePos) -> Option<&ValueAggregate> {
let StreamValueLocation {
generation,
position_in_generation,
} = self.values_by_pos.get(&position)?;
let value = &self.values[*generation][*position_in_generation];
Some(value)
}
pub(crate) fn iter(&self, generation: Generation) -> Option<StreamIter<'_>> {
let iter: Box<dyn Iterator<Item = &ValueAggregate>> = match generation {
Generation::Nth(generation) if generation as usize >= self.generations_count() => return None,
@ -295,21 +268,6 @@ impl<'slice> Iterator for StreamSliceIter<'slice> {
}
}
#[derive(Clone, Copy, Debug, Default)]
struct StreamValueLocation {
pub generation: usize,
pub position_in_generation: usize,
}
impl StreamValueLocation {
pub(super) fn new(generation: usize, position_in_generation: usize) -> Self {
Self {
generation,
position_in_generation,
}
}
}
use std::fmt;
impl fmt::Display for Stream {

View File

@ -20,7 +20,6 @@ use crate::JValue;
use crate::ToErrorCode;
use air_interpreter_cid::CidCalculationError;
use air_interpreter_data::TracePos;
use air_interpreter_data::ValueRef;
use air_trace_handler::GenerationCompatificationError;
use air_trace_handler::TraceHandlerError;
@ -77,12 +76,6 @@ pub enum UncatchableError {
#[error("new end block tries to pop up a variable '{scalar_name}' that wasn't defined at depth {depth}")]
ScalarsStateCorrupted { scalar_name: String, depth: usize },
/// Variable with such a position wasn't defined during AIR script execution.
/// Canon instruction requires this value to be present in data, otherwise it's considered
/// as a hard error.
#[error("variable with position '{0}' wasn't defined during script execution")]
VariableNotFoundByPos(TracePos),
#[error("can't deserialize stream {canonicalized_stream:?} with error: {de_error}")]
InvalidCanonStreamInData {
canonicalized_stream: JValue,