Skip to content

Commit e713cd8

Browse files
committed
Move EndpointBddTrait to traits, address PR issues
1 parent b443bed commit e713cd8

27 files changed

Lines changed: 74 additions & 42 deletions

File tree

docs/source-2.0/additional-specs/rules-engine/specification.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ on the scenario.
9494
This trait is experimental and subject to change.
9595

9696
Summary
97-
A Binary Decision Diagram (BDD) <https://en.wikipedia.org/wiki/Binary_decision_diagram>_ representation of endpoint
98-
rules that is more compact and efficient at runtime than the decision-tree-based EndpointRuleSet trait.
97+
A Binary `Decision Diagram (BDD) <https://en.wikipedia.org/wiki/Binary_decision_diagram>`_ representation of
98+
endpoint rules that is more compact and efficient at runtime than the decision-tree-based EndpointRuleSet trait.
9999
Trait selector
100100
``service``
101101
Value type

smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import software.amazon.smithy.model.validation.ValidationEvent;
1515
import software.amazon.smithy.rulesengine.aws.language.functions.AwsBuiltIns;
1616
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter;
17-
import software.amazon.smithy.rulesengine.logic.bdd.EndpointBddTrait;
17+
import software.amazon.smithy.rulesengine.traits.EndpointBddTrait;
1818
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
1919
import software.amazon.smithy.utils.SetUtils;
2020

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/BddCoverageChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import software.amazon.smithy.rulesengine.language.syntax.rule.Rule;
2121
import software.amazon.smithy.rulesengine.logic.ConditionEvaluator;
2222
import software.amazon.smithy.rulesengine.logic.bdd.Bdd;
23-
import software.amazon.smithy.rulesengine.logic.bdd.EndpointBddTrait;
23+
import software.amazon.smithy.rulesengine.traits.EndpointBddTrait;
2424
import software.amazon.smithy.rulesengine.traits.EndpointTestCase;
2525

2626
/**

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import software.amazon.smithy.rulesengine.language.syntax.rule.RuleValueVisitor;
2828
import software.amazon.smithy.rulesengine.logic.RuleBasedConditionEvaluator;
2929
import software.amazon.smithy.rulesengine.logic.bdd.Bdd;
30-
import software.amazon.smithy.rulesengine.logic.bdd.EndpointBddTrait;
30+
import software.amazon.smithy.rulesengine.traits.EndpointBddTrait;
3131
import software.amazon.smithy.utils.SmithyUnstableApi;
3232

3333
/**

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TestEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import software.amazon.smithy.rulesengine.language.evaluation.value.EndpointValue;
1414
import software.amazon.smithy.rulesengine.language.evaluation.value.Value;
1515
import software.amazon.smithy.rulesengine.language.syntax.Identifier;
16-
import software.amazon.smithy.rulesengine.logic.bdd.EndpointBddTrait;
16+
import software.amazon.smithy.rulesengine.traits.EndpointBddTrait;
1717
import software.amazon.smithy.rulesengine.traits.EndpointTestCase;
1818
import software.amazon.smithy.rulesengine.traits.EndpointTestExpectation;
1919
import software.amazon.smithy.rulesengine.traits.ExpectedEndpoint;

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Coalesce.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* A coalesce function that returns the first non-empty value.
2222
*
23-
* <p>This variadic function requires two or more arguments. At runtime, returns the first arguments that returns a
23+
* <p>This variadic function requires two or more arguments. At runtime, returns the first argument that contains a
2424
* non-EmptyValue, otherwise returns the result of the last argument.
2525
*
2626
* <p>Type checking rules:

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/Bdd.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ public Bdd(int rootRef, int conditionCount, int resultCount, int nodeCount, Cons
7171
}
7272

7373
/**
74-
* Package-private constructor for direct array initialization (used by BddTrait).
74+
* Creates a BDD by streaming nodes directly into the structure.
75+
*
76+
* @param rootRef the root reference
77+
* @param conditionCount the number of conditions
78+
* @param resultCount the number of results
79+
* @param nodeCount the exact number of nodes
80+
* @param nodes BDD nodes array where the condition, high, and low are all in succession.
7581
*/
76-
Bdd(int rootRef, int conditionCount, int resultCount, int nodeCount, int[] nodes) {
82+
public Bdd(int rootRef, int conditionCount, int resultCount, int nodeCount, int[] nodes) {
7783
validateCounts(conditionCount, resultCount, nodeCount);
7884
validateRootReference(rootRef, nodeCount);
7985

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/BddCompiler.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import software.amazon.smithy.rulesengine.logic.cfg.CfgNode;
2020
import software.amazon.smithy.rulesengine.logic.cfg.ConditionNode;
2121
import software.amazon.smithy.rulesengine.logic.cfg.ResultNode;
22+
import software.amazon.smithy.utils.SmithyInternalApi;
2223

2324
/**
24-
* BDD compiler that builds an unreduced BDD from CFG.
25+
* BDD compiler that builds a BDD from a CFG.
2526
*/
26-
final class BddCompiler {
27+
@SmithyInternalApi
28+
public final class BddCompiler {
2729
private static final Logger LOGGER = Logger.getLogger(BddCompiler.class.getName());
2830

2931
private final Cfg cfg;
@@ -43,6 +45,13 @@ final class BddCompiler {
4345
// Simple cache to avoid recomputing identical subgraphs
4446
private final Map<CfgNode, Integer> nodeCache = new HashMap<>();
4547

48+
/**
49+
* @param cfg CFG to convert to a BDD.
50+
*/
51+
public BddCompiler(Cfg cfg) {
52+
this(cfg, new BddBuilder());
53+
}
54+
4655
BddCompiler(Cfg cfg, BddBuilder bddBuilder) {
4756
this(cfg, OrderingStrategy.initialOrdering(cfg), bddBuilder);
4857
}
@@ -53,7 +62,12 @@ final class BddCompiler {
5362
this.bddBuilder = Objects.requireNonNull(bddBuilder, "BDD builder cannot be null");
5463
}
5564

56-
Bdd compile() {
65+
/**
66+
* Compile the CFG into a BDD.
67+
*
68+
* @return the compiled BDD.
69+
*/
70+
public Bdd compile() {
5771
long start = System.currentTimeMillis();
5872
extractAndOrderConditions();
5973

@@ -77,11 +91,21 @@ Bdd compile() {
7791
return bdd;
7892
}
7993

80-
List<Rule> getIndexedResults() {
94+
/**
95+
* The ordered result rules after BDD compilation.
96+
*
97+
* @return ordered BDD result rules.
98+
*/
99+
public List<Rule> getIndexedResults() {
81100
return indexedResults;
82101
}
83102

84-
List<Condition> getOrderedConditions() {
103+
/**
104+
* Get the ordered conditions referenced in the compiled BDD.
105+
*
106+
* @return the ordered BDD conditions.
107+
*/
108+
public List<Condition> getOrderedConditions() {
85109
return orderedConditions;
86110
}
87111

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/NodeReversal.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.function.Function;
88
import java.util.logging.Logger;
9+
import software.amazon.smithy.rulesengine.traits.EndpointBddTrait;
910

1011
/**
1112
* Reverses the node ordering in a BDD from bottom-up to top-down for better cache locality.

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/SiftingOptimization.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import software.amazon.smithy.rulesengine.language.syntax.rule.Rule;
1919
import software.amazon.smithy.rulesengine.logic.cfg.Cfg;
2020
import software.amazon.smithy.rulesengine.logic.cfg.ConditionDependencyGraph;
21+
import software.amazon.smithy.rulesengine.traits.EndpointBddTrait;
2122
import software.amazon.smithy.utils.SmithyBuilder;
2223

2324
/**

0 commit comments

Comments
 (0)