-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #62 by adding configuration mode for downstream dependency analys…
…is. (#63) This Resolves #62 by adding a configuration mode `Strict`. With this PR, we can now configure the analysis mode which will impact inference decisions. We have four different modes of analysis: 1. `Local`: Only considers the local effect of fixes. 2. `Lower Bound`: Considers the lower bounds of number of errors on downstream dependencies. 3. `Upper Bound`: Considers the upper bound of number of errors on downstream dependencies. 4. `Strict`: Guarantees that all errors in downstream due to changes in upstream will be resolved. To set the above modes via command line, pass `-am` or `--analysis-mode` followed by one of the options below: - `default` - `upper_bound` - `lower_bound` - `strict` Or set one of the values above In the `.json` config file at: ```json "DOWNSTREAM_DEPENDENCY_ANALYSIS":{ "ANALYSIS_MODE": "mode" } ```
- Loading branch information
1 parent
c824d26
commit 742a564
Showing
21 changed files
with
859 additions
and
10 deletions.
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
core/src/main/java/edu/ucr/cs/riple/core/AnalysisMode.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,157 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022 Nima Karimipour | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package edu.ucr.cs.riple.core; | ||
|
||
import static edu.ucr.cs.riple.core.Report.Tag.APPROVE; | ||
import static edu.ucr.cs.riple.core.Report.Tag.REJECT; | ||
|
||
import com.google.common.base.Preconditions; | ||
import edu.ucr.cs.riple.core.global.GlobalAnalyzer; | ||
import java.util.Collection; | ||
|
||
/** Analysis mode in making inference decisions. */ | ||
public enum AnalysisMode { | ||
/** | ||
* Only effects in target module is considered. Default mode if downstream dependencies analysis | ||
* is not activated. | ||
*/ | ||
LOCAL { | ||
@Override | ||
public void tag(Config config, GlobalAnalyzer analyzer, Collection<Report> reports) { | ||
reports.forEach( | ||
report -> { | ||
if (report.localEffect < 1) { | ||
report.tag(APPROVE); | ||
} else { | ||
report.tag(REJECT); | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
/** | ||
* Guarantees that no error will happen on downstream dependencies in the result of changes in | ||
* upstream. | ||
*/ | ||
STRICT { | ||
@Override | ||
public void tag(Config config, GlobalAnalyzer analyzer, Collection<Report> reports) { | ||
reports.forEach( | ||
report -> { | ||
// Check for destructive methods. | ||
if (report.containsDestructiveMethod(analyzer)) { | ||
report.tag(REJECT); | ||
return; | ||
} | ||
// Just a sanity check. | ||
Preconditions.checkArgument(report.getUpperBoundEffectOnDownstreamDependencies() == 0); | ||
// Apply if effect is less than 1. | ||
if (report.localEffect < 1) { | ||
report.tag(APPROVE); | ||
return; | ||
} | ||
// Discard. | ||
report.tag(REJECT); | ||
}); | ||
} | ||
}, | ||
|
||
/** | ||
* Experimental: Upper bound of number of errors on downstream dependencies will be considered. | ||
*/ | ||
UPPER_BOUND { | ||
@Override | ||
public void tag(Config config, GlobalAnalyzer analyzer, Collection<Report> reports) { | ||
reports.forEach( | ||
report -> { | ||
if (report.localEffect + report.getUpperBoundEffectOnDownstreamDependencies() < 1) { | ||
report.tag(APPROVE); | ||
} else { | ||
report.tag(REJECT); | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
/** | ||
* Lower bound of number of errors on downstream dependencies will be considered. Default mode if | ||
* downstream dependencies analysis is enabled. | ||
*/ | ||
LOWER_BOUND { | ||
@Override | ||
public void tag(Config config, GlobalAnalyzer analyzer, Collection<Report> reports) { | ||
reports.forEach( | ||
report -> { | ||
if (report.localEffect + report.getLowerBoundEffectOnDownstreamDependencies() < 1) { | ||
report.tag(APPROVE); | ||
} else { | ||
report.tag(REJECT); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Tags reports based on the analysis mode. | ||
* | ||
* @param config Annotator config. | ||
* @param analyzer Downstream dependency instance. | ||
* @param reports Reports to be processed. | ||
*/ | ||
public abstract void tag(Config config, GlobalAnalyzer analyzer, Collection<Report> reports); | ||
|
||
/** | ||
* Parses the received option and returns the corresponding {@link AnalysisMode}. Can only be one | ||
* of [default|upper_bound|lower_bound|strict] values. | ||
* | ||
* @param downStreamDependenciesAnalysisActivated if true, downstream dependency analysis is | ||
* activated. | ||
* @param mode passed mode. | ||
* @param useDefault if true, no value is provided by the user and the default mode will be | ||
* returned. (If downstream dependency analysis is activated default is {@link | ||
* AnalysisMode#LOWER_BOUND}, otherwise the default is {@link AnalysisMode#LOCAL}). | ||
* @return the corresponding {@link AnalysisMode}. | ||
*/ | ||
public static AnalysisMode parseMode( | ||
boolean downStreamDependenciesAnalysisActivated, String mode) { | ||
if (!downStreamDependenciesAnalysisActivated) { | ||
return LOCAL; | ||
} | ||
mode = mode.toLowerCase(); | ||
if (mode.equals("lower_bound") || mode.equals("default")) { | ||
return LOWER_BOUND; | ||
} | ||
if (mode.equals("upper_bound")) { | ||
return UPPER_BOUND; | ||
} | ||
if (mode.equals("strict")) { | ||
return STRICT; | ||
} | ||
throw new IllegalArgumentException( | ||
"Unrecognized mode request: " | ||
+ mode | ||
+ " .Can only be [default|upper_bound|lower_bound|strict]."); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.