Gross stdlib cleanup (part 1). (#1918)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
package kotlinx.wasm.jsinterop
|
||||
|
||||
import kotlin.native.*
|
||||
import kotlin.native.internal.ExportForCppRuntime
|
||||
import kotlinx.cinterop.*
|
||||
@@ -28,15 +29,15 @@ typealias Pointer = Int
|
||||
* from internalization and DCE
|
||||
*/
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_allocateArena")
|
||||
external public fun allocateArena(): Arena
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_freeArena")
|
||||
external public fun freeArena(arena: Arena)
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_pushIntToArena")
|
||||
external public fun pushIntToArena(arena: Arena, value: Int)
|
||||
|
||||
@@ -50,15 +51,15 @@ fun doubleUpper(value: Double): Int =
|
||||
fun doubleLower(value: Double): Int =
|
||||
(value.toBits() and 0x00000000ffffffff) .toInt()
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("ReturnSlot_getDouble")
|
||||
external public fun ReturnSlot_getDouble(): Double
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Kotlin_String_utf16pointer")
|
||||
external public fun stringPointer(message: String): Pointer
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Kotlin_String_utf16length")
|
||||
external public fun stringLengthBytes(message: String): Int
|
||||
|
||||
@@ -69,7 +70,7 @@ fun <R> wrapFunction(func: KtFunction<R>): Int {
|
||||
return ptr.toInt() // TODO: LP64 unsafe.
|
||||
}
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@ExportForCppRuntime("Konan_js_runLambda")
|
||||
fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int {
|
||||
val arguments = arrayListOf<JsValue>()
|
||||
@@ -105,19 +106,19 @@ open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
|
||||
get() = this.getInt("length")
|
||||
}
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_getInt")
|
||||
external public fun getInt(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_getProperty")
|
||||
external public fun Konan_js_getProperty(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_setFunction")
|
||||
external public fun setFunction(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int , function: Int)
|
||||
|
||||
@Used
|
||||
@Retain
|
||||
@SymbolName("Konan_js_setString")
|
||||
external public fun setString(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int, stringPtr: Pointer, stringLength: Int )
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
package kotlinx.cinterop
|
||||
|
||||
import kotlin.native.internal.getNativeNullPtr
|
||||
import kotlin.native.internal.Intrinsic
|
||||
import kotlin.native.internal.reinterpret
|
||||
import kotlin.native.internal.Intrinsic
|
||||
import kotlin.native.internal.VolatileLambda
|
||||
|
||||
typealias NativePtr = kotlin.native.internal.NativePtr
|
||||
internal typealias NonNullNativePtr = kotlin.native.internal.NonNullNativePtr
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package kotlinx.cinterop
|
||||
import kotlin.native.*
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
|
||||
interface ObjCObject
|
||||
interface ObjCClass : ObjCObject
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ private val cKeywords = setOf(
|
||||
"xor_eq"
|
||||
)
|
||||
|
||||
private val cnameAnnotation = FqName("kotlin.native.internal.CName")
|
||||
private val cnameAnnotation = FqName("kotlin.native.CName")
|
||||
|
||||
private fun org.jetbrains.kotlin.types.KotlinType.isGeneric() =
|
||||
constructor.declarationDescriptor is TypeParameterDescriptor
|
||||
|
||||
+2
-2
@@ -291,8 +291,8 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
val nativePtrPlusLong by lazy { nativePtr.unsubstitutedMemberScope.getContributedFunctions("plus").single() }
|
||||
val nativePtrToLong by lazy { nativePtr.unsubstitutedMemberScope.getContributedFunctions("toLong").single() }
|
||||
val getNativeNullPtr by lazy { packageScope.getContributedFunctions("getNativeNullPtr").single() }
|
||||
val immutableBinaryBlobOf by lazy {
|
||||
builtIns.builtInsModule.getPackage(KonanFqNames.packageName).memberScope.getContributedFunctions("immutableBinaryBlobOf").single()
|
||||
val immutableBlobOf by lazy {
|
||||
builtIns.builtInsModule.getPackage(KonanFqNames.packageName).memberScope.getContributedFunctions("immutableBlobOf").single()
|
||||
}
|
||||
|
||||
val specialDeclarationsFactory = SpecialDeclarationsFactory(this)
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ internal val arrayTypes = setOf(
|
||||
"kotlin.FloatArray",
|
||||
"kotlin.DoubleArray",
|
||||
"kotlin.BooleanArray",
|
||||
"kotlin.native.ImmutableBinaryBlob"
|
||||
"kotlin.native.ImmutableBlob"
|
||||
)
|
||||
|
||||
|
||||
|
||||
+2
-4
@@ -200,14 +200,12 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
|
||||
it to symbolTable.referenceSimpleFunction(context.getInternalFunctions(name).single())
|
||||
}
|
||||
|
||||
val immutableBinaryBlob = symbolTable.referenceClass(
|
||||
val immutableBlob = symbolTable.referenceClass(
|
||||
builtInsPackage("kotlin", "native").getContributedClassifier(
|
||||
Name.identifier("ImmutableBinaryBlob"), NoLookupLocation.FROM_BACKEND
|
||||
Name.identifier("ImmutableBlob"), NoLookupLocation.FROM_BACKEND
|
||||
) as ClassDescriptor
|
||||
)
|
||||
|
||||
val immutableBinaryBlobOf = symbolTable.referenceSimpleFunction(context.immutableBinaryBlobOf)
|
||||
|
||||
val scheduleImpl = symbolTable.referenceSimpleFunction(context.interopBuiltIns.scheduleImplFunction)
|
||||
|
||||
val areEqualByValue = context.getInternalFunctions("areEqualByValue").map {
|
||||
|
||||
+3
-9
@@ -69,9 +69,6 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
if (descriptorAnnotations.hasAnnotation(publishedApiAnnotation)){
|
||||
return true
|
||||
}
|
||||
if (descriptorAnnotations.hasAnnotation(inlineExposedAnnotation)){
|
||||
return true
|
||||
}
|
||||
|
||||
if (this.isAnonymousObject)
|
||||
return false
|
||||
@@ -87,8 +84,7 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
// TODO: this code is required because accessor doesn't have a reference to property.
|
||||
if (descriptor is PropertyAccessorDescriptor) {
|
||||
val property = descriptor.correspondingProperty
|
||||
if (property.annotations.hasAnnotation(inlineExposedAnnotation) ||
|
||||
property.annotations.hasAnnotation(publishedApiAnnotation)) return true
|
||||
if (property.annotations.hasAnnotation(publishedApiAnnotation)) return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,16 +115,14 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
|
||||
private val symbolNameAnnotation = FqName("kotlin.native.SymbolName")
|
||||
|
||||
private val exportForCppRuntimeAnnotation = FqName("kotlin.native.internal.ExportForCppRuntime")
|
||||
private val cnameAnnotation = FqName("kotlin.native.CName")
|
||||
|
||||
private val cnameAnnotation = FqName("kotlin.native.internal.CName")
|
||||
private val exportForCppRuntimeAnnotation = FqName("kotlin.native.internal.ExportForCppRuntime")
|
||||
|
||||
private val exportForCompilerAnnotation = FqName("kotlin.native.internal.ExportForCompiler")
|
||||
|
||||
private val publishedApiAnnotation = FqName("kotlin.PublishedApi")
|
||||
|
||||
private val inlineExposedAnnotation = FqName("kotlin.internal.InlineExposed")
|
||||
|
||||
private fun acyclicTypeMangler(visited: MutableSet<TypeParameterDescriptor>, type: IrType): String {
|
||||
val descriptor = (type.classifierOrNull as? IrTypeParameterSymbol)?.owner
|
||||
if (descriptor != null) {
|
||||
|
||||
+2
-2
@@ -1745,10 +1745,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
||||
return receiver
|
||||
}
|
||||
|
||||
context.immutableBinaryBlobOf -> {
|
||||
context.immutableBlobOf -> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val arg = expression.getValueArgument(0) as IrConst<String>
|
||||
return context.llvm.staticData.createImmutableBinaryBlob(arg)
|
||||
return context.llvm.staticData.createImmutableBlob(arg)
|
||||
}
|
||||
|
||||
context.ir.symbols.initInstance.descriptor -> {
|
||||
|
||||
+5
-3
@@ -97,11 +97,13 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
staticData.kotlinStringLiteral(string)
|
||||
}
|
||||
|
||||
private val EXPORT_TYPE_INFO_FQ_NAME = FqName.fromSegments(listOf("kotlin", "native", "internal", "ExportTypeInfo"))
|
||||
|
||||
private fun exportTypeInfoIfRequired(classDesc: ClassDescriptor, typeInfoGlobal: LLVMValueRef?) {
|
||||
val annot = classDesc.descriptor.annotations.findAnnotation(FqName("kotlin.native.ExportTypeInfo"))
|
||||
val annot = classDesc.descriptor.annotations.findAnnotation(EXPORT_TYPE_INFO_FQ_NAME)
|
||||
if (annot != null) {
|
||||
val name = getStringValue(annot)!!
|
||||
// TODO: use LLVMAddAlias?
|
||||
// TODO: use LLVMAddAlias.
|
||||
val global = addGlobal(name, pointerType(runtime.typeInfoType), isExported = true)
|
||||
LLVMSetInitializer(global, typeInfoGlobal)
|
||||
}
|
||||
@@ -118,7 +120,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
"kotlin.DoubleArray" to LLVMDoubleType()!!,
|
||||
"kotlin.BooleanArray" to LLVMInt8Type()!!,
|
||||
"kotlin.String" to LLVMInt16Type()!!,
|
||||
"kotlin.native.ImmutableBinaryBlob" to LLVMInt8Type()!!
|
||||
"kotlin.native.ImmutableBlob" to LLVMInt8Type()!!
|
||||
)
|
||||
|
||||
// Keep in sync with Konan_RuntimeType.
|
||||
|
||||
+2
-2
@@ -183,7 +183,7 @@ internal class StaticData(override val context: Context): ContextUtils {
|
||||
*
|
||||
* @param args data for constant creation.
|
||||
*/
|
||||
internal fun StaticData.createImmutableBinaryBlob(value: IrConst<String>): LLVMValueRef {
|
||||
internal fun StaticData.createImmutableBlob(value: IrConst<String>): LLVMValueRef {
|
||||
val args = value.value.map { Int8(it.toByte()).llvm }
|
||||
return createKotlinArray(context.ir.symbols.immutableBinaryBlob.owner, args)
|
||||
return createKotlinArray(context.ir.symbols.immutableBlob.owner, args)
|
||||
}
|
||||
+2
-2
@@ -107,7 +107,7 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
||||
val argumentDescriptor = descriptor.valueParameters.singleOrNull {
|
||||
cur.getValueArgument(it.index) == argument
|
||||
}
|
||||
if (argumentDescriptor != null && argumentDescriptor.annotations.findAnnotation(FqName("kotlin.native.VolatileLambda")) != null) {
|
||||
if (argumentDescriptor?.annotations?.findAnnotation(VOLATILE_LAMBDA_FQ_NAME) != null) {
|
||||
return expression
|
||||
}
|
||||
break
|
||||
@@ -141,9 +141,9 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
||||
val functionReferenceConstructor: IrConstructor)
|
||||
|
||||
private val COROUTINES_FQ_NAME = FqName.fromSegments(listOf("kotlin", "coroutines", "experimental"))
|
||||
private val VOLATILE_LAMBDA_FQ_NAME = FqName.fromSegments(listOf("kotlin", "native", "internal", "VolatileLambda"))
|
||||
|
||||
private val coroutinesScope = context.irModule!!.descriptor.getPackage(COROUTINES_FQ_NAME).memberScope
|
||||
private val kotlinPackageScope = context.builtIns.builtInsPackageScope
|
||||
|
||||
private val continuationClassDescriptor = coroutinesScope
|
||||
.getContributedClassifier(Name.identifier("Continuation"), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
|
||||
/**
|
||||
* This pass runs after inlining and performs the following additional transformations over some operations:
|
||||
* - Convert immutableBinaryBlobOf() arguments to special IrConst.
|
||||
* - Convert immutableBlobOf() arguments to special IrConst.
|
||||
* - Convert `obj::class` and `Class::class` to calls.
|
||||
*/
|
||||
internal class PostInlineLowering(val context: Context) : FileLoweringPass {
|
||||
@@ -77,7 +77,7 @@ internal class PostInlineLowering(val context: Context) : FileLoweringPass {
|
||||
// Function inlining is changing function symbol at callsite
|
||||
// and unbound symbol replacement is happening later.
|
||||
// So we compare descriptors for now.
|
||||
if (expression.descriptor == context.immutableBinaryBlobOf) {
|
||||
if (expression.descriptor == context.immutableBlobOf) {
|
||||
// Convert arguments of the binary blob to special IrConst<String> structure, so that
|
||||
// vararg lowering will not affect it.
|
||||
val args = expression.getValueArgument(0) as? IrVararg
|
||||
@@ -105,7 +105,7 @@ internal class PostInlineLowering(val context: Context) : FileLoweringPass {
|
||||
}
|
||||
expression.putValueArgument(0, IrConstImpl<String>(
|
||||
expression.startOffset, expression.endOffset,
|
||||
context.ir.symbols.immutableBinaryBlob.typeWithoutArguments,
|
||||
context.ir.symbols.immutableBlob.typeWithoutArguments,
|
||||
IrConstKind.String, builder.toString()))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -456,7 +456,7 @@ internal object DataFlowIR {
|
||||
|
||||
private val NAME_ESCAPES = Name.identifier("Escapes")
|
||||
private val NAME_POINTS_TO = Name.identifier("PointsTo")
|
||||
private val FQ_NAME_KONAN = FqName.fromSegments(listOf("kotlin", "native"))
|
||||
private val FQ_NAME_KONAN = FqName.fromSegments(listOf("kotlin", "native", "internal"))
|
||||
|
||||
private val FQ_NAME_ESCAPES = FQ_NAME_KONAN.child(NAME_ESCAPES)
|
||||
private val FQ_NAME_POINTS_TO = FQ_NAME_KONAN.child(NAME_POINTS_TO)
|
||||
|
||||
-5
@@ -131,9 +131,6 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
if (this.annotations.hasAnnotation(publishedApiAnnotation)){
|
||||
return true
|
||||
}
|
||||
if (this.annotations.hasAnnotation(inlineExposedAnnotation)){
|
||||
return true
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isAnonymousObject(this))
|
||||
return false
|
||||
@@ -172,8 +169,6 @@ private val exportForCompilerAnnotation = FqName("kotlin.native.internal.ExportF
|
||||
|
||||
private val publishedApiAnnotation = FqName("kotlin.PublishedApi")
|
||||
|
||||
private val inlineExposedAnnotation = FqName("kotlin.internal.InlineExposed")
|
||||
|
||||
private fun acyclicTypeMangler(visited: MutableSet<TypeParameterDescriptor>, type: KotlinType): String {
|
||||
val descriptor = TypeUtils.getTypeParameterDescriptorOrNull(type)
|
||||
if (descriptor != null) {
|
||||
|
||||
@@ -1481,7 +1481,7 @@ task if_else(type: RunKonanTest) {
|
||||
}
|
||||
|
||||
task immutable_binary_blob_in_lambda(type: RunKonanTest) {
|
||||
source = "lower/immutable_binary_blob_in_lambda.kt"
|
||||
source = "lower/immutable_blob_in_lambda.kt"
|
||||
goldValue = "123\n"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import platform.posix.printf
|
||||
|
||||
val golden = immutableBinaryBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer(0)
|
||||
val golden = immutableBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer(0)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
printf("%s\n", golden)
|
||||
|
||||
@@ -2,8 +2,8 @@ import kotlinx.cinterop.*
|
||||
|
||||
import platform.zlib.*
|
||||
|
||||
val source = immutableBinaryBlobOf(0xF3, 0x48, 0xCD, 0xC9, 0xC9, 0x57, 0x04, 0x00).asCPointer()
|
||||
val golden = immutableBinaryBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer()
|
||||
val source = immutableBlobOf(0xF3, 0x48, 0xCD, 0xC9, 0xC9, 0x57, 0x04, 0x00).asCPointer()
|
||||
val golden = immutableBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer()
|
||||
|
||||
fun main(args: Array<String>) = memScoped {
|
||||
val buffer = ByteArray(32)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package lower.immutable_binary_blob_in_lambda
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() = run {
|
||||
val golden = immutableBinaryBlobOf(123)
|
||||
println(golden[0])
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package lower.immutable_blob_in_lambda
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() = run {
|
||||
val golden = immutableBlobOf(123)
|
||||
println(golden[0])
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
import kotlin.native.CName
|
||||
|
||||
// Top level functions.
|
||||
fun hello() {
|
||||
println("Hello, dynamic!")
|
||||
@@ -13,15 +15,15 @@ open class Base {
|
||||
|
||||
open fun fooParam(arg0: String, arg1: Int) = println("Base.fooParam: $arg0 $arg1")
|
||||
|
||||
@kotlin.native.internal.CName(fullName = "", shortName = "strangeName") fun странноеИмя() = 111
|
||||
@CName(fullName = "", shortName = "strangeName") fun странноеИмя() = 111
|
||||
|
||||
}
|
||||
|
||||
// Top level functions.
|
||||
@kotlin.native.internal.CName(fullName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort")
|
||||
@CName(fullName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort")
|
||||
fun topLevelFunction(x1: Int, x2: Int) = x1 - x2
|
||||
|
||||
@kotlin.native.internal.CName("topLevelFunctionVoidFromC")
|
||||
@CName("topLevelFunctionVoidFromC")
|
||||
fun topLevelFunctionVoid(x1: Int, pointer: COpaquePointer?) {
|
||||
assert(x1 == 42)
|
||||
assert(pointer == null)
|
||||
|
||||
@@ -5,7 +5,7 @@ import kotlin.test.*
|
||||
import kotlin.native.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val data = immutableBinaryBlobOf(0x1, 0x2, 0x3, 0x7, 0x8, 0x9, 0x80, 0xff)
|
||||
val data = immutableBlobOf(0x1, 0x2, 0x3, 0x7, 0x8, 0x9, 0x80, 0xff)
|
||||
for (b in data) {
|
||||
print("$b ")
|
||||
}
|
||||
|
||||
@@ -10,5 +10,10 @@ import kotlin.test.*
|
||||
expect(0xdef0.toInt()) { array.charAt(5).toInt() }
|
||||
expect(0x9abc.toShort()) { array.shortAt(7) }
|
||||
expect(0x1234_5678) { array.intAt(9) }
|
||||
expect(0xdef0_0000u) { array.uintAt(3) }
|
||||
expect(0xf0_00u) { array.ushortAt(4) }
|
||||
expect(0xf0u) { array.ubyteAt(5) }
|
||||
expect(0x1234_5678_9abcuL) { array.ulongAt(7) }
|
||||
|
||||
println("OK")
|
||||
}
|
||||
@@ -464,7 +464,7 @@ KInt Kotlin_BooleanArray_getArrayLength(KConstRef thiz) {
|
||||
return array->count_;
|
||||
}
|
||||
|
||||
OBJ_GETTER(Kotlin_ImmutableBinaryBlob_toByteArray, KConstRef thiz, KInt start, KInt count) {
|
||||
OBJ_GETTER(Kotlin_ImmutableBlob_toByteArray, KConstRef thiz, KInt start, KInt count) {
|
||||
const ArrayHeader* array = thiz->array();
|
||||
if (start < 0 || count < 0 || start > array->count_ - count) {
|
||||
ThrowArrayIndexOutOfBoundsException();
|
||||
@@ -477,7 +477,7 @@ OBJ_GETTER(Kotlin_ImmutableBinaryBlob_toByteArray, KConstRef thiz, KInt start, K
|
||||
RETURN_OBJ(result->obj());
|
||||
}
|
||||
|
||||
KNativePtr Kotlin_ImmutableBinaryBlob_asCPointerImpl(KRef thiz, KInt offset) {
|
||||
KNativePtr Kotlin_ImmutableBlob_asCPointerImpl(KRef thiz, KInt offset) {
|
||||
ArrayHeader* array = thiz->array();
|
||||
if (offset < 0 || offset > array->count_) {
|
||||
ThrowArrayIndexOutOfBoundsException();
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
|
||||
/**
|
||||
* The root of the Kotlin class hierarchy. Every Kotlin class has [Any] as a superclass.
|
||||
*/
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
|
||||
package kotlin
|
||||
import kotlin.native.internal.ExportForCompiler
|
||||
import kotlin.native.internal.InlineConstructor
|
||||
|
||||
// TODO: remove that, as RTTI shall be per instantiation.
|
||||
import kotlin.native.internal.ExportForCompiler
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
import kotlin.native.internal.InlineConstructor
|
||||
import kotlin.native.internal.PointsTo
|
||||
|
||||
@ExportTypeInfo("theArrayTypeInfo")
|
||||
public final class Array<T> {
|
||||
// Constructors are handled with compiler magic.
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// TODO: Add SortedSed class and implement toSortedSet extensions
|
||||
// TODO: Add SortedSet class and implement toSortedSet extensions
|
||||
// TODO: Add fill and binary search methods for primitive arrays (with tests)
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.InlineConstructor
|
||||
import kotlin.collections.*
|
||||
import kotlin.internal.PureReifiable
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
import kotlin.native.internal.InlineConstructor
|
||||
import kotlin.util.sortArray
|
||||
import kotlin.util.sortArrayComparable
|
||||
import kotlin.util.sortArrayWith
|
||||
import kotlin.util.sortArray
|
||||
// TODO: make all iterator() methods inline.
|
||||
|
||||
/**
|
||||
* An array of bytes.
|
||||
@@ -40,7 +40,6 @@ public final class ByteArray {
|
||||
* 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.
|
||||
*/
|
||||
// TODO: What about inline constructors?
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Byte): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
@@ -66,7 +65,6 @@ public final class ByteArray {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: replace with generics, once implemented.
|
||||
private class ByteIteratorImpl(val collection: ByteArray) : ByteIterator() {
|
||||
var index : Int = 0
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.FixmeReflection
|
||||
|
||||
/**
|
||||
* Represents a value of a functional type, such as a lambda, an anonymous function or a function reference.
|
||||
*
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package kotlin
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.native.internal.FixmeConcurrency
|
||||
|
||||
/**
|
||||
* Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]
|
||||
@@ -27,7 +28,6 @@ import kotlin.reflect.KProperty
|
||||
* Note that the returned instance uses itself to synchronize on. Do not synchronize from external code on
|
||||
* the returned instance as it may cause accidental deadlock. Also this behavior can be changed in the future.
|
||||
*/
|
||||
@FixmeConcurrency
|
||||
public actual fun <T> lazy(initializer: () -> T): Lazy<T> = kotlin.native.worker.FreezeAwareLazyImpl(initializer)
|
||||
|
||||
/**
|
||||
@@ -43,8 +43,8 @@ public actual fun <T> lazy(initializer: () -> T): Lazy<T> = kotlin.native.worker
|
||||
@FixmeConcurrency
|
||||
public actual fun <T> lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy<T> =
|
||||
when (mode) {
|
||||
LazyThreadSafetyMode.SYNCHRONIZED -> TODO()//SynchronizedLazyImpl(initializer)
|
||||
LazyThreadSafetyMode.PUBLICATION -> TODO()//SafePublicationLazyImpl(initializer)
|
||||
LazyThreadSafetyMode.SYNCHRONIZED -> TODO() // was SynchronizedLazyImpl(initializer)
|
||||
LazyThreadSafetyMode.PUBLICATION -> TODO() // was SafePublicationLazyImpl(initializer)
|
||||
LazyThreadSafetyMode.NONE -> UnsafeLazyImpl(initializer)
|
||||
}
|
||||
|
||||
@@ -61,4 +61,4 @@ public actual fun <T> lazy(mode: LazyThreadSafetyMode, initializer: () -> T): La
|
||||
*/
|
||||
@FixmeConcurrency
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
public actual fun <T> lazy(lock: Any?, initializer: () -> T): Lazy<T> = TODO()//SynchronizedLazyImpl(initializer, lock)
|
||||
public actual fun <T> lazy(lock: Any?, initializer: () -> T): Lazy<T> = TODO() // was SynchronizedLazyImpl(initializer, lock)
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
import kotlin.native.internal.Frozen
|
||||
|
||||
@ExportTypeInfo("theStringTypeInfo")
|
||||
@kotlin.native.internal.Frozen
|
||||
@Frozen
|
||||
public final class String : Comparable<String>, CharSequence {
|
||||
public companion object {
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.FixmeReflection
|
||||
|
||||
/**
|
||||
* Represents a value of a functional type, such as a lambda, an anonymous function or a function reference.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
|
||||
/**
|
||||
* The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
|
||||
@ExportTypeInfo("theUnitTypeInfo")
|
||||
public object Unit {
|
||||
override fun toString() = "kotlin.Unit"
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
import kotlin.native.internal.PointsTo
|
||||
|
||||
/**
|
||||
* Returns an array of objects of the given type with the given [size], initialized with _uninitialized_ values.
|
||||
* Attempts to read _uninitialized_ values from this array work in implementation-dependent manner,
|
||||
* either throwing exception or returning some kind of implementation-specific default value.
|
||||
*/
|
||||
@kotlin.internal.InlineExposed
|
||||
@PublishedApi
|
||||
internal fun <E> arrayOfUninitializedElements(size: Int): Array<E> {
|
||||
// TODO: special case for size == 0?
|
||||
@Suppress("TYPE_PARAMETER_AS_REIFIED")
|
||||
@@ -33,21 +35,41 @@ internal fun <E> arrayOfUninitializedElements(size: Int): Array<E> {
|
||||
* Attempts to read _uninitialized_ values from this array work in implementation-dependent manner,
|
||||
* either throwing exception or returning some kind of implementation-specific default value.
|
||||
*/
|
||||
fun <E> Array<E>.copyOfUninitializedElements(newSize: Int): Array<E> = copyOfUninitializedElements(0, newSize)
|
||||
fun ByteArray.copyOfUninitializedElements(newSize: Int): ByteArray = copyOfUninitializedElements(0, newSize)
|
||||
fun ShortArray.copyOfUninitializedElements(newSize: Int): ShortArray = copyOfUninitializedElements(0, newSize)
|
||||
fun IntArray.copyOfUninitializedElements(newSize: Int): IntArray = copyOfUninitializedElements(0, newSize)
|
||||
fun LongArray.copyOfUninitializedElements(newSize: Int): LongArray = copyOfUninitializedElements(0, newSize)
|
||||
fun CharArray.copyOfUninitializedElements(newSize: Int): CharArray = copyOfUninitializedElements(0, newSize)
|
||||
fun FloatArray.copyOfUninitializedElements(newSize: Int): FloatArray = copyOfUninitializedElements(0, newSize)
|
||||
fun DoubleArray.copyOfUninitializedElements(newSize: Int): DoubleArray = copyOfUninitializedElements(0, newSize)
|
||||
fun BooleanArray.copyOfUninitializedElements(newSize: Int): BooleanArray = copyOfUninitializedElements(0, newSize)
|
||||
@PublishedApi
|
||||
internal fun <E> Array<E>.copyOfUninitializedElements(newSize: Int): Array<E> = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun ByteArray.copyOfUninitializedElements(newSize: Int): ByteArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun ShortArray.copyOfUninitializedElements(newSize: Int): ShortArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun IntArray.copyOfUninitializedElements(newSize: Int): IntArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun LongArray.copyOfUninitializedElements(newSize: Int): LongArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun CharArray.copyOfUninitializedElements(newSize: Int): CharArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun FloatArray.copyOfUninitializedElements(newSize: Int): FloatArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun DoubleArray.copyOfUninitializedElements(newSize: Int): DoubleArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun BooleanArray.copyOfUninitializedElements(newSize: Int): BooleanArray = copyOfUninitializedElements(0, newSize)
|
||||
|
||||
/**
|
||||
* Returns a new array which is a copy of the original array with new elements filled with null values.
|
||||
*/
|
||||
fun <E> Array<E>.copyOfNulls(newSize: Int): Array<E?> = copyOfNulls(0, newSize)
|
||||
fun <E> Array<E>.copyOfNulls(fromIndex: Int, toIndex: Int): Array<E?> {
|
||||
@PublishedApi
|
||||
internal fun <E> Array<E>.copyOfNulls(newSize: Int): Array<E?> = copyOfNulls(0, newSize)
|
||||
|
||||
@PublishedApi
|
||||
internal fun <E> Array<E>.copyOfNulls(fromIndex: Int, toIndex: Int): Array<E?> {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -90,7 +112,8 @@ internal fun <E> collectionToArray(collection: Collection<E>): Array<E>
|
||||
* Attempts to read _uninitialized_ values from this array work in implementation-dependent manner,
|
||||
* either throwing exception or returning some kind of implementation-specific default value.
|
||||
*/
|
||||
fun <E> Array<E>.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): Array<E> {
|
||||
@PublishedApi
|
||||
internal fun <E> Array<E>.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): Array<E> {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -100,7 +123,8 @@ fun <E> Array<E>.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): Arra
|
||||
return result
|
||||
}
|
||||
|
||||
fun ByteArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): ByteArray {
|
||||
@PublishedApi
|
||||
internal fun ByteArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): ByteArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -110,7 +134,8 @@ fun ByteArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): ByteArr
|
||||
return result
|
||||
}
|
||||
|
||||
fun ShortArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): ShortArray {
|
||||
@PublishedApi
|
||||
internal fun ShortArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): ShortArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -120,7 +145,8 @@ fun ShortArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): ShortA
|
||||
return result
|
||||
}
|
||||
|
||||
fun IntArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): IntArray {
|
||||
@PublishedApi
|
||||
internal fun IntArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): IntArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -130,7 +156,8 @@ fun IntArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): IntArray
|
||||
return result
|
||||
}
|
||||
|
||||
fun LongArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): LongArray {
|
||||
@PublishedApi
|
||||
internal fun LongArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): LongArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -140,7 +167,8 @@ fun LongArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): LongArr
|
||||
return result
|
||||
}
|
||||
|
||||
fun CharArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): CharArray {
|
||||
@PublishedApi
|
||||
internal fun CharArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): CharArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -150,7 +178,8 @@ fun CharArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): CharArr
|
||||
return result
|
||||
}
|
||||
|
||||
fun FloatArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): FloatArray {
|
||||
@PublishedApi
|
||||
internal fun FloatArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): FloatArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -160,7 +189,8 @@ fun FloatArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): FloatA
|
||||
return result
|
||||
}
|
||||
|
||||
fun DoubleArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): DoubleArray {
|
||||
@PublishedApi
|
||||
internal fun DoubleArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): DoubleArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -170,7 +200,8 @@ fun DoubleArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): Doubl
|
||||
return result
|
||||
}
|
||||
|
||||
fun BooleanArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): BooleanArray {
|
||||
@PublishedApi
|
||||
internal fun BooleanArray.copyOfUninitializedElements(fromIndex: Int, toIndex: Int): BooleanArray {
|
||||
val newSize = toIndex - fromIndex
|
||||
if (newSize < 0) {
|
||||
throw IllegalArgumentException("$fromIndex > $toIndex")
|
||||
@@ -282,66 +313,66 @@ fun <E> Array<out E>.copyRangeTo(destination: Array<in E>, fromIndex: Int, toInd
|
||||
destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun ByteArray.copyRangeTo(destination: ByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun ByteArray.copyRangeTo(destination: ByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun ShortArray.copyRangeTo(destination: ShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun ShortArray.copyRangeTo(destination: ShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun CharArray.copyRangeTo(destination: CharArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun CharArray.copyRangeTo(destination: CharArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun IntArray.copyRangeTo(destination: IntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun IntArray.copyRangeTo(destination: IntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun LongArray.copyRangeTo(destination: LongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun LongArray.copyRangeTo(destination: LongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
fun UByteArray.copyRangeTo(destination: UByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun UByteArray.copyRangeTo(destination: UByteArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
fun UShortArray.copyRangeTo(destination: UShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun UShortArray.copyRangeTo(destination: UShortArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
fun UIntArray.copyRangeTo(destination: UIntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun UIntArray.copyRangeTo(destination: UIntArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
fun ULongArray.copyRangeTo(destination: ULongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun ULongArray.copyRangeTo(destination: ULongArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun FloatArray.copyRangeTo(destination: FloatArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun FloatArray.copyRangeTo(destination: FloatArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun DoubleArray.copyRangeTo(destination: DoubleArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun DoubleArray.copyRangeTo(destination: DoubleArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
|
||||
fun BooleanArray.copyRangeTo(destination: BooleanArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
internal fun BooleanArray.copyRangeTo(destination: BooleanArray, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
|
||||
}
|
||||
/**
|
||||
* Copies a range of array elements at a specified [fromIndex] (inclusive) to [toIndex] (exclusive) range of indices
|
||||
* to another part of this array starting at [destinationIndex].
|
||||
*/
|
||||
fun <E> Array<E>.copyRange(fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
public fun <E> Array<E>.copyRange(fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) {
|
||||
copyRangeTo(this, fromIndex, toIndex, destinationIndex)
|
||||
}
|
||||
|
||||
|
||||
@@ -1152,9 +1152,8 @@ public actual fun CharArray.contentHashCode(): Int {
|
||||
return result
|
||||
}
|
||||
|
||||
// From JS collections.kt.
|
||||
internal actual fun <T> arrayOfNulls(reference: Array<T>, size: Int): Array<T> {
|
||||
return arrayOfNulls<Any>(size) as Array<T>
|
||||
return (@Suppress("UNCHECKED_CAST")(arrayOfNulls<Any>(size)) as Array<T>)
|
||||
}
|
||||
|
||||
internal actual fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
|
||||
@@ -1176,7 +1175,7 @@ internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<
|
||||
array[index++] = iterator.next() as T
|
||||
}
|
||||
if (index < array.size) {
|
||||
return (array as Array<T>).copyOf(index) as Array<T>
|
||||
return (@Suppress("UNCHECKED_CAST")(array as Array<T>)).copyOf(index) as Array<T>
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
@@ -16,13 +16,6 @@
|
||||
|
||||
package kotlin.internal
|
||||
|
||||
/**
|
||||
* Specifies that this part of internal API is effectively public exposed by using in public inline function
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class InlineExposed
|
||||
|
||||
/**
|
||||
* Specifies that the corresponding type parameter is not used for unsafe operations such as casts or 'is' checks
|
||||
* That means it's completely safe to use generic types as argument for such parameter.
|
||||
|
||||
@@ -25,25 +25,15 @@ import kotlin.reflect.KClass
|
||||
* so it should probably be allowed on `internal` and `private` functions only.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
// @Retention(AnnotationRetention.SOURCE)
|
||||
annotation class SymbolName(val name: String)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class SymbolName(val name: String)
|
||||
|
||||
/**
|
||||
* Exports the TypeInfo of this class by given name to use it from runtime.
|
||||
* Preserve the function entry point during global optimizations.
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class ExportTypeInfo(val name: String)
|
||||
|
||||
/**
|
||||
* If a lambda shall be carefully lowered by the compiler.
|
||||
*/
|
||||
annotation class VolatileLambda
|
||||
|
||||
/**
|
||||
* Preserve the function entry point during global optimizations
|
||||
*/
|
||||
public annotation class Used
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class Retain
|
||||
|
||||
// TODO: merge with [kotlin.jvm.Throws]
|
||||
/**
|
||||
@@ -61,22 +51,6 @@ public annotation class Used
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
public annotation class Throws(vararg val exceptionClasses: KClass<out Throwable>)
|
||||
|
||||
/**
|
||||
* Need to be fixed because of reflection.
|
||||
*/
|
||||
public annotation class FixmeReflection
|
||||
|
||||
/**
|
||||
* Need to be fixed because of concurrency.
|
||||
*/
|
||||
public annotation class FixmeConcurrency
|
||||
|
||||
/**
|
||||
* Escape analysis annotations.
|
||||
*/
|
||||
internal annotation class Escapes(val who: Int)
|
||||
internal annotation class PointsTo(vararg val onWhom: Int)
|
||||
|
||||
/**
|
||||
* Top level variable or object is thread local, and so could be mutable.
|
||||
* One may use this annotation as the stopgap measure for singleton
|
||||
@@ -85,4 +59,13 @@ internal annotation class PointsTo(vararg val onWhom: Int)
|
||||
*/
|
||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class ThreadLocal
|
||||
public annotation class ThreadLocal
|
||||
|
||||
/**
|
||||
* Makes top level function available from C/C++ code with the given name.
|
||||
* `fullName` controls the name of top level function, `shortName` controls the short name.
|
||||
* If `fullName` is empty, no top level declaration is being created.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class CName(val fullName: String = "", val shortName: String = "")
|
||||
@@ -1,75 +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 kotlin.native
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
/**
|
||||
* An immutable compile-time array of bytes.
|
||||
*/
|
||||
@ExportTypeInfo("theImmutableBinaryBlobTypeInfo")
|
||||
@Frozen
|
||||
public final class ImmutableBinaryBlob private constructor() {
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
// Data layout is the same as for ByteArray, so we can share native functions.
|
||||
@SymbolName("Kotlin_ByteArray_get")
|
||||
external public operator fun get(index: Int): Byte
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): ByteIterator {
|
||||
return ImmutableBinaryBlobIteratorImpl(this)
|
||||
}
|
||||
}
|
||||
|
||||
private class ImmutableBinaryBlobIteratorImpl(
|
||||
val collection: ImmutableBinaryBlob) : ByteIterator() {
|
||||
var index : Int = 0
|
||||
|
||||
public override fun nextByte(): Byte {
|
||||
if (!hasNext()) throw NoSuchElementException("$index")
|
||||
return collection[index++]
|
||||
}
|
||||
|
||||
public override operator fun hasNext(): Boolean {
|
||||
return index < collection.size
|
||||
}
|
||||
}
|
||||
|
||||
// Allocates new ByteArray and copies the data.
|
||||
@SymbolName("Kotlin_ImmutableBinaryBlob_toByteArray")
|
||||
public external fun ImmutableBinaryBlob.toByteArray(start: Int, count: Int): ByteArray
|
||||
public fun ImmutableBinaryBlob.toByteArray() = toByteArray(0, size)
|
||||
|
||||
// Returns stable C pointer to data at certain offset, useful as a way to pass resource
|
||||
// to C API.
|
||||
public fun ImmutableBinaryBlob.asCPointer(offset: Int = 0) =
|
||||
interpretCPointer<ByteVar>(asCPointerImpl(offset))!!
|
||||
@SymbolName("Kotlin_ImmutableBinaryBlob_asCPointerImpl")
|
||||
private external fun ImmutableBinaryBlob.asCPointerImpl(offset: Int): kotlin.native.internal.NativePtr
|
||||
|
||||
// Creates ImmutableBinaryBlob out of compile-time constant data.
|
||||
// This method accepts Short type, so that values in range 0x80 .. 0xff can be
|
||||
// provided without toByte() cast. One element still represent one byte in the output data.
|
||||
// This is the only way to create ImmutableBinaryBlob for now.
|
||||
// TODO: reconsider?
|
||||
@Intrinsic
|
||||
public external fun immutableBinaryBlobOf(vararg elements: Short): ImmutableBinaryBlob
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 kotlin.native
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
/**
|
||||
* An immutable compile-time array of bytes.
|
||||
*/
|
||||
@ExportTypeInfo("theImmutableBlobTypeInfo")
|
||||
public final class ImmutableBlob private constructor() {
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
// Data layout is the same as for ByteArray, so we can share native functions.
|
||||
@SymbolName("Kotlin_ByteArray_get")
|
||||
external public operator fun get(index: Int): Byte
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): ByteIterator {
|
||||
return ImmutableBlobIteratorImpl(this)
|
||||
}
|
||||
}
|
||||
|
||||
private class ImmutableBlobIteratorImpl(val blob: ImmutableBlob) : ByteIterator() {
|
||||
var index : Int = 0
|
||||
|
||||
public override fun nextByte(): Byte {
|
||||
if (!hasNext()) throw NoSuchElementException("$index")
|
||||
return blob[index++]
|
||||
}
|
||||
|
||||
public override operator fun hasNext(): Boolean {
|
||||
return index < blob.size
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates new ByteArray or UByteArray and copies the data from blob.
|
||||
*/
|
||||
@SymbolName("Kotlin_ImmutableBlob_toByteArray")
|
||||
public external fun ImmutableBlob.toByteArray(start: Int = 0, count: Int = size): ByteArray
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@SymbolName("Kotlin_ImmutableBlob_toByteArray")
|
||||
public external fun ImmutableBlob.toUByteArray(start: Int = 0, count: Int = size): UByteArray
|
||||
|
||||
/**
|
||||
* Returns stable C pointer to data at certain offset, useful as a way to pass resource
|
||||
* to C APIs.
|
||||
*/
|
||||
public fun ImmutableBlob.asCPointer(offset: Int = 0): CPointer<ByteVar> =
|
||||
interpretCPointer<ByteVar>(asCPointerImpl(offset))!!
|
||||
|
||||
/*
|
||||
public fun ImmutableBlob.asUCPointer(offset: Int = 0): CPointer<UByteVar> =
|
||||
interpretCPointer<UByteVar>(asCPointerImpl(offset))!!
|
||||
*/
|
||||
|
||||
@SymbolName("Kotlin_ImmutableBlob_asCPointerImpl")
|
||||
private external fun ImmutableBlob.asCPointerImpl(offset: Int): kotlin.native.internal.NativePtr
|
||||
|
||||
/**
|
||||
* Creates ImmutableBlob out of compile-time constant data.
|
||||
* This method accepts Short type, so that values in range 0x80 .. 0xff can be
|
||||
* provided without toByte() cast or 'u' suffix.
|
||||
* One element still represent one byte in the output data.
|
||||
* This is the only way to create ImmutableBlob for now.
|
||||
*/
|
||||
@Intrinsic
|
||||
public external fun immutableBlobOf(vararg elements: Short): ImmutableBlob
|
||||
+2
-1
@@ -17,7 +17,8 @@
|
||||
package kotlin
|
||||
|
||||
// Note:
|
||||
// Right now we don't want to have neither 'volatile' nor 'synchronized' at runtime.
|
||||
// Right now we don't want to have neither 'volatile' nor 'synchronized' at runtime, as it has different
|
||||
// concurrency approach.
|
||||
|
||||
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
@@ -17,18 +17,32 @@ package kotlin.native
|
||||
|
||||
import kotlin.native.SymbolName
|
||||
|
||||
fun ByteArray.ubyteAt(index: Int): UByte = UByte(get(index))
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getCharAt")
|
||||
external fun ByteArray.charAt(index: Int): Char
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getShortAt")
|
||||
external fun ByteArray.shortAt(index: Int): Short
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getShortAt")
|
||||
@ExperimentalUnsignedTypes
|
||||
external fun ByteArray.ushortAt(index: Int): UShort
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getIntAt")
|
||||
external fun ByteArray.intAt(index: Int): Int
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getIntAt")
|
||||
@ExperimentalUnsignedTypes
|
||||
external fun ByteArray.uintAt(index: Int): UInt
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getLongAt")
|
||||
external fun ByteArray.longAt(index: Int): Long
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getLongAt")
|
||||
@ExperimentalUnsignedTypes
|
||||
external fun ByteArray.ulongAt(index: Int): ULong
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getFloatAt")
|
||||
external fun ByteArray.floatAt(index: Int): Float
|
||||
|
||||
@@ -41,12 +55,23 @@ external fun ByteArray.setCharAt(index: Int, value: Char)
|
||||
@SymbolName("Kotlin_ByteArray_setShortAt")
|
||||
external fun ByteArray.setShortAt(index: Int, value: Short)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_setShortAt")
|
||||
@ExperimentalUnsignedTypes
|
||||
external fun ByteArray.setUShortAt(index: Int, value: UShort)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_setIntAt")
|
||||
external fun ByteArray.setIntAt(index: Int, value: Int)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_setIntAt")
|
||||
external fun ByteArray.setUIntAt(index: Int, value: UInt)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_setLongAt")
|
||||
external fun ByteArray.setLongAt(index: Int, value: Long)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_setLongAt")
|
||||
@ExperimentalUnsignedTypes
|
||||
external fun ByteArray.setULongAt(index: Int, value: ULong)
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_setFloatAt")
|
||||
external fun ByteArray.setFloatAt(index: Int, value: Float)
|
||||
|
||||
|
||||
@@ -23,40 +23,35 @@ package kotlin.native.internal
|
||||
* The function to call from C++ can be a wrapper around the original function.
|
||||
*
|
||||
* If the name is not specified, the function to call will be available by its Kotlin unqualified name.
|
||||
*
|
||||
* This annotation is not intended for the general consumption and is public only for the launcher!
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class ExportForCppRuntime(val name: String = "")
|
||||
|
||||
/**
|
||||
* Makes top level function available from C/C++ code with the given name.
|
||||
* `fullName` controls the name of top level function, `shortName` controls the short name.
|
||||
* If `fullName` is empty, no top level declaration is being created.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class CName(val fullName: String = "", val shortName: String = "")
|
||||
public annotation class ExportForCppRuntime(val name: String = "")
|
||||
|
||||
/**
|
||||
* This annotation denotes that the element is intrinsic and its usages require special handling in compiler.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class Intrinsic
|
||||
internal annotation class Intrinsic
|
||||
|
||||
/**
|
||||
* Exports symbol for compiler needs.
|
||||
*
|
||||
* This annotation is not intended for the general consumption and is public only for interop!
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class ExportForCompiler
|
||||
public annotation class ExportForCompiler
|
||||
|
||||
/**
|
||||
* Annotated constructor will be inlined.
|
||||
*/
|
||||
@Target(AnnotationTarget.CONSTRUCTOR)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class InlineConstructor
|
||||
internal annotation class InlineConstructor
|
||||
|
||||
/**
|
||||
* Class is frozen by default. Also this annotation is (ab)used for marking objects
|
||||
@@ -71,4 +66,43 @@ internal annotation class Frozen
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class NoReorderFields
|
||||
internal annotation class NoReorderFields
|
||||
|
||||
/**
|
||||
* Exports the TypeInfo of this class by given name to use it from runtime.
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class ExportTypeInfo(val name: String)
|
||||
|
||||
/**
|
||||
* If a lambda shall be carefully lowered by the compiler.
|
||||
*/
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class VolatileLambda
|
||||
|
||||
/**
|
||||
* Need to be fixed because of reflection.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
internal annotation class FixmeReflection
|
||||
|
||||
/**
|
||||
* Need to be fixed because of concurrency.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
internal annotation class FixmeConcurrency
|
||||
|
||||
/**
|
||||
* Escape analysis annotations.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class Escapes(val who: Int)
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class PointsTo(vararg val onWhom: Int)
|
||||
|
||||
@@ -100,7 +100,7 @@ fun <T> Collection<Future<T>>.waitForMultipleFutures(millis: Int): Set<Future<T>
|
||||
external internal fun stateOfFuture(id: FutureId): Int
|
||||
|
||||
@SymbolName("Kotlin_Worker_consumeFuture")
|
||||
@kotlin.internal.InlineExposed
|
||||
@PublishedApi
|
||||
external internal fun consumeFuture(id: FutureId): Any?
|
||||
|
||||
@SymbolName("Kotlin_Worker_waitForAnyFuture")
|
||||
|
||||
@@ -18,6 +18,7 @@ package kotlin.native.worker
|
||||
|
||||
import kotlin.native.SymbolName
|
||||
import kotlin.native.internal.ExportForCppRuntime
|
||||
import kotlin.native.internal.VolatileLambda
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin.reflect
|
||||
|
||||
import kotlin.native.internal.FixmeReflection
|
||||
|
||||
/**
|
||||
* Represents an annotated element and allows to obtain its annotations.
|
||||
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/annotations.html)
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin.reflect
|
||||
|
||||
import kotlin.native.internal.FixmeReflection
|
||||
|
||||
/**
|
||||
* Represents a callable entity, such as a function or a property.
|
||||
*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package kotlin.reflect
|
||||
|
||||
import kotlin.native.*
|
||||
import kotlin.native.internal.FixmeReflection
|
||||
|
||||
/**
|
||||
* Represents a property, such as a named `val` or `var` declaration.
|
||||
|
||||
@@ -18,6 +18,7 @@ package kotlin.sequences
|
||||
|
||||
import kotlin.comparisons.*
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.native.internal.FixmeConcurrency
|
||||
|
||||
@FixmeConcurrency
|
||||
internal actual class ConstrainedOnceSequence<T> actual constructor(sequence: Sequence<T>) : Sequence<T> {
|
||||
|
||||
Reference in New Issue
Block a user