From bd9cbbc45286a682d5fe2a757de599c097824ea1 Mon Sep 17 00:00:00 2001 From: Haifeng Shi Date: Thu, 30 Mar 2023 11:13:42 -0400 Subject: [PATCH 1/2] add makeDefaultsExplicit option --- tests/checkers/inference/test/CFInferenceTest.java | 7 ++++++- .../test/ImmutableInferenceTestConfiguration.java | 9 ++++++++- .../inference/test/InferenceTestConfiguration.java | 1 + .../test/InferenceTestConfigurationBuilder.java | 14 +++++++++++--- .../inference/test/InferenceTestExecutor.java | 3 +++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/checkers/inference/test/CFInferenceTest.java b/tests/checkers/inference/test/CFInferenceTest.java index b2ee3f9df..cd76a046f 100644 --- a/tests/checkers/inference/test/CFInferenceTest.java +++ b/tests/checkers/inference/test/CFInferenceTest.java @@ -30,6 +30,10 @@ public boolean useHacks() { return SystemUtil.getBooleanSystemProperty("use.hacks"); } + public boolean makeDefaultsExplicit() { + return false; + } + public abstract Pair> getSolverNameAndOptions(); public List getAdditionalInferenceOptions() { @@ -54,7 +58,8 @@ public void run() { InferenceTestConfiguration config = InferenceTestConfigurationBuilder.buildDefaultConfiguration(testDir, testFile, testDataDir, checker, checkerOptions, getAdditionalInferenceOptions(), solverArgs.first, - solverArgs.second, useHacks(), shouldEmitDebugInfo, getPathToAfuScripts(), getPathToInferenceScript()); + solverArgs.second, useHacks(), makeDefaultsExplicit(), shouldEmitDebugInfo, getPathToAfuScripts(), + getPathToInferenceScript()); InferenceTestResult testResult = new InferenceTestExecutor().runTest(config); InferenceTestUtilities.assertResultsAreValid(testResult); diff --git a/tests/checkers/inference/test/ImmutableInferenceTestConfiguration.java b/tests/checkers/inference/test/ImmutableInferenceTestConfiguration.java index f44fcf090..12a47261c 100644 --- a/tests/checkers/inference/test/ImmutableInferenceTestConfiguration.java +++ b/tests/checkers/inference/test/ImmutableInferenceTestConfiguration.java @@ -16,13 +16,15 @@ public class ImmutableInferenceTestConfiguration implements InferenceTestConfigu private final String solver; private final Map solverArgs; private final boolean shouldUseHacks; + private final boolean makeDefaultsExplicit; private final String pathToAfuScripts; private final String pathToInferenceScript; private final TestConfiguration initialConfig; public ImmutableInferenceTestConfiguration(File outputJaif, File testDataDir, File annotatedSourceDir, Map inferenceJavacArgs, String solver, - Map solverArgs, boolean shouldUseHacks, String pathToAfuScripts, + Map solverArgs, boolean shouldUseHacks, + boolean makeDefaultsExplicit, String pathToAfuScripts, String pathToInferenceScript, TestConfiguration initialConfig) { this.outputJaif = outputJaif; this.testDataDir = testDataDir; @@ -31,6 +33,7 @@ public ImmutableInferenceTestConfiguration(File outputJaif, File testDataDir, Fi this.solver = solver; this.solverArgs = solverArgs; this.shouldUseHacks = shouldUseHacks; + this.makeDefaultsExplicit = makeDefaultsExplicit; this.pathToAfuScripts = pathToAfuScripts; this.initialConfig = initialConfig; this.pathToInferenceScript = pathToInferenceScript; @@ -69,6 +72,10 @@ public boolean shouldUseHacks() { return shouldUseHacks; } + public boolean makeDefaultsExplicit() { + return makeDefaultsExplicit; + } + public String getPathToAfuScripts() { return pathToAfuScripts; } diff --git a/tests/checkers/inference/test/InferenceTestConfiguration.java b/tests/checkers/inference/test/InferenceTestConfiguration.java index b084f7bf7..d7c4ce90f 100644 --- a/tests/checkers/inference/test/InferenceTestConfiguration.java +++ b/tests/checkers/inference/test/InferenceTestConfiguration.java @@ -20,6 +20,7 @@ public interface InferenceTestConfiguration { List getFlatSolverArgs(); boolean shouldUseHacks(); + boolean makeDefaultsExplicit(); String getPathToAfuScripts(); String getPathToInferenceScript(); diff --git a/tests/checkers/inference/test/InferenceTestConfigurationBuilder.java b/tests/checkers/inference/test/InferenceTestConfigurationBuilder.java index 1d2962091..668b0f1d6 100644 --- a/tests/checkers/inference/test/InferenceTestConfigurationBuilder.java +++ b/tests/checkers/inference/test/InferenceTestConfigurationBuilder.java @@ -17,6 +17,7 @@ public class InferenceTestConfigurationBuilder { private File testDataDir = null; private String solver = null; private boolean shouldUseHacks; + private boolean makeDefaultsExplicit; private String pathToAfuScripts=""; private String pathToInferenceScript=""; @@ -60,6 +61,11 @@ public InferenceTestConfigurationBuilder setShouldUseHacks(boolean shouldUseHack return this; } + public InferenceTestConfigurationBuilder setMakeDefaultsExplicit(boolean makeDefaultsExplicit) { + this.makeDefaultsExplicit = makeDefaultsExplicit; + return this; + } + public InferenceTestConfigurationBuilder setPathToAfuScripts(String pathToAfuScripts) { this.pathToAfuScripts = pathToAfuScripts; return this; @@ -156,8 +162,8 @@ public List validate() { public InferenceTestConfiguration build() { return new ImmutableInferenceTestConfiguration(outputJaif, testDataDir, annotatedSourceDir, new LinkedHashMap<>(inferenceJavacArgs.getOptions()), - solver, new LinkedHashMap<>(solverArgs.getOptions()), shouldUseHacks,pathToAfuScripts, - pathToInferenceScript, initialConfiguration); + solver, new LinkedHashMap<>(solverArgs.getOptions()), shouldUseHacks, makeDefaultsExplicit, + pathToAfuScripts, pathToInferenceScript, initialConfiguration); } public InferenceTestConfiguration validateThenBuild() { @@ -175,7 +181,8 @@ public InferenceTestConfiguration validateThenBuild() { public static InferenceTestConfiguration buildDefaultConfiguration( String testSourcePath, File testFile, File testDataRoot, Class checker, List typecheckOptions, List inferenceOptions, String solverName, List solverOptions, - boolean shouldUseHacks, boolean shouldEmitDebugInfo, String pathToAfuScripts, String pathToInferenceScript) { + boolean shouldUseHacks, boolean makeDefaultsExplicit, boolean shouldEmitDebugInfo, String pathToAfuScripts, + String pathToInferenceScript) { final File defaultInferenceOutDir = new File("testdata/tmp"); final File defaultOutputJaif = new File(defaultInferenceOutDir, "default.jaif"); @@ -192,6 +199,7 @@ public static InferenceTestConfiguration buildDefaultConfiguration( .setAnnotatedSourceDir(defaultAnnotatedSourceDir) .setSolver(solverName) .setShouldUseHacks(shouldUseHacks) + .setMakeDefaultsExplicit(makeDefaultsExplicit) .setPathToAfuScripts(pathToAfuScripts) .setPathToInferenceScript(pathToInferenceScript); diff --git a/tests/checkers/inference/test/InferenceTestExecutor.java b/tests/checkers/inference/test/InferenceTestExecutor.java index 14345bf9b..39ee1b9af 100644 --- a/tests/checkers/inference/test/InferenceTestExecutor.java +++ b/tests/checkers/inference/test/InferenceTestExecutor.java @@ -80,6 +80,9 @@ public static InferenceResult infer(InferenceTestConfiguration configuration) { if (configuration.shouldUseHacks()) { options.add("--hacks"); } + if (configuration.makeDefaultsExplicit()) { + options.add("--makeDefaultsExplicit=true"); + } options.add("--jaifFile=" + configuration.getOutputJaif().getAbsolutePath()); From a0a9e74a50d749ee29fb2c99fffe2f50ce507969 Mon Sep 17 00:00:00 2001 From: Haifeng Shi Date: Thu, 30 Mar 2023 11:44:25 -0400 Subject: [PATCH 2/2] add makeDefaultsExplicit option --- src/checkers/inference/InferenceLauncher.java | 2 +- tests/checkers/inference/test/InferenceTestExecutor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checkers/inference/InferenceLauncher.java b/src/checkers/inference/InferenceLauncher.java index 3d1fdce1a..c229d2593 100644 --- a/src/checkers/inference/InferenceLauncher.java +++ b/src/checkers/inference/InferenceLauncher.java @@ -205,7 +205,7 @@ public void infer() { Mode mode = Mode.valueOf(InferenceOptions.mode); if (InferenceOptions.makeDefaultsExplicit - && (mode == Mode.ROUNDTRIP || mode == Mode.ROUNDTRIP_TYPECHECK)) { + && (mode == Mode.ROUNDTRIP || mode == Mode.ROUNDTRIP_TYPECHECK || mode == Mode.INFER)) { // Two conditions have to be met to make defaults explicit: // 1. the command-line flag `makeDefaultsExplicit` is provided // 2. the inference solution will be written back to the source code (roundtrip `mode`) diff --git a/tests/checkers/inference/test/InferenceTestExecutor.java b/tests/checkers/inference/test/InferenceTestExecutor.java index 39ee1b9af..310145d4d 100644 --- a/tests/checkers/inference/test/InferenceTestExecutor.java +++ b/tests/checkers/inference/test/InferenceTestExecutor.java @@ -81,7 +81,7 @@ public static InferenceResult infer(InferenceTestConfiguration configuration) { options.add("--hacks"); } if (configuration.makeDefaultsExplicit()) { - options.add("--makeDefaultsExplicit=true"); + options.add("--makeDefaultsExplicit"); } options.add("--jaifFile=" + configuration.getOutputJaif().getAbsolutePath());