Added "optimize" flag to settings everywhere
This commit is contained in:
committed by
Alexander Udalov
parent
433c9cd4a5
commit
0e683b0b99
@@ -24,6 +24,7 @@ import org.jetbrains.jet.buildtools.core.Util;
|
||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||
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.util.Arrays;
|
||||
@@ -50,6 +51,7 @@ public class BytecodeCompilerTask extends Task {
|
||||
private Path compileClasspath;
|
||||
private boolean includeRuntime = true;
|
||||
private String inline;
|
||||
private String optimize;
|
||||
|
||||
public void setOutput(File output) {
|
||||
this.output = output;
|
||||
@@ -97,6 +99,10 @@ public class BytecodeCompilerTask extends Task {
|
||||
this.inline = inline;
|
||||
}
|
||||
|
||||
public void setOptimize(String optimize) {
|
||||
this.optimize = optimize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the classpath to be used for this compilation.
|
||||
*
|
||||
@@ -144,10 +150,15 @@ public class BytecodeCompilerTask extends Task {
|
||||
String[] externalAnnotationsPath = (this.externalAnnotations != null) ? this.externalAnnotations.list() : null;
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(inline)) {
|
||||
throw new CompileEnvironmentException(CompilerArgumentsUtil.getWrongInlineOptionErrorMessage(inline));
|
||||
throw new CompileEnvironmentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", inline));
|
||||
}
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(optimize)) {
|
||||
throw new CompileEnvironmentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", optimize));
|
||||
}
|
||||
|
||||
boolean enableInline = CompilerArgumentsUtil.optionToBooleanFlag(inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG);
|
||||
boolean enableOptimization = CompilerArgumentsUtil.optionToBooleanFlag(optimize, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG);
|
||||
|
||||
if (this.src != null) {
|
||||
|
||||
@@ -161,10 +172,16 @@ public class BytecodeCompilerTask extends Task {
|
||||
log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination));
|
||||
|
||||
if (this.output != null) {
|
||||
compiler.sourcesToDir(source, destination, stdlibPath, classpath, externalAnnotationsPath, enableInline);
|
||||
compiler.sourcesToDir(
|
||||
source, destination, stdlibPath, classpath, externalAnnotationsPath,
|
||||
enableInline, enableOptimization
|
||||
);
|
||||
}
|
||||
else {
|
||||
compiler.sourcesToJar(source, destination, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath, enableInline);
|
||||
compiler.sourcesToJar(
|
||||
source, destination, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath,
|
||||
enableInline, enableOptimization
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (this.module != null) {
|
||||
@@ -179,7 +196,10 @@ public class BytecodeCompilerTask extends Task {
|
||||
log(jarPath != null ? String.format("Compiling [%s] => [%s]", modulePath, jarPath) :
|
||||
String.format("Compiling [%s]", modulePath));
|
||||
|
||||
compiler.moduleToJar(modulePath, jarPath, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath, enableInline);
|
||||
compiler.moduleToJar(
|
||||
modulePath, jarPath, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath,
|
||||
enableInline, enableOptimization
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw new CompileEnvironmentException("\"src\" or \"module\" should be specified");
|
||||
|
||||
@@ -40,9 +40,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY;
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY;
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ENABLE_INLINE;
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.*;
|
||||
import static org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil.loadModuleDescriptions;
|
||||
|
||||
|
||||
@@ -65,6 +63,7 @@ public class BytecodeCompiler {
|
||||
* @param classpath compilation classpath, only used if not null and not empty
|
||||
* @param sourceRoots
|
||||
* @param enableInline
|
||||
* @param enableOptimization
|
||||
* @return compile environment instance
|
||||
*/
|
||||
private JetCoreEnvironment env(
|
||||
@@ -72,9 +71,12 @@ public class BytecodeCompiler {
|
||||
String[] classpath,
|
||||
String[] externalAnnotationsPath,
|
||||
String[] sourceRoots,
|
||||
boolean enableInline
|
||||
boolean enableInline,
|
||||
boolean enableOptimization
|
||||
) {
|
||||
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourceRoots, enableInline);
|
||||
CompilerConfiguration configuration = createConfiguration(
|
||||
stdlib, classpath, externalAnnotationsPath, sourceRoots, enableInline, enableOptimization
|
||||
);
|
||||
|
||||
return JetCoreEnvironment.createForProduction(Disposer.newDisposable(), configuration);
|
||||
}
|
||||
@@ -84,7 +86,8 @@ public class BytecodeCompiler {
|
||||
@Nullable String[] classpath,
|
||||
@Nullable String[] externalAnnotationsPath,
|
||||
@NotNull String[] sourceRoots,
|
||||
boolean enableInline
|
||||
boolean enableInline,
|
||||
boolean enableOptimization
|
||||
) {
|
||||
KotlinPaths paths = getKotlinPathsForAntTask();
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
@@ -123,6 +126,7 @@ public class BytecodeCompiler {
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||
|
||||
configuration.put(ENABLE_INLINE, enableInline);
|
||||
configuration.put(ENABLE_OPTIMIZATION, enableOptimization);
|
||||
|
||||
// lets register any compiler plugins
|
||||
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
|
||||
@@ -169,9 +173,10 @@ public class BytecodeCompiler {
|
||||
@Nullable String stdlib,
|
||||
@Nullable String[] classpath,
|
||||
@Nullable String[] externalAnnotationsPath,
|
||||
boolean enableInline) {
|
||||
boolean enableInline,
|
||||
boolean enableOptimization) {
|
||||
try {
|
||||
JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline);
|
||||
JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline, enableOptimization);
|
||||
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, null, new File(output), true);
|
||||
if (!success) {
|
||||
@@ -199,9 +204,10 @@ public class BytecodeCompiler {
|
||||
@Nullable String stdlib,
|
||||
@Nullable String[] classpath,
|
||||
@Nullable String[] externalAnnotationsPath,
|
||||
boolean enableInline) {
|
||||
boolean enableInline,
|
||||
boolean enableOptimization) {
|
||||
try {
|
||||
JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline);
|
||||
JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline, enableOptimization);
|
||||
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, new File(jar), null, includeRuntime);
|
||||
if (!success) {
|
||||
@@ -222,6 +228,7 @@ public class BytecodeCompiler {
|
||||
* @param stdlib "kotlin-runtime.jar" path
|
||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||
* @param enableInline
|
||||
* @param enableOptimization
|
||||
*/
|
||||
public void moduleToJar(
|
||||
@NotNull String module,
|
||||
@@ -229,7 +236,7 @@ public class BytecodeCompiler {
|
||||
boolean includeRuntime,
|
||||
@Nullable String stdlib,
|
||||
@Nullable String[] classpath,
|
||||
@Nullable String[] externalAnnotationsPath, boolean enableInline
|
||||
@Nullable String[] externalAnnotationsPath, boolean enableInline, boolean enableOptimization
|
||||
) {
|
||||
try {
|
||||
ModuleScriptData moduleScriptData =
|
||||
@@ -240,7 +247,7 @@ public class BytecodeCompiler {
|
||||
sourcesRoots.addAll(m.getSourceFiles());
|
||||
}
|
||||
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourcesRoots.toArray(new String[0]),
|
||||
enableInline);
|
||||
enableInline, enableOptimization);
|
||||
File directory = new File(module).getParentFile();
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime);
|
||||
if (!success) {
|
||||
|
||||
@@ -20,4 +20,5 @@ 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;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ 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.optimization.OptimizationClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
@@ -117,7 +118,9 @@ public class GenerationState {
|
||||
@NotNull List<JetFile> files
|
||||
) {
|
||||
this(project, builderFactory, Progress.DEAF, module, bindingContext, files, true, false, GenerateClassFilter.GENERATE_ALL,
|
||||
InlineCodegenUtil.DEFAULT_INLINE_FLAG, null, null, DiagnosticHolder.DO_NOTHING, null);
|
||||
InlineCodegenUtil.DEFAULT_INLINE_FLAG, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG,
|
||||
null, null, DiagnosticHolder.DO_NOTHING, null
|
||||
);
|
||||
}
|
||||
|
||||
public GenerationState(
|
||||
@@ -131,6 +134,7 @@ public class GenerationState {
|
||||
boolean generateNotNullParamAssertions,
|
||||
GenerateClassFilter generateClassFilter,
|
||||
boolean inlineEnabled,
|
||||
boolean optimizationEnabled,
|
||||
@Nullable Collection<FqName> packagesWithRemovedFiles,
|
||||
@Nullable String moduleId,
|
||||
@NotNull DiagnosticHolder diagnostics,
|
||||
@@ -152,8 +156,13 @@ public class GenerationState {
|
||||
this.typeMapper = new JetTypeMapperWithOutDirectory(this.bindingContext, classBuilderMode, outDirectory);
|
||||
|
||||
this.intrinsics = new IntrinsicMethods();
|
||||
|
||||
if (optimizationEnabled) {
|
||||
builderFactory = new OptimizationClassBuilderFactory(builderFactory);
|
||||
}
|
||||
|
||||
this.classFileFactory = new ClassFileFactory(this, new BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
new OptimizationClassBuilderFactory(builderFactory), this.bindingContext, diagnostics));
|
||||
builderFactory, this.bindingContext, diagnostics));
|
||||
|
||||
this.generateNotNullAssertions = generateNotNullAssertions;
|
||||
this.generateNotNullParamAssertions = generateNotNullParamAssertions;
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ public class CompilerArgumentsUtil {
|
||||
"false".equalsIgnoreCase(option);
|
||||
}
|
||||
|
||||
public static String getWrongInlineOptionErrorMessage(@Nullable String inline) {
|
||||
return "Wrong value for inline option: '" + inline + "'. Should be 'on'/'off' or 'true'/'false'";
|
||||
public static String getWrongCheckOptionErrorMessage(@Nullable String option, @Nullable String value) {
|
||||
return "Wrong value for " + option + " option: '" + value + "'. Should be 'on'/'off' or 'true'/'false'";
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -79,6 +79,10 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@ValueDescription("{on,off}")
|
||||
public String inline;
|
||||
|
||||
@Argument(value = "optimize", description = "Optimization mode (default is on)")
|
||||
@ValueDescription("{on,off}")
|
||||
public String optimize;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String executableScriptFileName() {
|
||||
|
||||
@@ -39,6 +39,9 @@ public class JVMConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<Boolean> ENABLE_INLINE =
|
||||
CompilerConfigurationKey.create("enable inline");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> ENABLE_OPTIMIZATION =
|
||||
CompilerConfigurationKey.create("enable optimization");
|
||||
|
||||
public static final CompilerConfigurationKey<File> INCREMENTAL_CACHE_BASE_DIR =
|
||||
CompilerConfigurationKey.create("incremental cache base dir");
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal;
|
||||
import org.jetbrains.jet.codegen.CompilationException;
|
||||
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
|
||||
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
@@ -116,6 +117,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions);
|
||||
configuration.put(JVMConfigurationKeys.ENABLE_INLINE,
|
||||
CompilerArgumentsUtil.optionToBooleanFlag(arguments.inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG));
|
||||
configuration.put(JVMConfigurationKeys.ENABLE_OPTIMIZATION,
|
||||
CompilerArgumentsUtil.optionToBooleanFlag(arguments.optimize, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG));
|
||||
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
@@ -209,7 +212,11 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
super.checkArguments(argument);
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(argument.inline)) {
|
||||
throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongInlineOptionErrorMessage(argument.inline));
|
||||
throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", argument.inline));
|
||||
}
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(argument.optimize)) {
|
||||
throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", argument.optimize));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
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.Progress;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
@@ -344,6 +345,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
|
||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_OPTIMIZATION, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG),
|
||||
packagesWithRemovedFiles,
|
||||
moduleId,
|
||||
diagnosticHolder,
|
||||
|
||||
@@ -7,7 +7,7 @@ ERR:
|
||||
|
||||
BUILD FAILED
|
||||
[TestData]/build.xml:5: org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException: Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false'
|
||||
at org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask.execute(BytecodeCompilerTask.java:147)
|
||||
at org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask.execute(BytecodeCompilerTask.java:153)
|
||||
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
|
||||
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
||||
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
||||
|
||||
@@ -297,6 +297,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
|
||||
/*not-null assertions*/false, false,
|
||||
/*generateClassFilter=*/stubGenerationStrategy.getGenerateClassFilter(),
|
||||
/*to generate inline flag on methods*/true,
|
||||
/*optimize*/true,
|
||||
null,
|
||||
null,
|
||||
forExtraDiagnostics,
|
||||
|
||||
@@ -15,6 +15,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline {on,off} Inlining mode (default is on)
|
||||
-optimize {on,off} Optimization mode (default is on)
|
||||
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
|
||||
@@ -15,6 +15,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline {on,off} Inlining mode (default is on)
|
||||
-optimize {on,off} Optimization mode (default is on)
|
||||
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
|
||||
@@ -15,6 +15,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline {on,off} Inlining mode (default is on)
|
||||
-optimize {on,off} Optimization mode (default is on)
|
||||
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
|
||||
@@ -16,6 +16,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline {on,off} Inlining mode (default is on)
|
||||
-optimize {on,off} Optimization mode (default is on)
|
||||
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
|
||||
@@ -16,6 +16,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline {on,off} Inlining mode (default is on)
|
||||
-optimize {on,off} Optimization mode (default is on)
|
||||
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
|
||||
@@ -29,6 +29,7 @@ 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;
|
||||
@@ -68,6 +69,7 @@ public class CodegenTestUtil {
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_OPTIMIZATION, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG),
|
||||
null,
|
||||
null,
|
||||
forExtraDiagnostics,
|
||||
|
||||
@@ -115,7 +115,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
exhaust.getModuleDescriptor(), exhaust.getBindingContext(),
|
||||
Collections.singletonList(jetFile), true, true,
|
||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||
enableInline.isSelected(), null, null,
|
||||
enableInline.isSelected(), enableOptimization.isEnabled(), null, null,
|
||||
DiagnosticHolder.DO_NOTHING, null);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
}
|
||||
@@ -181,6 +181,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
private final Project myProject;
|
||||
private final ToolWindow toolWindow;
|
||||
private final JCheckBox enableInline;
|
||||
private final JCheckBox enableOptimization;
|
||||
|
||||
public KotlinBytecodeToolWindow(Project project, ToolWindow toolWindow) {
|
||||
super(new BorderLayout());
|
||||
@@ -196,7 +197,9 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
|
||||
/*TODO: try to extract default parameter from compiler options*/
|
||||
enableInline = new JCheckBox("Enable inline");
|
||||
enableOptimization = new JCheckBox("Enable optimization");
|
||||
optionPanel.add(enableInline, BorderLayout.WEST);
|
||||
optionPanel.add(enableOptimization, BorderLayout.CENTER);
|
||||
|
||||
new InfinitePeriodicalTask(UPDATE_DELAY, Alarm.ThreadToUse.SWING_THREAD, this, new Computable<LongRunningReadTask>() {
|
||||
@Override
|
||||
|
||||
+6
-1
@@ -121,9 +121,14 @@ public open class KotlinCompile(): AbstractCompile() {
|
||||
args.noStdlib = true
|
||||
args.noJdkAnnotations = true
|
||||
args.inline = kotlinOptions.inline
|
||||
args.optimize = kotlinOptions.optimize
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(args.inline)) {
|
||||
throw GradleException(CompilerArgumentsUtil.getWrongInlineOptionErrorMessage(args.inline))
|
||||
throw GradleException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", args.inline))
|
||||
}
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(args.optimize)) {
|
||||
throw GradleException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", args.optimize))
|
||||
}
|
||||
|
||||
val messageCollector = GradleMessageCollector(getLogger())
|
||||
|
||||
+6
@@ -43,6 +43,12 @@ class BasicKotlinGradleIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
Test fun testOptimizationDisabled() {
|
||||
Project("optimizationDisabled", "1.6").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
Test fun testSimpleKDoc() {
|
||||
Project("kdocProject", "1.6").build("kdoc", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") {
|
||||
assertSuccessful()
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin-core:0.1-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin
|
||||
|
||||
apply plugin: KotlinPlugin
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
kotlin {
|
||||
srcDir 'src'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.guava:guava:12.0'
|
||||
testCompile 'org.testng:testng:6.8'
|
||||
testRuntime 'org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
test {
|
||||
useTestNG()
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.annotations = "externalAnnotations"
|
||||
kotlinOptions.optimize = false
|
||||
}
|
||||
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion="1.4"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<root>
|
||||
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
|
||||
<annotation name="org.jetbrains.annotations.NotNull" />
|
||||
</item>
|
||||
<item name='com.google.common.base.Joiner com.google.common.base.Joiner.MapJoiner withKeyValueSeparator(java.lang.String)'>
|
||||
<annotation name="org.jetbrains.annotations.NotNull" />
|
||||
</item>
|
||||
<item name='com.google.common.base.Joiner com.google.common.base.Joiner skipNulls()'>
|
||||
<annotation name="org.jetbrains.annotations.NotNull" />
|
||||
</item>
|
||||
</root>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package demo
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class KotlinGreetingJoiner() {
|
||||
|
||||
val names = ArrayList<String?>()
|
||||
|
||||
fun addName(name : String?): Unit{
|
||||
names.add(name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-optimizationDisabled</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>process-test-sources</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<optimize>false</optimize>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.jetbrains
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
System.out?.println(getGreeting())
|
||||
}
|
||||
|
||||
fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
public class HelloWorldJavaTest {
|
||||
|
||||
@Test
|
||||
public void greeting() {
|
||||
assertEquals("Hello, World!", org.jetbrains.JetbrainsPackage.getGreeting());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import java.io.*;
|
||||
|
||||
File file = new File(basedir, "target/test-optimizationDisabled-0.1-SNAPSHOT.jar");
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new FileNotFoundException("Could not find generated JAR: " + file);
|
||||
}
|
||||
+22
-1
@@ -35,6 +35,7 @@ import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
|
||||
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -158,6 +159,13 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
*/
|
||||
public String inline;
|
||||
|
||||
/**
|
||||
* Switch method optimization on/off: possible values are "on" and "off".
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
public String optimize;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("Kotlin Compiler version " + KotlinVersion.VERSION);
|
||||
@@ -314,10 +322,23 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
arguments.annotations = getFullAnnotationsPath(log, annotationPaths);
|
||||
log.info("Using kotlin annotations from " + arguments.annotations);
|
||||
arguments.inline = inline;
|
||||
arguments.optimize = optimize;
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(arguments.inline)) {
|
||||
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongInlineOptionErrorMessage(arguments.inline));
|
||||
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", arguments.inline));
|
||||
}
|
||||
|
||||
if (!CompilerArgumentsUtil.checkOption(arguments.optimize)) {
|
||||
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", arguments.optimize));
|
||||
}
|
||||
|
||||
log.info("Method inlining is " + CompilerArgumentsUtil.optionToBooleanFlag(arguments.inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG));
|
||||
log.info(
|
||||
"Optimization mode is " + CompilerArgumentsUtil.optionToBooleanFlag(
|
||||
arguments.optimize,
|
||||
OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected String getFullAnnotationsPath(Log log, List<String> annotations) {
|
||||
|
||||
Reference in New Issue
Block a user