Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce canon instruction #292

Merged
merged 23 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
## Version 0.24.0 (2021-04-21)
## Version 0.27.0 (2022-08-23)

[PR 292](https://github.com/fluencelabs/aquavm/pull/292):
Introduced a new `canon` instruction

[PR 296](https://github.com/fluencelabs/aquavm/pull/296):
A bug with an inappropriate check of states in the `Ap` merger was fixed

## Version 0.26.0 (2022-08-19)

[PR 294](https://github.com/fluencelabs/aquavm/pull/294):
Accompanying to air-interpreter update that makes interface more handy for `air-trace`

## Version 0.25.0 (2022-07-27)

[PR 287](https://github.com/fluencelabs/aquavm/pull/287):
Memory leak introduced by switching to reactor/command model in WASI fixed

[PR 276](https://github.com/fluencelabs/aquavm/pull/276):
AquaVM performance was improved by removing excess logging

[PR 273](https://github.com/fluencelabs/aquavm/pull/273):
Introduced `TracePos` for `TraceHandler` positions

[PR 270](https://github.com/fluencelabs/aquavm/pull/270):
A bug with empty subtrace lore in TraceHandler was fixed

## Version 0.24.0 (2022-04-21)

[PR 253](https://github.com/fluencelabs/aquavm/pull/253):
Introduced %ttl% keyword

## Version 0.24.0 (2021-04-20)
## Version 0.24.0 (2022-04-20)

[PR 250](https://github.com/fluencelabs/aquavm/pull/250):
Introduced %timestamp% keyword

## Version 0.23.0 (2021-04-20)
## Version 0.23.0 (2022-04-20)

[PR 248](https://github.com/fluencelabs/aquavm/pull/248):
Introduced new for scalars

[PR 244](https://github.com/fluencelabs/aquavm/pull/244):
Stack size was increased to 50 MiB

## Version 0.22.0 (2021-04-14)
## Version 0.22.0 (2022-04-14)

[PR 243](https://github.com/fluencelabs/aquavm/pull/243):
Clean scalars at the end of scope, only one next in a fold over scalar is possible now
Expand All @@ -27,13 +54,13 @@ Test refactoring
[PR 228](https://github.com/fluencelabs/aquavm/pull/228):
Improve stream determinism

## Version 0.21.0 (2021-02-26)
## Version 0.21.0 (2022-02-26)

[PR 225](https://github.com/fluencelabs/aquavm/pull/225):
Introduce recursive streams

[PR 224](https://github.com/fluencelabs/aquavm/pull/224) [PR 220](https://github.com/fluencelabs/aquavm/pull/224) [PR 217](https://github.com/fluencelabs/aquavm/pull/217) [PR 215](https://github.com/fluencelabs/aquavm/pull/215) [PR 212](https://github.com/fluencelabs/aquavm/pull/212) [PR 207](https://github.com/fluencelabs/aquavm/pull/207):
Various bugs fixed
Various bugs were fixed

[PR 210](https://github.com/fluencelabs/aquavm/pull/210):
Add API for returning AquaVM consumed memory size
Expand Down
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion air-interpreter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "air-interpreter"
version = "0.26.0"
version = "0.27.0"
description = "Crate-wrapper for air"
authors = ["Fluence Labs"]
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion air/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "air"
version = "0.26.0"
version = "0.27.0"
description = "Interpreter of AIR scripts intended to coordinate request flow in the Fluence network"
authors = ["Fluence Labs"]
edition = "2018"
Expand Down
12 changes: 5 additions & 7 deletions air/src/execution_step/air/ap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use crate::SecurityTetraplet;
use apply_to_arguments::*;
use utils::*;

use air_parser::ast;
use air_parser::ast::Ap;
use air_parser::ast::ApResult;
use air_trace_handler::MergerApResult;

use std::rc::Rc;
Expand All @@ -57,7 +57,7 @@ impl<'i> super::ExecutableInstruction<'i> for Ap<'i> {
/// This function is intended to check whether a Ap instruction should produce
/// a new state in data.
fn should_touch_trace(ap: &Ap<'_>) -> bool {
matches!(ap.result, ast::Variable::Stream(_))
matches!(ap.result, ApResult::Stream(_))
}

fn to_merger_ap_result(
Expand All @@ -77,16 +77,14 @@ fn to_merger_ap_result(
}

fn update_context<'ctx>(
ap_result_type: &ast::Variable<'ctx>,
ap_result_type: &ApResult<'ctx>,
merger_ap_result: &MergerApResult,
result: ValueAggregate,
exec_ctx: &mut ExecutionCtx<'ctx>,
) -> ExecutionResult<Option<u32>> {
use ast::Variable::*;

match ap_result_type {
Scalar(scalar) => exec_ctx.scalars.set_value(scalar.name, result).map(|_| None),
Stream(stream) => {
ApResult::Scalar(scalar) => exec_ctx.scalars.set_scalar_value(scalar.name, result).map(|_| None),
ApResult::Stream(stream) => {
let generation = ap_result_to_generation(merger_ap_result);
exec_ctx
.streams
Expand Down
47 changes: 47 additions & 0 deletions air/src/execution_step/air/ap/apply_to_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub(super) fn apply_to_arg(
Boolean(value) => apply_const(*value, exec_ctx, trace_ctx),
EmptyArray => apply_const(serde_json::json!([]), exec_ctx, trace_ctx),
Scalar(scalar) => apply_scalar(scalar, exec_ctx, trace_ctx, should_touch_trace)?,
CanonStream(canon_stream) => apply_canon_stream(canon_stream, exec_ctx, trace_ctx)?,
};

Ok(result)
Expand Down Expand Up @@ -118,3 +119,49 @@ fn apply_scalar_wl_impl(

Ok(result)
}

fn apply_canon_stream(
canon_stream: &ast::CanonStreamWithLambda<'_>,
exec_ctx: &ExecutionCtx<'_>,
trace_ctx: &TraceHandler,
) -> ExecutionResult<ValueAggregate> {
match &canon_stream.lambda {
Some(lambda) => apply_canon_stream_with_lambda(canon_stream.name, lambda, exec_ctx, trace_ctx),
None => apply_canon_stream_without_lambda(canon_stream.name, exec_ctx, trace_ctx),
}
}

fn apply_canon_stream_with_lambda(
stream_name: &str,
lambda: &LambdaAST<'_>,
exec_ctx: &ExecutionCtx<'_>,
trace_ctx: &TraceHandler,
) -> ExecutionResult<ValueAggregate> {
use crate::execution_step::boxed_value::JValuable;

let canon_stream = exec_ctx.scalars.get_canon_stream(stream_name)?;
let jvaluable = &canon_stream as &dyn JValuable;
mikevoronov marked this conversation as resolved.
Show resolved Hide resolved
let (result, tetraplet) = jvaluable.apply_lambda_with_tetraplets(lambda, exec_ctx)?;
let position = trace_ctx.trace_pos();
// TODO: refactor this code after boxed value
let value = ValueAggregate::new(Rc::new(result.clone()), Rc::new(tetraplet), position);
Ok(value)
}

fn apply_canon_stream_without_lambda(
stream_name: &str,
exec_ctx: &ExecutionCtx<'_>,
trace_ctx: &TraceHandler,
) -> ExecutionResult<ValueAggregate> {
use crate::execution_step::boxed_value::JValuable;

let canon_stream = exec_ctx.scalars.get_canon_stream(stream_name)?;
let jvaluable = &canon_stream as &dyn JValuable;
// TODO: refactor this code after boxed value
let value = jvaluable.as_jvalue().into_owned();
mikevoronov marked this conversation as resolved.
Show resolved Hide resolved

let tetraplet = canon_stream.tetraplet().clone();
let position = trace_ctx.trace_pos();
let value = ValueAggregate::new(Rc::new(value), tetraplet, position);
Ok(value)
}
4 changes: 2 additions & 2 deletions air/src/execution_step/air/ap/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pub(super) fn try_match_trace_to_instr(merger_ap_result: &MergerApResult, instr:
}

fn match_position_variable(
variable: &ast::Variable<'_>,
variable: &ast::ApResult<'_>,
generation: Option<u32>,
ap_result: &MergerApResult,
) -> ExecutionResult<()> {
use crate::execution_step::UncatchableError::ApResultNotCorrespondToInstr;
use ast::Variable::*;
use ast::ApResult::*;

match (variable, generation) {
(Stream(_), Some(_)) => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion air/src/execution_step/air/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pub(crate) mod call_result_setter;
mod prev_result_handler;
mod resolved_call;
mod triplet;
pub(crate) mod triplet;
mikevoronov marked this conversation as resolved.
Show resolved Hide resolved

use resolved_call::ResolvedCall;

Expand Down
13 changes: 6 additions & 7 deletions air/src/execution_step/air/call/call_result_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use air_interpreter_data::CallResult;
use air_interpreter_data::TracePos;
use air_interpreter_data::Value;
use air_parser::ast::CallOutputValue;
use air_parser::ast::Variable;
use air_trace_handler::TraceHandler;

/// Writes result of a local `Call` instruction to `ExecutionCtx` at `output`.
Expand All @@ -35,11 +34,11 @@ pub(crate) fn set_local_result<'i>(
) -> ExecutionResult<CallResult> {
let result_value = executed_result.result.clone();
match output {
CallOutputValue::Variable(Variable::Scalar(scalar)) => {
exec_ctx.scalars.set_value(scalar.name, executed_result)?;
CallOutputValue::Scalar(scalar) => {
exec_ctx.scalars.set_scalar_value(scalar.name, executed_result)?;
Ok(CallResult::executed_scalar(result_value))
}
CallOutputValue::Variable(Variable::Stream(stream)) => {
CallOutputValue::Stream(stream) => {
let generation =
exec_ctx
.streams
Expand All @@ -58,11 +57,11 @@ pub(crate) fn set_result_from_value<'i>(
exec_ctx: &mut ExecutionCtx<'i>,
) -> ExecutionResult<()> {
match (output, value) {
(CallOutputValue::Variable(Variable::Scalar(scalar)), Value::Scalar(value)) => {
(CallOutputValue::Scalar(scalar), Value::Scalar(value)) => {
let result = ValueAggregate::new(value, tetraplet, trace_pos);
exec_ctx.scalars.set_value(scalar.name, result)?;
exec_ctx.scalars.set_scalar_value(scalar.name, result)?;
}
(CallOutputValue::Variable(Variable::Stream(stream)), Value::Stream { value, generation }) => {
(CallOutputValue::Stream(stream), Value::Stream { value, generation }) => {
let result = ValueAggregate::new(value, tetraplet, trace_pos);
let generation = Generation::Nth(generation);
let _ = exec_ctx
Expand Down
2 changes: 1 addition & 1 deletion air/src/execution_step/air/call/resolved_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn check_output_name(output: &ast::CallOutputValue<'_>, exec_ctx: &ExecutionCtx<
use crate::execution_step::boxed_value::ScalarRef;

let scalar_name = match output {
ast::CallOutputValue::Variable(ast::Variable::Scalar(scalar)) => scalar.name,
ast::CallOutputValue::Scalar(scalar) => scalar.name,
_ => return Ok(()),
};

Expand Down
6 changes: 5 additions & 1 deletion air/src/execution_step/air/call/triplet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ pub(crate) fn resolve<'i>(triplet: &ast::Triplet<'i>, ctx: &ExecutionCtx<'i>) ->

/// Resolve value to string by either resolving variable from `ExecutionCtx`, taking literal value, or etc.
// TODO: return Rc<String> to avoid excess cloning
fn resolve_to_string<'i>(value: &ast::CallInstrValue<'i>, ctx: &ExecutionCtx<'i>) -> ExecutionResult<String> {
// TODO: move this function into resolve in boxed value PR
pub(crate) fn resolve_to_string<'i>(
value: &ast::CallInstrValue<'i>,
ctx: &ExecutionCtx<'i>,
) -> ExecutionResult<String> {
use crate::execution_step::resolver::resolve_ast_variable_wl;
use ast::CallInstrValue::*;

Expand Down
Loading