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:
@@ -23,8 +23,6 @@ import org.jetbrains.jet.buildtools.core.BytecodeCompiler;
|
|||||||
import org.jetbrains.jet.buildtools.core.Util;
|
import org.jetbrains.jet.buildtools.core.Util;
|
||||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||||
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
|
|
||||||
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -143,7 +141,6 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
|
|
||||||
BytecodeCompiler compiler = new BytecodeCompiler();
|
BytecodeCompiler compiler = new BytecodeCompiler();
|
||||||
String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null);
|
String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null);
|
||||||
String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null);
|
String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null);
|
||||||
@@ -157,8 +154,8 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
throw new CompileEnvironmentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", optimize));
|
throw new CompileEnvironmentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", optimize));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean enableInline = CompilerArgumentsUtil.optionToBooleanFlag(inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG);
|
boolean enableInline = CompilerArgumentsUtil.optionToBooleanFlag(inline, true);
|
||||||
boolean enableOptimization = CompilerArgumentsUtil.optionToBooleanFlag(optimize, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG);
|
boolean enableOptimization = CompilerArgumentsUtil.optionToBooleanFlag(optimize, true);
|
||||||
|
|
||||||
if (this.src != null) {
|
if (this.src != null) {
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ import org.jetbrains.jet.cli.common.CompilerPlugin;
|
|||||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream;
|
import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream;
|
||||||
import org.jetbrains.jet.cli.common.modules.ModuleScriptData;
|
import org.jetbrains.jet.cli.common.modules.ModuleScriptData;
|
||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.*;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||||
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
|
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.utils.KotlinPaths;
|
import org.jetbrains.jet.utils.KotlinPaths;
|
||||||
@@ -125,8 +127,8 @@ public class BytecodeCompiler {
|
|||||||
}
|
}
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||||
|
|
||||||
configuration.put(ENABLE_INLINE, enableInline);
|
configuration.put(DISABLE_INLINE, !enableInline);
|
||||||
configuration.put(ENABLE_OPTIMIZATION, enableOptimization);
|
configuration.put(DISABLE_OPTIMIZATION, !enableOptimization);
|
||||||
|
|
||||||
// lets register any compiler plugins
|
// lets register any compiler plugins
|
||||||
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
|
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
|
||||||
|
|||||||
@@ -535,7 +535,7 @@ public class AsmUtil {
|
|||||||
@NotNull FunctionDescriptor descriptor,
|
@NotNull FunctionDescriptor descriptor,
|
||||||
@NotNull FrameMap frameMap
|
@NotNull FrameMap frameMap
|
||||||
) {
|
) {
|
||||||
if (!state.isGenerateNotNullParamAssertions()) return;
|
if (!state.isParamAssertionsEnabled()) return;
|
||||||
|
|
||||||
// Private method is not accessible from other classes, no assertions needed
|
// Private method is not accessible from other classes, no assertions needed
|
||||||
if (getVisibilityAccessFlag(descriptor) == ACC_PRIVATE) return;
|
if (getVisibilityAccessFlag(descriptor) == ACC_PRIVATE) return;
|
||||||
@@ -580,7 +580,7 @@ public class AsmUtil {
|
|||||||
@NotNull CallableDescriptor descriptor,
|
@NotNull CallableDescriptor descriptor,
|
||||||
@NotNull String assertMethodToCall
|
@NotNull String assertMethodToCall
|
||||||
) {
|
) {
|
||||||
if (!state.isGenerateNotNullAssertions()) return;
|
if (!state.isCallAssertionsEnabled()) return;
|
||||||
|
|
||||||
if (!isDeclaredInJava(descriptor)) return;
|
if (!isDeclaredInJava(descriptor)) return;
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
|
|||||||
public class InlineCodegenUtil {
|
public class InlineCodegenUtil {
|
||||||
public static final int API = Opcodes.ASM5;
|
public static final int API = Opcodes.ASM5;
|
||||||
public static final String INVOKE = "invoke";
|
public static final String INVOKE = "invoke";
|
||||||
public static final boolean DEFAULT_INLINE_FLAG = true;
|
|
||||||
|
|
||||||
public static final String CAPTURED_FIELD_PREFIX = "$";
|
public static final String CAPTURED_FIELD_PREFIX = "$";
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -23,6 +23,7 @@ import org.jetbrains.jet.codegen.optimization.boxing.RedundantBoxingMethodTransf
|
|||||||
import org.jetbrains.jet.codegen.optimization.boxing.RedundantNullCheckMethodTransformer;
|
import org.jetbrains.jet.codegen.optimization.boxing.RedundantNullCheckMethodTransformer;
|
||||||
import org.jetbrains.jet.codegen.optimization.transformer.MethodTransformer;
|
import org.jetbrains.jet.codegen.optimization.transformer.MethodTransformer;
|
||||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.LocalVariableNode;
|
import org.jetbrains.org.objectweb.asm.tree.LocalVariableNode;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
|
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
|
||||||
import org.jetbrains.org.objectweb.asm.util.Textifier;
|
import org.jetbrains.org.objectweb.asm.util.Textifier;
|
||||||
@@ -48,7 +49,7 @@ public class OptimizationMethodVisitor extends MethodVisitor {
|
|||||||
@Nullable String signature,
|
@Nullable String signature,
|
||||||
@Nullable String[] exceptions
|
@Nullable String[] exceptions
|
||||||
) {
|
) {
|
||||||
super(OptimizationUtils.API);
|
super(Opcodes.ASM5);
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.methodNode = new MethodNode(access, name, desc, signature, exceptions);
|
this.methodNode = new MethodNode(access, name, desc, signature, exceptions);
|
||||||
this.methodNode.localVariables = new ArrayList<LocalVariableNode>(5);
|
this.methodNode.localVariables = new ArrayList<LocalVariableNode>(5);
|
||||||
@@ -69,7 +70,7 @@ public class OptimizationMethodVisitor extends MethodVisitor {
|
|||||||
MAIN_METHOD_TRANSFORMER.transform("fake", methodNode);
|
MAIN_METHOD_TRANSFORMER.transform("fake", methodNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
methodNode.accept(new EndIgnoringMethodVisitorDecorator(OptimizationUtils.API, delegate));
|
methodNode.accept(new EndIgnoringMethodVisitorDecorator(Opcodes.ASM5, delegate));
|
||||||
|
|
||||||
|
|
||||||
// In case of empty instructions list MethodNode.accept doesn't call visitLocalVariables of delegate
|
// In case of empty instructions list MethodNode.accept doesn't call visitLocalVariables of delegate
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.codegen.optimization;
|
|
||||||
|
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
|
||||||
|
|
||||||
public class OptimizationUtils {
|
|
||||||
public final static int API = Opcodes.ASM5;
|
|
||||||
public static final boolean DEFAULT_OPTIMIZATION_FLAG = true;
|
|
||||||
}
|
|
||||||
+1
-2
@@ -20,7 +20,6 @@ import com.google.common.base.Predicate;
|
|||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
|
|
||||||
import org.jetbrains.jet.codegen.optimization.transformer.MethodTransformer;
|
import org.jetbrains.jet.codegen.optimization.transformer.MethodTransformer;
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
@@ -279,7 +278,7 @@ public class RedundantBoxingMethodTransformer extends MethodTransformer {
|
|||||||
@NotNull Pair<AbstractInsnNode, Type> castWithType
|
@NotNull Pair<AbstractInsnNode, Type> castWithType
|
||||||
) {
|
) {
|
||||||
AbstractInsnNode castInsn = castWithType.getFirst();
|
AbstractInsnNode castInsn = castWithType.getFirst();
|
||||||
MethodNode castInsnsListener = new MethodNode(OptimizationUtils.API);
|
MethodNode castInsnsListener = new MethodNode(Opcodes.ASM5);
|
||||||
new InstructionAdapter(castInsnsListener).cast(value.getPrimitiveType(), castWithType.getSecond());
|
new InstructionAdapter(castInsnsListener).cast(value.getPrimitiveType(), castWithType.getSecond());
|
||||||
|
|
||||||
for (AbstractInsnNode insn : castInsnsListener.instructions.toArray()) {
|
for (AbstractInsnNode insn : castInsnsListener.instructions.toArray()) {
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.*;
|
import org.jetbrains.jet.codegen.*;
|
||||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||||
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
|
|
||||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
|
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
|
||||||
import org.jetbrains.jet.codegen.optimization.OptimizationClassBuilderFactory;
|
import org.jetbrains.jet.codegen.optimization.OptimizationClassBuilderFactory;
|
||||||
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
|
|
||||||
import org.jetbrains.jet.codegen.when.MappingsClassesForWhenByEnum;
|
import org.jetbrains.jet.codegen.when.MappingsClassesForWhenByEnum;
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||||
@@ -89,13 +87,13 @@ public class GenerationState {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final JetTypeMapper typeMapper;
|
private final JetTypeMapper typeMapper;
|
||||||
|
|
||||||
private final boolean generateNotNullAssertions;
|
private final boolean disableCallAssertions;
|
||||||
|
|
||||||
private final boolean generateNotNullParamAssertions;
|
private final boolean disableParamAssertions;
|
||||||
|
|
||||||
private final GenerateClassFilter generateClassFilter;
|
private final GenerateClassFilter generateClassFilter;
|
||||||
|
|
||||||
private final boolean inlineEnabled;
|
private final boolean disableInline;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<ScriptDescriptor> earlierScriptsForReplInterpreter;
|
private List<ScriptDescriptor> earlierScriptsForReplInterpreter;
|
||||||
@@ -121,10 +119,8 @@ public class GenerationState {
|
|||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull List<JetFile> files
|
@NotNull List<JetFile> files
|
||||||
) {
|
) {
|
||||||
this(project, builderFactory, Progress.DEAF, module, bindingContext, files, true, false, GenerateClassFilter.GENERATE_ALL,
|
this(project, builderFactory, Progress.DEAF, module, bindingContext, files, true, true, GenerateClassFilter.GENERATE_ALL,
|
||||||
InlineCodegenUtil.DEFAULT_INLINE_FLAG, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG,
|
false, false, null, null, DiagnosticHolder.DO_NOTHING, null);
|
||||||
null, null, DiagnosticHolder.DO_NOTHING, null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenerationState(
|
public GenerationState(
|
||||||
@@ -134,11 +130,11 @@ public class GenerationState {
|
|||||||
@NotNull ModuleDescriptor module,
|
@NotNull ModuleDescriptor module,
|
||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull List<JetFile> files,
|
@NotNull List<JetFile> files,
|
||||||
boolean generateNotNullAssertions,
|
boolean disableCallAssertions,
|
||||||
boolean generateNotNullParamAssertions,
|
boolean disableParamAssertions,
|
||||||
GenerateClassFilter generateClassFilter,
|
GenerateClassFilter generateClassFilter,
|
||||||
boolean inlineEnabled,
|
boolean disableInline,
|
||||||
boolean optimizationEnabled,
|
boolean disableOptimization,
|
||||||
@Nullable Collection<FqName> packagesWithRemovedFiles,
|
@Nullable Collection<FqName> packagesWithRemovedFiles,
|
||||||
@Nullable String moduleId,
|
@Nullable String moduleId,
|
||||||
@NotNull DiagnosticHolder diagnostics,
|
@NotNull DiagnosticHolder diagnostics,
|
||||||
@@ -151,7 +147,7 @@ public class GenerationState {
|
|||||||
this.moduleId = moduleId;
|
this.moduleId = moduleId;
|
||||||
this.packagesWithRemovedFiles = packagesWithRemovedFiles == null ? Collections.<FqName>emptySet() : packagesWithRemovedFiles;
|
this.packagesWithRemovedFiles = packagesWithRemovedFiles == null ? Collections.<FqName>emptySet() : packagesWithRemovedFiles;
|
||||||
this.classBuilderMode = builderFactory.getClassBuilderMode();
|
this.classBuilderMode = builderFactory.getClassBuilderMode();
|
||||||
this.inlineEnabled = inlineEnabled;
|
this.disableInline = disableInline;
|
||||||
|
|
||||||
this.bindingTrace = new DelegatingBindingTrace(bindingContext, "trace in GenerationState");
|
this.bindingTrace = new DelegatingBindingTrace(bindingContext, "trace in GenerationState");
|
||||||
this.bindingContext = bindingTrace.getBindingContext();
|
this.bindingContext = bindingTrace.getBindingContext();
|
||||||
@@ -161,15 +157,15 @@ public class GenerationState {
|
|||||||
|
|
||||||
this.intrinsics = new IntrinsicMethods();
|
this.intrinsics = new IntrinsicMethods();
|
||||||
|
|
||||||
if (optimizationEnabled) {
|
if (!disableOptimization) {
|
||||||
builderFactory = new OptimizationClassBuilderFactory(builderFactory);
|
builderFactory = new OptimizationClassBuilderFactory(builderFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.classFileFactory = new ClassFileFactory(this, new BuilderFactoryForDuplicateSignatureDiagnostics(
|
this.classFileFactory = new ClassFileFactory(this, new BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||||
builderFactory, this.bindingContext, diagnostics));
|
builderFactory, this.bindingContext, diagnostics));
|
||||||
|
|
||||||
this.generateNotNullAssertions = generateNotNullAssertions;
|
this.disableCallAssertions = disableCallAssertions;
|
||||||
this.generateNotNullParamAssertions = generateNotNullParamAssertions;
|
this.disableParamAssertions = disableParamAssertions;
|
||||||
this.generateClassFilter = generateClassFilter;
|
this.generateClassFilter = generateClassFilter;
|
||||||
|
|
||||||
ReflectionTypes reflectionTypes = new ReflectionTypes(module);
|
ReflectionTypes reflectionTypes = new ReflectionTypes(module);
|
||||||
@@ -231,12 +227,12 @@ public class GenerationState {
|
|||||||
return mappingsClassesForWhenByEnum;
|
return mappingsClassesForWhenByEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGenerateNotNullAssertions() {
|
public boolean isCallAssertionsEnabled() {
|
||||||
return generateNotNullAssertions;
|
return !disableCallAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGenerateNotNullParamAssertions() {
|
public boolean isParamAssertionsEnabled() {
|
||||||
return generateNotNullParamAssertions;
|
return !disableParamAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -250,7 +246,7 @@ public class GenerationState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInlineEnabled() {
|
public boolean isInlineEnabled() {
|
||||||
return inlineEnabled;
|
return !disableInline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beforeCompile() {
|
public void beforeCompile() {
|
||||||
|
|||||||
@@ -31,16 +31,14 @@ public class JVMConfigurationKeys {
|
|||||||
|
|
||||||
public static final CompilerConfigurationKey<List<AnalyzerScriptParameter>> SCRIPT_PARAMETERS = CompilerConfigurationKey.create("script");
|
public static final CompilerConfigurationKey<List<AnalyzerScriptParameter>> SCRIPT_PARAMETERS = CompilerConfigurationKey.create("script");
|
||||||
|
|
||||||
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_ASSERTIONS =
|
public static final CompilerConfigurationKey<Boolean> DISABLE_CALL_ASSERTIONS =
|
||||||
CompilerConfigurationKey.create("generate not-null assertions");
|
CompilerConfigurationKey.create("disable not-null call assertions");
|
||||||
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_PARAMETER_ASSERTIONS =
|
public static final CompilerConfigurationKey<Boolean> DISABLE_PARAM_ASSERTIONS =
|
||||||
CompilerConfigurationKey.create("generate not-null parameter assertions");
|
CompilerConfigurationKey.create("disable not-null parameter assertions");
|
||||||
|
public static final CompilerConfigurationKey<Boolean> DISABLE_INLINE =
|
||||||
public static final CompilerConfigurationKey<Boolean> ENABLE_INLINE =
|
CompilerConfigurationKey.create("disable inline");
|
||||||
CompilerConfigurationKey.create("enable inline");
|
public static final CompilerConfigurationKey<Boolean> DISABLE_OPTIMIZATION =
|
||||||
|
CompilerConfigurationKey.create("disable optimization");
|
||||||
public static final CompilerConfigurationKey<Boolean> ENABLE_OPTIMIZATION =
|
|
||||||
CompilerConfigurationKey.create("enable optimization");
|
|
||||||
|
|
||||||
public static final CompilerConfigurationKey<File> INCREMENTAL_CACHE_BASE_DIR =
|
public static final CompilerConfigurationKey<File> INCREMENTAL_CACHE_BASE_DIR =
|
||||||
CompilerConfigurationKey.create("incremental cache base dir");
|
CompilerConfigurationKey.create("incremental cache base dir");
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
? CommandLineScriptUtils.scriptParameters()
|
? CommandLineScriptUtils.scriptParameters()
|
||||||
: Collections.<AnalyzerScriptParameter>emptyList());
|
: Collections.<AnalyzerScriptParameter>emptyList());
|
||||||
|
|
||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, !arguments.noCallAssertions);
|
configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, arguments.noCallAssertions);
|
||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, !arguments.noParamAssertions);
|
configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, arguments.noParamAssertions);
|
||||||
configuration.put(JVMConfigurationKeys.ENABLE_INLINE, !arguments.noInline);
|
configuration.put(JVMConfigurationKeys.DISABLE_INLINE, arguments.noInline);
|
||||||
configuration.put(JVMConfigurationKeys.ENABLE_OPTIMIZATION, !arguments.noOptimize);
|
configuration.put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize);
|
||||||
|
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -39,8 +39,6 @@ import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
|||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
import org.jetbrains.jet.codegen.*;
|
import org.jetbrains.jet.codegen.*;
|
||||||
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.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.Progress;
|
import org.jetbrains.jet.codegen.state.Progress;
|
||||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||||
@@ -369,15 +367,16 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
exhaust.getModuleDescriptor(),
|
exhaust.getModuleDescriptor(),
|
||||||
exhaust.getBindingContext(),
|
exhaust.getBindingContext(),
|
||||||
sourceFiles,
|
sourceFiles,
|
||||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
|
configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false),
|
||||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
|
configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false),
|
||||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
|
configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false),
|
||||||
configuration.get(JVMConfigurationKeys.ENABLE_OPTIMIZATION, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG),
|
configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false),
|
||||||
packagesWithRemovedFiles,
|
packagesWithRemovedFiles,
|
||||||
moduleId,
|
moduleId,
|
||||||
diagnosticHolder,
|
diagnosticHolder,
|
||||||
outputDirectory);
|
outputDirectory
|
||||||
|
);
|
||||||
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
AnalyzerWithCompilerReport.reportDiagnostics(
|
AnalyzerWithCompilerReport.reportDiagnostics(
|
||||||
new FilteredJvmDiagnostics(
|
new FilteredJvmDiagnostics(
|
||||||
|
|||||||
+5
-4
@@ -294,14 +294,15 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
|
|||||||
context.getModule(),
|
context.getModule(),
|
||||||
context.getBindingContext(),
|
context.getBindingContext(),
|
||||||
Lists.newArrayList(files),
|
Lists.newArrayList(files),
|
||||||
/*not-null assertions*/false, false,
|
/*disable not-null assertions*/false, false,
|
||||||
/*generateClassFilter=*/stubGenerationStrategy.getGenerateClassFilter(),
|
/*generateClassFilter=*/stubGenerationStrategy.getGenerateClassFilter(),
|
||||||
/*to generate inline flag on methods*/true,
|
/*disableInline=*/false,
|
||||||
/*optimize*/true,
|
/*disableOptimization=*/false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
forExtraDiagnostics,
|
forExtraDiagnostics,
|
||||||
null);
|
null
|
||||||
|
);
|
||||||
KotlinCodegenFacade.prepareForCompilation(state);
|
KotlinCodegenFacade.prepareForCompilation(state);
|
||||||
|
|
||||||
bindingContext = state.getBindingContext();
|
bindingContext = state.getBindingContext();
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
|||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
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.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.Progress;
|
import org.jetbrains.jet.codegen.state.Progress;
|
||||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
@@ -47,7 +45,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class CodegenTestUtil {
|
public class CodegenTestUtil {
|
||||||
private CodegenTestUtil() {}
|
private CodegenTestUtil() {}
|
||||||
@@ -57,7 +55,8 @@ public class CodegenTestUtil {
|
|||||||
AnalyzeExhaust analyzeExhaust = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
AnalyzeExhaust analyzeExhaust = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||||
environment.getProject(),
|
environment.getProject(),
|
||||||
files.getPsiFiles(),
|
files.getPsiFiles(),
|
||||||
Predicates.<PsiFile>alwaysTrue());
|
Predicates.<PsiFile>alwaysTrue()
|
||||||
|
);
|
||||||
analyzeExhaust.throwIfError();
|
analyzeExhaust.throwIfError();
|
||||||
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||||
CompilerConfiguration configuration = environment.getConfiguration();
|
CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
@@ -65,15 +64,16 @@ public class CodegenTestUtil {
|
|||||||
GenerationState state = new GenerationState(
|
GenerationState state = new GenerationState(
|
||||||
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF,
|
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF,
|
||||||
analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(), files.getPsiFiles(),
|
analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(), files.getPsiFiles(),
|
||||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false),
|
||||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false),
|
||||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
|
configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false),
|
||||||
configuration.get(JVMConfigurationKeys.ENABLE_OPTIMIZATION, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG),
|
configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
forExtraDiagnostics,
|
forExtraDiagnostics,
|
||||||
null);
|
null
|
||||||
|
);
|
||||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
|
|
||||||
// For JVM-specific errors
|
// For JVM-specific errors
|
||||||
|
|||||||
@@ -41,35 +41,35 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpEnvironment(boolean generateAssertions, boolean generateParamAssertions, File... extraClassPath) {
|
private void setUpEnvironment(boolean disableCallAssertions, boolean disableParamAssertions, File... extraClassPath) {
|
||||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath);
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath);
|
||||||
|
|
||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, generateAssertions);
|
configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, disableCallAssertions);
|
||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, generateParamAssertions);
|
configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, disableParamAssertions);
|
||||||
|
|
||||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
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");
|
File javaClassesTempDirectory = compileJava("notNullAssertions/A.java");
|
||||||
|
|
||||||
setUpEnvironment(generateAssertions, false, javaClassesTempDirectory);
|
setUpEnvironment(disableCallAssertions, true, javaClassesTempDirectory);
|
||||||
|
|
||||||
loadFile("notNullAssertions/AssertionChecker.kt");
|
loadFile("notNullAssertions/AssertionChecker.kt");
|
||||||
generateFunction("checkAssertions").invoke(null, generateAssertions);
|
generateFunction("checkAssertions").invoke(null, !disableCallAssertions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGenerateAssertions() throws Exception {
|
public void testGenerateAssertions() throws Exception {
|
||||||
doTestGenerateAssertions(true);
|
doTestCallAssertions(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDoNotGenerateAssertions() throws Exception {
|
public void testDoNotGenerateAssertions() throws Exception {
|
||||||
doTestGenerateAssertions(false);
|
doTestCallAssertions(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoAssertionsForKotlinFromSource() throws Exception {
|
public void testNoAssertionsForKotlinFromSource() throws Exception {
|
||||||
setUpEnvironment(true, false);
|
setUpEnvironment(false, true);
|
||||||
|
|
||||||
loadFiles("notNullAssertions/noAssertionsForKotlin.kt", "notNullAssertions/noAssertionsForKotlinMain.kt");
|
loadFiles("notNullAssertions/noAssertionsForKotlin.kt", "notNullAssertions/noAssertionsForKotlinMain.kt");
|
||||||
|
|
||||||
@@ -77,13 +77,13 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNoAssertionsForKotlinFromBinary() throws Exception {
|
public void testNoAssertionsForKotlinFromBinary() throws Exception {
|
||||||
setUpEnvironment(true, false);
|
setUpEnvironment(false, true);
|
||||||
loadFile("notNullAssertions/noAssertionsForKotlin.kt");
|
loadFile("notNullAssertions/noAssertionsForKotlin.kt");
|
||||||
OutputFileCollection outputFiles = generateClassesInFile();
|
OutputFileCollection outputFiles = generateClassesInFile();
|
||||||
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
|
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
|
||||||
OutputUtilsPackage.writeAllTo(outputFiles, compiledDirectory);
|
OutputUtilsPackage.writeAllTo(outputFiles, compiledDirectory);
|
||||||
|
|
||||||
setUpEnvironment(true, false, compiledDirectory);
|
setUpEnvironment(false, true, compiledDirectory);
|
||||||
loadFile("notNullAssertions/noAssertionsForKotlinMain.kt");
|
loadFile("notNullAssertions/noAssertionsForKotlinMain.kt");
|
||||||
|
|
||||||
assertNoIntrinsicsMethodIsCalled(PackageClassUtils.getPackageClassName(FqName.ROOT));
|
assertNoIntrinsicsMethodIsCalled(PackageClassUtils.getPackageClassName(FqName.ROOT));
|
||||||
@@ -92,14 +92,14 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
public void testGenerateParamAssertions() throws Exception {
|
public void testGenerateParamAssertions() throws Exception {
|
||||||
File javaClassesTempDirectory = compileJava("notNullAssertions/doGenerateParamAssertions.java");
|
File javaClassesTempDirectory = compileJava("notNullAssertions/doGenerateParamAssertions.java");
|
||||||
|
|
||||||
setUpEnvironment(false, true, javaClassesTempDirectory);
|
setUpEnvironment(true, false, javaClassesTempDirectory);
|
||||||
|
|
||||||
loadFile("notNullAssertions/doGenerateParamAssertions.kt");
|
loadFile("notNullAssertions/doGenerateParamAssertions.kt");
|
||||||
generateFunction().invoke(null);
|
generateFunction().invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDoNotGenerateParamAssertions() throws Exception {
|
public void testDoNotGenerateParamAssertions() throws Exception {
|
||||||
setUpEnvironment(false, false);
|
setUpEnvironment(true, true);
|
||||||
|
|
||||||
loadFile("notNullAssertions/doNotGenerateParamAssertions.kt");
|
loadFile("notNullAssertions/doNotGenerateParamAssertions.kt");
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNoParamAssertionForPrivateMethod() throws Exception {
|
public void testNoParamAssertionForPrivateMethod() throws Exception {
|
||||||
setUpEnvironment(false, true);
|
setUpEnvironment(true, false);
|
||||||
|
|
||||||
loadFile("notNullAssertions/noAssertionForPrivateMethod.kt");
|
loadFile("notNullAssertions/noAssertionForPrivateMethod.kt");
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayListGet() {
|
public void testArrayListGet() {
|
||||||
setUpEnvironment(true, true);
|
setUpEnvironment(false, false);
|
||||||
|
|
||||||
loadFile("notNullAssertions/arrayListGet.kt");
|
loadFile("notNullAssertions/arrayListGet.kt");
|
||||||
String text = generateToText();
|
String text = generateToText();
|
||||||
@@ -126,7 +126,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void testJavaMultipleSubstitutions() {
|
public void testJavaMultipleSubstitutions() {
|
||||||
File javaClassesTempDirectory = compileJava("notNullAssertions/javaMultipleSubstitutions.java");
|
File javaClassesTempDirectory = compileJava("notNullAssertions/javaMultipleSubstitutions.java");
|
||||||
setUpEnvironment(true, true, javaClassesTempDirectory);
|
setUpEnvironment(false, false, javaClassesTempDirectory);
|
||||||
|
|
||||||
loadFile("notNullAssertions/javaMultipleSubstitutions.kt");
|
loadFile("notNullAssertions/javaMultipleSubstitutions.kt");
|
||||||
String text = generateToText();
|
String text = generateToText();
|
||||||
@@ -136,7 +136,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAssertionForNotNullTypeParam() {
|
public void testAssertionForNotNullTypeParam() {
|
||||||
setUpEnvironment(true, true);
|
setUpEnvironment(false, false);
|
||||||
|
|
||||||
loadFile("notNullAssertions/assertionForNotNullTypeParam.kt");
|
loadFile("notNullAssertions/assertionForNotNullTypeParam.kt");
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNoAssertionForNullableGenericMethod() {
|
public void testNoAssertionForNullableGenericMethod() {
|
||||||
setUpEnvironment(true, false);
|
setUpEnvironment(false, true);
|
||||||
|
|
||||||
loadFile("notNullAssertions/noAssertionForNullableGenericMethod.kt");
|
loadFile("notNullAssertions/noAssertionForNullableGenericMethod.kt");
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNoAssertionForNullableGenericMethodCall() {
|
public void testNoAssertionForNullableGenericMethodCall() {
|
||||||
setUpEnvironment(true, false);
|
setUpEnvironment(false, true);
|
||||||
|
|
||||||
loadFile("notNullAssertions/noAssertionForNullableGenericMethodCall.kt");
|
loadFile("notNullAssertions/noAssertionForNullableGenericMethodCall.kt");
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
|||||||
exhaust.getModuleDescriptor(), exhaust.getBindingContext(),
|
exhaust.getModuleDescriptor(), exhaust.getBindingContext(),
|
||||||
Collections.singletonList(jetFile), true, true,
|
Collections.singletonList(jetFile), true, true,
|
||||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||||
enableInline.isSelected(), enableOptimization.isSelected(), null, null,
|
!enableInline.isSelected(), !enableOptimization.isSelected(), null, null,
|
||||||
DiagnosticHolder.DO_NOTHING, null);
|
DiagnosticHolder.DO_NOTHING, null);
|
||||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user