-
Notifications
You must be signed in to change notification settings - Fork 581
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
Added option to print used resources for tests. #5266
Conversation
84854a6
to
5f98dc2
Compare
5f98dc2
to
f903e0f
Compare
f903e0f
to
a9918ac
Compare
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.
Reviewed 9 of 23 files at r2.
Reviewable status: 9 of 28 files reviewed, 2 unresolved discussions (waiting on @orizi)
crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs
line 251 at r2 (raw file):
Infos: Iterator<Item = &'b Self::Info> + Clone, { let arm_demands = zip_eq(match_info.arms(), infos.clone())
can't you use .iter() here and below to avoid this clone?
Code quote:
clone()
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 296 at r2 (raw file):
match self.0.entry(key.clone()) { Entry::Occupied(mut e) => { merge(e.get_mut(), value);
wouldn't it make more sense to let the function only output the value to use and not also insert it?
Also - I think it makes sense for the merge function to get the key as input for the decision.
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.
Reviewable status: 0 of 28 files reviewed, 2 unresolved discussions (waiting on @yuvalsw)
crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs
line 251 at r2 (raw file):
Previously, yuvalsw wrote…
can't you use .iter() here and below to avoid this clone?
it is a clone of the iterator - not of the iterators content.
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 296 at r2 (raw file):
Previously, yuvalsw wrote…
wouldn't it make more sense to let the function only output the value to use and not also insert it?
Also - I think it makes sense for the merge function to get the key as input for the decision.
- it is an edit for the merge state - if we extract it, and add again it will be less efficient for no good reason.
- Probably makes sense - but for now not really needed, fn is really easily adapted to support.
a9918ac
to
95cdd0c
Compare
95cdd0c
to
eba8ec1
Compare
eba8ec1
to
237ebb7
Compare
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.
Reviewed 5 of 5 files at r1, 10 of 10 files at r3, 13 of 13 files at r4, all commit messages.
Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @orizi)
crates/cairo-lang-runner/src/lib.rs
line 106 at r4 (raw file):
/// The used resources in a run. #[derive(Debug, Eq, PartialEq, Clone, Default)] pub struct UsedResources {
IIUC the diff between UsedResources and ExecutionResource is the syscalls, that is, starknet. So I would call one this one StarknetExecutionResources, and specify starknet in the doc too.
crates/cairo-lang-runner/src/lib.rs
line 114 at r4 (raw file):
impl UsedResources { /// Adds the resources of `other` to `self`. pub fn add(&mut self, other: Self) {
Can you impl Add/AddAssign?
crates/cairo-lang-runner/src/lib.rs
line 251 at r4 (raw file):
syscalls_used_resources: Default::default(), }; let RunResult { gas_counter, memory, value, used_resources, profiling_info } = self
it's confusing that it's called used_resources when its type isn't UsedResources but ExecutionResources. (unless you rename to UsedResources and StarknetUsedResources/SyscallsUsedResources)
Code quote:
used_resources
crates/cairo-lang-runner/src/casm_run/mod.rs
line 102 at r4 (raw file):
/// The starknet state. pub starknet_state: StarknetState, /// Maintains the resources of the run.
the VM resources?
Worth making the difference clearer.
Code quote:
ins the resources of the run.
crates/cairo-lang-runner/src/casm_run/mod.rs
line 2092 at r4 (raw file):
} type RunFunctionRes = (Vec<Option<Felt252>>, usize, ExecutionResources);
This may be a good time to make it named.
crates/cairo-lang-runner/src/casm_run/mod.rs
line 2155 at r4 (raw file):
let used_resources = runner .get_execution_resources(vm) .expect("Failed to get execution resources, but the run was successful.");
so we don't want to panic, right?
crates/cairo-lang-runner/src/casm_run/test.rs
line 114 at r4 (raw file):
fn test_runner(function: CasmContext, n_returns: usize, expected: &[i128]) { let (hints_dict, string_to_hint) = build_hints_dict(function.instructions.iter()); let mut hint_processor = CairoHintProcessor {
Maybe add a new
function from a string_to_hint?
crates/cairo-lang-test-runner/src/lib.rs
line 443 at r4 (raw file):
}; let summary = wrapped_summary.as_mut().unwrap(); let (res_type, status_str, gas_usage, used_resources, profiling_info) = if let Some(x) = status
please rename
Code quote:
x
crates/cairo-lang-test-runner/src/lib.rs
line 468 at r4 (raw file):
} if let Some(used_resources) = used_resources { let filtered = used_resources.execution_resources.filter_unused_builtins();
I can't find this method.
Code quote:
filter_unused_builtins
crates/cairo-lang-test-runner/src/lib.rs
line 469 at r4 (raw file):
if let Some(used_resources) = used_resources { let filtered = used_resources.execution_resources.filter_unused_builtins(); println!(" steps: {}", filtered.n_steps);
can you add an example of the output?
crates/cairo-lang-test-runner/src/lib.rs
line 470 at r4 (raw file):
let filtered = used_resources.execution_resources.filter_unused_builtins(); println!(" steps: {}", filtered.n_steps); println!(" memory holes: {}", filtered.n_memory_holes);
I can't find these members of the result struct. too.
Code quote:
n_memory_holes
crates/cairo-lang-test-runner/src/lib.rs
line 475 at r4 (raw file):
println!( " {name}: ({})", m.into_iter().sorted().map(|(k, v)| format!("{k:?}: {v}")).join(", ")
Is this :?
needed?
Code quote:
:?
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.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @orizi)
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 296 at r2 (raw file):
Previously, orizi wrote…
- it is an edit for the merge state - if we extract it, and add again it will be less efficient for no good reason.
- Probably makes sense - but for now not really needed, fn is really easily adapted to support.
- I meant that the
merge
function here chooses the value, and the editing is done here in the case of Occupied.
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 286 at r4 (raw file):
/// Merges the map with another map. If a key is present in both maps, the given merge function /// is used to combine the values. pub fn merge<M>(&mut self, other: &Self, merge: M)
Suggest to rename BTW, it has the same name as the function itself.
Code quote:
merge: M
237ebb7
to
81f45ae
Compare
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.
Reviewable status: 22 of 28 files reviewed, 13 unresolved discussions (waiting on @yuvalsw)
crates/cairo-lang-runner/src/lib.rs
line 106 at r4 (raw file):
Previously, yuvalsw wrote…
IIUC the diff between UsedResources and ExecutionResource is the syscalls, that is, starknet. So I would call one this one StarknetExecutionResources, and specify starknet in the doc too.
Done.
crates/cairo-lang-runner/src/lib.rs
line 114 at r4 (raw file):
Previously, yuvalsw wrote…
Can you impl Add/AddAssign?
Done - but just add_assign as only it was needed.
crates/cairo-lang-runner/src/lib.rs
line 251 at r4 (raw file):
Previously, yuvalsw wrote…
it's confusing that it's called used_resources when its type isn't UsedResources but ExecutionResources. (unless you rename to UsedResources and StarknetUsedResources/SyscallsUsedResources)
the type can hold general execution resources - but the meaning of it in this case is the actual used resources.
crates/cairo-lang-runner/src/casm_run/mod.rs
line 102 at r4 (raw file):
Previously, yuvalsw wrote…
the VM resources?
Worth making the difference clearer.
I don't know what the first one means - it is unrelated to this PR.
it seems to count steps across multiple runners.
crates/cairo-lang-runner/src/casm_run/mod.rs
line 2155 at r4 (raw file):
Previously, yuvalsw wrote…
so we don't want to panic, right?
this cannot actually happen - as all sierra runs should complete.
crates/cairo-lang-runner/src/casm_run/test.rs
line 114 at r4 (raw file):
Previously, yuvalsw wrote…
Maybe add a
new
function from a string_to_hint?
maybe - but unrelated to the PR.
crates/cairo-lang-test-runner/src/lib.rs
line 443 at r4 (raw file):
Previously, yuvalsw wrote…
please rename
Done.
crates/cairo-lang-test-runner/src/lib.rs
line 468 at r4 (raw file):
Previously, yuvalsw wrote…
I can't find this method.
this is in the cairo-vm repo.
crates/cairo-lang-test-runner/src/lib.rs
line 469 at r4 (raw file):
Previously, yuvalsw wrote…
can you add an example of the output?
Done.
crates/cairo-lang-test-runner/src/lib.rs
line 470 at r4 (raw file):
Previously, yuvalsw wrote…
I can't find these members of the result struct. too.
this is in the cairo-vm repo.
crates/cairo-lang-test-runner/src/lib.rs
line 475 at r4 (raw file):
Previously, yuvalsw wrote…
Is this
:?
needed?
used longer form instead.
(basically we print the same way as foundry does)
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 296 at r2 (raw file):
Previously, yuvalsw wrote…
- I meant that the
merge
function here chooses the value, and the editing is done here in the case of Occupied.
- it is already inserted - so i need to edit it - or to do awful lifetime stuff.
https://reviewable.io/reviews/starkware-libs/cairo/5291
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 286 at r4 (raw file):
Previously, yuvalsw wrote…
Suggest to rename BTW, it has the same name as the function itself.
81f45ae
to
e0a2a0b
Compare
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.
Reviewed 6 of 6 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)
crates/cairo-lang-test-runner/src/lib.rs
line 474 at r5 (raw file):
// steps: 42 // memory holes: 20 // builtins: ("range_check_builtin": 3)
IIUC with another builtin it would be:
builtins: ("range_check_builtin": 3, "another_builtin": 1)
Are the parentheses and the quotes needed then?
Suggestion:
builtins: range_check_builtin: 3
crates/cairo-lang-utils/src/unordered_hash_map.rs
line 296 at r2 (raw file):
Previously, orizi wrote…
- it is already inserted - so i need to edit it - or to do awful lifetime stuff.
https://reviewable.io/reviews/starkware-libs/cairo/5291
Replied there.
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @yuvalsw)
crates/cairo-lang-test-runner/src/lib.rs
line 474 at r5 (raw file):
Previously, yuvalsw wrote…
IIUC with another builtin it would be:
builtins: ("range_check_builtin": 3, "another_builtin": 1)Are the parentheses and the quotes needed then?
took the option people are happy with in foundry.
these encapsulate the cases where more than one is used quite comfortably.
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @orizi)
commit-id:008454fd fixup! Added option to print used resources for tests.
e0a2a0b
to
ffc962c
Compare
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.
Reviewed 2 of 2 files at r6, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @orizi)
Stack:
UnorderedHashMap::merge
. #5291This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)