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 Display trait to Memory struct #812

Merged
merged 6 commits into from
Feb 13, 2023
Merged

Conversation

Jrigada
Copy link
Contributor

@Jrigada Jrigada commented Feb 2, 2023

Add Display trait to Memory struct

Description

#799

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.

Copy link
Member

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the temporary memory too.
Ideally something like

temp_memory: [[1,2,3][1,2]]
real_memory: [[1,2]]

should look like this:

-1:0 : 1
-1:1 : 2
-1:2 : 3
-2:0 : 1
-2:1 : 2
0;0 : 1
0:1 : 2

for (i, segment) in self.data.iter().enumerate() {
for (j, cell) in segment.iter().enumerate() {
if let Some(cell) = cell {
writeln!(f, " {},{} : {}", i, j, cell)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
writeln!(f, " {},{} : {}", i, j, cell)?;
writeln!(f, " ({i},{j}) : {cell}")?;

@@ -300,6 +301,29 @@ impl Memory {
}
}

impl Display for Memory {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
writeln!(f, "temp_memory {{")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid making distinctions between real and temporary memory and just pritnt them out as a single memory. Temporary segments can be identified by their negative index

Comment on lines 307 to 310
for (i, segment) in self.temp_data.iter().enumerate() {
for (j, cell) in segment.iter().enumerate() {
if let Some(cell) = cell {
writeln!(f, " ({i},{j}) : {cell}")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that temporary memory segment indexes start from -1, but we store them from 0 (cuz vec). So when printing out the temporary addresses we should be printing -(i + 1) instead of i

@@ -300,6 +301,28 @@ impl Memory {
}
}

impl Display for Memory {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
writeln!(f, "memory {{")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is necessary, the user already knows its the memory being displayed if they print the memory

}
}
}
writeln!(f, "}}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These symbols make it look like a Debug rather than a Display, we could avoid them

@codecov
Copy link

codecov bot commented Feb 13, 2023

Codecov Report

Merging #812 (9d9aab1) into main (4a642c7) will increase coverage by 97.81%.
The diff coverage is 93.33%.

@@            Coverage Diff            @@
##           main     #812       +/-   ##
=========================================
+ Coverage      0   97.81%   +97.81%     
=========================================
  Files         0       69       +69     
  Lines         0    29410    +29410     
=========================================
+ Hits          0    28767    +28767     
- Misses        0      643      +643     
Impacted Files Coverage Δ
src/vm/vm_memory/memory.rs 99.18% <93.33%> (ø)
src/types/layout.rs 99.50% <0.00%> (ø)
src/types/relocatable.rs 99.31% <0.00%> (ø)
src/vm/runners/builtin_runner/hash.rs 99.06% <0.00%> (ø)
...or/builtin_hint_processor/skip_next_instruction.rs 100.00% <0.00%> (ø)
...uiltin_hint_processor/cairo_keccak/keccak_hints.rs 95.37% <0.00%> (ø)
...ocessor/builtin_hint_processor/secp/field_utils.rs 100.00% <0.00%> (ø)
src/vm/runners/builtin_runner/signature.rs 97.58% <0.00%> (ø)
...t_processor/builtin_hint_processor/sha256_utils.rs 100.00% <0.00%> (ø)
src/vm/runners/builtin_runner/bitwise.rs 96.73% <0.00%> (ø)
... and 60 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@fmoletta fmoletta added this pull request to the merge queue Feb 13, 2023
Merged via the queue into main with commit 0991fb4 Feb 13, 2023
@fmoletta fmoletta deleted the add-display-trait-to-memory branch February 13, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants