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 {
|
override fun defineSharedValue(originalDeclaration: IrVariable, sharedVariableDeclaration: IrVariable): IrStatement {
|
||||||
val initializer = originalDeclaration.initializer ?: return sharedVariableDeclaration
|
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) {
|
val initializationStatement = with(initializer) {
|
||||||
IrSetVariableImpl(startOffset, endOffset, irBuiltIns.unitType, originalDeclaration.symbol, this, null)
|
IrSetVariableImpl(startOffset, endOffset, irBuiltIns.unitType, originalDeclaration.symbol, this, null)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fun test() {
|
fun test() {
|
||||||
var x = 0
|
var x = 1
|
||||||
run {
|
run {
|
||||||
val obj = object {
|
val obj = object {
|
||||||
fun foo() { ++x }
|
fun foo() { ++x }
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
fun runNoInline(f: () -> Unit) = f()
|
fun runNoInline(f: () -> Unit) = f()
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
var x = 0
|
var x = 1
|
||||||
runNoInline { ++x }
|
runNoInline { ++x }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
fun runNoInline(f: () -> Unit) = f()
|
fun runNoInline(f: () -> Unit) = f()
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
var x = 0
|
var x = 1
|
||||||
run {
|
run {
|
||||||
run {
|
run {
|
||||||
runNoInline {
|
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 {
|
fun box(): String {
|
||||||
run {
|
run {
|
||||||
run {
|
run {
|
||||||
@@ -24,8 +21,7 @@ fun box(): String {
|
|||||||
// 4 ILOAD 6
|
// 4 ILOAD 6
|
||||||
// 4 ISTORE 6
|
// 4 ISTORE 6
|
||||||
|
|
||||||
// Temporary variable slots for 'x2++' + store to fake index:
|
// Temporary variable for 'x2++' + store to fake variable marking the outer `run`:
|
||||||
// 0 ILOAD 1
|
|
||||||
// 2 ISTORE 1
|
// 2 ISTORE 1
|
||||||
|
|
||||||
// 0 NEW
|
// 0 NEW
|
||||||
|
|||||||
@@ -7,10 +7,4 @@ fun test(): Char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1 LOCALVARIABLE c Ljava/lang/Object;
|
// 1 LOCALVARIABLE c Ljava/lang/Object;
|
||||||
|
|
||||||
// JVM_TEMPLATES
|
|
||||||
// 2 ASTORE 0
|
// 2 ASTORE 0
|
||||||
|
|
||||||
// JVM_IR_TEMPLATES
|
|
||||||
// 3 ASTORE 0
|
|
||||||
// *two* of them are after the start of c's live range
|
|
||||||
Reference in New Issue
Block a user