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

Refactor Memory::relocate_memory #784

Merged
merged 28 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
386cb05
Add first draft inefficient implementation
fmoletta Jan 26, 2023
dd32ffb
Add new test cases
fmoletta Jan 26, 2023
a8a953f
Clean leftover segments + add tests
fmoletta Jan 26, 2023
a8a6bc0
Add temporal fix + TODO
fmoletta Jan 26, 2023
7f0664e
Add test programs
fmoletta Jan 26, 2023
911a9b2
Simplify code
fmoletta Jan 26, 2023
bf7d84f
Simplify code
fmoletta Jan 26, 2023
7535b72
Remove intermediate storange vec
fmoletta Jan 26, 2023
56e2a27
Reserve memory for relocated values
fmoletta Jan 26, 2023
156a940
Remove impossible-case code
fmoletta Jan 26, 2023
d01472e
Add tests
fmoletta Jan 26, 2023
2d59dac
Clippy
fmoletta Jan 26, 2023
f86017e
Remove temp_data trim
fmoletta Jan 26, 2023
1e67dc5
Simplify code + add test case
fmoletta Jan 26, 2023
88f9514
Remove comments + add cairo progran
fmoletta Jan 26, 2023
f60629a
Use remove instead of swap for relocated temporary memory
fmoletta Jan 26, 2023
80ca679
Rely on insertion errors + add tests
fmoletta Jan 27, 2023
39d1cf9
Merge branch 'main' of github.com:lambdaclass/cairo-rs into refactor-…
fmoletta Jan 27, 2023
04fc450
Add newline at eof
fmoletta Jan 27, 2023
0acd321
Add comment
fmoletta Jan 27, 2023
70e1a12
Change method name + add tests
fmoletta Jan 27, 2023
5169f42
Merge branch 'main' into refactor-relocate-memory
fmoletta Jan 27, 2023
72cecd8
Update CHANGELOG.md
fmoletta Jan 27, 2023
d317f20
Merge branch 'main' into refactor-relocate-memory
fmoletta Jan 27, 2023
37fd791
Update src/vm/vm_memory/memory.rs
fmoletta Feb 2, 2023
f18f31b
Update src/vm/vm_memory/memory.rs
fmoletta Feb 2, 2023
dfd4c29
Merge branch 'main' of github.com:lambdaclass/cairo-rs into refactor-…
fmoletta Feb 2, 2023
510c59c
Merge branch 'refactor-relocate-memory' of github.com:lambdaclass/cai…
fmoletta Feb 2, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#### Upcoming Changes

* Refactor `Memory::relocate_memory` [#784](https://github.com/lambdaclass/cairo-rs/pull/784)
* Bugfixes:
* `Memory::relocate_memory` now moves data in the temporary memory relocated by a relocation rule to the real memory
* Aditional Notes:
* When relocating temporary memory produces clashes with pre-existing values in the real memory, an InconsistentMemory error is returned instead of keeping the last inserted value. This differs from the original implementation.

* Restrict addresses to Relocatable + fix some error variants used in signature.rs [#792](https://github.com/lambdaclass/cairo-rs/pull/792)
* Public Api Changes:
* Change `ValidationRule` inner type to `Box<dyn Fn(&Memory, &Relocatable) -> Result<Vec<Relocatable>, MemoryError>>`.
Expand Down
4 changes: 0 additions & 4 deletions cairo_programs/relocate_segments.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ func main() {
ids.temporary_array = segments.add_temp_segment()
%}

// Insert values into temporary_array
assert temporary_array[0] = 1;
assert temporary_array[1] = 2;

// Create array
let (array : felt*) = alloc();

Expand Down
4 changes: 0 additions & 4 deletions cairo_programs/relocate_segments_with_offset.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ func main() {
ids.temporary_array = segments.add_temp_segment()
%}

// Insert values into temporary_array_no_offset
assert temporary_array[0] = 1;
assert temporary_array[1] = 2;

// Create array
let (array : felt*) = alloc();

Expand Down
27 changes: 27 additions & 0 deletions cairo_programs/relocate_temporary_segment_append.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.segments import relocate_segment

func main() {
alloc_locals;
// Create temporary_array in a temporary segment
local temporary_array: felt*;
%{
ids.temporary_array = segments.add_temp_segment()
%}

// Insert values into temporary_array
assert temporary_array[0] = 4;
assert temporary_array[1] = 5;
assert temporary_array[2] = 6;

// Create array
let (array: felt*) = alloc();
assert array[0] = 1;
assert array[1] = 2;
assert array[2] = 3;

// Realocate temporary_array into the array segment
relocate_segment(src_ptr=temporary_array, dest_ptr=array + 3);

return ();
}
24 changes: 24 additions & 0 deletions cairo_programs/relocate_temporary_segment_into_new.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.segments import relocate_segment

func main() {
alloc_locals;
// Create temporary_array in a temporary segment
local temporary_array: felt*;
%{
ids.temporary_array = segments.add_temp_segment()
%}

// Insert values into temporary_array
assert temporary_array[0] = 1;
assert temporary_array[1] = 2;
assert temporary_array[2] = 3;

// Create array
let (array: felt*) = alloc();

// Realocate temporary_array into the array segment
relocate_segment(src_ptr=temporary_array, dest_ptr=array);

return ();
}
Loading