JVM_IR: do not explicitly initialize Refs to default values
This commit is contained in:
+5
@@ -107,6 +107,11 @@ class JvmSharedVariablesManager(
|
||||
|
||||
override fun defineSharedValue(originalDeclaration: IrVariable, sharedVariableDeclaration: IrVariable): IrStatement {
|
||||
val initializer = originalDeclaration.initializer ?: return sharedVariableDeclaration
|
||||
val default = IrConstImpl.defaultValueForType(initializer.startOffset, initializer.endOffset, originalDeclaration.type)
|
||||
if (initializer is IrConst<*> && initializer.value == default.value) {
|
||||
// The field is preinitialized to the default value, so an explicit set is not required.
|
||||
return sharedVariableDeclaration
|
||||
}
|
||||
val initializationStatement = with(initializer) {
|
||||
IrSetVariableImpl(startOffset, endOffset, irBuiltIns.unitType, originalDeclaration.symbol, this, null)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun test() {
|
||||
var x = 0
|
||||
var x = 1
|
||||
run {
|
||||
val obj = object {
|
||||
fun foo() { ++x }
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
fun runNoInline(f: () -> Unit) = f()
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
var x = 1
|
||||
runNoInline { ++x }
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
fun runNoInline(f: () -> Unit) = f()
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
var x = 1
|
||||
run {
|
||||
run {
|
||||
runNoInline {
|
||||
|
||||
Vendored
+1
-5
@@ -1,6 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TODO KT-36648 Captured variables not optimized in JVM_IR
|
||||
|
||||
fun box(): String {
|
||||
run {
|
||||
run {
|
||||
@@ -24,8 +21,7 @@ fun box(): String {
|
||||
// 4 ILOAD 6
|
||||
// 4 ISTORE 6
|
||||
|
||||
// Temporary variable slots for 'x2++' + store to fake index:
|
||||
// 0 ILOAD 1
|
||||
// Temporary variable for 'x2++' + store to fake variable marking the outer `run`:
|
||||
// 2 ISTORE 1
|
||||
|
||||
// 0 NEW
|
||||
|
||||
@@ -7,10 +7,4 @@ fun test(): Char {
|
||||
}
|
||||
|
||||
// 1 LOCALVARIABLE c Ljava/lang/Object;
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 2 ASTORE 0
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
// 3 ASTORE 0
|
||||
// *two* of them are after the start of c's live range
|
||||
// 2 ASTORE 0
|
||||
Reference in New Issue
Block a user