Skip to content

Add spark2#851

Closed
jadnohra wants to merge 1 commit intomainfrom
08-28-spark2
Closed

Add spark2#851
jadnohra wants to merge 1 commit intomainfrom
08-28-spark2

Conversation

@jadnohra
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor Author

jadnohra commented Aug 28, 2025


How to use the Graphite Merge Queue

Add the label merge-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jadnohra jadnohra mentioned this pull request Aug 28, 2025
Comment on lines +67 to +70
if let Some(pattern_op) = op
&& pattern_op != expr_op {
return false;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's a logic issue in the pattern matching condition. The current code:

if let Some(pattern_op) = op
    && pattern_op != expr_op {
        return false;
    }

This will always evaluate to false when pattern_op is Some because the && is binding too tightly with the comparison.

To fix this, either use a nested if statement:

if let Some(pattern_op) = op {
    if pattern_op != *expr_op {
        return false;
    }
}

Or use a match statement for clearer control flow:

match op {
    Some(pattern_op) if pattern_op != *expr_op => return false,
    _ => {}
}
Suggested change
if let Some(pattern_op) = op
&& pattern_op != expr_op {
return false;
}
if let Some(pattern_op) = op {
if pattern_op != expr_op {
return false;
}
}

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jadnohra jadnohra changed the base branch from 08-21-spark to graphite-base/851 August 28, 2025 17:10
@jadnohra jadnohra changed the base branch from graphite-base/851 to main August 28, 2025 17:10
Comment thread crates/spark2/Cargo.toml
Comment on lines +8 to +9
binius-core = { path = "../core" }
binius-field = { path = "../field" }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dependencies must use workspace-wide declarations. Replace binius-core = { path = "../core" } with binius-core.workspace = true and binius-field = { path = "../field" } with binius-field.workspace = true. These dependencies must be declared in the workspace root Cargo.toml file.

Spotted by Diamond (based on custom rule: Irreducible Rust and Cargo)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +101 to +108
Expr::Unary { op, expr: inner } => {
self.apply_rule_recursive(rule, inner).map(|new_inner| {
Expr::Unary {
op: *op,
expr: Box::new(new_inner),
}
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Unary case should handle both scenarios: when the inner expression changes and when it doesn't. Currently, it only returns Some when the inner expression changes, unlike the Binary case which correctly handles both scenarios. Consider updating to:

Expr::Unary { op, expr: inner } => {
    let new_inner = self.apply_rule_recursive(rule, inner)
        .map(Box::new)
        .unwrap_or_else(|| inner.clone());
    
    if &new_inner != inner {
        Some(Expr::Unary {
            op: *op,
            expr: new_inner,
        })
    } else {
        None
    }
}

This ensures consistent behavior with the other expression types.

Suggested change
Expr::Unary { op, expr: inner } => {
self.apply_rule_recursive(rule, inner).map(|new_inner| {
Expr::Unary {
op: *op,
expr: Box::new(new_inner),
}
})
}
Expr::Unary { op, expr: inner } => {
let new_inner = self.apply_rule_recursive(rule, inner)
.map(Box::new)
.unwrap_or_else(|| inner.clone());
if &new_inner != inner {
Some(Expr::Unary {
op: *op,
expr: new_inner,
})
} else {
None
}
}

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jadnohra jadnohra force-pushed the 08-28-spark2 branch 2 times, most recently from a114660 to c39660a Compare August 28, 2025 17:39
Comment on lines +23 to +36
Pattern::xor_chain(vec![
Pattern::Unary {
op: Some(UnOp::Ror(0)), // Will be matched with actual rotation amounts
pattern: Box::new(Pattern::var("x")),
},
Pattern::Unary {
op: Some(UnOp::Ror(0)),
pattern: Box::new(Pattern::var("x")),
},
Pattern::Unary {
op: Some(UnOp::Ror(0)),
pattern: Box::new(Pattern::var("x")),
},
])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The pattern uses hardcoded rotation values of 0 in UnOp::Ror(0), but the comment suggests it should match any rotation amount. Consider either:

  1. Using None for the op field to match any rotation operation:
Pattern::Unary {
    op: None,
    pattern: Box::new(Pattern::var("x")),
}
  1. Or creating specific patterns for the exact rotation combinations used in SHA256 (e.g., Sigma0: 2, 13, 22 and Sigma1: 6, 11, 25).

This would ensure the pattern correctly matches the intended SHA256 rotation operations.

Suggested change
Pattern::xor_chain(vec![
Pattern::Unary {
op: Some(UnOp::Ror(0)), // Will be matched with actual rotation amounts
pattern: Box::new(Pattern::var("x")),
},
Pattern::Unary {
op: Some(UnOp::Ror(0)),
pattern: Box::new(Pattern::var("x")),
},
Pattern::Unary {
op: Some(UnOp::Ror(0)),
pattern: Box::new(Pattern::var("x")),
},
])
Pattern::xor_chain(vec![
Pattern::Unary {
op: None, // Will match any rotation operation
pattern: Box::new(Pattern::var("x")),
},
Pattern::Unary {
op: None,
pattern: Box::new(Pattern::var("x")),
},
Pattern::Unary {
op: None,
pattern: Box::new(Pattern::var("x")),
},
])

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jadnohra jadnohra mentioned this pull request Aug 29, 2025
@jadnohra jadnohra closed this Aug 29, 2025
@jimpo jimpo deleted the 08-28-spark2 branch November 21, 2025 20:57
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.

1 participant