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

add SquashedFelt252Dict in executor #611

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,18 @@ fn parse_result(
),
},
CoreTypeConcrete::Felt252DictEntry(_) => todo!(),
CoreTypeConcrete::SquashedFelt252Dict(_) => todo!(),
CoreTypeConcrete::SquashedFelt252Dict(_) => match return_ptr {
Some(return_ptr) => JitValue::from_jit(
unsafe { *return_ptr.cast::<NonNull<()>>().as_ref() },
type_id,
registry,
),
None => JitValue::from_jit(
NonNull::new(ret_registers[0] as *mut ()).unwrap(),
type_id,
registry,
),
},
CoreTypeConcrete::Span(_) => todo!(),
CoreTypeConcrete::Snapshot(_) => todo!(),
CoreTypeConcrete::Bytes31(_) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/cairo_vm/felt_dict_squash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() -> SquashedFelt252Dict<Nullable<Span<felt252>>> {

// Create the array to insert
let a = array![8, 9, 10, 11];
let b = array![1, 2, 3];
let b = array![1, 2, 3, 44];
let c = array![4, 5, 6];

// Insert it as a `Span`
Expand Down
27 changes: 27 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ pub fn compare_outputs(
CoreTypeConcrete::NonZero(info) => map_vm_sizes(size_cache, registry, &info.ty),
CoreTypeConcrete::EcPoint(_) => 2,
CoreTypeConcrete::EcState(_) => 4,
CoreTypeConcrete::Snapshot(info) => {
map_vm_sizes(size_cache, registry, &info.ty)
}
x => todo!("vm size not yet implemented: {:?}", x.info()),
};
size_cache.insert(ty.clone(), type_size);
Expand Down Expand Up @@ -459,6 +462,30 @@ pub fn compare_outputs(
.collect(),
debug_name: ty.debug_name.as_deref().map(String::from),
},
CoreTypeConcrete::SquashedFelt252Dict(info) => JitValue::Felt252Dict {
value: (values[0].to_usize().unwrap()..values[1].to_usize().unwrap())
.step_by(3)
.map(|index| {
(
Felt::from_bytes_le(&memory[index].clone().unwrap().to_le_bytes()),
match &info.info.long_id.generic_args[0] {
cairo_lang_sierra::program::GenericArg::Type(ty) => map_vm_values(
size_cache,
registry,
memory,
&[memory[index + 2].clone().unwrap()],
ty,
),
_ => unimplemented!("unsupported dict value type"),
},
)
})
.collect(),
debug_name: ty.debug_name.as_deref().map(String::from),
},
CoreTypeConcrete::Snapshot(info) => {
map_vm_values(size_cache, registry, memory, values, &info.ty)
}
CoreTypeConcrete::Nullable(info) => {
assert_eq!(values.len(), 1);

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ use test_case::test_case;
#[test_case("tests/cases/cairo_vm/array_integer_tuple.cairo")]
#[test_case("tests/cases/cairo_vm/bitwise.cairo")]
// #[test_case("tests/cases/cairo_vm/bytes31_ret.cairo")]
// #[test_case("tests/cases/cairo_vm/dict_with_struct.cairo")]
#[test_case("tests/cases/cairo_vm/dict_with_struct.cairo")]
#[test_case("tests/cases/cairo_vm/dictionaries.cairo")]
#[test_case("tests/cases/cairo_vm/ecdsa_recover.cairo")]
#[test_case("tests/cases/cairo_vm/enum_flow.cairo")]
#[test_case("tests/cases/cairo_vm/enum_match.cairo")]
#[test_case("tests/cases/cairo_vm/factorial.cairo")]
// #[test_case("tests/cases/cairo_vm/felt_dict.cairo")]
// #[test_case("tests/cases/cairo_vm/felt_dict_squash.cairo")]
#[test_case("tests/cases/cairo_vm/felt_dict_squash.cairo")]
// #[test_case("tests/cases/cairo_vm/felt_span.cairo")]
#[test_case("tests/cases/cairo_vm/fibonacci.cairo")]
#[test_case("tests/cases/cairo_vm/hello.cairo")]
Expand Down
Loading