Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/cli/bin/kotlinc-jklib
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Copyright 2010-2021 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.

export KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jklib.K2JKlibCompiler

DIR="${BASH_SOURCE[0]%/*}"
: ${DIR:="."}

"${DIR}"/kotlinc "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@file:Suppress("unused", "DuplicatedCode")

// DO NOT EDIT MANUALLY!
// Generated by generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateCompilerArgumentsCopy.kt
// To regenerate run 'generateCompilerArgumentsCopy' task

package org.jetbrains.kotlin.cli.common.arguments

@OptIn(org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI::class)
fun copyK2JKlibCompilerArguments(from: K2JKlibCompilerArguments, to: K2JKlibCompilerArguments): K2JKlibCompilerArguments {
copyCommonCompilerArguments(from, to)

to.classpath = from.classpath
to.destination = from.destination
to.friendPaths = from.friendPaths?.copyOf()
to.klibLibraries = from.klibLibraries
to.moduleName = from.moduleName
to.noReflect = from.noReflect
to.noStdlib = from.noStdlib

return to
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/*
* Copyright 2010-2024 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.cli.common.arguments

import org.jetbrains.kotlin.config.*

class K2JKlibCompilerArguments : CommonCompilerArguments() {
companion object {
@JvmStatic private val serialVersionUID = 0L
}

@Argument(value = "-d", valueDescription = "<klib>", description = "Destination for generated files.")
var destination: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}

@Argument(value = "-p", valueDescription = "<library|ir>", description = "")
var produce: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}

@Argument(
value = "-classpath",
shortName = "-cp",
valueDescription = "<path>",
description = "List of directories and JAR/ZIP archives to search for user .kotlin_metadata files."
)
var classpath: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}

@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file.")
var moduleName: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}

@Argument(
value = "-Xfriend-paths",
valueDescription = "<path>",
description = "Paths to output directories for friend modules (modules whose internals should be visible)."
)
var friendPaths: Array<String>? = null
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xklib",
valueDescription = "<path>",
description = "Paths to cross-platform libraries in the .klib format."
)
var klibLibraries: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}

@Argument(
value = "-no-stdlib",
description = "Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection dependencies in the classpath."
)
var noStdlib = false
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xcompile-builtins-as-part-of-stdlib",
description = "Enable behaviour needed to compile builtins as part of JVM stdlib"
)
var expectBuiltinsAsPartOfStdlib = false
set(value) {
checkFrozen()
field = value
}


@Argument(value = "-no-jdk", description = "Don't automatically include the Java runtime in the classpath.")
var noJdk = false
set(value) {
checkFrozen()
field = value
}


@Argument(value = "-no-reflect", description = "Don't automatically include the Kotlin reflection dependency in the classpath.")
var noReflect = false
set(value) {
checkFrozen()
field = value
}
@Argument(
value = "-Xtype-enhancement-improvements-strict-mode",
description = """Enable strict mode for improvements to type enhancement for loaded Java types based on nullability annotations,
including the ability to read type-use annotations from class files.
See KT-45671 for more details."""
)
var typeEnhancementImprovementsInStrictMode = false
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xenhance-type-parameter-types-to-def-not-null",
description = "Enhance not-null-annotated type parameter types to definitely-non-nullable types ('@NotNull T' => 'T & Any')."
)
var enhanceTypeParameterTypesToDefNotNull = false
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xjvm-default",
valueDescription = "{all|all-compatibility|disable}",
description = """Emit JVM default methods for interface declarations with bodies. The default is 'disable'.
-Xjvm-default=all Generate JVM default methods for all interface declarations with bodies in the module.
Do not generate 'DefaultImpls' stubs for interface declarations with bodies. If an interface inherits a method with a
body from an interface compiled in 'disable' mode and doesn't override it, then a 'DefaultImpls' stub will be
generated for it.
This BREAKS BINARY COMPATIBILITY if some client code relies on the presence of 'DefaultImpls' classes.
Note that if interface delegation is used, all interface methods are delegated.
-Xjvm-default=all-compatibility Like 'all', but additionally generate compatibility stubs in the 'DefaultImpls' classes.
Compatibility stubs can help library and runtime authors maintain backward binary compatibility
for existing clients compiled against previous library versions.
'all' and 'all-compatibility' modes change the library ABI surface that will be used by clients after
the recompilation of the library. Because of this, clients might be incompatible with previous library
versions. This usually means that proper library versioning is required, for example with major version increases in SemVer.
In subtypes of Kotlin interfaces compiled in 'all' or 'all-compatibility' mode, 'DefaultImpls'
compatibility stubs will invoke the default method of the interface with standard JVM runtime resolution semantics.
Perform additional compatibility checks for classes inheriting generic interfaces where in some cases an
additional implicit method with specialized signatures was generated in 'disable' mode.
Unlike in 'disable' mode, the compiler will report an error if such a method is not overridden explicitly
and the class is not annotated with '@JvmDefaultWithoutCompatibility' (see KT-39603 for more details).
-Xjvm-default=disable Default behavior. Do not generate JVM default methods."""
)
var jvmDefault: String = JvmDefaultMode.DISABLE.description
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xvalue-classes",
description = "Enable experimental value classes."
)
var valueClasses = false
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xjsr305",
deprecatedName = "-Xjsr305-annotations",
valueDescription =
"{ignore/strict/warn}" +
"|under-migration:{ignore/strict/warn}" +
"|@<fq.name>:{ignore/strict/warn}",
description =
"""Specify the behavior of 'JSR-305' nullability annotations:
-Xjsr305={ignore/strict/warn} global (all non-@UnderMigration annotations)
-Xjsr305=under-migration:{ignore/strict/warn} all @UnderMigration annotations
-Xjsr305=@<fq.name>:{ignore/strict/warn} annotation with the given fully qualified class name
Modes:
* ignore
* strict (experimental; treat like other supported nullability annotations)
* warn (report a warning)""",
)
var jsr305: Array<String>? = null
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xsupport-compatqual-checker-framework-annotations",
valueDescription = "enable|disable",
description =
"""Specify the behavior for Checker Framework 'compatqual' annotations ('NullableDecl'/'NonNullDecl').
The default value is 'enable'.""",
)
var supportCompatqualCheckerFrameworkAnnotations: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}

@Argument(
value = "-Xjspecify-annotations",
valueDescription = "ignore|strict|warn",
description =
"""Specify the behavior of 'jspecify' annotations.
The default value is 'warn'.""",
)
var jspecifyAnnotations: String? = null
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "Xmultifile-parts-inherit",
description = "Compile multifile classes as a hierarchy of parts and a facade."
)
var inheritMultifileParts: Boolean = false
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xoutput-builtins-metadata",
description = "Output builtins metadata as .kotlin_builtins files",
)
var outputBuiltinsMetadata: Boolean = false
set(value) {
checkFrozen()
field = value
}

@Argument(
value = "-Xnullability-annotations",
valueDescription = "@<fq.name>:{ignore/strict/warn}",
description =
"""Specify the behavior for specific Java nullability annotations (provided with fully qualified package name).
Modes:
* ignore
* strict
* warn (report a warning)""",
)
var nullabilityAnnotations: Array<String>? = null
set(value) {
checkFrozen()
field = value
}

override fun copyOf(): Freezable = TODO() // copyK2JKlibCompilerArguments(this, K2JKlibCompilerArguments())

override val configurator: CommonCompilerArgumentsConfigurator = K2JKlibCompilerArgumentsConfigurator()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2010-2025 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.cli.common.arguments

import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.config.*

class K2JKlibCompilerArgumentsConfigurator : CommonCompilerArgumentsConfigurator() {
override fun configureAnalysisFlags(
arguments: CommonCompilerArguments,
collector: MessageCollector,
languageVersion: LanguageVersion,
): MutableMap<AnalysisFlag<*>, Any> = with(arguments) {
require(this is K2JKlibCompilerArguments)
val result = super.configureAnalysisFlags(arguments, collector, languageVersion)
result[JvmAnalysisFlags.javaTypeEnhancementState] = JavaTypeEnhancementStateParser(collector, languageVersion.toKotlinVersion())
.parse(jsr305, supportCompatqualCheckerFrameworkAnnotations, jspecifyAnnotations, nullabilityAnnotations)

result[JvmAnalysisFlags.inheritMultifileParts] = inheritMultifileParts
result[JvmAnalysisFlags.outputBuiltinsMetadata] = outputBuiltinsMetadata
if (expectBuiltinsAsPartOfStdlib && !stdlibCompilation) {
collector.report(
CompilerMessageSeverity.ERROR,
"-Xcompile-builtins-as-part-of-stdlib must not be used without -Xstdlib-compilation"
)
}
result[JvmAnalysisFlags.expectBuiltinsAsPartOfStdlib] = expectBuiltinsAsPartOfStdlib
return result
}

private fun K2JVMCompilerArguments.configureJvmDefaultMode(collector: MessageCollector?): JvmDefaultMode? = when {
jvmDefaultStable != null -> JvmDefaultMode.fromStringOrNull(jvmDefaultStable).also {
if (it == null) {
collector?.report(
CompilerMessageSeverity.ERROR,
"Unknown -jvm-default mode: $jvmDefaultStable, supported modes: " +
"${JvmDefaultMode.entries.map(JvmDefaultMode::description)}"
)
}
}
jvmDefault != null -> JvmDefaultMode.fromStringOrNullOld(jvmDefault).also {
if (it == null) {
collector?.report(
CompilerMessageSeverity.ERROR,
"Unknown -Xjvm-default mode: $jvmDefault, supported modes: " +
"${JvmDefaultMode.entries.map(JvmDefaultMode::oldDescription)}"
)
}
}
else -> null
}

override fun configureLanguageFeatures(
arguments: CommonCompilerArguments,
collector: MessageCollector,
): MutableMap<LanguageFeature, LanguageFeature.State> = with(arguments) {
require(this is K2JKlibCompilerArguments)
val result = super.configureLanguageFeatures(arguments, collector)
if (typeEnhancementImprovementsInStrictMode) {
result[LanguageFeature.TypeEnhancementImprovementsInStrictMode] = LanguageFeature.State.ENABLED
}
if (enhanceTypeParameterTypesToDefNotNull) {
result[LanguageFeature.ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated] = LanguageFeature.State.ENABLED
}
if (valueClasses) {
result[LanguageFeature.ValueClasses] = LanguageFeature.State.ENABLED
}
return result
}
}
Loading