Codereview
This commit is contained in:
committed by
Space Team
parent
78b72efd32
commit
c71a2c6dd3
+2
-4
@@ -118,13 +118,13 @@ private val lateinitUsageLoweringPhase = makeWasmModulePhase(
|
||||
private val arrayConstructorReferencePhase = makeWasmModulePhase(
|
||||
::WasmArrayConstructorReferenceLowering,
|
||||
name = "ArrayConstructorReference",
|
||||
description = "Transform `::Array` into a lambda"
|
||||
description = "Transform `::Array` into a ::create#Array"
|
||||
)
|
||||
|
||||
private val arrayConstructorPhase = makeWasmModulePhase(
|
||||
::WasmArrayConstructorLowering,
|
||||
name = "ArrayConstructor",
|
||||
description = "Transform `Array(size) { index -> value }` into a loop",
|
||||
description = "Transform `Array(size) { index -> value }` into create#Array { index -> value } call",
|
||||
prerequisite = setOf(arrayConstructorReferencePhase)
|
||||
)
|
||||
|
||||
@@ -629,8 +629,6 @@ val wasmPhases = SameTypeNamedCompilerPhase(
|
||||
localClassesInInlineFunctionsPhase then
|
||||
localClassesExtractionFromInlineFunctionsPhase then
|
||||
|
||||
// TODO: Need some helpers from stdlib
|
||||
// arrayConstructorPhase then
|
||||
wrapInlineDeclarationsWithReifiedTypeParametersPhase then
|
||||
|
||||
functionInliningPhase then
|
||||
|
||||
+10
-7
@@ -141,12 +141,6 @@ internal class WasmUsefulDeclarationProcessor(
|
||||
irClass.getWasmArrayAnnotation()?.type
|
||||
?.enqueueType(irClass, "array type for wasm array annotated")
|
||||
|
||||
if (irClass.symbol in context.wasmSymbols.primitiveTypeToCreateTypedArray.keys) {
|
||||
irClass.declarations.forEach {
|
||||
(it as? IrField)?.enqueue(irClass, "preserve all fields for primitive arrays")
|
||||
}
|
||||
}
|
||||
|
||||
if (context.inlineClassesUtils.isClassInlineLike(irClass)) {
|
||||
irClass.declarations
|
||||
.firstIsInstanceOrNull<IrConstructor>()
|
||||
@@ -187,9 +181,18 @@ internal class WasmUsefulDeclarationProcessor(
|
||||
|
||||
override fun processConstructor(irConstructor: IrConstructor) {
|
||||
super.processConstructor(irConstructor)
|
||||
if (!context.inlineClassesUtils.isClassInlineLike(irConstructor.parentAsClass)) {
|
||||
val constructedClass = irConstructor.constructedClass
|
||||
if (!context.inlineClassesUtils.isClassInlineLike(constructedClass)) {
|
||||
processIrFunction(irConstructor)
|
||||
}
|
||||
|
||||
if (irConstructor.hasWasmPrimitiveConstructorAnnotation()) {
|
||||
constructedClass.declarations.forEach { declaration ->
|
||||
if (declaration is IrField) {
|
||||
declaration.enqueue(constructedClass, "preserve all fields for primitive constructors")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun isExported(declaration: IrDeclaration): Boolean = declaration.isJsExport()
|
||||
|
||||
@@ -86,8 +86,8 @@ internal fun <T> arrayIterator(array: Array<T>) = object : Iterator<T> {
|
||||
override fun next() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun <reified T> createAnyArray(size: Int, invokable: (Int) -> T): Array<T> {
|
||||
internal inline fun <reified T> createAnyArray(size: Int, init: (Int) -> T): Array<T> {
|
||||
val result = WasmAnyArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return Array(result)
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ internal fun byteArrayIterator(array: ByteArray) = object : ByteIterator() {
|
||||
override fun nextByte() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createByteArray(size: Int, invokable: (Int) -> Byte): ByteArray {
|
||||
internal inline fun createByteArray(size: Int, init: (Int) -> Byte): ByteArray {
|
||||
val result = WasmByteArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return ByteArray(result)
|
||||
}
|
||||
|
||||
@@ -82,9 +82,9 @@ internal fun charArrayIterator(array: CharArray) = object : CharIterator() {
|
||||
override fun nextChar() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createCharArray(size: Int, invokable: (Int) -> Char): CharArray {
|
||||
internal inline fun createCharArray(size: Int, init: (Int) -> Char): CharArray {
|
||||
val result = WasmCharArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return CharArray(result)
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ internal fun shortArrayIterator(array: ShortArray) = object : ShortIterator() {
|
||||
override fun nextShort() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createShortArray(size: Int, invokable: (Int) -> Short): ShortArray {
|
||||
internal inline fun createShortArray(size: Int, init: (Int) -> Short): ShortArray {
|
||||
val result = WasmShortArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return ShortArray(result)
|
||||
}
|
||||
|
||||
@@ -156,9 +156,9 @@ internal fun intArrayIterator(array: IntArray) = object : IntIterator() {
|
||||
override fun nextInt() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createIntArray(size: Int, invokable: (Int) -> Int): IntArray {
|
||||
internal inline fun createIntArray(size: Int, init: (Int) -> Int): IntArray {
|
||||
val result = WasmIntArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return IntArray(result)
|
||||
}
|
||||
|
||||
@@ -192,9 +192,9 @@ internal fun longArrayIterator(array: LongArray) = object : LongIterator() {
|
||||
override fun nextLong() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createLongArray(size: Int, invokable: (Int) -> Long): LongArray {
|
||||
internal inline fun createLongArray(size: Int, init: (Int) -> Long): LongArray {
|
||||
val result = WasmLongArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return LongArray(result)
|
||||
}
|
||||
|
||||
@@ -228,9 +228,9 @@ internal fun floatArrayIterator(array: FloatArray) = object : FloatIterator() {
|
||||
override fun nextFloat() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createFloatArray(size: Int, invokable: (Int) -> Float): FloatArray {
|
||||
internal inline fun createFloatArray(size: Int, init: (Int) -> Float): FloatArray {
|
||||
val result = WasmFloatArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return FloatArray(result)
|
||||
}
|
||||
|
||||
@@ -264,9 +264,9 @@ internal fun doubleArrayIterator(array: DoubleArray) = object : DoubleIterator()
|
||||
override fun nextDouble() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
|
||||
}
|
||||
|
||||
internal inline fun createDoubleArray(size: Int, invokable: (Int) -> Double): DoubleArray {
|
||||
internal inline fun createDoubleArray(size: Int, init: (Int) -> Double): DoubleArray {
|
||||
val result = WasmDoubleArray(size)
|
||||
result.fill(size, invokable)
|
||||
result.fill(size, init)
|
||||
return DoubleArray(result)
|
||||
}
|
||||
|
||||
@@ -304,10 +304,10 @@ internal fun booleanArrayIterator(array: BooleanArray) = object : BooleanIterato
|
||||
private fun Boolean.reinterpretAsByte(): Byte =
|
||||
implementedAsIntrinsic
|
||||
|
||||
internal inline fun createBooleanArray(size: Int, invokable: (Int) -> Boolean): BooleanArray {
|
||||
internal inline fun createBooleanArray(size: Int, init: (Int) -> Boolean): BooleanArray {
|
||||
val result = WasmByteArray(size)
|
||||
result.fill(size) {
|
||||
invokable(it).reinterpretAsByte()
|
||||
init(it).reinterpretAsByte()
|
||||
}
|
||||
return BooleanArray(result)
|
||||
}
|
||||
Reference in New Issue
Block a user