Simplify and enable by default inline/optimize/assertions

Inline, optimize, call assertions, param assertions are turned on by default
now almost everywhere; invert their meaning
This commit is contained in:
Alexander Udalov
2014-07-30 11:38:40 -07:00
parent 160cde09d6
commit 45a57011d8
15 changed files with 83 additions and 115 deletions
@@ -28,8 +28,6 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.Progress;
import org.jetbrains.jet.config.CompilerConfiguration;
@@ -47,7 +45,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
public class CodegenTestUtil {
private CodegenTestUtil() {}
@@ -57,7 +55,8 @@ public class CodegenTestUtil {
AnalyzeExhaust analyzeExhaust = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
environment.getProject(),
files.getPsiFiles(),
Predicates.<PsiFile>alwaysTrue());
Predicates.<PsiFile>alwaysTrue()
);
analyzeExhaust.throwIfError();
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
CompilerConfiguration configuration = environment.getConfiguration();
@@ -65,15 +64,16 @@ public class CodegenTestUtil {
GenerationState state = new GenerationState(
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF,
analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(), files.getPsiFiles(),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false),
configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false),
GenerationState.GenerateClassFilter.GENERATE_ALL,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
configuration.get(JVMConfigurationKeys.ENABLE_OPTIMIZATION, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG),
configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false),
configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false),
null,
null,
forExtraDiagnostics,
null);
null
);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
// For JVM-specific errors
@@ -41,35 +41,35 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
super.setUp();
}
private void setUpEnvironment(boolean generateAssertions, boolean generateParamAssertions, File... extraClassPath) {
private void setUpEnvironment(boolean disableCallAssertions, boolean disableParamAssertions, File... extraClassPath) {
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath);
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, generateAssertions);
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, generateParamAssertions);
configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, disableCallAssertions);
configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, disableParamAssertions);
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
}
private void doTestGenerateAssertions(boolean generateAssertions) throws Exception {
private void doTestCallAssertions(boolean disableCallAssertions) throws Exception {
File javaClassesTempDirectory = compileJava("notNullAssertions/A.java");
setUpEnvironment(generateAssertions, false, javaClassesTempDirectory);
setUpEnvironment(disableCallAssertions, true, javaClassesTempDirectory);
loadFile("notNullAssertions/AssertionChecker.kt");
generateFunction("checkAssertions").invoke(null, generateAssertions);
generateFunction("checkAssertions").invoke(null, !disableCallAssertions);
}
public void testGenerateAssertions() throws Exception {
doTestGenerateAssertions(true);
doTestCallAssertions(false);
}
public void testDoNotGenerateAssertions() throws Exception {
doTestGenerateAssertions(false);
doTestCallAssertions(true);
}
public void testNoAssertionsForKotlinFromSource() throws Exception {
setUpEnvironment(true, false);
setUpEnvironment(false, true);
loadFiles("notNullAssertions/noAssertionsForKotlin.kt", "notNullAssertions/noAssertionsForKotlinMain.kt");
@@ -77,13 +77,13 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
public void testNoAssertionsForKotlinFromBinary() throws Exception {
setUpEnvironment(true, false);
setUpEnvironment(false, true);
loadFile("notNullAssertions/noAssertionsForKotlin.kt");
OutputFileCollection outputFiles = generateClassesInFile();
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
OutputUtilsPackage.writeAllTo(outputFiles, compiledDirectory);
setUpEnvironment(true, false, compiledDirectory);
setUpEnvironment(false, true, compiledDirectory);
loadFile("notNullAssertions/noAssertionsForKotlinMain.kt");
assertNoIntrinsicsMethodIsCalled(PackageClassUtils.getPackageClassName(FqName.ROOT));
@@ -92,14 +92,14 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
public void testGenerateParamAssertions() throws Exception {
File javaClassesTempDirectory = compileJava("notNullAssertions/doGenerateParamAssertions.java");
setUpEnvironment(false, true, javaClassesTempDirectory);
setUpEnvironment(true, false, javaClassesTempDirectory);
loadFile("notNullAssertions/doGenerateParamAssertions.kt");
generateFunction().invoke(null);
}
public void testDoNotGenerateParamAssertions() throws Exception {
setUpEnvironment(false, false);
setUpEnvironment(true, true);
loadFile("notNullAssertions/doNotGenerateParamAssertions.kt");
@@ -107,7 +107,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
public void testNoParamAssertionForPrivateMethod() throws Exception {
setUpEnvironment(false, true);
setUpEnvironment(true, false);
loadFile("notNullAssertions/noAssertionForPrivateMethod.kt");
@@ -115,7 +115,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
public void testArrayListGet() {
setUpEnvironment(true, true);
setUpEnvironment(false, false);
loadFile("notNullAssertions/arrayListGet.kt");
String text = generateToText();
@@ -126,7 +126,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
public void testJavaMultipleSubstitutions() {
File javaClassesTempDirectory = compileJava("notNullAssertions/javaMultipleSubstitutions.java");
setUpEnvironment(true, true, javaClassesTempDirectory);
setUpEnvironment(false, false, javaClassesTempDirectory);
loadFile("notNullAssertions/javaMultipleSubstitutions.kt");
String text = generateToText();
@@ -136,7 +136,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
public void testAssertionForNotNullTypeParam() {
setUpEnvironment(true, true);
setUpEnvironment(false, false);
loadFile("notNullAssertions/assertionForNotNullTypeParam.kt");
@@ -144,7 +144,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
public void testNoAssertionForNullableGenericMethod() {
setUpEnvironment(true, false);
setUpEnvironment(false, true);
loadFile("notNullAssertions/noAssertionForNullableGenericMethod.kt");
@@ -152,7 +152,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
public void testNoAssertionForNullableGenericMethodCall() {
setUpEnvironment(true, false);
setUpEnvironment(false, true);
loadFile("notNullAssertions/noAssertionForNullableGenericMethodCall.kt");