Extract module 'config.jvm' out of 'frontend.java'

This allows to get rid of dependency cli.common -> frontend.java.
This commit is contained in:
Alexander Udalov
2020-03-14 23:14:04 +01:00
committed by Alexander Udalov
parent 90ae416b72
commit 15d2a06132
14 changed files with 21 additions and 2 deletions
@@ -1,24 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.config
enum class JVMAssertionsMode(val description: String) {
ALWAYS_ENABLE("always-enable"),
ALWAYS_DISABLE("always-disable"),
JVM("jvm"),
LEGACY("legacy");
companion object {
@JvmField
val DEFAULT = LEGACY
@JvmStatic
fun fromStringOrNull(string: String?) = values().find { it.description == string }
@JvmStatic
fun fromString(string: String?) = fromStringOrNull(string) ?: DEFAULT
}
}
@@ -1,125 +0,0 @@
/*
* Copyright 2010-2017 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.kotlin.config;
import org.jetbrains.kotlin.load.java.JavaClassesTracker;
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
import org.jetbrains.kotlin.modules.Module;
import java.io.File;
import java.util.List;
public class JVMConfigurationKeys {
private JVMConfigurationKeys() {
}
public static final CompilerConfigurationKey<File> OUTPUT_DIRECTORY =
CompilerConfigurationKey.create("output directory");
public static final CompilerConfigurationKey<File> OUTPUT_JAR =
CompilerConfigurationKey.create("output .jar");
public static final CompilerConfigurationKey<Boolean> INCLUDE_RUNTIME =
CompilerConfigurationKey.create("include runtime to the resulting .jar");
public static final CompilerConfigurationKey<File> JDK_HOME =
CompilerConfigurationKey.create("jdk home");
public static final CompilerConfigurationKey<Boolean> NO_JDK =
CompilerConfigurationKey.create("no jdk");
public static final CompilerConfigurationKey<Boolean> DISABLE_STANDARD_SCRIPT_DEFINITION =
CompilerConfigurationKey.create("Disable standard kotlin script support");
public static final CompilerConfigurationKey<Boolean> RETAIN_OUTPUT_IN_MEMORY =
CompilerConfigurationKey.create("retain compiled classes in memory for further use, e.g. when running scripts");
public static final CompilerConfigurationKey<Boolean> DISABLE_CALL_ASSERTIONS =
CompilerConfigurationKey.create("disable not-null call assertions");
public static final CompilerConfigurationKey<Boolean> DISABLE_RECEIVER_ASSERTIONS =
CompilerConfigurationKey.create("disable not-null call receiver assertions");
public static final CompilerConfigurationKey<Boolean> DISABLE_PARAM_ASSERTIONS =
CompilerConfigurationKey.create("disable not-null parameter assertions");
public static final CompilerConfigurationKey<JVMAssertionsMode> ASSERTIONS_MODE =
CompilerConfigurationKey.create("assertions mode");
public static final CompilerConfigurationKey<JVMConstructorCallNormalizationMode> CONSTRUCTOR_CALL_NORMALIZATION_MODE =
CompilerConfigurationKey.create("constructor call normalization mode");
public static final CompilerConfigurationKey<Boolean> NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL =
CompilerConfigurationKey.create("do not throw NPE on explicit 'equals' call for null receiver of platform boxed primitive type");
public static final CompilerConfigurationKey<Boolean> DISABLE_OPTIMIZATION =
CompilerConfigurationKey.create("disable optimization");
public static final CompilerConfigurationKey<Boolean> USE_TYPE_TABLE =
CompilerConfigurationKey.create("use type table in serializer");
public static final CompilerConfigurationKey<Boolean> USE_SINGLE_MODULE =
CompilerConfigurationKey.create("combine modules for source files and binary dependencies into a single module");
public static final CompilerConfigurationKey<Boolean> SKIP_RUNTIME_VERSION_CHECK =
CompilerConfigurationKey.create("do not perform checks on runtime versions consistency");
public static final CompilerConfigurationKey<JvmTarget> JVM_TARGET =
CompilerConfigurationKey.create("JVM bytecode target version");
public static final CompilerConfigurationKey<Boolean> PARAMETERS_METADATA =
CompilerConfigurationKey.create("Parameters metadata for java 1.8 reflection");
public static final CompilerConfigurationKey<IncrementalCompilationComponents> INCREMENTAL_COMPILATION_COMPONENTS =
CompilerConfigurationKey.create("incremental cache provider");
public static final CompilerConfigurationKey<JavaClassesTracker> JAVA_CLASSES_TRACKER =
CompilerConfigurationKey.create("Java classes tracker");
public static final CompilerConfigurationKey<File> MODULE_XML_FILE =
CompilerConfigurationKey.create("path to module.xml");
public static final CompilerConfigurationKey<String> DECLARATIONS_JSON_PATH =
CompilerConfigurationKey.create("path to declarations output");
public static final CompilerConfigurationKey<List<Module>> MODULES =
CompilerConfigurationKey.create("module data");
public static final CompilerConfigurationKey<List<String>> FRIEND_PATHS =
CompilerConfigurationKey.create("friend module paths");
public static final CompilerConfigurationKey<Boolean> IR =
CompilerConfigurationKey.create("IR");
public static final CompilerConfigurationKey<Boolean> USE_PSI_CLASS_FILES_READING =
CompilerConfigurationKey.create("use a slower (PSI-based) class files reading implementation");
public static final CompilerConfigurationKey<Boolean> USE_JAVAC =
CompilerConfigurationKey.create("use javac [experimental]");
public static final CompilerConfigurationKey<Boolean> COMPILE_JAVA =
CompilerConfigurationKey.create("compile java files [experimental]");
public static final CompilerConfigurationKey<List<String>> ADDITIONAL_JAVA_MODULES =
CompilerConfigurationKey.create("additional Java modules");
public static final CompilerConfigurationKey<Boolean> ENABLE_JVM_DEFAULT =
CompilerConfigurationKey.create("Allow to use '@JvmDefault'");
public static final CompilerConfigurationKey<Boolean> EMIT_JVM_TYPE_ANNOTATIONS =
CompilerConfigurationKey.create("Emit JVM type annotations in bytecode");
public static final CompilerConfigurationKey<List<String>> KLIB_PATHS =
CompilerConfigurationKey.create("Paths to .klib libraries");
public static final CompilerConfigurationKey<Boolean> IS_IR_WITH_STABLE_ABI =
CompilerConfigurationKey.create("Is IR with stable ABI");
public static final CompilerConfigurationKey<Boolean> NO_OPTIMIZED_CALLABLE_REFERENCES =
CompilerConfigurationKey.create("Do not use optimized callable reference superclasses available from 1.4");
}
@@ -1,38 +0,0 @@
/*
* Copyright 2010-2017 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.kotlin.config
enum class JVMConstructorCallNormalizationMode(
val description: String,
val isEnabled: Boolean,
val shouldPreserveClassInitialization: Boolean
) {
DISABLE("disable", false, false),
ENABLE("enable", true, false),
PRESERVE_CLASS_INITIALIZATION("preserve-class-initialization", true, true)
;
companion object {
@JvmStatic
fun isSupportedValue(string: String?) =
string == null || values().any { it.description == string }
@JvmStatic
fun fromStringOrNull(string: String?) =
values().find { it.description == string }
}
}
@@ -1,29 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.config
object JvmAnalysisFlags {
@JvmStatic
val strictMetadataVersionSemantics by AnalysisFlag.Delegates.Boolean
@JvmStatic
val jsr305 by AnalysisFlag.Delegates.Jsr305StateWarnByDefault
@JvmStatic
val jvmDefaultMode by AnalysisFlag.Delegates.JvmDefaultModeDisabledByDefault
@JvmStatic
val inheritMultifileParts by AnalysisFlag.Delegates.Boolean
@JvmStatic
val sanitizeParentheses by AnalysisFlag.Delegates.Boolean
@JvmStatic
val suppressMissingBuiltinsError by AnalysisFlag.Delegates.Boolean
@JvmStatic
val irCheckLocalNames by AnalysisFlag.Delegates.Boolean
}
@@ -1,62 +0,0 @@
/*
* Copyright 2010-2017 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.kotlin.config
import org.jetbrains.kotlin.platform.TargetPlatformVersion
import org.jetbrains.org.objectweb.asm.Opcodes
enum class JvmTarget(override val description: String) : TargetPlatformVersion {
JVM_1_6("1.6"),
JVM_1_8("1.8"),
JVM_9("9"),
JVM_10("10"),
JVM_11("11"),
JVM_12("12"),
JVM_13("13"),
;
val bytecodeVersion: Int by lazy {
when (this) {
JVM_1_6 -> Opcodes.V1_6
JVM_1_8 -> Opcodes.V1_8
JVM_9 -> Opcodes.V9
JVM_10 -> Opcodes.V10
JVM_11 -> Opcodes.V11
JVM_12 -> Opcodes.V12
JVM_13 -> Opcodes.V12 + 1
}
}
companion object {
@JvmField
val DEFAULT = JVM_1_6
@JvmStatic
fun fromString(string: String) = values().find { it.description == string }
fun getDescription(bytecodeVersion: Int): String {
val platformDescription = values().find { it.bytecodeVersion == bytecodeVersion }?.description ?: when (bytecodeVersion) {
Opcodes.V1_7 -> "1.7"
else -> null
}
return if (platformDescription != null) "JVM target $platformDescription"
else "JVM bytecode version $bytecodeVersion"
}
}
}
@@ -1,74 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.platform.jvm
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.platform.SimplePlatform
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.toTargetPlatform
import org.jetbrains.kotlin.platform.TargetPlatformVersion
abstract class JvmPlatform : SimplePlatform("JVM") {
override val oldFashionedDescription: String
get() = "JVM "
}
@Suppress("DEPRECATION_ERROR")
object JvmPlatforms {
private val UNSPECIFIED_SIMPLE_JVM_PLATFORM = JdkPlatform(JvmTarget.JVM_1_6)
private val jvmTargetToJdkPlatform: Map<JvmTarget, TargetPlatform> =
JvmTarget.values().map { it to JdkPlatform(it).toTargetPlatform() }.toMap()
// This platform is needed mostly for compatibility and migration of code base,
// as previously some clients used TargetPlatform just as platform-marker
// and didn't care about particular jvmTarget.
// TODO(dsavvinov): review all usages and choose proper JvmTarget
val unspecifiedJvmPlatform: TargetPlatform
get() = CompatJvmPlatform
val defaultJvmPlatform: TargetPlatform = jvmTargetToJdkPlatform[JvmTarget.DEFAULT]!!
val jvm16: TargetPlatform = jvmTargetToJdkPlatform[JvmTarget.JVM_1_6]!!
val jvm18: TargetPlatform = jvmTargetToJdkPlatform[JvmTarget.JVM_1_8]!!
fun jvmPlatformByTargetVersion(targetVersion: JvmTarget): TargetPlatform =
jvmTargetToJdkPlatform[targetVersion]!!
val allJvmPlatforms: List<TargetPlatform> = jvmTargetToJdkPlatform.values.toList()
@Deprecated(
message = "Should be accessed only by compatibility layer, other clients should use 'unspecifiedJvmPlatform'",
level = DeprecationLevel.ERROR
)
object CompatJvmPlatform : TargetPlatform(setOf(UNSPECIFIED_SIMPLE_JVM_PLATFORM)),
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform {
override val platformName: String
get() = "JVM"
}
}
class JdkPlatform(val targetVersion: JvmTarget) : JvmPlatform() {
override fun toString(): String = "$platformName ($targetVersion)"
override val oldFashionedDescription: String
get() = "JVM " + targetVersion.description
override val targetPlatformVersion: TargetPlatformVersion
get() = targetVersion
// TODO(dsavvinov): temporarily conservative measure; make JdkPlatform data class later
// Explanation: previously we had only one JvmPlatform, and all 'TargetPlatform's had an
// equality (actually, identity, because each platform had only one instance). This lead
// to common pattern of putting them in map (e.g., see KotlinCacheServiceImpl.globalFacadesPerPlatformAndSdk).
//
// If we start distinguishing JvmPlatforms with different JvmTarget right now, it may accidentally
// break some clients (in particular, we'll create global facade for *each* JvmTarget, which is a bad idea)
override fun equals(other: Any?): Boolean = other is JdkPlatform
override fun hashCode(): Int = JdkPlatform::class.hashCode()
}
fun TargetPlatform?.isJvm(): Boolean = this?.singleOrNull() is JvmPlatform
@@ -1,23 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION_ERROR")
package org.jetbrains.kotlin.resolve.jvm.platform
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.resolve.TargetPlatform
@Deprecated(
message = "This class is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead",
replaceWith = ReplaceWith("JvmPlatforms.unspecifiedJvmPlatform", "org.jetbrains.kotlin.platform.jvm.JvmPlatforms"),
level = DeprecationLevel.ERROR
)
interface JvmPlatform : TargetPlatform {
companion object {
@JvmField
val INSTANCE: JvmPlatform = JvmPlatforms.CompatJvmPlatform
}
}