diff --git a/crates/euclid/src/dssa/analyzer.rs b/crates/euclid/src/dssa/analyzer.rs index dc1da99a83..926e1a4deb 100644 --- a/crates/euclid/src/dssa/analyzer.rs +++ b/crates/euclid/src/dssa/analyzer.rs @@ -207,7 +207,7 @@ fn perform_condition_analyses( fn perform_context_analyses( context: &types::ConjunctiveContext<'_>, - knowledge_graph: &ConstraintGraph<'_, dir::DirValue>, + knowledge_graph: &ConstraintGraph, ) -> Result<(), types::AnalysisError> { perform_condition_analyses(context)?; let mut memo = Memoization::new(); @@ -222,7 +222,7 @@ fn perform_context_analyses( pub fn analyze( program: ast::Program, - knowledge_graph: Option<&ConstraintGraph<'_, dir::DirValue>>, + knowledge_graph: Option<&ConstraintGraph>, ) -> Result, types::AnalysisError> { let dir_program = ast::lowering::lower_program(program)?; diff --git a/crates/euclid/src/dssa/graph.rs b/crates/euclid/src/dssa/graph.rs index e6439a2f55..008b562851 100644 --- a/crates/euclid/src/dssa/graph.rs +++ b/crates/euclid/src/dssa/graph.rs @@ -221,7 +221,7 @@ pub trait CgraphExt { ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), cgraph::GraphError>; fn value_analysis( @@ -230,7 +230,7 @@ pub trait CgraphExt { ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), cgraph::GraphError>; fn check_value_validity( @@ -239,7 +239,7 @@ pub trait CgraphExt { analysis_ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result>; fn key_value_analysis( @@ -248,7 +248,7 @@ pub trait CgraphExt { ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), cgraph::GraphError>; fn assertion_analysis( @@ -257,7 +257,7 @@ pub trait CgraphExt { analysis_ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), AnalysisError>; fn negation_analysis( @@ -266,25 +266,25 @@ pub trait CgraphExt { analysis_ctx: &mut AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), AnalysisError>; fn perform_context_analysis( &self, ctx: &types::ConjunctiveContext<'_>, memo: &mut cgraph::Memoization, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), AnalysisError>; } -impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { +impl CgraphExt for cgraph::ConstraintGraph { fn key_analysis( &self, key: dir::DirKey, ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), cgraph::GraphError> { self.value_map .get(&cgraph::NodeValue::Key(key)) @@ -307,7 +307,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), cgraph::GraphError> { self.value_map .get(&cgraph::NodeValue::Value(val)) @@ -330,7 +330,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { analysis_ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result> { let maybe_node_id = self.value_map.get(&cgraph::NodeValue::Value(val)); @@ -365,7 +365,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), cgraph::GraphError> { self.key_analysis(val.get_key(), ctx, memo, cycle_map, domains) .and_then(|_| self.value_analysis(val, ctx, memo, cycle_map, domains)) @@ -377,7 +377,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { analysis_ctx: &AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), AnalysisError> { positive_ctx.iter().try_for_each(|(value, metadata)| { self.key_value_analysis((*value).clone(), analysis_ctx, memo, cycle_map, domains) @@ -391,7 +391,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { analysis_ctx: &mut AnalysisContext, memo: &mut cgraph::Memoization, cycle_map: &mut cgraph::CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), AnalysisError> { let mut keywise_metadata: FxHashMap> = FxHashMap::default(); let mut keywise_negation: FxHashMap> = @@ -449,7 +449,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> { &self, ctx: &types::ConjunctiveContext<'_>, memo: &mut cgraph::Memoization, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), AnalysisError> { let mut analysis_ctx = AnalysisContext::from_dir_values( ctx.iter() diff --git a/crates/euclid/src/dssa/truth.rs b/crates/euclid/src/dssa/truth.rs index 7e79e4ddc6..949d9e2f11 100644 --- a/crates/euclid/src/dssa/truth.rs +++ b/crates/euclid/src/dssa/truth.rs @@ -3,7 +3,7 @@ use once_cell::sync::Lazy; use crate::{dssa::graph::euclid_graph_prelude, frontend::dir}; -pub static ANALYSIS_GRAPH: Lazy> = +pub static ANALYSIS_GRAPH: Lazy> = Lazy::new(|| { knowledge! { // Payment Method should be `Card` for a CardType to be present diff --git a/crates/euclid_wasm/src/lib.rs b/crates/euclid_wasm/src/lib.rs index 3047051014..e92552002b 100644 --- a/crates/euclid_wasm/src/lib.rs +++ b/crates/euclid_wasm/src/lib.rs @@ -33,12 +33,12 @@ use wasm_bindgen::prelude::*; use crate::utils::JsResultExt; type JsResult = Result; -struct SeedData<'a> { - cgraph: hyperswitch_constraint_graph::ConstraintGraph<'a, dir::DirValue>, +struct SeedData { + cgraph: hyperswitch_constraint_graph::ConstraintGraph, connectors: Vec, } -static SEED_DATA: OnceCell> = OnceCell::new(); +static SEED_DATA: OnceCell = OnceCell::new(); static SEED_FOREX: OnceCell = OnceCell::new(); /// This function can be used by the frontend to educate wasm about the forex rates data. diff --git a/crates/hyperswitch_constraint_graph/src/builder.rs b/crates/hyperswitch_constraint_graph/src/builder.rs index fdd87eac51..ad28375616 100644 --- a/crates/hyperswitch_constraint_graph/src/builder.rs +++ b/crates/hyperswitch_constraint_graph/src/builder.rs @@ -12,28 +12,34 @@ use crate::{ }, }; -pub enum DomainIdOrIdentifier<'a> { +pub enum DomainIdOrIdentifier { DomainId(DomainId), - DomainIdentifier(DomainIdentifier<'a>), + DomainIdentifier(DomainIdentifier), } -impl<'a> From<&'a str> for DomainIdOrIdentifier<'a> { - fn from(value: &'a str) -> Self { +impl From for DomainIdOrIdentifier { + fn from(value: String) -> Self { Self::DomainIdentifier(DomainIdentifier::new(value)) } } -impl From for DomainIdOrIdentifier<'_> { +impl From for DomainIdOrIdentifier { + fn from(value: DomainIdentifier) -> Self { + Self::DomainIdentifier(value) + } +} + +impl From for DomainIdOrIdentifier { fn from(value: DomainId) -> Self { Self::DomainId(value) } } #[derive(Debug)] -pub struct ConstraintGraphBuilder<'a, V: ValueNode> { - domain: DenseMap>, +pub struct ConstraintGraphBuilder { + domain: DenseMap, nodes: DenseMap>, edges: DenseMap, - domain_identifier_map: FxHashMap, DomainId>, + domain_identifier_map: FxHashMap, value_map: FxHashMap, NodeId>, edges_map: FxHashMap<(NodeId, NodeId, Option), EdgeId>, node_info: DenseMap>, @@ -41,7 +47,7 @@ pub struct ConstraintGraphBuilder<'a, V: ValueNode> { } #[allow(clippy::new_without_default)] -impl<'a, V> ConstraintGraphBuilder<'a, V> +impl ConstraintGraphBuilder where V: ValueNode, { @@ -58,7 +64,7 @@ where } } - pub fn build(self) -> ConstraintGraph<'a, V> { + pub fn build(self) -> ConstraintGraph { ConstraintGraph { domain: self.domain, domain_identifier_map: self.domain_identifier_map, @@ -72,7 +78,7 @@ where fn retrieve_domain_from_identifier( &self, - domain_ident: DomainIdentifier<'_>, + domain_ident: DomainIdentifier, ) -> Result> { self.domain_identifier_map .get(&domain_ident) @@ -82,7 +88,7 @@ where pub fn make_domain( &mut self, - domain_identifier: &'a str, + domain_identifier: String, domain_description: &str, ) -> Result> { let domain_identifier = DomainIdentifier::new(domain_identifier); @@ -93,7 +99,7 @@ where .map_or_else( || { let domain_id = self.domain.push(DomainInfo { - domain_identifier, + domain_identifier: domain_identifier.clone(), domain_description: domain_description.to_string(), }); self.domain_identifier_map @@ -123,7 +129,7 @@ where }) } - pub fn make_edge<'short, T: Into>>( + pub fn make_edge>( &mut self, pred_id: NodeId, succ_id: NodeId, @@ -188,7 +194,7 @@ where nodes: &[(NodeId, Relation, Strength)], info: Option<&'static str>, metadata: Option, - domain: Option<&str>, + domain: Option, ) -> Result> { nodes .iter() @@ -202,7 +208,13 @@ where .push(metadata.map(|meta| -> Arc { Arc::new(meta) })); for (node_id, relation, strength) in nodes { - self.make_edge(*node_id, aggregator_id, *strength, *relation, domain)?; + self.make_edge( + *node_id, + aggregator_id, + *strength, + *relation, + domain.clone(), + )?; } Ok(aggregator_id) @@ -213,7 +225,7 @@ where nodes: &[(NodeId, Relation, Strength)], info: Option<&'static str>, metadata: Option, - domain: Option<&str>, + domain: Option, ) -> Result> { nodes .iter() @@ -227,7 +239,13 @@ where .push(metadata.map(|meta| -> Arc { Arc::new(meta) })); for (node_id, relation, strength) in nodes { - self.make_edge(*node_id, aggregator_id, *strength, *relation, domain)?; + self.make_edge( + *node_id, + aggregator_id, + *strength, + *relation, + domain.clone(), + )?; } Ok(aggregator_id) diff --git a/crates/hyperswitch_constraint_graph/src/graph.rs b/crates/hyperswitch_constraint_graph/src/graph.rs index d6d26c0e71..7c435fee29 100644 --- a/crates/hyperswitch_constraint_graph/src/graph.rs +++ b/crates/hyperswitch_constraint_graph/src/graph.rs @@ -26,9 +26,9 @@ struct CheckNodeContext<'a, V: ValueNode, C: CheckingContext> { } #[derive(Debug)] -pub struct ConstraintGraph<'a, V: ValueNode> { - pub domain: DenseMap>, - pub domain_identifier_map: FxHashMap, DomainId>, +pub struct ConstraintGraph { + pub domain: DenseMap, + pub domain_identifier_map: FxHashMap, pub nodes: DenseMap>, pub edges: DenseMap, pub value_map: FxHashMap, NodeId>, @@ -36,7 +36,7 @@ pub struct ConstraintGraph<'a, V: ValueNode> { pub node_metadata: DenseMap>>, } -impl<'a, V> ConstraintGraph<'a, V> +impl ConstraintGraph where V: ValueNode, { @@ -70,7 +70,7 @@ where strength: Strength, memo: &mut Memoization, cycle_map: &mut CycleCheck, - domains: Option<&[&str]>, + domains: Option<&[String]>, ) -> Result<(), GraphError> where C: CheckingContext, @@ -81,7 +81,7 @@ where .iter() .map(|domain_ident| { self.domain_identifier_map - .get(&DomainIdentifier::new(domain_ident)) + .get(&DomainIdentifier::new(domain_ident.to_string())) .copied() .ok_or(GraphError::DomainNotFound) }) @@ -482,15 +482,15 @@ where Ok(()) } - pub fn combine<'b>(g1: &'b Self, g2: &'b Self) -> Result> { + pub fn combine(g1: &Self, g2: &Self) -> Result> { let mut node_builder = builder::ConstraintGraphBuilder::new(); let mut g1_old2new_id = DenseMap::::new(); let mut g2_old2new_id = DenseMap::::new(); let mut g1_old2new_domain_id = DenseMap::::new(); let mut g2_old2new_domain_id = DenseMap::::new(); - let add_domain = |node_builder: &mut builder::ConstraintGraphBuilder<'a, V>, - domain: DomainInfo<'a>| + let add_domain = |node_builder: &mut builder::ConstraintGraphBuilder, + domain: DomainInfo| -> Result> { node_builder.make_domain( domain.domain_identifier.into_inner(), @@ -498,7 +498,7 @@ where ) }; - let add_node = |node_builder: &mut builder::ConstraintGraphBuilder<'a, V>, + let add_node = |node_builder: &mut builder::ConstraintGraphBuilder, node: &Node| -> Result> { match &node.node_type { @@ -553,14 +553,14 @@ where .domain .map(|domain_id| g1.domain.get(domain_id).ok_or(GraphError::DomainNotFound)) .transpose()? - .map(|domain| domain.domain_identifier); + .map(|domain| domain.domain_identifier.clone()); node_builder.make_edge( *new_pred_id, *new_succ_id, edge.strength, edge.relation, - domain_ident.as_deref(), + domain_ident, )?; } @@ -575,14 +575,14 @@ where .domain .map(|domain_id| g2.domain.get(domain_id).ok_or(GraphError::DomainNotFound)) .transpose()? - .map(|domain| domain.domain_identifier); + .map(|domain| domain.domain_identifier.clone()); node_builder.make_edge( *new_pred_id, *new_succ_id, edge.strength, edge.relation, - domain_ident.as_deref(), + domain_ident, )?; } @@ -604,7 +604,7 @@ mod viz { format!("N{}", node_id.get_id()) } - impl<'a, V> ConstraintGraph<'a, V> + impl ConstraintGraph where V: ValueNode + NodeViz, ::Key: NodeViz, diff --git a/crates/hyperswitch_constraint_graph/src/types.rs b/crates/hyperswitch_constraint_graph/src/types.rs index 51818f2fee..174a7cdaea 100644 --- a/crates/hyperswitch_constraint_graph/src/types.rs +++ b/crates/hyperswitch_constraint_graph/src/types.rs @@ -139,36 +139,36 @@ pub struct DomainId(usize); impl_entity!(DomainId); -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct DomainIdentifier<'a>(&'a str); +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct DomainIdentifier(String); -impl<'a> DomainIdentifier<'a> { - pub fn new(identifier: &'a str) -> Self { +impl DomainIdentifier { + pub fn new(identifier: String) -> Self { Self(identifier) } - pub fn into_inner(&self) -> &'a str { - self.0 + pub fn into_inner(&self) -> String { + self.0.clone() } } -impl<'a> From<&'a str> for DomainIdentifier<'a> { - fn from(value: &'a str) -> Self { +impl From for DomainIdentifier { + fn from(value: String) -> Self { Self(value) } } -impl<'a> Deref for DomainIdentifier<'a> { - type Target = str; - - fn deref(&self) -> &'a Self::Target { - self.0 - } -} +// impl Deref for DomainIdentifier { +// type Target = &String; +// +// fn deref(&self) -> Self::Target { +// self.0 +// } +// } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DomainInfo<'a> { - pub domain_identifier: DomainIdentifier<'a>, +pub struct DomainInfo { + pub domain_identifier: DomainIdentifier, pub domain_description: String, } diff --git a/crates/kgraph_utils/benches/evaluation.rs b/crates/kgraph_utils/benches/evaluation.rs index 6710dfc764..820e3da42d 100644 --- a/crates/kgraph_utils/benches/evaluation.rs +++ b/crates/kgraph_utils/benches/evaluation.rs @@ -16,10 +16,10 @@ use euclid::{ use hyperswitch_constraint_graph::{CycleCheck, Memoization}; use kgraph_utils::{error::KgraphError, transformers::IntoDirValue, types::CountryCurrencyFilter}; -fn build_test_data<'a>( +fn build_test_data( total_enabled: usize, total_pm_types: usize, -) -> hyperswitch_constraint_graph::ConstraintGraph<'a, dir::DirValue> { +) -> hyperswitch_constraint_graph::ConstraintGraph { use api_models::{admin::*, payment_methods::*}; let mut pms_enabled: Vec = Vec::new(); diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs index 453ccb74e2..74cc096e73 100644 --- a/crates/kgraph_utils/src/mca.rs +++ b/crates/kgraph_utils/src/mca.rs @@ -147,7 +147,7 @@ fn get_dir_value_payment_method( } fn compile_request_pm_types( - builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>, + builder: &mut cgraph::ConstraintGraphBuilder, pm_types: RequestPaymentMethodTypes, pm: api_enums::PaymentMethod, ) -> Result { @@ -332,7 +332,7 @@ fn compile_request_pm_types( } fn compile_payment_method_enabled( - builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>, + builder: &mut cgraph::ConstraintGraphBuilder, enabled: admin_api::PaymentMethodsEnabled, ) -> Result, KgraphError> { let agg_id = if !enabled @@ -400,7 +400,7 @@ macro_rules! collect_global_variants { } fn global_vec_pmt( enabled_pmt: Vec, - builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>, + builder: &mut cgraph::ConstraintGraphBuilder, ) -> Vec { let mut global_vector: Vec = Vec::new(); @@ -437,7 +437,7 @@ fn global_vec_pmt( } fn compile_graph_for_countries_and_currencies( - builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>, + builder: &mut cgraph::ConstraintGraphBuilder, config: &kgraph_types::CurrencyCountryFlowFilter, payment_method_type_node: cgraph::NodeId, ) -> Result { @@ -503,7 +503,7 @@ fn compile_graph_for_countries_and_currencies( } fn compile_config_graph( - builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>, + builder: &mut cgraph::ConstraintGraphBuilder, config: &kgraph_types::CountryCurrencyFilter, connector: &api_enums::RoutableConnectors, ) -> Result { @@ -596,7 +596,7 @@ fn compile_config_graph( } fn compile_merchant_connector_graph( - builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>, + builder: &mut cgraph::ConstraintGraphBuilder, mca: admin_api::MerchantConnectorResponse, config: &kgraph_types::CountryCurrencyFilter, ) -> Result<(), KgraphError> { @@ -669,13 +669,13 @@ fn compile_merchant_connector_graph( Ok(()) } -pub fn make_mca_graph<'a>( +pub fn make_mca_graph( accts: Vec, config: &kgraph_types::CountryCurrencyFilter, -) -> Result, KgraphError> { +) -> Result, KgraphError> { let mut builder = cgraph::ConstraintGraphBuilder::new(); let _domain = builder.make_domain( - DOMAIN_IDENTIFIER, + DOMAIN_IDENTIFIER.to_string(), "Payment methods enabled for MerchantConnectorAccount", ); for acct in accts { @@ -701,7 +701,7 @@ mod tests { use super::*; use crate::types as kgraph_types; - fn build_test_data<'a>() -> ConstraintGraph<'a, dir::DirValue> { + fn build_test_data() -> ConstraintGraph { use api_models::{admin::*, payment_methods::*}; let stripe_account = MerchantConnectorResponse { diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs index 042bf8612e..8c27e3b3ca 100644 --- a/crates/router/src/core/payments/routing.rs +++ b/crates/router/src/core/payments/routing.rs @@ -539,7 +539,7 @@ pub async fn get_merchant_cgraph<'a>( key_store: &domain::MerchantKeyStore, #[cfg(feature = "business_profile_routing")] profile_id: Option, transaction_type: &api_enums::TransactionType, -) -> RoutingResult>> { +) -> RoutingResult>> { let merchant_id = &key_store.merchant_id; #[cfg(feature = "business_profile_routing")] @@ -565,7 +565,7 @@ pub async fn get_merchant_cgraph<'a>( }; let cached_cgraph = CGRAPH_CACHE - .get_val::>>( + .get_val::>>( CacheKey { key: key.clone(), prefix: state.tenant.redis_key_prefix.clone(), @@ -596,7 +596,7 @@ pub async fn refresh_cgraph_cache<'a>( key: String, #[cfg(feature = "business_profile_routing")] profile_id: Option, transaction_type: &api_enums::TransactionType, -) -> RoutingResult>> { +) -> RoutingResult>> { let mut merchant_connector_accounts = state .store .find_merchant_connector_account_by_merchant_id_and_disabled_list(