-
Notifications
You must be signed in to change notification settings - Fork 651
allow shallow specialization of recursive functions #8717
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
base: main
Are you sure you want to change the base?
allow shallow specialization of recursive functions #8717
Conversation
orizi
left a comment
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.
@orizi reviewed 18 of 19 files at r1, all commit messages.
Reviewable status: 18 of 19 files reviewed, 5 unresolved discussions
crates/cairo-lang-lowering/src/lower/specialized_test.rs line 68 at r1 (raw file):
.and_then(|call| call.function.body(db).ok().flatten()) }) .last()
Suggestion:
.next_back()crates/cairo-lang-lowering/src/inline/mod.rs line 64 at r1 (raw file):
return Ok(false); } // Breaks cycles.
doc what is the cycle break.
crates/cairo-lang-lowering/src/objects.rs line 408 at r1 (raw file):
pub outputs: Vec<VariableId>, /// Is the call is to be inlined as part of the specialization wrapper function. pub is_specialization_inlining: bool,
improve name
crates/cairo-lang-lowering/src/optimizations/const_folding.rs line 694 at r1 (raw file):
if scc.len() > 1 && scc.contains(&self.caller_base) { return None; }
doc what it means
Code quote:
let scc = self.db.lowered_scc(base, DependencyType::Call, LoweringStage::Monomorphized);
if scc.len() > 1 && scc.contains(&self.caller_base) {
return None;
}crates/cairo-lang-lowering/src/lower/test_data/specialized line 833 at r1 (raw file):
error: Wrong number of arguments. Expected 2, found: 1 --> lib.cairo:15:12 return bar1(a - 1);
?
297571b to
db714a9
Compare
orizi
left a comment
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.
@orizi reviewed 9 of 22 files at r2, all commit messages.
Reviewable status: 14 of 27 files reviewed, 5 unresolved discussions (waiting on @TomerStarkware)
crates/cairo-lang-lowering/src/inline/mod.rs line 64 at r2 (raw file):
return Ok(false); } // Prevents inlining of functions that may call themselves.
still explain why this suffices and what this does specifically.
crates/cairo-lang-lowering/src/lower/test_data/specialized line 828 at r2 (raw file):
} return bar1(keep, a - 1); }
Suggestion:
fn bar1(keep: bool, a: felt252) -> felt252 {
if !keep || a == 0 {
0
} else {
bar2(keep, a - 1)
}
}
fn bar2(keep: bool, a: felt252) -> felt252 {
if !keep || a == 0 {
0
} else {
bar1(keep, a - 1)
}
}
orizi
left a comment
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.
@orizi reviewed 6 of 22 files at r2.
Reviewable status: 20 of 27 files reviewed, 4 unresolved discussions (waiting on @TomerStarkware)
db714a9 to
ffa5a5e
Compare
TomerStarkware
left a comment
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: 20 of 27 files reviewed, 4 unresolved discussions (waiting on @orizi)
crates/cairo-lang-lowering/src/inline/mod.rs line 64 at r1 (raw file):
Previously, orizi wrote…
doc what is the cycle break.
Done.
crates/cairo-lang-lowering/src/inline/mod.rs line 64 at r2 (raw file):
Previously, orizi wrote…
still explain why this suffices and what this does specifically.
Done.
crates/cairo-lang-lowering/src/lower/test_data/specialized line 833 at r1 (raw file):
Previously, orizi wrote…
?
Done.
crates/cairo-lang-lowering/src/optimizations/const_folding.rs line 694 at r1 (raw file):
Previously, orizi wrote…
doc what it means
// Avoid specializing with a function that is in the same SCC as the caller.
this is relevant for this check as well
crates/cairo-lang-lowering/src/lower/specialized_test.rs line 68 at r1 (raw file):
.and_then(|call| call.function.body(db).ok().flatten()) }) .last()
Done.
crates/cairo-lang-lowering/src/lower/test_data/specialized line 828 at r2 (raw file):
} return bar1(keep, a - 1); }
Done.
orizi
left a comment
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.
@orizi reviewed 7 of 22 files at r2, 1 of 2 files at r3, all commit messages.
Reviewable status: 26 of 27 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
crates/cairo-lang-lowering/src/inline/mod.rs line 64 at r2 (raw file):
Previously, TomerStarkware wrote…
Done.
wait - does that mean that if a loop function is called, it would be specialized, but not inlined?
crates/cairo-lang-lowering/src/lower/test_data/specialized line 813 at r3 (raw file):
//! > module_code fn bar1(keep: bool, a: felt252) -> felt252 {
dup

No description provided.