Skip to content

Commit 4131e80

Browse files
broadwaylambSpace Team
authored andcommitted
[stdlib] Annotate JS stdlib with @UsedFromCompilerGeneratedCode
KT-78572
1 parent 9114fad commit 4131e80

31 files changed

+239
-19
lines changed

libraries/stdlib/common-non-jvm/src/kotlin/internal/IrLinkageError.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package kotlin.internal
77

88
internal class IrLinkageError(message: String?) : Error(message)
99

10+
@UsedFromCompilerGeneratedCode
1011
internal fun throwIrLinkageError(message: String?): Nothing {
1112
throw IrLinkageError(message)
1213
}

libraries/stdlib/common-non-jvm/src/kotlin/internal/SharedVariableBox.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

6-
@file:Suppress("unused") // Usages are generated by the compiler
7-
86
package kotlin.internal
97

108
// NOTE: It is deliberate that only the generic variant is marked as @PublishedAbi.
@@ -14,20 +12,29 @@ package kotlin.internal
1412
// see SharedVariablesPrimitiveBoxSpecializationLowering.
1513

1614
@PublishedApi
15+
@UsedFromCompilerGeneratedCode
1716
internal class SharedVariableBox<T>(var element: T)
1817

18+
@UsedFromCompilerGeneratedCode
1919
internal class SharedVariableBoxBoolean(var element: Boolean)
2020

21+
@UsedFromCompilerGeneratedCode
2122
internal class SharedVariableBoxByte(var element: Byte)
2223

24+
@UsedFromCompilerGeneratedCode
2325
internal class SharedVariableBoxShort(var element: Short)
2426

27+
@UsedFromCompilerGeneratedCode
2528
internal class SharedVariableBoxInt(var element: Int)
2629

30+
@UsedFromCompilerGeneratedCode
2731
internal class SharedVariableBoxLong(var element: Long)
2832

33+
@UsedFromCompilerGeneratedCode
2934
internal class SharedVariableBoxFloat(var element: Float)
3035

36+
@UsedFromCompilerGeneratedCode
3137
internal class SharedVariableBoxDouble(var element: Double)
3238

39+
@UsedFromCompilerGeneratedCode
3340
internal class SharedVariableBoxChar(var element: Char)

libraries/stdlib/js-ir-minimal-for-test/js-src/minimalReflect.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package kotlin.reflect.js.internal
77

8+
import kotlin.internal.UsedFromCompilerGeneratedCode
89
import kotlin.reflect.KClassifier
910
import kotlin.reflect.KType
1011
import kotlin.reflect.KTypeParameter
@@ -24,17 +25,20 @@ internal object DynamicKType : KType {
2425
override lateinit var arguments: List<KTypeProjection>
2526
}
2627

28+
@UsedFromCompilerGeneratedCode
2729
internal fun createKType(
2830
classifier: KClassifier,
2931
arguments: Array<KTypeProjection>,
3032
isMarkedNullable: Boolean
3133
) =
3234
KTypeImpl(classifier, arguments.unsafeCast<List<KTypeProjection>>(), isMarkedNullable)
3335

36+
@UsedFromCompilerGeneratedCode
3437
internal fun createDynamicKType(): KType = DynamicKType
3538

3639
internal fun markKTypeNullable(kType: KType) = KTypeImpl(kType.classifier!!, kType.arguments, true)
3740

41+
@UsedFromCompilerGeneratedCode
3842
internal fun createKTypeParameter(
3943
name: String,
4044
upperBounds: Array<KType>,
@@ -51,14 +55,18 @@ internal fun createKTypeParameter(
5155
return KTypeParameterImpl(name, upperBounds.unsafeCast<List<KType>>(), kVariance, isReified, container)
5256
}
5357

58+
@UsedFromCompilerGeneratedCode
5459
internal fun getStarKTypeProjection(): KTypeProjection =
5560
KTypeProjection.STAR
5661

62+
@UsedFromCompilerGeneratedCode
5763
internal fun createCovariantKTypeProjection(type: KType): KTypeProjection =
5864
KTypeProjection.covariant(type)
5965

66+
@UsedFromCompilerGeneratedCode
6067
internal fun createInvariantKTypeProjection(type: KType): KTypeProjection =
6168
KTypeProjection.invariant(type)
6269

70+
@UsedFromCompilerGeneratedCode
6371
internal fun createContravariantKTypeProjection(type: KType): KTypeProjection =
6472
KTypeProjection.contravariant(type)

libraries/stdlib/js/runtime/DefaultConstructorMarker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55

66
package kotlin.js
77

8-
internal object DefaultConstructorMarker
8+
import kotlin.internal.UsedFromCompilerGeneratedCode
9+
10+
@UsedFromCompilerGeneratedCode
11+
internal object DefaultConstructorMarker

libraries/stdlib/js/runtime/FunctionAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
package kotlin.js
66

77
import kotlin.Function
8+
import kotlin.internal.UsedFromCompilerGeneratedCode
89

10+
@UsedFromCompilerGeneratedCode
911
internal interface FunctionAdapter {
1012
fun getFunctionDelegate(): Function<*>
11-
}
13+
}

libraries/stdlib/js/runtime/arrays.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package kotlin.js
77

88
import withType
9+
import kotlin.internal.UsedFromCompilerGeneratedCode
910

1011
@PublishedApi
1112
internal external fun <T> Array(size: Int): Array<T>
@@ -30,68 +31,83 @@ internal inline fun <T> fillArrayFun(array: dynamic, init: (Int) -> T): Array<T>
3031
return result
3132
}
3233

34+
@UsedFromCompilerGeneratedCode
3335
internal fun booleanArray(size: Int): BooleanArray = withType("BooleanArray", fillArrayVal(Array<Boolean>(size), false)).unsafeCast<BooleanArray>()
3436

37+
@UsedFromCompilerGeneratedCode
3538
internal fun booleanArrayOf(arr: Array<Boolean>): BooleanArray = withType("BooleanArray", arr.asDynamic().slice()).unsafeCast<BooleanArray>()
3639

3740
@Suppress("UNUSED_PARAMETER")
41+
@UsedFromCompilerGeneratedCode
3842
internal fun charArray(size: Int): CharArray = withType("CharArray", js("new Uint16Array(size)")).unsafeCast<CharArray>()
3943

4044
@Suppress("UNUSED_PARAMETER")
45+
@UsedFromCompilerGeneratedCode
4146
internal fun charArrayOf(arr: Array<Char>): CharArray = withType("CharArray", js("new Uint16Array(arr)")).unsafeCast<CharArray>()
4247

48+
@UsedFromCompilerGeneratedCode
4349
internal fun longArray(size: Int): LongArray = withType("LongArray", fillArrayVal(Array<Long>(size), 0L)).unsafeCast<LongArray>()
4450

51+
@UsedFromCompilerGeneratedCode
4552
internal fun longArrayOf(arr: Array<Long>): LongArray = withType("LongArray", arr.asDynamic().slice()).unsafeCast<LongArray>()
4653

54+
@UsedFromCompilerGeneratedCode
4755
internal fun <T> arrayIterator(array: Array<T>) = object : Iterator<T> {
4856
var index = 0
4957
override fun hasNext() = index != array.size
5058
override fun next() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
5159
}
5260

61+
@UsedFromCompilerGeneratedCode
5362
internal fun booleanArrayIterator(array: BooleanArray) = object : BooleanIterator() {
5463
var index = 0
5564
override fun hasNext() = index != array.size
5665
override fun nextBoolean() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
5766
}
5867

68+
@UsedFromCompilerGeneratedCode
5969
internal fun byteArrayIterator(array: ByteArray) = object : ByteIterator() {
6070
var index = 0
6171
override fun hasNext() = index != array.size
6272
override fun nextByte() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
6373
}
6474

75+
@UsedFromCompilerGeneratedCode
6576
internal fun shortArrayIterator(array: ShortArray) = object : ShortIterator() {
6677
var index = 0
6778
override fun hasNext() = index != array.size
6879
override fun nextShort() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
6980
}
7081

82+
@UsedFromCompilerGeneratedCode
7183
internal fun charArrayIterator(array: CharArray) = object : CharIterator() {
7284
var index = 0
7385
override fun hasNext() = index != array.size
7486
override fun nextChar() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
7587
}
7688

89+
@UsedFromCompilerGeneratedCode
7790
internal fun intArrayIterator(array: IntArray) = object : IntIterator() {
7891
var index = 0
7992
override fun hasNext() = index != array.size
8093
override fun nextInt() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
8194
}
8295

96+
@UsedFromCompilerGeneratedCode
8397
internal fun floatArrayIterator(array: FloatArray) = object : FloatIterator() {
8498
var index = 0
8599
override fun hasNext() = index != array.size
86100
override fun nextFloat() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
87101
}
88102

103+
@UsedFromCompilerGeneratedCode
89104
internal fun doubleArrayIterator(array: DoubleArray) = object : DoubleIterator() {
90105
var index = 0
91106
override fun hasNext() = index != array.size
92107
override fun nextDouble() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
93108
}
94109

110+
@UsedFromCompilerGeneratedCode
95111
internal fun longArrayIterator(array: LongArray) = object : LongIterator() {
96112
var index = 0
97113
override fun hasNext() = index != array.size

libraries/stdlib/js/runtime/bitUtils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package kotlin.js
77

8+
import kotlin.internal.UsedFromCompilerGeneratedCode
89
import kotlin.js.internal.boxedLong.BoxedLongApi
910

1011
// TODO use declarations from stdlib
@@ -56,6 +57,7 @@ internal fun doubleSignBit(value: Double): Int {
5657
return bufInt32[highIndex] and Int.MIN_VALUE
5758
}
5859

60+
@UsedFromCompilerGeneratedCode
5961
internal fun getNumberHashCode(obj: Double): Int {
6062
@Suppress("DEPRECATED_IDENTITY_EQUALS")
6163
if (jsBitwiseOr(obj, 0).unsafeCast<Double>() === obj) {

libraries/stdlib/js/runtime/booleanInExternalHelpers.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
package kotlin.js
77

88
import JsError
9+
import kotlin.internal.UsedFromCompilerGeneratedCode
910

1011
@JsName("Boolean")
12+
@UsedFromCompilerGeneratedCode
1113
internal external fun nativeBoolean(obj: Any?): Boolean
1214

15+
@UsedFromCompilerGeneratedCode
1316
internal fun booleanInExternalLog(name: String, obj: dynamic) {
1417
if (jsTypeOf(obj) != "boolean") {
1518
console.asDynamic().error("Boolean expected for '$name', but actual:", obj)
1619
}
1720
}
1821

22+
@UsedFromCompilerGeneratedCode
1923
internal fun booleanInExternalException(name: String, obj: dynamic) {
2024
if (jsTypeOf(obj) != "boolean") {
2125
throw JsError("Boolean expected for '$name', but actual: $obj")
2226
}
23-
}
27+
}

0 commit comments

Comments
 (0)