[K/N] Reenable constant inlining except for Double nan constants
^KT-52970
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
open class A(val a: String = DEFAULT_A){
|
||||
companion object: A(){
|
||||
const val DEFAULT_A = "OK"
|
||||
const val DEFAULT_A = "O"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A().a
|
||||
open class B(val b: String = DEFAULT_B){
|
||||
companion object: B(){
|
||||
const val DEFAULT_B = "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A.a + B().b
|
||||
+6
-2
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.checkDeclarationParents
|
||||
@@ -276,8 +281,7 @@ internal val allLoweringsPhase = NamedCompilerPhase(
|
||||
coroutinesPhase,
|
||||
typeOperatorPhase,
|
||||
expressionBodyTransformPhase,
|
||||
// Disabled for now because it leads to problems with Double.NaN and Float.NaN on macOS AArch 64.
|
||||
// constantInliningPhase,
|
||||
constantInliningPhase,
|
||||
fileInitializersPhase,
|
||||
bridgesPhase,
|
||||
exportInternalAbiPhase,
|
||||
|
||||
+8
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstKind
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
@@ -23,7 +24,13 @@ internal class ConstLowering(val context: Context) : FileLoweringPass {
|
||||
|
||||
private class NativeInlineConstTransformer : InlineConstTransformer() {
|
||||
override val IrField.constantInitializer get() =
|
||||
(initializer?.expression as? IrConst<*>)?.takeIf { correspondingPropertySymbol?.owner?.isConst == true }
|
||||
(initializer?.expression as? IrConst<*>)
|
||||
?.takeIf { correspondingPropertySymbol?.owner?.isConst == true }
|
||||
// NaN constants has inconsistencies between IR and metadata representation,
|
||||
// so inlining them can lead to incorrect behaviour. Check KT-53258 for details.
|
||||
?.takeUnless { it.kind == IrConstKind.Double && IrConstKind.Double.valueOf(it).isNaN() }
|
||||
?.takeUnless { it.kind == IrConstKind.Float && IrConstKind.Float.valueOf(it).isNaN() }
|
||||
|
||||
override fun reportInlineConst(field: IrField, value: IrConst<*>) {}
|
||||
// on jvm IrGetObjectValue is also dropped. This would be breaking change for native.
|
||||
// Some design work is required to decide what is correct, let just keep current behaviour for now
|
||||
|
||||
@@ -76,3 +76,8 @@ enum {
|
||||
|
||||
void increment(int* counter);
|
||||
#define increment(counter) { (*(counter))++; }
|
||||
|
||||
#define DEFAULT_DOUBLE_NAN __builtin_nan("")
|
||||
#define DEFAULT_FLOAT_NAN __builtin_nanf("")
|
||||
#define OTHER_DOUBLE_NAN __builtin_nan("0x7ffc0123456789ab")
|
||||
#define OTHER_FLOAT_NAN __builtin_nanf("0x7fc12345")
|
||||
|
||||
@@ -45,4 +45,9 @@ fun main(args: Array<String>) {
|
||||
increment(counter.ptr)
|
||||
assertEquals(43, counter.value)
|
||||
}
|
||||
|
||||
assertEquals(Double.NaN.toRawBits(), DEFAULT_DOUBLE_NAN.toRawBits())
|
||||
assertEquals(Float.NaN.toRawBits(), DEFAULT_FLOAT_NAN.toRawBits())
|
||||
assertEquals(0x7fc12345, OTHER_FLOAT_NAN.toRawBits())
|
||||
assertEquals(0x7ffc0123456789abL, OTHER_DOUBLE_NAN.toRawBits())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user