Skip to content

Commit

Permalink
fix(execution-engine): quickfix for canon map iteration order (#845)
Browse files Browse the repository at this point in the history
An O(n) quickfix for the canon map reverse iteration bug.
  • Loading branch information
monoid authored Jul 22, 2024
1 parent c611ae5 commit 038637f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions air/src/execution_step/instructions/fold/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ pub(crate) fn create_canon_stream_map_iterable_value(
}
}
}
// the reverse iteration of the original data produce `values` in reverse order;
// the spec requires direct order of iteration, so reverse it one more time
//
// it can be solved at O(1) with special handling of reversed iterators in fold,
// so this O(n) implementation is just a quick fix
values.reverse();

let iterable_ingredients = CanonStreamMapIterableIngredients::init(values);
let iterable = Box::new(iterable_ingredients);
Expand Down
28 changes: 14 additions & 14 deletions air/tests/test_module/instructions/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,12 +955,12 @@ async fn fold_canon_stream_map() {
(seq
(seq
(seq
(ap ("key" "value4") %map)
(ap (-42 "value3") %map)
(ap ("key" "value1") %map)
(ap (-42 "value2") %map)
)
(seq
(ap (-42 "value2") %map)
(ap ("key" "value1") %map)
(ap (-42 "value3") %map)
(ap ("key" "value4") %map)
)
)
(seq
Expand All @@ -986,8 +986,8 @@ async fn fold_canon_stream_map() {
let mut cid_tracker: ExecutionCidState = ExecutionCidState::new();
let tetraplet = json!({"function_name": "", "lens": "", "peer_pk": vm_1_peer_id, "service_id": ""});

let map_value_2 = json!({"key": -42, "value": "value2"});
let map_value_1 = json!({"key": "key", "value": "value1"});
let map_value_2 = json!({"key": -42, "value": "value2"});
let map_value_3 = json!({"key": -42, "value": "value3"});
let map_value_4 = json!({"key": "key", "value": "value4"});

Expand All @@ -999,44 +999,44 @@ async fn fold_canon_stream_map() {
canon_tracked(
json!({"tetraplet": tetraplet,
"values": [
{
"result": map_value_4,
{
"result": map_value_1,
"tetraplet": tetraplet,
"provenance": Provenance::Literal,
},
{
"result": map_value_3,
"result": map_value_2,
"tetraplet": tetraplet,
"provenance": Provenance::Literal,
},
{
"result": map_value_2,
"result": map_value_3,
"tetraplet": tetraplet,
"provenance": Provenance::Literal,
},
{
"result": map_value_1,
"result": map_value_4,
"tetraplet": tetraplet,
"provenance": Provenance::Literal,
},
]}),
&mut cid_tracker,
),
scalar_tracked!(
map_value_1.clone(),
map_value_3.clone(),
cid_tracker,
peer = &vm_1_peer_id,
service = "m..0",
function = "f",
args = [map_value_1]
args = [map_value_3]
),
scalar_tracked!(
map_value_2.clone(),
map_value_4.clone(),
cid_tracker,
peer = vm_1_peer_id,
service = "m..0",
function = "f",
args = [map_value_2]
args = [map_value_4]
),
];

Expand Down

0 comments on commit 038637f

Please sign in to comment.