Skip to content

Conversation

ksew1
Copy link
Member

@ksew1 ksew1 commented Aug 12, 2025

Stack:

⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

@ksew1 ksew1 requested a review from a team as a code owner August 12, 2025 10:04
@ksew1 ksew1 requested review from franciszekjob and MKowalski8 and removed request for a team August 12, 2025 10:04
@ksew1 ksew1 force-pushed the spr/master/3a7228bd branch 2 times, most recently from 8a25e67 to 19afecd Compare August 13, 2025 10:44
@ksew1 ksew1 force-pushed the spr/master/6dc6b503 branch from d88921d to 546c8a7 Compare August 13, 2025 10:44
github-merge-queue bot pushed a commit that referenced this pull request Aug 19, 2025
commit-id:d194aae4

---

**Stack**:
- #3634
- #3633
- #3621
- #3620⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
Comment on lines +7 to +8
pub value: FunctionName,
pub children: Vec<FunctionNode>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Imo it's reasonable to make it private and expose with getters if needed.

serde_json.workspace = true
starknet-types-core.workspace = true
starknet.workspace = true
starknet_api.workspace = true
thiserror.workspace = true
thiserror.workspace = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Newline 😅

@ksew1 ksew1 force-pushed the spr/master/3a7228bd branch from 19afecd to df6c5f0 Compare August 19, 2025 08:23
@ksew1 ksew1 force-pushed the spr/master/6dc6b503 branch from 546c8a7 to 2ba7a7c Compare August 19, 2025 08:23

/// Builds a [`FunctionTrace`] from the given stacks of function names.
fn build_function_trace(stacks: Vec<Vec<FunctionName>>) -> FunctionTrace {
let mut dummy_root = FunctionNode::new(FunctionName::NonInlined("root".to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: dummy_root works, but placeholder_root might better convey that it's a temporary node for building the tree:

Suggested change
let mut dummy_root = FunctionNode::new(FunctionName::NonInlined("root".to_string()));
let mut placeholder_root = FunctionNode::new(FunctionName::NonInlined("root".to_string()));

github-merge-queue bot pushed a commit that referenced this pull request Aug 19, 2025
commit-id:6dc6b503

---

**Stack**:
- #3634
- #3633
- #3621⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
Base automatically changed from spr/master/6dc6b503 to master August 19, 2025 08:50
@ksew1 ksew1 force-pushed the spr/master/3a7228bd branch from df6c5f0 to 6bc9621 Compare August 19, 2025 08:58
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum FunctionName {
NonInlined(String),
// TODO: Add inlined variant in next PR.
Copy link
Member

Choose a reason for hiding this comment

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

Gotta love stacks 🙏 🙏 🙏

Comment on lines +36 to +37
Regex::new(r"\[expr\d*]")
.expect("Failed to create regex for normalizing loop function names")
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we have the regex as a const/static and reuse it instead of creating it multiple times?

/// Remove parameters from monomorphised Cairo generics e.g. `<felt252>`.
fn remove_monomorphization_suffix(function_name: &str) -> String {
static RE_MONOMORPHIZATION: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"::<.*>")
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Comment on lines +27 to +28
if let Some(child) = self.children.iter_mut().find(|c| c.value == next) {
child.add_path_recursive(iter);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I get it, why do we have this logic?

/// Enters a new function call by updating the stack with the new call stack.
/// It saves the current stack length to allow returning to it later.
///
/// The New call stack is expected to be a prefix of the current stack.
Copy link
Member

Choose a reason for hiding this comment

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

What's ensuring that? Only the user contract?
Would checking that be too expensive?

}

/// Exits the current function call by truncating the stack to the previous length.
/// If there is no previous length, it does nothing.
Copy link
Member

Choose a reason for hiding this comment

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

Why is that? Shouldn't it truncate the stack entirely in this case?

Comment on lines +40 to +46
let empty_or_different_function = self.stack.last().is_none_or(|current_function| {
current_function.function_name() != function_name.function_name()
});

if empty_or_different_function {
stack.push(function_name);
}
Copy link
Member

Choose a reason for hiding this comment

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

So basically it appends to new function to the stack if it's not already present as last?


let program = &program_artifact.program;

let sierra_program_registry = ProgramRegistry::<CoreType, CoreLibfunc>::new(program)
Copy link
Member

Choose a reason for hiding this comment

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

Some of these objects, like ProgramRegistry we already create during forge runtime. I wonder if there would be any significant benefit in trying to reuse them?

Copy link
Member

Choose a reason for hiding this comment

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

Same goes for constructing trace

}

impl NodeDisplay for FunctionNode {
const TAG: &'static str = "inlined";
Copy link
Member

Choose a reason for hiding this comment

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

Are they always inlined?

commit-id:3a7228bd
@ksew1 ksew1 force-pushed the spr/master/3a7228bd branch from 2d73b2a to b329d45 Compare August 21, 2025 13:45
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.

3 participants