-
Notifications
You must be signed in to change notification settings - Fork 167
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
Merge Cairo Pie extra segments into one segment #1960
base: main
Are you sure you want to change the base?
Conversation
|
Benchmark Results for unmodified programs 🚀
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1960 +/- ##
==========================================
+ Coverage 96.39% 96.40% +0.01%
==========================================
Files 102 102
Lines 41566 41776 +210
==========================================
+ Hits 40068 40276 +208
- Misses 1498 1500 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @FrancoGiachetta! I left you some comments.
/// Relocates a `Relocatable` value, which represented by its | ||
/// index and offset, according to a given segment offsets | ||
fn relocate_value( | ||
index: usize, | ||
offset: usize, | ||
segment_offsets: &Option<HashMap<usize, Relocatable>>, | ||
) -> (usize, usize) { | ||
if let Some(offsets) = segment_offsets { | ||
return match offsets.get(&index) { | ||
Some(relocatable) => ( | ||
relocatable.segment_index as usize, | ||
relocatable.offset + offset, | ||
), | ||
None => (index, offset), | ||
}; | ||
} | ||
|
||
(index, offset) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function only relocates the value if segment_offsets is not None, ignoring it otherwise. I think its better if we remove the Option and let the caller handle the default case (when there is no segment_offsets)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make the method inconsistent with the python implementation. See:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, but while we aim to be compatible with the python implementation, I don't think the internal implementation has to be exactly the same. We may change the implementation to better suit the language features, although I'm not 100% sure about it. What do you think @gabrielbosio?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see your point. I wasn't talking about "inconsistent" in terms of implementation but rather in terms of the results. This function seems to have only one behavior. So if the default case isn't gonna change, isn't it better to let the function handle it all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use the language features you can do something like this:
fn relocate_value(
index: usize,
offset: usize,
segment_offsets: Option<&HashMap<usize, Relocatable>>,
) -> (usize, usize) {
segment_offsets
.and_then(|offsets| offsets.get(&index))
.and_then(|relocatable| {
Some((
relocatable.segment_index as usize,
relocatable.offset + offset,
))
})
.unwrap_or((index, offset))
}
and call to_bytes
this way:
self.memory.to_bytes(segment_offsets.as_ref())
You can remove the Option
in the relocate_value
argument but you would need to deal with it outside:
let (segment, offset) = if let Some(offsets) = seg_offsets {
Self::relocate_value(*segment, *offset, offsets)
} else {
(*segment, *offset)
};
I'm not sure if there's a cleaner way to deal with the Option
value here. I would choose to deal with it inside the function for now.
Allow merging extra_segments with Cairo Pie to increase the segments number limit
Description
The PR adds the method
merge_extra_segments
to mergeextra_segments
into one segment. This solves the issue of cairo pie limiting the number of segments to2^16
. This method returns a tuple with the merged segment and aHasMap
with the new offsets (made out of the old segment indices mapped to their new offset in the new segment). This new offsets are then used during the memory serialization.A new flag
merge_extra_segments
was added to the cli, which merges the extra segments if there were any. Memory serialization is then done taking into account this new segment. If there were no extra segments, it defaults to normal behavior.Closes #1947
Checklist