Introduce CompilerConfiguration#getNotNull and getBoolean
To reduce boilerplate at call sites
This commit is contained in:
@@ -614,7 +614,7 @@ public class AsmUtil {
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull FrameMap frameMap
|
||||
) {
|
||||
if (!state.isParamAssertionsEnabled()) return;
|
||||
if (state.isParamAssertionsDisabled()) return;
|
||||
|
||||
// Private method is not accessible from other classes, no assertions needed
|
||||
if (getVisibilityAccessFlag(descriptor) == ACC_PRIVATE) return;
|
||||
@@ -655,7 +655,7 @@ public class AsmUtil {
|
||||
@NotNull final StackValue stackValue,
|
||||
@Nullable final RuntimeAssertionInfo runtimeAssertionInfo
|
||||
) {
|
||||
if (!state.isCallAssertionsEnabled()) return stackValue;
|
||||
if (state.isCallAssertionsDisabled()) return stackValue;
|
||||
if (runtimeAssertionInfo == null || !runtimeAssertionInfo.getNeedNotNullAssertion()) return stackValue;
|
||||
|
||||
return new StackValue(stackValue.type) {
|
||||
|
||||
@@ -1879,7 +1879,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
CallableMemberDescriptor descriptor = getContext().getContextDescriptor();
|
||||
NonLocalReturnInfo nonLocalReturn = getNonLocalReturnInfo(descriptor, expression);
|
||||
boolean isNonLocalReturn = nonLocalReturn != null;
|
||||
if (isNonLocalReturn && !state.isInlineEnabled()) {
|
||||
if (isNonLocalReturn && state.isInlineDisabled()) {
|
||||
state.getDiagnostics().report(Errors.NON_LOCAL_RETURN_IN_DISABLED_INLINE.on(expression));
|
||||
genThrow(v, "java/lang/UnsupportedOperationException",
|
||||
"Non-local returns are not allowed with inlining disabled");
|
||||
@@ -2520,7 +2520,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
// We should inline callable containing reified type parameters even if inline is disabled
|
||||
// because they may contain something to reify and straight call will probably fail at runtime
|
||||
boolean isInline = (state.isInlineEnabled() || InlineUtil.containsReifiedTypeParameters(descriptor)) &&
|
||||
boolean isInline = (!state.isInlineDisabled() || InlineUtil.containsReifiedTypeParameters(descriptor)) &&
|
||||
(InlineUtil.isInline(descriptor) || InlineUtil.isArrayConstructorWithLambda(descriptor));
|
||||
|
||||
if (!isInline) return defaultCallGenerator;
|
||||
|
||||
@@ -155,7 +155,7 @@ public class InlineCodegenUtil {
|
||||
public static void initDefaultSourceMappingIfNeeded(
|
||||
@NotNull CodegenContext context, @NotNull MemberCodegen codegen, @NotNull GenerationState state
|
||||
) {
|
||||
if (!state.isInlineEnabled()) return;
|
||||
if (state.isInlineDisabled()) return;
|
||||
|
||||
CodegenContext<?> parentContext = context.getParentContext();
|
||||
while (parentContext != null) {
|
||||
|
||||
@@ -147,11 +147,11 @@ class GenerationState @JvmOverloads constructor(
|
||||
var hasResult: Boolean = false
|
||||
}
|
||||
|
||||
val isCallAssertionsEnabled: Boolean = !configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false)
|
||||
val isParamAssertionsEnabled: Boolean = !configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false)
|
||||
val isInlineEnabled: Boolean = !configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false)
|
||||
val useTypeTableInSerializer: Boolean = configuration.get(JVMConfigurationKeys.USE_TYPE_TABLE, false)
|
||||
val inheritMultifileParts: Boolean = configuration.get(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, false)
|
||||
val isCallAssertionsDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS)
|
||||
val isParamAssertionsDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS)
|
||||
val isInlineDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_INLINE)
|
||||
val useTypeTableInSerializer: Boolean = configuration.getBoolean(JVMConfigurationKeys.USE_TYPE_TABLE)
|
||||
val inheritMultifileParts: Boolean = configuration.getBoolean(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS)
|
||||
|
||||
val rootContext: CodegenContext<*> = RootContext(this)
|
||||
|
||||
|
||||
@@ -248,11 +248,9 @@ open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
|
||||
fun reportPerf(configuration: CompilerConfiguration, message: String) {
|
||||
if (!configuration.get(CLIConfigurationKeys.REPORT_PERF, false)) {
|
||||
return
|
||||
}
|
||||
if (!configuration.getBoolean(CLIConfigurationKeys.REPORT_PERF)) return
|
||||
|
||||
val collector = configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]!!
|
||||
val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
collector.report(CompilerMessageSeverity.INFO, "PERF: " + message, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
|
||||
|
||||
@@ -244,8 +244,7 @@ class KotlinCoreEnvironment private constructor(
|
||||
fun getSourceFiles(): List<KtFile> = sourceFiles
|
||||
|
||||
private fun report(severity: CompilerMessageSeverity, message: String) {
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
?: throw CompileEnvironmentException(message)
|
||||
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
messageCollector.report(severity, message, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -417,7 +417,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
private fun checkKotlinPackageUsage(environment: KotlinCoreEnvironment, files: Collection<KtFile>): Boolean {
|
||||
if (environment.configuration.get(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE) == true) {
|
||||
if (environment.configuration.getBoolean(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE)) {
|
||||
return true
|
||||
}
|
||||
val messageCollector = environment.configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
@@ -434,8 +434,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
private val KotlinCoreEnvironment.messageCollector: MessageCollector
|
||||
get() = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
?: error("Message collector not specified in compiler configuration")
|
||||
get() = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
private fun reportRuntimeConflicts(messageCollector: MessageCollector, jvmClasspathRoots: List<File>) {
|
||||
fun String.removeIdeaVersionSuffix(): String {
|
||||
|
||||
@@ -41,19 +41,25 @@ public class CompilerConfiguration {
|
||||
|
||||
@NotNull
|
||||
public <T> T get(@NotNull CompilerConfigurationKey<T> key, @NotNull T defaultValue) {
|
||||
T data = (T) map.get(key.ideaKey);
|
||||
return data == null ? defaultValue : unmodifiable(data);
|
||||
T data = get(key);
|
||||
return data == null ? defaultValue : data;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> T getNotNull(@NotNull CompilerConfigurationKey<T> key) {
|
||||
T data = get(key);
|
||||
assert data != null : "No value for configuration key: " + key;
|
||||
return data;
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull CompilerConfigurationKey<Boolean> key) {
|
||||
return get(key, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> List<T> getList(@NotNull CompilerConfigurationKey<List<T>> key) {
|
||||
List<T> data = (List<T>) map.get(key.ideaKey);
|
||||
if (data == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
return Collections.unmodifiableList(data);
|
||||
}
|
||||
List<T> data = get(key);
|
||||
return data == null ? Collections.<T>emptyList() : data;
|
||||
}
|
||||
|
||||
public <T> void put(@NotNull CompilerConfigurationKey<T> key, @Nullable T value) {
|
||||
|
||||
@@ -30,4 +30,9 @@ public class CompilerConfigurationKey<T> {
|
||||
public static <T> CompilerConfigurationKey<T> create(@NotNull @NonNls String name) {
|
||||
return new CompilerConfigurationKey<T>(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ideaKey.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext();
|
||||
|
||||
kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(
|
||||
resolutionFacade, bindingContextForFile, ktFile, configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false)
|
||||
resolutionFacade, bindingContextForFile, ktFile, configuration.getBoolean(JVMConfigurationKeys.DISABLE_INLINE)
|
||||
);
|
||||
|
||||
BindingContext bindingContext = result.getFirst();
|
||||
|
||||
Reference in New Issue
Block a user