mirror of
https://github.com/fluencelabs/aquavm
synced 2025-07-05 17:41:33 +00:00
feat(air): introduce explicit types for generation numbers (#530)
--------- Co-authored-by: vms <michail.vms@gmail.com> Co-authored-by: Anatolios Laskaris <github_me@nahsi.dev>
This commit is contained in:
@ -21,9 +21,11 @@ mod utils;
|
||||
use crate::execution_step::ExecutionResult;
|
||||
use crate::execution_step::Stream;
|
||||
use crate::ExecutionError;
|
||||
|
||||
use stream_descriptor::*;
|
||||
pub(crate) use stream_value_descriptor::StreamValueDescriptor;
|
||||
|
||||
use air_interpreter_data::GenerationIdx;
|
||||
use air_interpreter_data::GlobalStreamGens;
|
||||
use air_interpreter_data::RestrictedStreamGens;
|
||||
use air_parser::ast::Span;
|
||||
@ -82,7 +84,10 @@ impl Streams {
|
||||
.and_then(|descriptors| find_closest_mut(descriptors.iter_mut(), position))
|
||||
}
|
||||
|
||||
pub(crate) fn add_stream_value(&mut self, value_descriptor: StreamValueDescriptor<'_>) -> ExecutionResult<u32> {
|
||||
pub(crate) fn add_stream_value(
|
||||
&mut self,
|
||||
value_descriptor: StreamValueDescriptor<'_>,
|
||||
) -> ExecutionResult<GenerationIdx> {
|
||||
let StreamValueDescriptor {
|
||||
value,
|
||||
name,
|
||||
@ -105,17 +110,16 @@ impl Streams {
|
||||
let descriptor = StreamDescriptor::global(stream);
|
||||
self.streams.insert(name.to_string(), vec![descriptor]);
|
||||
let generation = 0;
|
||||
Ok(generation)
|
||||
Ok(generation.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn meet_scope_start(&mut self, name: impl Into<String>, span: Span, iteration: u32) {
|
||||
pub(crate) fn meet_scope_start(&mut self, name: impl Into<String>, span: Span, iteration: usize) {
|
||||
let name = name.into();
|
||||
let (prev_gens_count, current_gens_count) =
|
||||
self.stream_generation_from_data(&name, span.left, iteration as usize);
|
||||
let (prev_gens_count, current_gens_count) = self.stream_generation_from_data(&name, span.left, iteration);
|
||||
|
||||
let new_stream = Stream::from_generations_count(prev_gens_count as usize, current_gens_count as usize);
|
||||
let new_stream = Stream::from_generations_count(prev_gens_count, current_gens_count);
|
||||
let new_descriptor = StreamDescriptor::restricted(new_stream, span);
|
||||
match self.streams.entry(name) {
|
||||
Occupied(mut entry) => {
|
||||
@ -143,7 +147,7 @@ impl Streams {
|
||||
}
|
||||
let gens_count = last_descriptor.stream.compactify(trace_ctx)?;
|
||||
|
||||
self.collect_stream_generation(name, position, gens_count as u32);
|
||||
self.collect_stream_generation(name, position, gens_count);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -164,14 +168,19 @@ impl Streams {
|
||||
// of the execution
|
||||
let stream = descriptors.pop().unwrap().stream;
|
||||
let gens_count = stream.compactify(trace_ctx)?;
|
||||
Ok((name, gens_count as u32))
|
||||
Ok((name, gens_count))
|
||||
})
|
||||
.collect::<Result<GlobalStreamGens, _>>()?;
|
||||
|
||||
Ok((global_streams, self.new_restricted_stream_gens))
|
||||
}
|
||||
|
||||
fn stream_generation_from_data(&self, name: &str, position: AirPos, iteration: usize) -> (u32, u32) {
|
||||
fn stream_generation_from_data(
|
||||
&self,
|
||||
name: &str,
|
||||
position: AirPos,
|
||||
iteration: usize,
|
||||
) -> (GenerationIdx, GenerationIdx) {
|
||||
let previous_generation =
|
||||
Self::restricted_stream_generation(&self.previous_restricted_stream_gens, name, position, iteration)
|
||||
.unwrap_or_default();
|
||||
@ -187,14 +196,14 @@ impl Streams {
|
||||
name: &str,
|
||||
position: AirPos,
|
||||
iteration: usize,
|
||||
) -> Option<u32> {
|
||||
) -> Option<GenerationIdx> {
|
||||
restricted_stream_gens
|
||||
.get(name)
|
||||
.and_then(|scopes| scopes.get(&position).and_then(|iterations| iterations.get(iteration)))
|
||||
.copied()
|
||||
}
|
||||
|
||||
fn collect_stream_generation(&mut self, name: String, position: AirPos, generation: u32) {
|
||||
fn collect_stream_generation(&mut self, name: String, position: AirPos, generation: GenerationIdx) {
|
||||
match self.new_restricted_stream_gens.entry(name) {
|
||||
Occupied(mut streams) => match streams.get_mut().entry(position) {
|
||||
Occupied(mut iterations) => iterations.get_mut().push(generation),
|
||||
|
Reference in New Issue
Block a user