Skip to content
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

feat(constraint_graph): make the constraint graph framework generic and move it into a separate crate #3071

Merged
merged 30 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a185e7b
feat(constraint_graph): make the constraint graph framework generic a…
vspecky Dec 6, 2023
524a9bf
refactor(euclid): remove redundant dense_map and utils modules
vspecky Dec 7, 2023
4ba45ec
refactor(constraint_graph): uncomment validation in builder
vspecky Dec 7, 2023
e252ccb
refactor(constraint_graph): add description for the constraint graph …
vspecky Dec 8, 2023
b0d3e09
Merge branch 'main' into make-constraint-graphs-generic
vspecky Dec 8, 2023
9e4c50f
Merge branch 'main' into make-constraint-graphs-generic
vspecky Dec 13, 2023
1a50355
feat(constraint_graph): make constraint graph edges domain specific a…
vspecky Dec 14, 2023
d9746e3
Merge branch 'edge-domain-assoc-in-constraint-graph' into make-constr…
vspecky Dec 14, 2023
393c34f
Merge branch 'main' into make-constraint-graphs-generic
vspecky Dec 14, 2023
5410e5b
Merge branch 'main' into make-constraint-graphs-generic
vspecky Dec 15, 2023
189459f
chore: merge with 'main' and resolve conflicts/errors
vspecky Dec 21, 2023
d7b872b
refactor(constraint_graph): take &str when checking nodes in constrai…
vspecky Dec 21, 2023
2dbee41
refactor(constraint_graph): take &str in builder for domain identifiers
vspecky Dec 21, 2023
c89f696
refactor(euclid_wasm): address nitpicks
vspecky Jan 4, 2024
0d652fb
Merge branch 'main' into make-constraint-graphs-generic
vspecky Jan 9, 2024
3922a6a
Merge branch 'main' into make-constraint-graphs-generic
vspecky Jan 9, 2024
3f9c231
fix(euclid): fix key naming issues in the DIR
vspecky Jan 9, 2024
5dd57c4
fix(kgraph_utils): remove redundant domain parameter when constructin…
vspecky Jan 16, 2024
6eb7715
Merge branch 'main' into make-constraint-graphs-generic
vspecky Jan 16, 2024
59932be
Merge branch 'main' into make-constraint-graphs-generic
vspecky Feb 15, 2024
b050ccc
fix(constraint_graph): fix certain discrepancies in the constraint graph
vspecky Feb 15, 2024
3f40a65
Merge branch 'main' into make-constraint-graphs-generic
vspecky Feb 16, 2024
cfa3eb6
chore: merge with 'main' and resolve conflicts/errors
vspecky Apr 16, 2024
b129948
chore: merge with 'main' and resolve conflicts/errors
vspecky Apr 17, 2024
eb1e286
refactor(constraint_graph): allow specifying edge strength for any ag…
vspecky Apr 22, 2024
8f7ea3a
Merge branch 'main' into make-constraint-graphs-generic
vspecky Apr 30, 2024
279312f
refactor(constraint_graph): rename the constraint_graph crate to hype…
vspecky May 2, 2024
dc160b1
fix: incorrect constraint_graph crate name
vspecky May 2, 2024
884375b
fix: hyperswitch constraint graph crate directory in codeowners
vspecky May 2, 2024
6acf704
chore: merge with 'main' and resolve conflicts/errors
vspecky May 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ crates/router/src/compatibility/ @juspay/hyperswitch-compatibility
crates/router/src/core/ @juspay/hyperswitch-core

crates/api_models/src/routing.rs @juspay/hyperswitch-routing
crates/hyperswitch_constraint_graph @juspay/hyperswitch-routing
crates/euclid @juspay/hyperswitch-routing
crates/euclid_macros @juspay/hyperswitch-routing
crates/euclid_wasm @juspay/hyperswitch-routing
Expand Down
53 changes: 50 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/euclid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ utoipa = { version = "4.2.0", features = ["preserve_order", "preserve_path_order

# First party dependencies
common_enums = { version = "0.1.0", path = "../common_enums" }
hyperswitch_constraint_graph = { version = "0.1.0", path = "../hyperswitch_constraint_graph" }
euclid_macros = { version = "0.1.0", path = "../euclid_macros" }

[features]
Expand Down
37 changes: 23 additions & 14 deletions crates/euclid/src/dssa/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
//! in the Euclid Rule DSL. These include standard control flow analyses like testing
//! conflicting assertions, to Domain Specific Analyses making use of the
//! [`Knowledge Graph Framework`](crate::dssa::graph).
use hyperswitch_constraint_graph::{ConstraintGraph, Memoization};
use rustc_hash::{FxHashMap, FxHashSet};

use super::{graph::Memoization, types::EuclidAnalysable};
use crate::{
dssa::{graph, state_machine, truth, types},
dssa::{
graph::CgraphExt,
state_machine, truth,
types::{self, EuclidAnalysable},
},
frontend::{
ast,
dir::{self, EuclidDirFilter},
Expand Down Expand Up @@ -203,12 +207,12 @@ fn perform_condition_analyses(

fn perform_context_analyses(
context: &types::ConjunctiveContext<'_>,
knowledge_graph: &graph::KnowledgeGraph<'_>,
knowledge_graph: &ConstraintGraph<'_, dir::DirValue>,
) -> Result<(), types::AnalysisError> {
perform_condition_analyses(context)?;
let mut memo = Memoization::new();
knowledge_graph
.perform_context_analysis(context, &mut memo)
.perform_context_analysis(context, &mut memo, None)
.map_err(|err| types::AnalysisError {
error_type: types::AnalysisErrorType::GraphAnalysis(err, memo),
metadata: Default::default(),
Expand All @@ -218,7 +222,7 @@ fn perform_context_analyses(

pub fn analyze<O: EuclidAnalysable + EuclidDirFilter>(
program: ast::Program<O>,
knowledge_graph: Option<&graph::KnowledgeGraph<'_>>,
knowledge_graph: Option<&ConstraintGraph<'_, dir::DirValue>>,
) -> Result<vir::ValuedProgram<O>, types::AnalysisError> {
let dir_program = ast::lowering::lower_program(program)?;

Expand All @@ -241,9 +245,14 @@ mod tests {
use std::{ops::Deref, sync::Weak};

use euclid_macros::knowledge;
use hyperswitch_constraint_graph as cgraph;

use super::*;
use crate::{dirval, types::DummyOutput};
use crate::{
dirval,
dssa::graph::{self, euclid_graph_prelude},
types::DummyOutput,
};

#[test]
fn test_conflicting_assertion_detection() {
Expand Down Expand Up @@ -368,7 +377,7 @@ mod tests {

#[test]
fn test_negation_graph_analysis() {
let graph = knowledge! {crate
let graph = knowledge! {
CaptureMethod(Automatic) ->> PaymentMethod(Card);
};

Expand Down Expand Up @@ -410,18 +419,18 @@ mod tests {
.deref()
.clone()
{
graph::AnalysisTrace::Value { predecessors, .. } => {
let _value = graph::NodeValue::Value(dir::DirValue::PaymentMethod(
cgraph::AnalysisTrace::Value { predecessors, .. } => {
let _value = cgraph::NodeValue::Value(dir::DirValue::PaymentMethod(
dir::enums::PaymentMethod::Card,
));
let _relation = graph::Relation::Positive;
let _relation = cgraph::Relation::Positive;
predecessors
}
_ => panic!("Expected Negation Trace for payment method = card"),
};

let pred = match predecessor {
Some(graph::ValueTracePredecessor::Mandatory(predecessor)) => predecessor,
Some(cgraph::error::ValueTracePredecessor::Mandatory(predecessor)) => predecessor,
_ => panic!("No predecessor found"),
};
assert_eq!(
Expand All @@ -433,11 +442,11 @@ mod tests {
*Weak::upgrade(&pred)
.expect("Expected Arc not found")
.deref(),
graph::AnalysisTrace::Value {
value: graph::NodeValue::Value(dir::DirValue::CaptureMethod(
cgraph::AnalysisTrace::Value {
value: cgraph::NodeValue::Value(dir::DirValue::CaptureMethod(
dir::enums::CaptureMethod::Automatic
)),
relation: graph::Relation::Positive,
relation: cgraph::Relation::Positive,
info: None,
metadata: None,
predecessors: None,
Expand Down
Loading
Loading