[Wasm] Fix unit issues

- Materialize unit when its value is actually needed.
- Special-case Unit_getInstance return type at codegen. It should be a
  proper Unit object instead of a "void"
This commit is contained in:
Svyatoslav Kuzmich
2021-05-24 18:06:26 +03:00
committed by TeamCityServer
parent 20ddaa9ebf
commit b79719d6f5
45 changed files with 289 additions and 141 deletions
@@ -156,6 +156,8 @@ class InlineClassLowering(val context: CommonBackendContext) {
+statement.transformStatement(object : IrElementTransformerVoid() {
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression {
expression.transformChildrenVoid()
// Static function for delegating constructors return unboxed instance of inline class
expression.type = irClass.defaultType
return irBlock(expression) {
thisVar = createTmpVariable(
expression,
@@ -7,13 +7,11 @@ package org.jetbrains.kotlin.ir.backend.js.lower
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
import org.jetbrains.kotlin.backend.common.lower.AbstractValueUsageTransformer
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.isPrimitiveArray
@@ -126,7 +124,7 @@ class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsag
if (actualType.isUnit() && !expectedType.isUnit()) {
// Don't materialize Unit if value is known to be proper Unit on runtime
if (!this.isGetUnit()) {
if (!this.isGetUnit(irBuiltIns)) {
val unitValue = JsIrBuilder.buildGetObjectValue(actualType, context.irBuiltIns.unitClass)
return JsIrBuilder.buildComposite(actualType, listOf(this, unitValue))
}
@@ -160,20 +158,6 @@ class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsag
}
}
private tailrec fun IrExpression.isGetUnit(): Boolean =
when (this) {
is IrContainerExpression ->
when (val lastStmt = this.statements.lastOrNull()) {
is IrExpression -> lastStmt.isGetUnit()
else -> false
}
is IrGetObjectValue ->
this.symbol == irBuiltIns.unitClass
else -> false
}
private fun buildSafeCall(
arg: IrExpression,
actualType: IrType,
@@ -206,4 +190,33 @@ class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsag
)
}
}
}
}
class UnitMaterializationPass(val context: JsCommonBackendContext) : AbstractValueUsageTransformer(context.irBuiltIns), BodyLoweringPass {
override fun lower(irBody: IrBody, container: IrDeclaration) {
irBody.transformChildrenVoid()
}
override fun IrExpression.useAsValue(value: IrValueDeclaration): IrExpression {
if (this.type == irBuiltIns.unitType && !this.isGetUnit(irBuiltIns)) {
val unitValue = JsIrBuilder.buildGetObjectValue(type, irBuiltIns.unitClass)
return JsIrBuilder.buildComposite(type, listOf(this, unitValue))
}
return this
}
}
private tailrec fun IrExpression.isGetUnit(irBuiltIns: IrBuiltIns): Boolean =
when (this) {
is IrContainerExpression ->
when (val lastStmt = this.statements.lastOrNull()) {
is IrExpression -> lastStmt.isGetUnit(irBuiltIns)
else -> false
}
is IrGetObjectValue ->
this.symbol == irBuiltIns.unitClass
else -> false
}
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny
import org.jetbrains.kotlin.backend.common.ir.isTopLevel
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.backend.js.JsLoweredDeclarationOrigin
import org.jetbrains.kotlin.ir.backend.js.export.isExported
@@ -115,6 +116,9 @@ fun IrBody.prependFunctionCall(
}
}
fun JsCommonBackendContext.findUnitGetInstanceFunction(): IrSimpleFunction =
mapping.objectToGetInstanceFunction[irBuiltIns.unitClass.owner]!!
fun IrDeclaration.isImportedFromModuleOnly(): Boolean {
return isTopLevel && isEffectivelyExternal() && (getJsModule() != null && !isJsNonModule() || (parent as? IrAnnotationContainer)?.getJsModule() != null)
}
@@ -328,6 +328,12 @@ private val wasmNullSpecializationLowering = makeWasmModulePhase(
description = "Specialize assigning Nothing? values to other types."
)
private val unitMaterializationPass = makeWasmModulePhase(
{ context -> UnitMaterializationPass(context) },
name = "UnitLoweringPass",
description = "Materialize unit instances"
)
private val staticMembersLoweringPhase = makeWasmModulePhase(
::StaticMembersLowering,
name = "StaticMembersLowering",
@@ -499,5 +505,6 @@ val wasmPhases = NamedCompilerPhase(
wasmThrowDebugLoweringPhase then
staticMembersLoweringPhase then
wasmNullSpecializationLowering then
unitMaterializationPass then
validateIrAfterLowering
)
@@ -20,10 +20,7 @@ import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.defaultType
import org.jetbrains.kotlin.ir.util.getInlineClassBackingField
import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.wasm.ir.*
@@ -40,6 +37,13 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
error("Unexpected element of type ${element::class}")
}
val unitGetInstance by lazy { backendContext.mapping.objectToGetInstanceFunction[irBuiltIns.unitClass.owner]!! }
override fun visitGetObjectValue(expression: IrGetObjectValue) {
require(expression.symbol == irBuiltIns.unitClass)
body.buildCall(context.referenceFunction(unitGetInstance.symbol))
}
override fun visitTypeOperator(expression: IrTypeOperatorCall) {
require(expression.operator == IrTypeOperator.REINTERPRET_CAST) { "Other types of casts must be lowered" }
generateExpression(expression.argument)
@@ -329,11 +333,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
statementToWasmInstruction(it)
}
if (expression.type != irBuiltIns.unitType) {
generateExpression(statements.last() as IrExpression)
} else {
statementToWasmInstruction(statements.last())
}
generateExpression(statements.last() as IrExpression)
}
override fun visitBreak(jump: IrBreak) {
@@ -345,18 +345,17 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
}
override fun visitReturn(expression: IrReturn) {
generateExpression(expression.value)
// FIXME: Hack for "returning" Unit from functions with generic return type.
// Common case -- lambdas returning unit.
if (expression.value.type == irBuiltIns.unitType &&
expression.returnTargetSymbol.owner.returnType(backendContext) != irBuiltIns.unitType
if (
expression.value.type == irBuiltIns.unitType &&
expression.returnTargetSymbol.owner.returnType(backendContext) == irBuiltIns.unitType
) {
val irReturnType = expression.returnTargetSymbol.owner.returnType(backendContext)
statementToWasmInstruction(expression.value)
} else {
generateExpression(expression.value)
}
if (irReturnType != irBuiltIns.unitType) {
generateDefaultInitializerForType(context.transformType(irReturnType), body)
}
if (context.irFunction is IrConstructor) {
body.buildGetLocal(context.referenceLocal(0))
}
// Handle complex exported parameters.
@@ -371,25 +370,6 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
}
override fun visitWhen(expression: IrWhen) {
if (expression.type == irBuiltIns.unitType) {
var ifCount = 0
for (branch in expression.branches) {
if (!isElseBranch(branch)) {
generateExpression(branch.condition)
body.buildIf(label = null, resultType = null)
statementToWasmInstruction(branch.result)
body.buildElse()
ifCount++
} else {
statementToWasmInstruction(branch.result)
break
}
}
repeat(ifCount) { body.buildEnd() }
return
}
val resultType = context.transformBlockResultType(expression.type)
var ifCount = 0
for (branch in expression.branches) {
@@ -489,10 +469,47 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
return
}
generateExpression(statement as IrExpression)
if (statement is IrContainerExpression) {
statement.statements.forEach { it ->
statementToWasmInstruction(it)
}
} else if (statement is IrWhen) {
var ifCount = 0
for (branch in statement.branches) {
if (!isElseBranch(branch)) {
generateExpression(branch.condition)
body.buildIf(label = null, resultType = null)
statementToWasmInstruction(branch.result)
body.buildElse()
ifCount++
} else {
statementToWasmInstruction(branch.result)
break
}
}
if (statement.type != irBuiltIns.unitType && statement.type != irBuiltIns.nothingType) {
body.buildInstr(WasmOp.DROP)
repeat(ifCount) { body.buildEnd() }
} else {
generateExpression(statement as IrExpression)
var needDrop = true
if (statement.type == irBuiltIns.nothingType)
needDrop = false
if (statement is IrSetValue || statement is IrBreakContinue || statement is IrSetField || statement is IrLoop || statement is IrDelegatingConstructorCall) {
needDrop = false
}
if (statement is IrCall || statement is IrConstructorCall) {
val unitGetInstanceCall = statement is IrCall && statement.symbol.owner == unitGetInstance
if (statement.type == irBuiltIns.unitType && !unitGetInstanceCall) {
needDrop = false
}
}
if (needDrop) {
body.buildInstr(WasmOp.DROP)
}
}
}
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.backend.js.utils.findUnitGetInstanceFunction
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
@@ -29,6 +30,8 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
private val backendContext: WasmBackendContext = context.backendContext
private val irBuiltIns: IrBuiltIns = backendContext.irBuiltIns
private val unitGetInstanceFunction: IrSimpleFunction by lazy { backendContext.findUnitGetInstanceFunction() }
override fun visitElement(element: IrElement) {
error("Unexpected element of type ${element::class}")
}
@@ -84,8 +87,18 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
}
},
resultTypes = listOfNotNull(
resultType.let {
if (importedName != null && it is WasmRefNullType) WasmEqRef else it
run {
val type = if (declaration == unitGetInstanceFunction) {
// Unit_getInstance returns true Unit reference instead of "void"
context.transformType(declaration.returnType)
} else {
resultType
}
if (importedName != null && type is WasmRefNullType)
WasmEqRef
else
type
}
)
)
@@ -14,9 +14,12 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
import org.jetbrains.kotlin.backend.common.lower.irNot
import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
import org.jetbrains.kotlin.backend.wasm.ir2wasm.erasedUpperBound
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.backend.js.utils.findUnitGetInstanceFunction
import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
@@ -35,6 +38,7 @@ class WasmTypeOperatorLowering(val context: WasmBackendContext) : FileLoweringPa
class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrElementTransformerVoidWithContext() {
private val symbols = context.wasmSymbols
private val builtIns = context.irBuiltIns
private val unitGetInstance = context.findUnitGetInstanceFunction()
private lateinit var builder: DeclarationIrBuilder
@@ -45,7 +49,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
return when (expression.operator) {
IrTypeOperator.IMPLICIT_CAST -> lowerImplicitCast(expression)
IrTypeOperator.IMPLICIT_DYNAMIC_CAST -> error("Dynamic casts are not supported in Wasm backend")
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> expression.argument
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> builder.irComposite(resultType = builtIns.unitType) { +expression.argument }
IrTypeOperator.IMPLICIT_INTEGER_COERCION -> lowerIntegerCoercion(expression)
IrTypeOperator.IMPLICIT_NOTNULL -> lowerImplicitCast(expression)
IrTypeOperator.INSTANCEOF -> lowerInstanceOf(expression, inverted = false)
@@ -57,6 +61,19 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
}
}
override fun visitVariable(declaration: IrVariable): IrStatement {
// Some IR passes, notable for-loops-lowering assumes implicit cast during variable initialization
val initializer = declaration.initializer
if (initializer != null &&
initializer.type != declaration.type
) {
builder = context.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol).at(declaration)
declaration.initializer = narrowType(initializer.type, declaration.type, initializer)
}
return super.visitVariable(declaration)
}
private fun lowerInstanceOf(
expression: IrTypeOperatorCall,
inverted: Boolean
@@ -135,10 +152,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
private fun generateTypeCheckNonNull(argument: IrExpression, toType: IrType): IrExpression {
assert(!toType.isMarkedNullable())
return when {
toType.isNothing() -> builder.irComposite(resultType = builtIns.booleanType) {
+(argument)
+builder.irFalse()
}
toType.isNothing() -> builder.irFalse()
toType.isTypeParameter() -> generateTypeCheckWithTypeParameter(argument, toType)
toType.isInterface() -> generateIsInterface(argument, toType)
else -> generateIsSubClass(argument, toType)
@@ -281,16 +295,10 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
val fromTypeErased = fromType.erasedType
val toTypeErased = toType.erasedType
if (fromTypeErased.isSubtypeOfClass(toTypeErased.classOrNull!!)) {
return builder.irComposite {
+argument
+builder.irTrue()
}
return builder.irTrue()
}
if (!toTypeErased.isSubtypeOfClass(fromTypeErased.classOrNull!!)) {
return builder.irComposite {
+argument
+builder.irFalse()
}
return builder.irFalse()
}
return builder.irCall(symbols.refTest).apply {
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.*
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.*
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
package array_test
fun box() : String {
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: INLINE_ARRAY_CONSTRUCTOR
typealias ArrayS = Array<String>
fun testArray() {
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: EXCEPTIONS_NOT_IMPLEMENTED
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: EXCEPTIONS_NOT_IMPLEMENTED
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun println(s: String) {
}
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun println(s: String) {
}
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun foo() {}
fun bar(): Int? = foo() as? Int
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
class Bar {
}
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
class ArrayWrapper<T>() {
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: COROUTINES
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun box(): String {
var i = 0
{
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
data class A(val x: Unit)
fun box(): String {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
data class A(val x: Unit)
fun box(): String {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// DONT_RUN_GENERATED_CODE: JS
tailrec fun foo(x: Int) {
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
interface A {
val method : () -> Unit?
}
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
class A {
fun get(vararg x: Int) = x.size
}
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
open class T(var value: Int) {}
fun localExtensionOnNullableParameter(): T {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun <T> myRun(action: () -> T): T = action()
fun foo(): String = "foo"
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
class Inv<T>(val x: T?)
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// !LANGUAGE: +InlineClasses
inline class UInt(private val value: Int) {
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun <T> tableView(init: Table<T>.() -> Unit) {
Table<T>().init()
}
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
+1 -1
View File
@@ -1,5 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
inline fun run2(block: () -> Unit) = block()
class A {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
class A {
val prop: Int
constructor(arg: Boolean) {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
class A {
val prop: Int
constructor(arg: Boolean) {
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun foo() {}
fun box(): String {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun isNull(x: Unit?) = x == null
fun box(): String {
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
val c = Unit
val d = c
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun foo(): Any? = bar()
fun bar() {}
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun <T : Any, R> T.let(f: (T) -> R): R = f(this)
fun box(): String {
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun isNull(x: Unit?) = x == null
fun <T : Any> isNullGeneric(x: T?) = x == null
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun foo() {}
fun box(): String {
-2
View File
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
fun box(): String {
Unit
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: UNIT_ISSUES
enum class En {
A,
B
@@ -458,6 +458,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/arrays/kt4357.kt");
}
@TestMetadata("kt594.kt")
public void testKt594() throws Exception {
runTest("compiler/testData/codegen/box/arrays/kt594.kt");
}
@TestMetadata("kt7009.kt")
public void testKt7009() throws Exception {
runTest("compiler/testData/codegen/box/arrays/kt7009.kt");
@@ -1971,6 +1976,21 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/casts/objectToPrimitiveWithAssertion.kt");
}
@TestMetadata("unitAsAny.kt")
public void testUnitAsAny() throws Exception {
runTest("compiler/testData/codegen/box/casts/unitAsAny.kt");
}
@TestMetadata("unitAsSafeAny.kt")
public void testUnitAsSafeAny() throws Exception {
runTest("compiler/testData/codegen/box/casts/unitAsSafeAny.kt");
}
@TestMetadata("unitNullableCast.kt")
public void testUnitNullableCast() throws Exception {
runTest("compiler/testData/codegen/box/casts/unitNullableCast.kt");
}
@TestMetadata("compiler/testData/codegen/box/casts/functions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -2284,6 +2304,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/classes/kt1891.kt");
}
@TestMetadata("kt1918.kt")
public void testKt1918() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt1918.kt");
}
@TestMetadata("kt1976.kt")
public void testKt1976() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt1976.kt");
@@ -3436,6 +3461,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/controlStructures/kt2416.kt");
}
@TestMetadata("kt2597.kt")
public void testKt2597() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt2597.kt");
}
@TestMetadata("kt299.kt")
public void testKt299() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt299.kt");
@@ -3840,6 +3870,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/dataClasses/twoVarParams.kt");
}
@TestMetadata("unitComponent.kt")
public void testUnitComponent() throws Exception {
runTest("compiler/testData/codegen/box/dataClasses/unitComponent.kt");
}
@TestMetadata("compiler/testData/codegen/box/dataClasses/copy")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -4035,6 +4070,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
public void testMixedParams() throws Exception {
runTest("compiler/testData/codegen/box/dataClasses/toString/mixedParams.kt");
}
@TestMetadata("unitComponent.kt")
public void testUnitComponent() throws Exception {
runTest("compiler/testData/codegen/box/dataClasses/toString/unitComponent.kt");
}
}
}
@@ -4780,6 +4820,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/sum.kt");
}
@TestMetadata("tailCallInBlockInParentheses.kt")
public void testTailCallInBlockInParentheses() throws Exception {
runTest("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/tailCallInBlockInParentheses.kt");
}
@TestMetadata("tailCallInParentheses.kt")
public void testTailCallInParentheses() throws Exception {
runTest("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/tailCallInParentheses.kt");
@@ -5809,6 +5854,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/functions/kt1649_1.kt");
}
@TestMetadata("kt1649_2.kt")
public void testKt1649_2() throws Exception {
runTest("compiler/testData/codegen/box/functions/kt1649_2.kt");
}
@TestMetadata("kt2270.kt")
public void testKt2270() throws Exception {
runTest("compiler/testData/codegen/box/functions/kt2270.kt");
@@ -5844,6 +5894,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/functions/kt2929.kt");
}
@TestMetadata("kt3214.kt")
public void testKt3214() throws Exception {
runTest("compiler/testData/codegen/box/functions/kt3214.kt");
}
@TestMetadata("kt3313.kt")
public void testKt3313() throws Exception {
runTest("compiler/testData/codegen/box/functions/kt3313.kt");
@@ -6155,6 +6210,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/functions/localFunctions/kt4989.kt");
}
@TestMetadata("localExtensionOnNullableParameter.kt")
public void testLocalExtensionOnNullableParameter() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/localExtensionOnNullableParameter.kt");
}
@TestMetadata("localFunctionInConstructor.kt")
public void testLocalFunctionInConstructor() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/localFunctionInConstructor.kt");
@@ -6578,6 +6638,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inference/capturedTypesSubstitutionIntoAbbreviation.kt");
}
@TestMetadata("coercionToUnitWithLastLambdaExpression.kt")
public void testCoercionToUnitWithLastLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("earlyReturnInsideCrossinlineLambda.kt")
public void testEarlyReturnInsideCrossinlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/inference/earlyReturnInsideCrossinlineLambda.kt");
@@ -6633,6 +6698,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
}
@TestMetadata("noCoercionToUnitWithEqualityConstraintForNullableReturnType.kt")
public void testNoCoercionToUnitWithEqualityConstraintForNullableReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/noCoercionToUnitWithEqualityConstraintForNullableReturnType.kt");
}
@TestMetadata("recursiveConstraintInsideTypeArgumentWithStarProjection.kt")
public void testRecursiveConstraintInsideTypeArgumentWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/recursiveConstraintInsideTypeArgumentWithStarProjection.kt");
@@ -6792,6 +6862,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt");
}
@TestMetadata("boxUnboxOfInlineClassForCapturedVars.kt")
public void testBoxUnboxOfInlineClassForCapturedVars() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxUnboxOfInlineClassForCapturedVars.kt");
}
@TestMetadata("bridgeForFunctionReturningInlineClass.kt")
public void testBridgeForFunctionReturningInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/bridgeForFunctionReturningInlineClass.kt");
@@ -9076,6 +9151,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/ir/hashCodeOnGenericSubstitutedWithPrimitive.kt");
}
@TestMetadata("kt25405.kt")
public void testKt25405() throws Exception {
runTest("compiler/testData/codegen/box/ir/kt25405.kt");
}
@TestMetadata("kt40083.kt")
public void testKt40083() throws Exception {
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
@@ -14626,6 +14706,21 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/secondaryConstructors/varargs.kt");
}
@TestMetadata("withNonLocalReturn.kt")
public void testWithNonLocalReturn() throws Exception {
runTest("compiler/testData/codegen/box/secondaryConstructors/withNonLocalReturn.kt");
}
@TestMetadata("withReturn.kt")
public void testWithReturn() throws Exception {
runTest("compiler/testData/codegen/box/secondaryConstructors/withReturn.kt");
}
@TestMetadata("withReturnUnit.kt")
public void testWithReturnUnit() throws Exception {
runTest("compiler/testData/codegen/box/secondaryConstructors/withReturnUnit.kt");
}
@TestMetadata("withoutPrimarySimple.kt")
public void testWithoutPrimarySimple() throws Exception {
runTest("compiler/testData/codegen/box/secondaryConstructors/withoutPrimarySimple.kt");
@@ -15955,11 +16050,36 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/unit"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("closureReturnsNullableUnit.kt")
public void testClosureReturnsNullableUnit() throws Exception {
runTest("compiler/testData/codegen/box/unit/closureReturnsNullableUnit.kt");
}
@TestMetadata("ifElse.kt")
public void testIfElse() throws Exception {
runTest("compiler/testData/codegen/box/unit/ifElse.kt");
}
@TestMetadata("kt3634.kt")
public void testKt3634() throws Exception {
runTest("compiler/testData/codegen/box/unit/kt3634.kt");
}
@TestMetadata("kt4212.kt")
public void testKt4212() throws Exception {
runTest("compiler/testData/codegen/box/unit/kt4212.kt");
}
@TestMetadata("kt4265.kt")
public void testKt4265() throws Exception {
runTest("compiler/testData/codegen/box/unit/kt4265.kt");
}
@TestMetadata("nullableUnit.kt")
public void testNullableUnit() throws Exception {
runTest("compiler/testData/codegen/box/unit/nullableUnit.kt");
}
@TestMetadata("nullableUnitInWhen1.kt")
public void testNullableUnitInWhen1() throws Exception {
runTest("compiler/testData/codegen/box/unit/nullableUnitInWhen1.kt");
@@ -15969,6 +16089,21 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
public void testNullableUnitInWhen2() throws Exception {
runTest("compiler/testData/codegen/box/unit/nullableUnitInWhen2.kt");
}
@TestMetadata("nullableUnitInWhen3.kt")
public void testNullableUnitInWhen3() throws Exception {
runTest("compiler/testData/codegen/box/unit/nullableUnitInWhen3.kt");
}
@TestMetadata("unitClassObject.kt")
public void testUnitClassObject() throws Exception {
runTest("compiler/testData/codegen/box/unit/unitClassObject.kt");
}
@TestMetadata("UnitValue.kt")
public void testUnitValue() throws Exception {
runTest("compiler/testData/codegen/box/unit/UnitValue.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/unsignedTypes")
@@ -16330,6 +16465,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/when/noElseExhaustiveStatement.kt");
}
@TestMetadata("noElseExhaustiveUnitExpected.kt")
public void testNoElseExhaustiveUnitExpected() throws Exception {
runTest("compiler/testData/codegen/box/when/noElseExhaustiveUnitExpected.kt");
}
@TestMetadata("noElseInStatement.kt")
public void testNoElseInStatement() throws Exception {
runTest("compiler/testData/codegen/box/when/noElseInStatement.kt");