-
Notifications
You must be signed in to change notification settings - Fork 347
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
Fix potential exponential behavior in obligation tracking in Must Cal… #6567
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 216 additions & 0 deletions
216
checker/tests/ainfer-resourceleak/non-annotated/FuzzyEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
/** | ||
* The test case reveals issues in the url90b6689baa_adsonrocha_PD321_tgz-pJ8-MyFuzzyLiteClassJ8 | ||
* project from the NJR dataset, where the lack of the | ||
* MustCallConsistencyAnalyzer::shouldTrackInvocationResult bailout check leads to exponential | ||
* growth in complexity. This results from an unchecked accumulation of obligations to track across | ||
* multiple control-flow paths, originally suspected to cause non-termination. | ||
*/ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FuzzyEngine { | ||
private List<InputVariable> inputVariables; | ||
private List<OutputVariable> outputVariables; | ||
private List<RuleBlock> ruleBlocks; | ||
|
||
public FuzzyEngine() { | ||
inputVariables = new ArrayList<>(); | ||
outputVariables = new ArrayList<>(); | ||
ruleBlocks = new ArrayList<>(); | ||
} | ||
|
||
public boolean isReady(StringBuilder message) { | ||
message.setLength(0); | ||
if (inputVariables.isEmpty()) { | ||
message.append("- Engine has no input variables\n"); | ||
} | ||
for (int i = 0; i < inputVariables.size(); ++i) { | ||
InputVariable inputVariable = inputVariables.get(i); | ||
if (inputVariable == null) { | ||
message.append(String.format("- Engine has a null input variable at index <%d>\n", i)); | ||
} else if (inputVariable.getTerms().isEmpty()) { | ||
// ignore because sometimes inputs can be empty: takagi-sugeno/matlab/slcpp1.fis | ||
// message.append(String.format("- Input variable <%s> has no terms\n", inputVariable | ||
// .getName())); | ||
} | ||
} | ||
|
||
if (outputVariables.isEmpty()) { | ||
message.append("- Engine has no output variables\n"); | ||
} | ||
for (int i = 0; i < outputVariables.size(); ++i) { | ||
OutputVariable outputVariable = outputVariables.get(i); | ||
if (outputVariable == null) { | ||
message.append(String.format("- Engine has a null output variable at index <%d>\n", i)); | ||
} else { | ||
if (outputVariable.getTerms().isEmpty()) { | ||
message.append( | ||
String.format("- Output variable <%s> has no terms\n", outputVariable.getName())); | ||
} | ||
Defuzzifier defuzzifier = outputVariable.getDefuzzifier(); | ||
if (defuzzifier == null) { | ||
message.append( | ||
String.format( | ||
"- Output variable <%s> has no defuzzifier\n", outputVariable.getName())); | ||
} else if (defuzzifier instanceof IntegralDefuzzifier | ||
&& outputVariable.fuzzyOutput().getAccumulation() == null) { | ||
message.append( | ||
String.format( | ||
"- Output variable <%s> has no Accumulation\n", outputVariable.getName())); | ||
} | ||
} | ||
} | ||
|
||
if (ruleBlocks.isEmpty()) { | ||
message.append("- Engine has no rule blocks\n"); | ||
} | ||
for (int i = 0; i < ruleBlocks.size(); ++i) { | ||
RuleBlock ruleBlock = ruleBlocks.get(i); | ||
if (ruleBlock == null) { | ||
message.append(String.format("- Engine has a null rule block at index <%d>\n", i)); | ||
} else { | ||
if (ruleBlock.getRules().isEmpty()) { | ||
message.append(String.format("- Rule block <%s> has no rules\n", ruleBlock.getName())); | ||
} | ||
int requiresConjunction = 0; | ||
int requiresDisjunction = 0; | ||
for (Rule rule : ruleBlock.getRules()) { | ||
if (rule == null) { | ||
message.append( | ||
String.format( | ||
"- Rule block <%s> has a null rule at index <%d>\n", | ||
ruleBlock.getName(), ruleBlocks.indexOf(rule))); | ||
} else { | ||
int thenIndex = rule.getText().indexOf(" " + Rule.FL_THEN + " "); | ||
if (rule.getText().indexOf(" " + Rule.FL_AND + " ") < thenIndex) { | ||
++requiresConjunction; | ||
} | ||
if (rule.getText().indexOf(" " + Rule.FL_OR + " ") < thenIndex) { | ||
++requiresDisjunction; | ||
} | ||
} | ||
} | ||
if (requiresConjunction > 0 && ruleBlock.getConjunction() == null) { | ||
message.append( | ||
String.format("- Rule block <%s> has no Conjunction\n", ruleBlock.getName())); | ||
message.append( | ||
String.format( | ||
"- Rule block <%s> has %d rules that require " + "Conjunction\n", | ||
ruleBlock.getName(), requiresConjunction)); | ||
} | ||
if (requiresDisjunction > 0 && ruleBlock.getDisjunction() == null) { | ||
message.append( | ||
String.format("- Rule block <%s> has no Disjunction\n", ruleBlock.getName())); | ||
message.append( | ||
String.format( | ||
"- Rule block <%s> has %d rules that require " + "Disjunction\n", | ||
ruleBlock.getName(), requiresDisjunction)); | ||
} | ||
if (ruleBlock.getActivation() == null) { | ||
message.append( | ||
String.format("- Rule block <%s> has no Activation\n", ruleBlock.getName())); | ||
} | ||
} | ||
} | ||
return message.length() == 0; | ||
} | ||
|
||
// Inner classes and interfaces definitions | ||
|
||
private interface Defuzzifier {} | ||
|
||
private static class IntegralDefuzzifier implements Defuzzifier { | ||
// Implementations specific to Integral Defuzzifier | ||
} | ||
|
||
private class InputVariable { | ||
private List<String> terms; | ||
private String name; | ||
|
||
public List<String> getTerms() { | ||
return terms; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
|
||
private class OutputVariable { | ||
private List<String> terms; | ||
private String name; | ||
private Defuzzifier defuzzifier; | ||
private FuzzyOutput fuzzyOutput; | ||
|
||
public List<String> getTerms() { | ||
return terms; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Defuzzifier getDefuzzifier() { | ||
return defuzzifier; | ||
} | ||
|
||
public FuzzyOutput fuzzyOutput() { | ||
return fuzzyOutput; | ||
} | ||
} | ||
|
||
private class FuzzyOutput { | ||
private Accumulation accumulation; | ||
|
||
public Accumulation getAccumulation() { | ||
return accumulation; | ||
} | ||
} | ||
|
||
private class RuleBlock { | ||
private List<Rule> rules; | ||
private String name; | ||
private Conjunction conjunction; | ||
private Disjunction disjunction; | ||
private Activation activation; | ||
|
||
public List<Rule> getRules() { | ||
return rules; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Conjunction getConjunction() { | ||
return conjunction; | ||
} | ||
|
||
public Disjunction getDisjunction() { | ||
return disjunction; | ||
} | ||
|
||
public Activation getActivation() { | ||
return activation; | ||
} | ||
} | ||
|
||
private static class Rule { | ||
public static final String FL_THEN = "then"; | ||
public static final String FL_AND = "and"; | ||
public static final String FL_OR = "or"; | ||
private String text; | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
} | ||
|
||
private interface Conjunction {} | ||
|
||
private interface Disjunction {} | ||
|
||
private interface Activation {} | ||
|
||
private class Accumulation {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking, did you confirm that without your fix, you see the exponential behavior on this input when running the inference regression tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and without the fix I was encountering OOM in my machine.