Compiler inline on/off flag

This commit is contained in:
Mikhael Bogdanov
2013-11-22 17:12:17 +04:00
parent 4079735bf2
commit 8533fd64ff
21 changed files with 167 additions and 12 deletions
@@ -70,11 +70,13 @@ public class GenerationState {
private final boolean generateDeclaredClasses;
private final boolean inlineEnabled;
@Nullable
private List<ScriptDescriptor> earlierScriptsForReplInterpreter;
public GenerationState(Project project, ClassBuilderFactory builderFactory, BindingContext bindingContext, List<JetFile> files) {
this(project, builderFactory, Progress.DEAF, bindingContext, files, true, false, true);
public GenerationState(Project project, ClassBuilderFactory builderFactory, BindingContext bindingContext, List<JetFile> files, boolean inlineEnabled) {
this(project, builderFactory, Progress.DEAF, bindingContext, files, true, false, true, inlineEnabled);
}
public GenerationState(
@@ -85,12 +87,14 @@ public class GenerationState {
@NotNull List<JetFile> files,
boolean generateNotNullAssertions,
boolean generateNotNullParamAssertions,
boolean generateDeclaredClasses
boolean generateDeclaredClasses,
boolean inlineEnabled
) {
this.project = project;
this.progress = progress;
this.files = files;
this.classBuilderMode = builderFactory.getClassBuilderMode();
this.inlineEnabled = inlineEnabled;
bindingTrace = new DelegatingBindingTrace(bindingContext, "trace in GenerationState");
this.bindingContext = bindingTrace.getBindingContext();
@@ -169,6 +173,10 @@ public class GenerationState {
return generateDeclaredClasses;
}
public boolean isInlineEnabled() {
return inlineEnabled;
}
public void beforeCompile() {
markUsed();
@@ -65,4 +65,7 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
public String kotlinHome;
@Argument(value = "inline", description = "Inlining mode: on/off (default is off)")
public String enableInline;
}
@@ -63,6 +63,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
try {
arguments.freeArgs = Args.parse(arguments, args);
checkArguments(arguments);
return true;
}
catch (IllegalArgumentException e) {
@@ -76,6 +77,10 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
return false;
}
protected void checkArguments(@NotNull A argument) {
}
/**
* Allow derived classes to add additional command line arguments
*/
@@ -35,4 +35,7 @@ public class JVMConfigurationKeys {
CompilerConfigurationKey.create("generate not-null assertions");
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_PARAMETER_ASSERTIONS =
CompilerConfigurationKey.create("generate not-null parameter assertions");
public static final CompilerConfigurationKey<Boolean> ENABLE_INLINE =
CompilerConfigurationKey.create("enable inline");
}
@@ -107,6 +107,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions);
configuration.put(JVMConfigurationKeys.ENABLE_INLINE, "on".equalsIgnoreCase(arguments.enableInline));
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
@@ -190,4 +191,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
}
return annotationsPath;
}
@Override
protected void checkArguments(@NotNull K2JVMCompilerArguments argument) {
super.checkArguments(argument);
String inline = argument.enableInline;
if (inline != null) {
if (!"on".equalsIgnoreCase(inline) && !"off".equalsIgnoreCase(inline)) {
throw new IllegalArgumentException("Wrong value for inline option: '" + inline + "'. Should be 'on' or 'off'");
}
}
}
}
@@ -47,6 +47,7 @@ import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.plugin.JetMainDetector;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -293,7 +294,8 @@ public class KotlinToJVMBytecodeCompiler {
project, ClassBuilderFactories.BINARIES, Progress.DEAF, exhaust.getBindingContext(), environment.getSourceFiles(),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
/*generateDeclaredClasses = */true
/*generateDeclaredClasses = */true,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG)
);
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
@@ -57,6 +57,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.JetLanguage;
import org.jetbrains.jet.utils.ExceptionUtils;
@@ -236,7 +237,7 @@ public class ReplInterpreter {
BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext();
GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.BINARIES,
bindingContext, Collections.singletonList(psiFile));
bindingContext, Collections.singletonList(psiFile), InlineUtil.DEFAULT_INLINE_FLAG);
compileScript(psiFile.getScript(), scriptClassType, earlierScripts, generationState,
CompilationErrorHandler.THROW_EXCEPTION);
@@ -45,6 +45,7 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import java.util.Collection;
import java.util.Collections;
@@ -152,7 +153,8 @@ public class KotlinJavaFileStubProvider implements CachedValueProvider<PsiJavaFi
context.getBindingContext(),
Lists.newArrayList(files),
/*not-null assertions*/false, false,
/*generateDeclaredClasses=*/stubGenerationStrategy.generateDeclaredClasses());
/*generateDeclaredClasses=*/stubGenerationStrategy.generateDeclaredClasses(),
InlineUtil.DEFAULT_INLINE_FLAG_FOR_STUB);
state.beforeCompile();
stubGenerationStrategy.generate(state, files);
+2 -1
View File
@@ -13,10 +13,11 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-module [String] module to compile
-script [flag] evaluate script
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is off)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Show help
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print commandline arguments
OK
OK
@@ -0,0 +1,3 @@
-inline
off
-help
+23
View File
@@ -0,0 +1,23 @@
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-jar [String] jar file name
-src [String] source file or directory (allows many paths separated by the system path separator)
-classpath [String] classpath to use when compiling
-annotations [String] paths to external annotations
-includeRuntime [flag] include Kotlin runtime in to resulting jar
-noJdk [flag] don't include Java runtime into classpath
-noStdlib [flag] don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] don't include JDK external annotations into classpath
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
-notNullParamAssertions [flag] generate not-null assertions on parameters of methods accessible from Java
-output [String] output directory
-module [String] module to compile
-script [flag] evaluate script
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is off)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Show help
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print commandline arguments
OK
+3
View File
@@ -0,0 +1,3 @@
-inline
on
-help
+23
View File
@@ -0,0 +1,23 @@
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-jar [String] jar file name
-src [String] source file or directory (allows many paths separated by the system path separator)
-classpath [String] classpath to use when compiling
-annotations [String] paths to external annotations
-includeRuntime [flag] include Kotlin runtime in to resulting jar
-noJdk [flag] don't include Java runtime into classpath
-noStdlib [flag] don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] don't include JDK external annotations into classpath
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
-notNullParamAssertions [flag] generate not-null assertions on parameters of methods accessible from Java
-output [String] output directory
-module [String] module to compile
-script [flag] evaluate script
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is off)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Show help
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print commandline arguments
OK
@@ -0,0 +1,2 @@
-inline
wrong
@@ -0,0 +1,24 @@
Wrong value for inline option: 'wrong'. Should be 'on' or 'off'
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-jar [String] jar file name
-src [String] source file or directory (allows many paths separated by the system path separator)
-classpath [String] classpath to use when compiling
-annotations [String] paths to external annotations
-includeRuntime [flag] include Kotlin runtime in to resulting jar
-noJdk [flag] don't include Java runtime into classpath
-noStdlib [flag] don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] don't include JDK external annotations into classpath
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
-notNullParamAssertions [flag] generate not-null assertions on parameters of methods accessible from Java
-output [String] output directory
-module [String] module to compile
-script [flag] evaluate script
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is off)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Show help
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print commandline arguments
INTERNAL_ERROR
+2 -1
View File
@@ -14,10 +14,11 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-module [String] module to compile
-script [flag] evaluate script
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is off)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Show help
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print commandline arguments
INTERNAL_ERROR
INTERNAL_ERROR
@@ -33,7 +33,7 @@ import org.jetbrains.jet.cli.AbstractKotlincExecutableTest;
@InnerTestClasses({KotlincExecutableTestGenerated.Jvm.class, KotlincExecutableTestGenerated.Js.class})
public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTest {
@TestMetadata("compiler/testData/cli/jvm")
@InnerTestClasses({Jvm.WrongAbiVersionLib.class})
@InnerTestClasses({Jvm.Inline.class, Jvm.WrongAbiVersionLib.class})
public static class Jvm extends AbstractKotlincExecutableTest {
public void testAllFilesPresentInJvm() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/cli/jvm"), Pattern.compile("^(.+)\\.args$"), true);
@@ -104,6 +104,29 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
doJvmTest("compiler/testData/cli/jvm/wrongKotlinSignature.args");
}
@TestMetadata("compiler/testData/cli/jvm/inline")
public static class Inline extends AbstractKotlincExecutableTest {
public void testAllFilesPresentInInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/cli/jvm/inline"), Pattern.compile("^(.+)\\.args$"), true);
}
@TestMetadata("off.args")
public void testOff() throws Exception {
doJvmTest("compiler/testData/cli/jvm/inline/off.args");
}
@TestMetadata("on.args")
public void testOn() throws Exception {
doJvmTest("compiler/testData/cli/jvm/inline/on.args");
}
@TestMetadata("wrong.args")
public void testWrong() throws Exception {
doJvmTest("compiler/testData/cli/jvm/inline/wrong.args");
}
}
@TestMetadata("compiler/testData/cli/jvm/wrongAbiVersionLib")
@InnerTestClasses({})
public static class WrongAbiVersionLib extends AbstractKotlincExecutableTest {
@@ -121,6 +144,7 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
public static Test innerSuite() {
TestSuite suite = new TestSuite("Jvm");
suite.addTestSuite(Jvm.class);
suite.addTestSuite(Inline.class);
suite.addTest(WrongAbiVersionLib.innerSuite());
return suite;
}
@@ -31,6 +31,7 @@ import org.jetbrains.jet.codegen.state.Progress;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.utils.ExceptionUtils;
import java.io.File;
@@ -60,7 +61,8 @@ public class CodegenTestUtil {
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF, analyzeExhaust.getBindingContext(), files.getPsiFiles(),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
/*generateDeclaredClasses = */true
/*generateDeclaredClasses = */true,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST)
);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state.getFactory();
@@ -25,6 +25,7 @@ import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import java.util.Collections;
import java.util.List;
@@ -57,7 +58,8 @@ public class GenerationUtils {
@NotNull
public static GenerationState compileFilesGetGenerationState(@NotNull Project project, @NotNull AnalyzeExhaust analyzeExhaust, @NotNull List<JetFile> files) {
analyzeExhaust.throwIfError();
GenerationState state = new GenerationState(project, ClassBuilderFactories.TEST, analyzeExhaust.getBindingContext(), files);
GenerationState state = new GenerationState(project, ClassBuilderFactories.TEST, analyzeExhaust.getBindingContext(), files,
InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state;
}
@@ -31,6 +31,14 @@ import java.util.List;
public class InlineUtil {
public static boolean DEFAULT_INLINE_FLAG = false;
public static boolean DEFAULT_INLINE_FLAG_FOR_TEST = true;
public static boolean DEFAULT_INLINE_FLAG_FOR_TOOLWINDOW = false;
public static boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/
@NotNull
public static InlineStrategy getInlineType(@NotNull Annotated annotated) {
return getInlineType(annotated.getAnnotations());
@@ -40,6 +40,7 @@ import org.jetbrains.jet.codegen.KotlinCodegenFacade;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.Progress;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.plugin.internal.Location;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.util.LongRunningReadTask;
@@ -97,7 +98,8 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
return printStackTraceToString(exhaust.getError());
}
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEXT, Progress.DEAF, exhaust.getBindingContext(),
Collections.singletonList(jetFile), true, true, true);
Collections.singletonList(jetFile), true, true, true,
InlineUtil.DEFAULT_INLINE_FLAG_FOR_TOOLWINDOW /*TODO add checkbox or extract it from option*/);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
}
catch (ProcessCanceledException e) {