[JS IR BE] Load builtins from code to runtime

Bypass builtins deserialization mechanism in legacy JS backend and load
bultins direcly as kotlin code.

This way we won't have separated IR declarations for Enum, Char, Long

Some "native" builtins are implemented in libraries/stdlib/js/irRuntime/builtins/
Other builtins are moved by MoveExternalDeclarationsToSeparatePlace and
used only in compile-time
This commit is contained in:
Svyatoslav Kuzmich
2019-01-24 18:44:59 +03:00
parent 7e263fd68e
commit 8c89ffbe2d
19 changed files with 1506 additions and 127 deletions
@@ -43,10 +43,10 @@ private fun makeJsPhase(
prerequisite: Set<CompilerPhase<JsIrBackendContext, IrModuleFragment>> = emptySet()
) = makePhase(lowering, description, name, prerequisite)
private val MoveExternalDeclarationsToSeparatePlacePhase = makeJsPhase(
{ _, module -> MoveExternalDeclarationsToSeparatePlace().lower(module) },
name = "MoveExternalDeclarationsToSeparatePlace",
description = "Move `external` declarations into separate place to make the following lowerings do not care about them"
private val MoveBodilessDeclarationsToSeparatePlacePhase = makeJsPhase(
{ _, module -> MoveBodilessDeclarationsToSeparatePlace().lower(module) },
name = "MoveBodilessDeclarationsToSeparatePlace",
description = "Move `external` and `built-in` declarations into separate place to make the following lowerings do not care about them"
)
private val ExpectDeclarationsRemovingPhase = makeJsPhase(
@@ -337,7 +337,7 @@ private val IrToJsPhase = makeJsPhase(
val jsPhases = listOf(
IrModuleStartPhase,
MoveExternalDeclarationsToSeparatePlacePhase,
MoveBodilessDeclarationsToSeparatePlacePhase,
ExpectDeclarationsRemovingPhase,
CoroutineIntrinsicLoweringPhase,
ArrayInlineConstructorLoweringPhase,
@@ -27,7 +27,8 @@ fun compile(
configuration: CompilerConfiguration,
export: FqName? = null,
dependencies: List<ModuleDescriptor> = listOf(),
irDependencyModules: List<IrModuleFragment> = listOf()
irDependencyModules: List<IrModuleFragment> = listOf(),
builtInsModule: ModuleDescriptorImpl? = null
): Result {
val analysisResult =
TopDownAnalyzerFacadeForJS.analyzeFiles(
@@ -35,7 +36,9 @@ fun compile(
project,
configuration,
dependencies.mapNotNull { it as? ModuleDescriptorImpl },
emptyList()
emptyList(),
thisIsBuiltInsModule = builtInsModule == null,
customBuiltInsModule = builtInsModule
)
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
@@ -51,7 +51,7 @@ class JsDefaultArgumentStubGenerator(override val context: JsIrBackendContext) :
private fun resolveInvoke(paramCount: Int): IrSimpleFunction {
assert(paramCount > 0)
val fqn = FqName.fromSegments(listOf("kotlin", "Function$paramCount"))
val functionKlass = context.run { symbolTable.referenceClass(getClass(fqn)) }.owner
val functionKlass = context.run { symbolTable.lazyWrapper.referenceClass(getClass(fqn)) }.owner
return functionKlass.declarations.filterIsInstance<IrSimpleFunction>().first { it.name == Name.identifier("invoke") }
}
}
@@ -8,14 +8,42 @@ package org.jetbrains.kotlin.ir.backend.js.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.ir.backend.js.lower.inline.addChild
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
class MoveBodilessDeclarationsToSeparatePlace : FileLoweringPass {
private val builtInClasses = listOf(
"String",
"Nothing",
"Array",
"Any",
"ByteArray",
"CharArray",
"ShortArray",
"IntArray",
"LongArray",
"FloatArray",
"DoubleArray",
"BooleanArray",
"Boolean",
"Byte",
"Short",
"Int",
"Float",
"Double"
).map { Name.identifier(it) }.toSet()
private fun isBuiltInClass(declaration: IrDeclaration): Boolean =
declaration is IrClass && declaration.name in builtInClasses
class MoveExternalDeclarationsToSeparatePlace : FileLoweringPass {
private val packageFragment = IrExternalPackageFragmentImpl(object : IrExternalPackageFragmentSymbol {
override val descriptor: PackageFragmentDescriptor
get() = error("Operation is unsupported")
@@ -36,7 +64,7 @@ class MoveExternalDeclarationsToSeparatePlace : FileLoweringPass {
while (it.hasNext()) {
val d = it.next()
if (d.isEffectivelyExternal()) {
if (d.isEffectivelyExternal() || isBuiltInClass(d)) {
it.remove()
packageFragment.addChild(d)
}
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2018 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.builtins
interface FunctionInterfacePackageFragment : BuiltInsPackageFragment
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.builtins.functions
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment
import org.jetbrains.kotlin.builtins.FunctionInterfacePackageFragment
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor.Kind
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -81,7 +82,12 @@ class BuiltInFictitiousFunctionClassFactory(
val packageFqName = classId.packageFqName
val (kind, arity) = parseClassName(className, packageFqName) ?: return null
val containingPackageFragment = module.getPackage(packageFqName).fragments.filterIsInstance<BuiltInsPackageFragment>().first()
val builtInsFragments = module.getPackage(packageFqName).fragments.filterIsInstance<BuiltInsPackageFragment>()
// JS IR backend uses separate FunctionInterfacePackageFragment for function interfaces
val containingPackageFragment =
builtInsFragments.filterIsInstance<FunctionInterfacePackageFragment>().firstOrNull() ?: builtInsFragments.first()
return FunctionClassDescriptor(storageManager, containingPackageFragment, kind, arity)
}
@@ -5,14 +5,13 @@
package org.jetbrains.kotlin.builtins.functions
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.AbstractClassDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE
@@ -108,9 +107,9 @@ class FunctionClassDescriptor(
override fun computeSupertypes(): Collection<KotlinType> {
val result = ArrayList<KotlinType>(2)
fun add(packageFragment: PackageFragmentDescriptor, name: Name) {
val descriptor = packageFragment.getMemberScope().getContributedClassifier(name, NoLookupLocation.FROM_BUILTINS) as? ClassDescriptor
?: error("Class $name not found in $packageFragment")
fun add(id: ClassId) {
val moduleDescriptor = containingDeclaration.containingDeclaration
val descriptor = moduleDescriptor.findClassAcrossModuleDependencies(id) ?: error("Built-in class $id not found")
val typeConstructor = descriptor.typeConstructor
@@ -124,20 +123,21 @@ class FunctionClassDescriptor(
when (functionKind) {
Kind.SuspendFunction -> // SuspendFunction$N<...> <: Function
add(getBuiltInPackage(BUILT_INS_PACKAGE_FQ_NAME), Name.identifier("Function"))
add(functionClassId)
Kind.KSuspendFunction -> // KSuspendFunction$N<...> <: KFunction
add(containingDeclaration, Name.identifier("KFunction"))
else -> // Add unnumbered base class, e.g. Function for Function{n}, KFunction for KFunction{n}
add(containingDeclaration, Name.identifier(functionKind.classNamePrefix))
add(kFunctionClassId)
Kind.Function -> // Function$N <: Function
add(functionClassId)
Kind.KFunction -> // KFunction$N <: KFunction
add(kFunctionClassId)
}
// For K{Suspend}Function{n}, add corresponding numbered {Suspend}Function{n} class, e.g. {Suspend}Function2 for K{Suspend}Function2
when (functionKind) {
Kind.KFunction -> add(getBuiltInPackage(BUILT_INS_PACKAGE_FQ_NAME), Kind.Function.numberedClassName(arity))
Kind.KSuspendFunction -> add(
getBuiltInPackage(COROUTINES_PACKAGE_FQ_NAME_RELEASE),
Kind.SuspendFunction.numberedClassName(arity)
)
Kind.KFunction ->
add(ClassId(BUILT_INS_PACKAGE_FQ_NAME, Kind.Function.numberedClassName(arity)))
Kind.KSuspendFunction ->
add(ClassId(COROUTINES_PACKAGE_FQ_NAME_RELEASE, Kind.SuspendFunction.numberedClassName(arity)))
else -> {
}
}
@@ -145,11 +145,6 @@ class FunctionClassDescriptor(
return result.toList()
}
private fun getBuiltInPackage(fqName: FqName): BuiltInsPackageFragment {
val packageView = containingDeclaration.containingDeclaration.getPackage(fqName)
return packageView.fragments.filterIsInstance<BuiltInsPackageFragment>().first()
}
override fun getParameters() = this@FunctionClassDescriptor.parameters
override fun getDeclarationDescriptor() = this@FunctionClassDescriptor
@@ -162,4 +157,9 @@ class FunctionClassDescriptor(
}
override fun toString() = name.asString()
companion object {
val functionClassId = ClassId(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("Function"))
val kFunctionClassId = ClassId(KOTLIN_REFLECT_FQ_NAME, Name.identifier("KFunction"))
}
}
@@ -0,0 +1,83 @@
/*
* Copyright 2010-2018 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.builtins.functions
import org.jetbrains.kotlin.builtins.FunctionInterfacePackageFragment
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.deserialization.ClassDescriptorFactory
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.utils.Printer
class FunctionInterfaceMemberScope(
private val classDescriptorFactory: ClassDescriptorFactory,
val packageName: FqName
) : MemberScopeImpl() {
override fun getContributedDescriptors(
kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean
) =
classDescriptorFactory.getAllContributedClassesIfPossible(packageName)
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> =
emptyList()
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> =
emptyList()
override fun getFunctionNames(): Set<Name> =
emptySet()
override fun getVariableNames(): Set<Name> =
emptySet()
override fun getClassifierNames(): Set<Name>? = null
override fun printScopeStructure(p: Printer) {
TODO()
}
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = when {
classDescriptorFactory.shouldCreateClass(packageName, name) ->
classDescriptorFactory.createClass(ClassId.topLevel(packageName.child(name)))
else -> null
}
}
class FunctionInterfacePackageFragmentImpl(
classDescriptorFactory: ClassDescriptorFactory,
module: ModuleDescriptor,
name: FqName
) : FunctionInterfacePackageFragment,
PackageFragmentDescriptorImpl(module, name) {
private val memberScope = FunctionInterfaceMemberScope(classDescriptorFactory, fqName)
override fun getMemberScope() = memberScope
}
fun functionInterfacePackageFragmentProvider(
storageManager: StorageManager,
module: ModuleDescriptor
): PackageFragmentProvider {
val classFactory = BuiltInFictitiousFunctionClassFactory(storageManager, module)
val fragments = listOf(
KOTLIN_REFLECT_FQ_NAME,
KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME,
COROUTINES_PACKAGE_FQ_NAME_RELEASE
).map { fqName ->
FunctionInterfacePackageFragmentImpl(classFactory, module, fqName)
}
return PackageFragmentProviderImpl(fragments)
}
@@ -44,7 +44,7 @@ fun createTopDownAnalyzerForJs(
languageVersionSettings: LanguageVersionSettings,
lookupTracker: LookupTracker,
expectActualTracker: ExpectActualTracker,
fallbackPackage: PackageFragmentProvider?
additionalPackages: List<PackageFragmentProvider>
): LazyTopDownAnalyzer {
val storageComponentContainer = createContainer("TopDownAnalyzerForJs", JsPlatform) {
configureModule(moduleContext, JsPlatform, TargetPlatformVersion.NoVersion, bindingTrace)
@@ -62,7 +62,7 @@ fun createTopDownAnalyzerForJs(
}.apply {
val packagePartProviders = mutableListOf(get<KotlinCodeAnalyzer>().packageFragmentProvider)
val moduleDescriptor = get<ModuleDescriptorImpl>()
fallbackPackage?.let { packagePartProviders += it }
packagePartProviders += additionalPackages
moduleDescriptor.initialize(CompositePackageFragmentProvider(packagePartProviders))
}
return storageComponentContainer.get<LazyTopDownAnalyzer>()
@@ -6,12 +6,15 @@
package org.jetbrains.kotlin.js.analyze
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.functions.functionInterfacePackageFragmentProvider
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.context.ContextForNewModule
import org.jetbrains.kotlin.context.ModuleContext
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.frontend.js.di.createTopDownAnalyzerForJs
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
@@ -45,31 +48,55 @@ object TopDownAnalyzerFacadeForJS {
project: Project,
configuration: CompilerConfiguration,
moduleDescriptors: List<ModuleDescriptorImpl>,
friendModuleDescriptors: List<ModuleDescriptorImpl>
friendModuleDescriptors: List<ModuleDescriptorImpl>,
thisIsBuiltInsModule: Boolean = false,
customBuiltInsModule: ModuleDescriptorImpl? = null
): JsAnalysisResult {
require(!thisIsBuiltInsModule || customBuiltInsModule == null) {
"Can't simultaneously use custom built-ins module and set current module as built-ins"
}
val projectContext = ProjectContext(project)
val builtIns = if (thisIsBuiltInsModule || customBuiltInsModule != null) {
object : KotlinBuiltIns(projectContext.storageManager) {}
} else {
JsPlatform.builtIns
}
val moduleName = configuration[CommonConfigurationKeys.MODULE_NAME]!!
val context = ContextForNewModule(ProjectContext(project), Name.special("<$moduleName>"), JsPlatform.builtIns, null)
context.module.setDependencies(
listOf(context.module) +
moduleDescriptors +
listOf(JsPlatform.builtIns.builtInsModule),
friendModuleDescriptors.toSet()
val context = ContextForNewModule(
projectContext,
Name.special("<$moduleName>"),
builtIns,
multiTargetPlatform = null
)
val additionalPackages = mutableListOf<PackageFragmentProvider>()
if (customBuiltInsModule != null) {
builtIns.builtInsModule = customBuiltInsModule
}
if (thisIsBuiltInsModule) {
builtIns.builtInsModule = context.module
additionalPackages += functionInterfacePackageFragmentProvider(context.storageManager, context.module)
}
val dependencies = mutableSetOf(context.module) + moduleDescriptors + builtIns.builtInsModule
context.module.setDependencies(dependencies.toList(), friendModuleDescriptors.toSet())
val moduleKind = configuration.get(JSConfigurationKeys.MODULE_KIND, ModuleKind.PLAIN)
val trace = BindingTraceContext()
trace.record(MODULE_KIND, context.module, moduleKind)
return analyzeFilesWithGivenTrace(files, trace, context, configuration)
return analyzeFilesWithGivenTrace(files, trace, context, configuration, additionalPackages)
}
fun analyzeFilesWithGivenTrace(
files: Collection<KtFile>,
trace: BindingTrace,
moduleContext: ModuleContext,
configuration: CompilerConfiguration
configuration: CompilerConfiguration,
additionalPackages: List<PackageFragmentProvider> = emptyList()
): JsAnalysisResult {
val lookupTracker = configuration.get(CommonConfigurationKeys.LOOKUP_TRACKER) ?: LookupTracker.DO_NOTHING
val expectActualTracker = configuration.get(CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER) ?: ExpectActualTracker.DoNothing
@@ -91,7 +118,7 @@ object TopDownAnalyzerFacadeForJS {
languageVersionSettings,
lookupTracker,
expectActualTracker,
packageFragment
additionalPackages + listOfNotNull(packageFragment)
)
analyzerForJs.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, files)
return JsAnalysisResult.success(trace, moduleContext.module)
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.js.test
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.ir.backend.js.Result
import org.jetbrains.kotlin.ir.backend.js.compile
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
@@ -13,6 +14,7 @@ import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.MainCallParameters
import org.jetbrains.kotlin.js.facade.TranslationUnit
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TargetBackend
import java.io.File
@@ -112,7 +114,8 @@ abstract class BasicIrBoxTest(
config.configuration,
FqName((testPackage?.let { "$it." } ?: "") + testFunction),
dependencies,
irDependencies
irDependencies,
runtimeResult.moduleDescriptor as ModuleDescriptorImpl
)
compilationCache[outputFile.name.replace(".js", ".meta.js")] = result
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.js.test
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
private const val runtimeDir = "js/js.translator/testData/out/irBox"
@@ -26,6 +27,29 @@ enum class JsIrTestRuntime(
)
}
// Required to compile native builtins with the rest of runtime
private const val builtInsHeader = """@file:Suppress(
"NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
"MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
"EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
"PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
"WRONG_MODIFIER_TARGET"
)
"""
// Native builtins that were not implemented in JS IR runtime
private val unimplementedNativeBuiltInsDir = KotlinTestUtils.tmpDir("unimplementedBuiltins").also { tmpDir ->
val allBuiltins = listOfKtFilesFrom("core/builtins/native/kotlin").map { File(it).name }
val implementedBuiltIns = listOfKtFilesFrom("libraries/stdlib/js/irRuntime/builtins/").map { File(it).name }
val unimplementedBuiltIns = allBuiltins - implementedBuiltIns
for (filename in unimplementedBuiltIns) {
val originalFile = File("core/builtins/native/kotlin", filename)
val newFile = File(tmpDir, filename)
val sourceCode = builtInsHeader + originalFile.readText()
newFile.writeText(sourceCode)
}
}
private val fullRuntimeSources = listOfKtFilesFrom(
"core/builtins/src/kotlin",
"libraries/stdlib/common/src",
@@ -36,15 +60,8 @@ private val fullRuntimeSources = listOfKtFilesFrom(
"libraries/stdlib/js/runtime",
"libraries/stdlib/unsigned",
"core/builtins/native/kotlin/Annotation.kt",
"core/builtins/native/kotlin/Number.kt",
"core/builtins/native/kotlin/Comparable.kt",
"core/builtins/native/kotlin/Collections.kt",
"core/builtins/native/kotlin/Iterator.kt",
"core/builtins/native/kotlin/CharSequence.kt",
"core/builtins/src/kotlin/Unit.kt",
unimplementedNativeBuiltInsDir.path,
BasicBoxTest.COMMON_FILES_DIR_PATH
) - listOfKtFilesFrom(
"libraries/stdlib/common/src/kotlin/JvmAnnotationsH.kt",
@@ -102,10 +119,6 @@ private val fullRuntimeSources = listOfKtFilesFrom(
val reducedRuntimeSources = fullRuntimeSources - listOfKtFilesFrom(
"libraries/stdlib/unsigned",
"core/builtins/src/kotlin/reflect/KParameter.kt",
"core/builtins/src/kotlin/reflect/KType.kt",
"core/builtins/src/kotlin/reflect/KTypeParameter.kt",
"core/builtins/src/kotlin/reflect/KVisibility.kt",
"libraries/stdlib/common/src/generated/_Arrays.kt",
"libraries/stdlib/common/src/generated/_Collections.kt",
"libraries/stdlib/common/src/generated/_Maps.kt",
-31
View File
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2018 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 kotlin
import kotlin.js.*
abstract class Enum<E : Enum<E>>(val name: String, val ordinal: Int) : Comparable<E> {
override fun compareTo(other: E) = ordinal.compareTo(other.ordinal)
override fun equals(other: Any?) = this === other
override fun hashCode(): Int = identityHashCode(this)
override fun toString() = name
companion object
}
// Use non-inline calls to enumValuesIntrinsic and enumValueOfIntrinsic calls in order
// for compiler to replace them with method calls of concrete enum classes after inlining.
// TODO: Figure out better solution (Inline hacks? Dynamic calls to stable mangled names?)
@SinceKotlin("1.1")
public inline fun <reified T : Enum<T>> enumValues(): Array<T> = enumValuesIntrinsic<T>()
@SinceKotlin("1.1")
public inline fun <reified T : Enum<T>> enumValueOf(name: String): T = enumValueOfIntrinsic<T>(name)
@@ -0,0 +1,204 @@
/*
* Copyright 2010-2018 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.
*/
@file:Suppress(
"NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
"MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
"EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
"PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
"WRONG_MODIFIER_TARGET"
)
package kotlin
/**
* An array of bytes. When targeting the JVM, instances of this class are represented as `byte[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class ByteArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Byte)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Byte
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Byte): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): ByteIterator
}
/**
* An array of chars. When targeting the JVM, instances of this class are represented as `char[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to null char (`\u0000').
*/
public class CharArray(size: Int) {
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Char
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Char): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): CharIterator
}
@kotlin.internal.InlineOnly
public inline fun CharArray(size: Int, init: (Int) -> Char): CharArray {
val result = CharArray(size)
var i = 0
while (i != result.size) {
result[i] = init(i)
++i
}
return result
}
/**
* An array of shorts. When targeting the JVM, instances of this class are represented as `short[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class ShortArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Short)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Short
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Short): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): ShortIterator
}
/**
* An array of ints. When targeting the JVM, instances of this class are represented as `int[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class IntArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Int)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Int
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Int): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): IntIterator
}
/**
* An array of longs. When targeting the JVM, instances of this class are represented as `long[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class LongArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Long)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Long
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Long): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): LongIterator
}
/**
* An array of floats. When targeting the JVM, instances of this class are represented as `float[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class FloatArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Float)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Float
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Float): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): FloatIterator
}
/**
* An array of doubles. When targeting the JVM, instances of this class are represented as `double[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class DoubleArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Double)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Double
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Double): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): DoubleIterator
}
/**
* An array of booleans. When targeting the JVM, instances of this class are represented as `boolean[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to `false`.
*/
public class BooleanArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Boolean)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Boolean
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Boolean): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): BooleanIterator
}
@@ -0,0 +1,21 @@
/*
* 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 kotlin
import kotlin.js.*
abstract class Enum<E : Enum<E>>(val name: String, val ordinal: Int) : Comparable<E> {
override fun compareTo(other: E) = ordinal.compareTo(other.ordinal)
override fun equals(other: Any?) = this === other
override fun hashCode(): Int = identityHashCode(this)
override fun toString() = name
companion object
}
@@ -0,0 +1,88 @@
/*
* 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 kotlin
import kotlin.internal.PureReifiable
/**
* Returns a string representation of the object. Can be called with a null receiver, in which case
* it returns the string "null".
*/
public fun Any?.toString(): String = this?.toString() ?: "null"
/**
* Concatenates this string with the string representation of the given [other] object. If either the receiver
* or the [other] object are null, they are represented as the string "null".
*/
public operator fun String?.plus(other: Any?): String =
(this?.toString() ?: "null").plus(other?.toString() ?: "null")
/**
* Returns an array of objects of the given type with the given [size], initialized with null values.
*/
public inline fun <reified T> arrayOfNulls(size: Int): Array<T?> = Array<T?>(size)
/**
* Returns an array containing the specified elements.
*/
public inline fun <T> arrayOf(vararg elements: T): Array<T> = elements.unsafeCast<Array<T>>()
/**
* Returns an array containing the specified [Double] numbers.
*/
public inline fun doubleArrayOf(vararg elements: Double): DoubleArray = elements
/**
* Returns an array containing the specified [Float] numbers.
*/
public inline fun floatArrayOf(vararg elements: Float): FloatArray = elements
/**
* Returns an array containing the specified [Long] numbers.
*/
public inline fun longArrayOf(vararg elements: Long): LongArray = elements
/**
* Returns an array containing the specified [Int] numbers.
*/
public inline fun intArrayOf(vararg elements: Int): IntArray = elements
/**
* Returns an array containing the specified characters.
*/
public inline fun charArrayOf(vararg elements: Char): CharArray = elements
/**
* Returns an array containing the specified [Short] numbers.
*/
public inline fun shortArrayOf(vararg elements: Short): ShortArray = elements
/**
* Returns an array containing the specified [Byte] numbers.
*/
public inline fun byteArrayOf(vararg elements: Byte): ByteArray = elements
/**
* Returns an array containing the specified boolean values.
*/
public inline fun booleanArrayOf(vararg elements: Boolean): BooleanArray = elements
// Use non-inline calls to enumValuesIntrinsic and enumValueOfIntrinsic calls in order
// for compiler to replace them with method calls of concrete enum classes after inlining.
// TODO: Figure out better solution (Inline hacks? Dynamic calls to stable mangled names?)
/**
* Returns an array containing enum T entries.
*/
@SinceKotlin("1.1")
public inline fun <reified T : Enum<T>> enumValues(): Array<T> = enumValuesIntrinsic<T>()
/**
* Returns an enum entry with specified name.
*/
@SinceKotlin("1.1")
public inline fun <reified T : Enum<T>> enumValueOf(name: String): T = enumValueOfIntrinsic<T>(name)
@@ -0,0 +1,965 @@
/*
* Copyright 2010-2018 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.
*/
// Auto-generated file. DO NOT EDIT!
@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY")
package kotlin
/**
* Represents a 8-bit signed integer.
* On the JVM, non-nullable values of this type are represented as values of the primitive type `byte`.
*/
public class Byte private constructor() : Number(), Comparable<Byte> {
companion object {
/**
* A constant holding the minimum value an instance of Byte can have.
*/
public const val MIN_VALUE: Byte = -128
/**
* A constant holding the maximum value an instance of Byte can have.
*/
public const val MAX_VALUE: Byte = 127
/**
* The number of bytes used to represent an instance of Byte in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BYTES: Int = 1
/**
* The number of bits used to represent an instance of Byte in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BITS: Int = 8
}
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: Byte): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Short): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Int): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Long): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Float): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Double): Int
/** Adds the other value to this value. */
public operator fun plus(other: Byte): Int
/** Adds the other value to this value. */
public operator fun plus(other: Short): Int
/** Adds the other value to this value. */
public operator fun plus(other: Int): Int
/** Adds the other value to this value. */
public operator fun plus(other: Long): Long
/** Adds the other value to this value. */
public operator fun plus(other: Float): Float
/** Adds the other value to this value. */
public operator fun plus(other: Double): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Byte): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Short): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Int): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Long): Long
/** Subtracts the other value from this value. */
public operator fun minus(other: Float): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Double): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Byte): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Short): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Int): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Long): Long
/** Multiplies this value by the other value. */
public operator fun times(other: Float): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Double): Double
/** Divides this value by the other value. */
public operator fun div(other: Byte): Int
/** Divides this value by the other value. */
public operator fun div(other: Short): Int
/** Divides this value by the other value. */
public operator fun div(other: Int): Int
/** Divides this value by the other value. */
public operator fun div(other: Long): Long
/** Divides this value by the other value. */
public operator fun div(other: Float): Float
/** Divides this value by the other value. */
public operator fun div(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Byte): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Short): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Int): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Long): Long
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Byte): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Short): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Int): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Long): Long
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Double): Double
/** Increments this value. */
public operator fun inc(): Byte
/** Decrements this value. */
public operator fun dec(): Byte
/** Returns this value. */
public operator fun unaryPlus(): Int
/** Returns the negative of this value. */
public operator fun unaryMinus(): Int
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
public override fun toByte(): Byte
public override fun toChar(): Char
public override fun toShort(): Short
public override fun toInt(): Int
public override fun toLong(): Long
public override fun toFloat(): Float
public override fun toDouble(): Double
}
/**
* Represents a 16-bit signed integer.
* On the JVM, non-nullable values of this type are represented as values of the primitive type `short`.
*/
public class Short private constructor() : Number(), Comparable<Short> {
companion object {
/**
* A constant holding the minimum value an instance of Short can have.
*/
public const val MIN_VALUE: Short = -32768
/**
* A constant holding the maximum value an instance of Short can have.
*/
public const val MAX_VALUE: Short = 32767
/**
* The number of bytes used to represent an instance of Short in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BYTES: Int = 2
/**
* The number of bits used to represent an instance of Short in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BITS: Int = 16
}
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Byte): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: Short): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Int): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Long): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Float): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Double): Int
/** Adds the other value to this value. */
public operator fun plus(other: Byte): Int
/** Adds the other value to this value. */
public operator fun plus(other: Short): Int
/** Adds the other value to this value. */
public operator fun plus(other: Int): Int
/** Adds the other value to this value. */
public operator fun plus(other: Long): Long
/** Adds the other value to this value. */
public operator fun plus(other: Float): Float
/** Adds the other value to this value. */
public operator fun plus(other: Double): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Byte): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Short): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Int): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Long): Long
/** Subtracts the other value from this value. */
public operator fun minus(other: Float): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Double): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Byte): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Short): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Int): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Long): Long
/** Multiplies this value by the other value. */
public operator fun times(other: Float): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Double): Double
/** Divides this value by the other value. */
public operator fun div(other: Byte): Int
/** Divides this value by the other value. */
public operator fun div(other: Short): Int
/** Divides this value by the other value. */
public operator fun div(other: Int): Int
/** Divides this value by the other value. */
public operator fun div(other: Long): Long
/** Divides this value by the other value. */
public operator fun div(other: Float): Float
/** Divides this value by the other value. */
public operator fun div(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Byte): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Short): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Int): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Long): Long
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Byte): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Short): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Int): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Long): Long
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Double): Double
/** Increments this value. */
public operator fun inc(): Short
/** Decrements this value. */
public operator fun dec(): Short
/** Returns this value. */
public operator fun unaryPlus(): Int
/** Returns the negative of this value. */
public operator fun unaryMinus(): Int
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
public override fun toByte(): Byte
public override fun toChar(): Char
public override fun toShort(): Short
public override fun toInt(): Int
public override fun toLong(): Long
public override fun toFloat(): Float
public override fun toDouble(): Double
}
/**
* Represents a 32-bit signed integer.
* On the JVM, non-nullable values of this type are represented as values of the primitive type `int`.
*/
public class Int private constructor() : Number(), Comparable<Int> {
companion object {
/**
* A constant holding the minimum value an instance of Int can have.
*/
public const val MIN_VALUE: Int = -2147483648
/**
* A constant holding the maximum value an instance of Int can have.
*/
public const val MAX_VALUE: Int = 2147483647
/**
* The number of bytes used to represent an instance of Int in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BYTES: Int = 4
/**
* The number of bits used to represent an instance of Int in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BITS: Int = 32
}
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Byte): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Short): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: Int): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Long): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Float): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Double): Int
/** Adds the other value to this value. */
public operator fun plus(other: Byte): Int
/** Adds the other value to this value. */
public operator fun plus(other: Short): Int
/** Adds the other value to this value. */
public operator fun plus(other: Int): Int
/** Adds the other value to this value. */
public operator fun plus(other: Long): Long
/** Adds the other value to this value. */
public operator fun plus(other: Float): Float
/** Adds the other value to this value. */
public operator fun plus(other: Double): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Byte): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Short): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Int): Int
/** Subtracts the other value from this value. */
public operator fun minus(other: Long): Long
/** Subtracts the other value from this value. */
public operator fun minus(other: Float): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Double): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Byte): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Short): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Int): Int
/** Multiplies this value by the other value. */
public operator fun times(other: Long): Long
/** Multiplies this value by the other value. */
public operator fun times(other: Float): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Double): Double
/** Divides this value by the other value. */
public operator fun div(other: Byte): Int
/** Divides this value by the other value. */
public operator fun div(other: Short): Int
/** Divides this value by the other value. */
public operator fun div(other: Int): Int
/** Divides this value by the other value. */
public operator fun div(other: Long): Long
/** Divides this value by the other value. */
public operator fun div(other: Float): Float
/** Divides this value by the other value. */
public operator fun div(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Byte): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Short): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Int): Int
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Long): Long
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Byte): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Short): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Int): Int
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Long): Long
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Double): Double
/** Increments this value. */
public operator fun inc(): Int
/** Decrements this value. */
public operator fun dec(): Int
/** Returns this value. */
public operator fun unaryPlus(): Int
/** Returns the negative of this value. */
public operator fun unaryMinus(): Int
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
/** Shifts this value left by the [bitCount] number of bits. */
public infix fun shl(bitCount: Int): Int
/** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with copies of the sign bit. */
public infix fun shr(bitCount: Int): Int
/** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */
public infix fun ushr(bitCount: Int): Int
/** Performs a bitwise AND operation between the two values. */
public infix fun and(other: Int): Int
/** Performs a bitwise OR operation between the two values. */
public infix fun or(other: Int): Int
/** Performs a bitwise XOR operation between the two values. */
public infix fun xor(other: Int): Int
/** Inverts the bits in this value. */
public fun inv(): Int
public override fun toByte(): Byte
public override fun toChar(): Char
public override fun toShort(): Short
public override fun toInt(): Int
public override fun toLong(): Long
public override fun toFloat(): Float
public override fun toDouble(): Double
}
/**
* Represents a single-precision 32-bit IEEE 754 floating point number.
* On the JVM, non-nullable values of this type are represented as values of the primitive type `float`.
*/
public class Float private constructor() : Number(), Comparable<Float> {
companion object {
/**
* A constant holding the smallest *positive* nonzero value of Float.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val MIN_VALUE: Float
/**
* A constant holding the largest positive finite value of Float.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val MAX_VALUE: Float
/**
* A constant holding the positive infinity value of Float.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val POSITIVE_INFINITY: Float
/**
* A constant holding the negative infinity value of Float.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val NEGATIVE_INFINITY: Float
/**
* A constant holding the "not a number" value of Float.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val NaN: Float
}
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Byte): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Short): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Int): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Long): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: Float): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Double): Int
/** Adds the other value to this value. */
public operator fun plus(other: Byte): Float
/** Adds the other value to this value. */
public operator fun plus(other: Short): Float
/** Adds the other value to this value. */
public operator fun plus(other: Int): Float
/** Adds the other value to this value. */
public operator fun plus(other: Long): Float
/** Adds the other value to this value. */
public operator fun plus(other: Float): Float
/** Adds the other value to this value. */
public operator fun plus(other: Double): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Byte): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Short): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Int): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Long): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Float): Float
/** Subtracts the other value from this value. */
public operator fun minus(other: Double): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Byte): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Short): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Int): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Long): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Float): Float
/** Multiplies this value by the other value. */
public operator fun times(other: Double): Double
/** Divides this value by the other value. */
public operator fun div(other: Byte): Float
/** Divides this value by the other value. */
public operator fun div(other: Short): Float
/** Divides this value by the other value. */
public operator fun div(other: Int): Float
/** Divides this value by the other value. */
public operator fun div(other: Long): Float
/** Divides this value by the other value. */
public operator fun div(other: Float): Float
/** Divides this value by the other value. */
public operator fun div(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Byte): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Short): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Int): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Long): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Byte): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Short): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Int): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Long): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Float): Float
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Double): Double
/** Increments this value. */
public operator fun inc(): Float
/** Decrements this value. */
public operator fun dec(): Float
/** Returns this value. */
public operator fun unaryPlus(): Float
/** Returns the negative of this value. */
public operator fun unaryMinus(): Float
public override fun toByte(): Byte
public override fun toChar(): Char
public override fun toShort(): Short
public override fun toInt(): Int
public override fun toLong(): Long
public override fun toFloat(): Float
public override fun toDouble(): Double
}
/**
* Represents a double-precision 64-bit IEEE 754 floating point number.
* On the JVM, non-nullable values of this type are represented as values of the primitive type `double`.
*/
public class Double private constructor() : Number(), Comparable<Double> {
companion object {
/**
* A constant holding the smallest *positive* nonzero value of Double.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val MIN_VALUE: Double
/**
* A constant holding the largest positive finite value of Double.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val MAX_VALUE: Double
/**
* A constant holding the positive infinity value of Double.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val POSITIVE_INFINITY: Double
/**
* A constant holding the negative infinity value of Double.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val NEGATIVE_INFINITY: Double
/**
* A constant holding the "not a number" value of Double.
*/
@Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT")
public val NaN: Double
}
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Byte): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Short): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Int): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Long): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: Float): Int
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: Double): Int
/** Adds the other value to this value. */
public operator fun plus(other: Byte): Double
/** Adds the other value to this value. */
public operator fun plus(other: Short): Double
/** Adds the other value to this value. */
public operator fun plus(other: Int): Double
/** Adds the other value to this value. */
public operator fun plus(other: Long): Double
/** Adds the other value to this value. */
public operator fun plus(other: Float): Double
/** Adds the other value to this value. */
public operator fun plus(other: Double): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Byte): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Short): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Int): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Long): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Float): Double
/** Subtracts the other value from this value. */
public operator fun minus(other: Double): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Byte): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Short): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Int): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Long): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Float): Double
/** Multiplies this value by the other value. */
public operator fun times(other: Double): Double
/** Divides this value by the other value. */
public operator fun div(other: Byte): Double
/** Divides this value by the other value. */
public operator fun div(other: Short): Double
/** Divides this value by the other value. */
public operator fun div(other: Int): Double
/** Divides this value by the other value. */
public operator fun div(other: Long): Double
/** Divides this value by the other value. */
public operator fun div(other: Float): Double
/** Divides this value by the other value. */
public operator fun div(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Byte): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Short): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Int): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Long): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Float): Double
/** Calculates the remainder of dividing this value by the other value. */
@Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.ERROR)
public operator fun mod(other: Double): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Byte): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Short): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Int): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Long): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Float): Double
/** Calculates the remainder of dividing this value by the other value. */
@SinceKotlin("1.1")
public operator fun rem(other: Double): Double
/** Increments this value. */
public operator fun inc(): Double
/** Decrements this value. */
public operator fun dec(): Double
/** Returns this value. */
public operator fun unaryPlus(): Double
/** Returns the negative of this value. */
public operator fun unaryMinus(): Double
public override fun toByte(): Byte
public override fun toChar(): Char
public override fun toShort(): Short
public override fun toInt(): Int
public override fun toLong(): Long
public override fun toFloat(): Float
public override fun toDouble(): Double
}
-39
View File
@@ -5,45 +5,6 @@
package kotlin
// TODO: Ignore FunctionN interfaces
public interface Function0<out R> : Function<R> {
public operator fun invoke(): R
}
public interface Function1<in P1, out R> : Function<R> {
public operator fun invoke(p1: P1): R
}
public interface Function2<in P1, in P2, out R> : Function<R> {
public operator fun invoke(p1: P1, p2: P2): R
}
public interface Function3<in P1, in P2, in P3, out R> : Function<R> {
public operator fun invoke(p1: P1, p2: P2, p3: P3): R
}
public inline fun <reified T> arrayOfNulls(size: Int): Array<T?> = Array<T?>(size)
public inline fun <T> arrayOf(vararg a: T): Array<T> = a.unsafeCast<Array<T>>()
public inline fun booleanArrayOf(vararg a: Boolean) = a
public inline fun byteArrayOf(vararg a: Byte) = a
public inline fun shortArrayOf(vararg a: Short) = a
public inline fun charArrayOf(vararg a: Char) = a
public inline fun intArrayOf(vararg a: Int) = a
public inline fun floatArrayOf(vararg a: Float) = a
public inline fun doubleArrayOf(vararg a: Double) = a
public inline fun longArrayOf(vararg a: Long) = a
@PublishedApi
internal fun throwUninitializedPropertyAccessException(name: String): Nothing =
throw UninitializedPropertyAccessException("lateinit property $name has not been initialized")