[K/N] Stdlib: warnings as errors
Fix or suppress warnings in Native stdlib.
This commit is contained in:
@@ -404,8 +404,6 @@ val stdLibSrcDirs = interopSrcDirs + listOf(
|
|||||||
project(":kotlin-stdlib-common").file("../native-wasm/src/")
|
project(":kotlin-stdlib-common").file("../native-wasm/src/")
|
||||||
)
|
)
|
||||||
|
|
||||||
val args = listOf<String>(/* -Werror (TODO: check) */)
|
|
||||||
|
|
||||||
lateinit var stdlibBuildTask: TaskProvider<Task>
|
lateinit var stdlibBuildTask: TaskProvider<Task>
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
@@ -418,8 +416,9 @@ konanArtifacts {
|
|||||||
noDefaultLibs(true)
|
noDefaultLibs(true)
|
||||||
noEndorsedLibs(true)
|
noEndorsedLibs(true)
|
||||||
|
|
||||||
extraOpts(args + project.globalBuildArgs)
|
extraOpts(project.globalBuildArgs)
|
||||||
extraOpts(
|
extraOpts(
|
||||||
|
"-Werror",
|
||||||
"-module-name", "stdlib",
|
"-module-name", "stdlib",
|
||||||
"-opt-in=kotlin.RequiresOptIn",
|
"-opt-in=kotlin.RequiresOptIn",
|
||||||
"-opt-in=kotlin.contracts.ExperimentalContracts",
|
"-opt-in=kotlin.contracts.ExperimentalContracts",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ enum class FutureState(val value: Int) {
|
|||||||
* Class representing abstract computation, whose result may become available in the future.
|
* Class representing abstract computation, whose result may become available in the future.
|
||||||
*/
|
*/
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
public inline class Future<T> @PublishedApi internal constructor(val id: Int) {
|
public value class Future<T> @PublishedApi internal constructor(val id: Int) {
|
||||||
/**
|
/**
|
||||||
* Blocks execution until the future is ready.
|
* Blocks execution until the future is ready.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import kotlinx.cinterop.*
|
|||||||
* Class representing worker.
|
* Class representing worker.
|
||||||
*/
|
*/
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
public inline class Worker @PublishedApi internal constructor(val id: Int) {
|
public value class Worker @PublishedApi internal constructor(val id: Int) {
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Start new scheduling primitive, such as thread, to accept new tasks via `execute` interface.
|
* Start new scheduling primitive, such as thread, to accept new tasks via `execute` interface.
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ internal class KClassImpl<T : Any>(private val typeInfo: NativePtr) : KClass<T>
|
|||||||
|
|
||||||
@ExportForCompiler
|
@ExportForCompiler
|
||||||
@ConstantConstructorIntrinsic("KCLASS_IMPL")
|
@ConstantConstructorIntrinsic("KCLASS_IMPL")
|
||||||
|
@Suppress("UNREACHABLE_CODE")
|
||||||
constructor() : this(TODO("This is intrinsic constructor and it shouldn't be used directly"))
|
constructor() : this(TODO("This is intrinsic constructor and it shouldn't be used directly"))
|
||||||
|
|
||||||
// TODO: consider replacing '$' by another delimeter that can't be used in class name specified with backticks (``)
|
// TODO: consider replacing '$' by another delimeter that can't be used in class name specified with backticks (``)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ internal class KTypeImpl<T>(
|
|||||||
|
|
||||||
@ExportForCompiler
|
@ExportForCompiler
|
||||||
@ConstantConstructorIntrinsic("KTYPE_IMPL")
|
@ConstantConstructorIntrinsic("KTYPE_IMPL")
|
||||||
|
@Suppress("UNREACHABLE_CODE")
|
||||||
constructor() : this(null, TODO("This is intrinsic constructor and it shouldn't be used directly"), false)
|
constructor() : this(null, TODO("This is intrinsic constructor and it shouldn't be used directly"), false)
|
||||||
|
|
||||||
override fun equals(other: Any?) =
|
override fun equals(other: Any?) =
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ package kotlin.native.internal.test
|
|||||||
internal class GTestLogger : TestLoggerWithStatistics() {
|
internal class GTestLogger : TestLoggerWithStatistics() {
|
||||||
|
|
||||||
private val Collection<TestSuite>.totalTestsNotIgnored: Int
|
private val Collection<TestSuite>.totalTestsNotIgnored: Int
|
||||||
get() = asSequence().filter { !it.ignored }.sumBy { it.testCases.values.count { !it.ignored } }
|
get() = asSequence().filter { !it.ignored }.sumOf { it.testCases.values.count { !it.ignored } }
|
||||||
|
|
||||||
private val Collection<TestSuite>.totalNotIgnored: Int
|
private val Collection<TestSuite>.totalNotIgnored: Int
|
||||||
get() = filter { !it.ignored }.size
|
get() = filter { !it.ignored }.size
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
package kotlin.collections
|
package kotlin.collections
|
||||||
|
|
||||||
actual class ArrayList<E> private constructor(
|
actual class ArrayList<E> private constructor(
|
||||||
private var array: Array<E>,
|
private var backingArray: Array<E>,
|
||||||
private var offset: Int,
|
private var offset: Int,
|
||||||
private var length: Int,
|
private var length: Int,
|
||||||
private var isReadOnly: Boolean,
|
private var isReadOnly: Boolean,
|
||||||
private val backing: ArrayList<E>?,
|
private val backingList: ArrayList<E>?,
|
||||||
private val root: ArrayList<E>?
|
private val root: ArrayList<E>?
|
||||||
) : MutableList<E>, RandomAccess, AbstractMutableList<E>() {
|
) : MutableList<E>, RandomAccess, AbstractMutableList<E>() {
|
||||||
|
|
||||||
actual constructor() : this(10)
|
actual constructor() : this(10)
|
||||||
@@ -25,7 +25,7 @@ actual class ArrayList<E> private constructor(
|
|||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun build(): List<E> {
|
internal fun build(): List<E> {
|
||||||
if (backing != null) throw IllegalStateException() // just in case somebody casts subList to ArrayList
|
if (backingList != null) throw IllegalStateException() // just in case somebody casts subList to ArrayList
|
||||||
checkIsMutable()
|
checkIsMutable()
|
||||||
isReadOnly = true
|
isReadOnly = true
|
||||||
return this
|
return this
|
||||||
@@ -38,21 +38,21 @@ actual class ArrayList<E> private constructor(
|
|||||||
|
|
||||||
override actual fun get(index: Int): E {
|
override actual fun get(index: Int): E {
|
||||||
checkElementIndex(index)
|
checkElementIndex(index)
|
||||||
return array[offset + index]
|
return backingArray[offset + index]
|
||||||
}
|
}
|
||||||
|
|
||||||
override actual operator fun set(index: Int, element: E): E {
|
override actual operator fun set(index: Int, element: E): E {
|
||||||
checkIsMutable()
|
checkIsMutable()
|
||||||
checkElementIndex(index)
|
checkElementIndex(index)
|
||||||
val old = array[offset + index]
|
val old = backingArray[offset + index]
|
||||||
array[offset + index] = element
|
backingArray[offset + index] = element
|
||||||
return old
|
return old
|
||||||
}
|
}
|
||||||
|
|
||||||
override actual fun indexOf(element: E): Int {
|
override actual fun indexOf(element: E): Int {
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < length) {
|
while (i < length) {
|
||||||
if (array[offset + i] == element) return i
|
if (backingArray[offset + i] == element) return i
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
@@ -61,7 +61,7 @@ actual class ArrayList<E> private constructor(
|
|||||||
override actual fun lastIndexOf(element: E): Int {
|
override actual fun lastIndexOf(element: E): Int {
|
||||||
var i = length - 1
|
var i = length - 1
|
||||||
while (i >= 0) {
|
while (i >= 0) {
|
||||||
if (array[offset + i] == element) return i
|
if (backingArray[offset + i] == element) return i
|
||||||
i--
|
i--
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
@@ -132,21 +132,21 @@ actual class ArrayList<E> private constructor(
|
|||||||
|
|
||||||
override actual fun subList(fromIndex: Int, toIndex: Int): MutableList<E> {
|
override actual fun subList(fromIndex: Int, toIndex: Int): MutableList<E> {
|
||||||
checkRangeIndexes(fromIndex, toIndex)
|
checkRangeIndexes(fromIndex, toIndex)
|
||||||
return ArrayList(array, offset + fromIndex, toIndex - fromIndex, isReadOnly, this, root ?: this)
|
return ArrayList(backingArray, offset + fromIndex, toIndex - fromIndex, isReadOnly, this, root ?: this)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun trimToSize() {
|
actual fun trimToSize() {
|
||||||
if (backing != null) throw IllegalStateException() // just in case somebody casts subList to ArrayList
|
if (backingList != null) throw IllegalStateException() // just in case somebody casts subList to ArrayList
|
||||||
if (length < array.size)
|
if (length < backingArray.size)
|
||||||
array = array.copyOfUninitializedElements(length)
|
backingArray = backingArray.copyOfUninitializedElements(length)
|
||||||
}
|
}
|
||||||
|
|
||||||
final actual fun ensureCapacity(minCapacity: Int) {
|
final actual fun ensureCapacity(minCapacity: Int) {
|
||||||
if (backing != null) throw IllegalStateException() // just in case somebody casts subList to ArrayList
|
if (backingList != null) throw IllegalStateException() // just in case somebody casts subList to ArrayList
|
||||||
if (minCapacity < 0) throw OutOfMemoryError() // overflow
|
if (minCapacity < 0) throw OutOfMemoryError() // overflow
|
||||||
if (minCapacity > array.size) {
|
if (minCapacity > backingArray.size) {
|
||||||
val newSize = ArrayDeque.newCapacity(array.size, minCapacity)
|
val newSize = ArrayDeque.newCapacity(backingArray.size, minCapacity)
|
||||||
array = array.copyOfUninitializedElements(newSize)
|
backingArray = backingArray.copyOfUninitializedElements(newSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,32 +156,32 @@ actual class ArrayList<E> private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return array.subarrayContentHashCode(offset, length)
|
return backingArray.subarrayContentHashCode(offset, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
@Suppress("DEPRECATION_ERROR")
|
@Suppress("DEPRECATION_ERROR")
|
||||||
return array.subarrayContentToString(offset, length)
|
return backingArray.subarrayContentToString(offset, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun <T> toArray(destination: Array<T>): Array<T> {
|
override fun <T> toArray(array: Array<T>): Array<T> {
|
||||||
if (destination.size < length) {
|
if (array.size < length) {
|
||||||
return array.copyOfRange(fromIndex = offset, toIndex = offset + length) as Array<T>
|
return backingArray.copyOfRange(fromIndex = offset, toIndex = offset + length) as Array<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
(array as Array<T>).copyInto(destination, 0, startIndex = offset, endIndex = offset + length)
|
(backingArray as Array<T>).copyInto(array, 0, startIndex = offset, endIndex = offset + length)
|
||||||
|
|
||||||
if (destination.size > length) {
|
if (array.size > length) {
|
||||||
destination[length] = null as T // null-terminate
|
array[length] = null as T // null-terminate
|
||||||
}
|
}
|
||||||
|
|
||||||
return destination
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toArray(): Array<Any?> {
|
override fun toArray(): Array<Any?> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return array.copyOfRange(fromIndex = offset, toIndex = offset + length) as Array<Any?>
|
return backingArray.copyOfRange(fromIndex = offset, toIndex = offset + length) as Array<Any?>
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------- private ----------------------------
|
// ---------------------------- private ----------------------------
|
||||||
@@ -216,85 +216,85 @@ actual class ArrayList<E> private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun contentEquals(other: List<*>): Boolean {
|
private fun contentEquals(other: List<*>): Boolean {
|
||||||
return array.subarrayContentEquals(offset, length, other)
|
return backingArray.subarrayContentEquals(offset, length, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun insertAtInternal(i: Int, n: Int) {
|
private fun insertAtInternal(i: Int, n: Int) {
|
||||||
ensureExtraCapacity(n)
|
ensureExtraCapacity(n)
|
||||||
array.copyInto(array, startIndex = i, endIndex = offset + length, destinationOffset = i + n)
|
backingArray.copyInto(backingArray, startIndex = i, endIndex = offset + length, destinationOffset = i + n)
|
||||||
length += n
|
length += n
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addAtInternal(i: Int, element: E) {
|
private fun addAtInternal(i: Int, element: E) {
|
||||||
if (backing != null) {
|
if (backingList != null) {
|
||||||
backing.addAtInternal(i, element)
|
backingList.addAtInternal(i, element)
|
||||||
array = backing.array
|
backingArray = backingList.backingArray
|
||||||
length++
|
length++
|
||||||
} else {
|
} else {
|
||||||
insertAtInternal(i, 1)
|
insertAtInternal(i, 1)
|
||||||
array[i] = element
|
backingArray[i] = element
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addAllInternal(i: Int, elements: Collection<E>, n: Int) {
|
private fun addAllInternal(i: Int, elements: Collection<E>, n: Int) {
|
||||||
if (backing != null) {
|
if (backingList != null) {
|
||||||
backing.addAllInternal(i, elements, n)
|
backingList.addAllInternal(i, elements, n)
|
||||||
array = backing.array
|
backingArray = backingList.backingArray
|
||||||
length += n
|
length += n
|
||||||
} else {
|
} else {
|
||||||
insertAtInternal(i, n)
|
insertAtInternal(i, n)
|
||||||
var j = 0
|
var j = 0
|
||||||
val it = elements.iterator()
|
val it = elements.iterator()
|
||||||
while (j < n) {
|
while (j < n) {
|
||||||
array[i + j] = it.next()
|
backingArray[i + j] = it.next()
|
||||||
j++
|
j++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeAtInternal(i: Int): E {
|
private fun removeAtInternal(i: Int): E {
|
||||||
if (backing != null) {
|
if (backingList != null) {
|
||||||
val old = backing.removeAtInternal(i)
|
val old = backingList.removeAtInternal(i)
|
||||||
length--
|
length--
|
||||||
return old
|
return old
|
||||||
} else {
|
} else {
|
||||||
val old = array[i]
|
val old = backingArray[i]
|
||||||
array.copyInto(array, startIndex = i + 1, endIndex = offset + length, destinationOffset = i)
|
backingArray.copyInto(backingArray, startIndex = i + 1, endIndex = offset + length, destinationOffset = i)
|
||||||
array.resetAt(offset + length - 1)
|
backingArray.resetAt(offset + length - 1)
|
||||||
length--
|
length--
|
||||||
return old
|
return old
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeRangeInternal(rangeOffset: Int, rangeLength: Int) {
|
private fun removeRangeInternal(rangeOffset: Int, rangeLength: Int) {
|
||||||
if (backing != null) {
|
if (backingList != null) {
|
||||||
backing.removeRangeInternal(rangeOffset, rangeLength)
|
backingList.removeRangeInternal(rangeOffset, rangeLength)
|
||||||
} else {
|
} else {
|
||||||
array.copyInto(array, startIndex = rangeOffset + rangeLength, endIndex = length, destinationOffset = rangeOffset)
|
backingArray.copyInto(backingArray, startIndex = rangeOffset + rangeLength, endIndex = length, destinationOffset = rangeOffset)
|
||||||
array.resetRange(fromIndex = length - rangeLength, toIndex = length)
|
backingArray.resetRange(fromIndex = length - rangeLength, toIndex = length)
|
||||||
}
|
}
|
||||||
length -= rangeLength
|
length -= rangeLength
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Retains elements if [retain] == true and removes them it [retain] == false. */
|
/** Retains elements if [retain] == true and removes them it [retain] == false. */
|
||||||
private fun retainOrRemoveAllInternal(rangeOffset: Int, rangeLength: Int, elements: Collection<E>, retain: Boolean): Int {
|
private fun retainOrRemoveAllInternal(rangeOffset: Int, rangeLength: Int, elements: Collection<E>, retain: Boolean): Int {
|
||||||
if (backing != null) {
|
if (backingList != null) {
|
||||||
val removed = backing.retainOrRemoveAllInternal(rangeOffset, rangeLength, elements, retain)
|
val removed = backingList.retainOrRemoveAllInternal(rangeOffset, rangeLength, elements, retain)
|
||||||
length -= removed
|
length -= removed
|
||||||
return removed
|
return removed
|
||||||
} else {
|
} else {
|
||||||
var i = 0
|
var i = 0
|
||||||
var j = 0
|
var j = 0
|
||||||
while (i < rangeLength) {
|
while (i < rangeLength) {
|
||||||
if (elements.contains(array[rangeOffset + i]) == retain) {
|
if (elements.contains(backingArray[rangeOffset + i]) == retain) {
|
||||||
array[rangeOffset + j++] = array[rangeOffset + i++]
|
backingArray[rangeOffset + j++] = backingArray[rangeOffset + i++]
|
||||||
} else {
|
} else {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val removed = rangeLength - j
|
val removed = rangeLength - j
|
||||||
array.copyInto(array, startIndex = rangeOffset + rangeLength, endIndex = length, destinationOffset = rangeOffset + j)
|
backingArray.copyInto(backingArray, startIndex = rangeOffset + rangeLength, endIndex = length, destinationOffset = rangeOffset + j)
|
||||||
array.resetRange(fromIndex = length - removed, toIndex = length)
|
backingArray.resetRange(fromIndex = length - removed, toIndex = length)
|
||||||
length -= removed
|
length -= removed
|
||||||
return removed
|
return removed
|
||||||
}
|
}
|
||||||
@@ -320,13 +320,13 @@ actual class ArrayList<E> private constructor(
|
|||||||
override fun previous(): E {
|
override fun previous(): E {
|
||||||
if (index <= 0) throw NoSuchElementException()
|
if (index <= 0) throw NoSuchElementException()
|
||||||
lastIndex = --index
|
lastIndex = --index
|
||||||
return list.array[list.offset + lastIndex]
|
return list.backingArray[list.offset + lastIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): E {
|
override fun next(): E {
|
||||||
if (index >= list.length) throw NoSuchElementException()
|
if (index >= list.length) throw NoSuchElementException()
|
||||||
lastIndex = index++
|
lastIndex = index++
|
||||||
return list.array[list.offset + lastIndex]
|
return list.backingArray[list.offset + lastIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun set(element: E) {
|
override fun set(element: E) {
|
||||||
|
|||||||
Reference in New Issue
Block a user