Skip to content

Commit

Permalink
Add hint location logic to get_location
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Dec 29, 2022
1 parent 160fe32 commit bd6111a
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/vm/errors/vm_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl VmException {
let error_attr_value = get_error_attr_value(pc, runner);
VmException {
pc,
inst_location: get_location(pc, runner),
inst_location: get_location(pc, runner, None),
inner_exc: error,
error_attr_value,
traceback: get_traceback(vm, runner),
Expand All @@ -50,13 +50,20 @@ pub fn get_error_attr_value(pc: usize, runner: &CairoRunner) -> Option<String> {
(!errors.is_empty()).then(|| errors)
}

pub fn get_location(pc: usize, runner: &CairoRunner) -> Option<Location> {
runner
.program
.instruction_locations
.as_ref()?
.get(&pc)
.map(|inst_location| inst_location.inst.clone())
pub fn get_location(
pc: usize,
runner: &CairoRunner,
hint_index: Option<usize>,
) -> Option<Location> {
let instruction_location = runner.program.instruction_locations.as_ref()?.get(&pc)?;
if let Some(index) = hint_index {
instruction_location
.hints
.get(index)
.map(|hint_location| hint_location.location.clone())
} else {
Some(instruction_location.inst.clone())
}
}

// Returns the traceback at the current pc.
Expand All @@ -66,7 +73,7 @@ pub fn get_traceback(vm: &VirtualMachine, runner: &CairoRunner) -> Option<String
if let Some(ref attr) = get_error_attr_value(traceback_pc.offset, runner) {
traceback.push_str(attr)
}
match get_location(traceback_pc.offset, runner) {
match get_location(traceback_pc.offset, runner, None) {
Some(location) => traceback.push_str(&format!(
"{}\n",
location.to_string_with_content(&format!("(pc=0:{})", traceback_pc.offset))
Expand Down Expand Up @@ -189,7 +196,7 @@ mod test {
start_col: 1,
};
let instruction_location = InstructionLocation {
inst: location,
inst: location.clone(),
hints: vec![],
};
let program = program!(
Expand Down Expand Up @@ -421,7 +428,7 @@ mod test {
instruction_locations = Some(HashMap::from([(2, instruction_location.clone())])),
);
let runner = cairo_runner!(program);
assert_eq!(get_location(2, &runner), Some(location));
assert_eq!(get_location(2, &runner, None), Some(location));
}

#[test]
Expand All @@ -443,7 +450,7 @@ mod test {
let program =
program!(instruction_locations = Some(HashMap::from([(2, instruction_location)])),);
let runner = cairo_runner!(program);
assert_eq!(get_location(3, &runner), None);
assert_eq!(get_location(3, &runner, None), None);
}

#[test]
Expand Down

1 comment on commit bd6111a

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: bd6111a Previous: 34e2a4a Ratio
cairo_run(cairo_programs/benchmarks/compare_arrays_200000.json 2476056980 ns/iter (± 37468784) 1848653640 ns/iter (± 5687081) 1.34
cairo_run(cairo_programs/benchmarks/fibonacci_1000_multirun.json 432629089 ns/iter (± 11846862) 319181710 ns/iter (± 1257293) 1.36
cairo_run(cairo_programs/benchmarks/integration_builtins.json 1204998106 ns/iter (± 13780897) 910634823 ns/iter (± 6080610) 1.32
cairo_run(cairo_programs/benchmarks/linear_search.json 312631574 ns/iter (± 6827754) 236797734 ns/iter (± 2724952) 1.32
cairo_run(cairo_programs/benchmarks/keccak_integration_benchmark.json 3540104500 ns/iter (± 56464750) 2661232347 ns/iter (± 8956008) 1.33
cairo_run(cairo_programs/benchmarks/secp_integration_benchmark.json 3802590453 ns/iter (± 58791821) 2769141286 ns/iter (± 20915118) 1.37
cairo_run(cairo_programs/benchmarks/blake2s_integration_benchmark.json 3262303845 ns/iter (± 44681813) 2423622487 ns/iter (± 15868283) 1.35
cairo_run(cairo_programs/benchmarks/dict_integration_benchmark.json 2366923474 ns/iter (± 39705917) 1743359086 ns/iter (± 9797600) 1.36
cairo_run(cairo_programs/benchmarks/math_integration_benchmark.json 1229069074 ns/iter (± 18187773) 932492184 ns/iter (± 5744264) 1.32
cairo_run(cairo_programs/benchmarks/memory_integration_benchmark.json 1490273487 ns/iter (± 23623622) 1098971820 ns/iter (± 8313907) 1.36
cairo_run(cairo_programs/benchmarks/operations_with_data_structures_benchmarks.json 5093919734 ns/iter (± 79470922) 3772524127 ns/iter (± 22800354) 1.35
cairo_run(cairo_programs/benchmarks/uint256_integration_benchmark.json 3472240480 ns/iter (± 42426957) 2491213460 ns/iter (± 6794363) 1.39
cairo_run(cairo_programs/benchmarks/set_integration_benchmark.json 375931670 ns/iter (± 9129529) 270848584 ns/iter (± 569260) 1.39

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.