[JS IR BE] Fix @DoNotIntrinsify processing. Reuse it for compareTo
This commit is contained in:
@@ -134,8 +134,6 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
|||||||
val jsToString = getInternalFunction("toString")
|
val jsToString = getInternalFunction("toString")
|
||||||
val jsAnyToString = getInternalFunction("anyToString")
|
val jsAnyToString = getInternalFunction("anyToString")
|
||||||
val jsCompareTo = getInternalFunction("compareTo")
|
val jsCompareTo = getInternalFunction("compareTo")
|
||||||
// TODO: Use annotations
|
|
||||||
val compareToDoNotIntrinsicify = getInternalFunction("compareToDoNotIntrinsicify")
|
|
||||||
val jsEquals = getInternalFunction("equals")
|
val jsEquals = getInternalFunction("equals")
|
||||||
|
|
||||||
// Coroutines
|
// Coroutines
|
||||||
|
|||||||
+1
-5
@@ -343,7 +343,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunction(declaration: IrFunction): IrStatement {
|
override fun visitFunction(declaration: IrFunction): IrStatement {
|
||||||
if (declaration.symbol == intrinsics.compareToDoNotIntrinsicify)
|
if (declaration.hasAnnotation(intrinsics.doNotIntrinsifyAnnotationSymbol))
|
||||||
return declaration
|
return declaration
|
||||||
return super.visitFunction(declaration)
|
return super.visitFunction(declaration)
|
||||||
}
|
}
|
||||||
@@ -355,10 +355,6 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
|
|||||||
val symbol = call.symbol
|
val symbol = call.symbol
|
||||||
val declaration = symbol.owner
|
val declaration = symbol.owner
|
||||||
|
|
||||||
if (declaration.annotations.any { it.superQualifierSymbol == intrinsics.doNotIntrinsifyAnnotationSymbol }) {
|
|
||||||
return call
|
|
||||||
}
|
|
||||||
|
|
||||||
if (declaration.isDynamic() || declaration.isEffectivelyExternal()) {
|
if (declaration.isDynamic() || declaration.isEffectivelyExternal()) {
|
||||||
when (call.origin) {
|
when (call.origin) {
|
||||||
IrStatementOrigin.GET_PROPERTY -> {
|
IrStatementOrigin.GET_PROPERTY -> {
|
||||||
|
|||||||
@@ -336,6 +336,12 @@ fun IrAnnotationContainer.hasAnnotation(name: FqName) =
|
|||||||
it.symbol.owner.parentAsClass.descriptor.fqNameSafe == name
|
it.symbol.owner.parentAsClass.descriptor.fqNameSafe == name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun IrAnnotationContainer.hasAnnotation(symbol: IrClassSymbol) =
|
||||||
|
annotations.any {
|
||||||
|
it.symbol.owner.parentAsClass.symbol == symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val IrConstructor.constructedClassType get() = (parent as IrClass).thisReceiver?.type!!
|
val IrConstructor.constructedClassType get() = (parent as IrClass).thisReceiver?.type!!
|
||||||
|
|
||||||
fun IrFunction.isFakeOverriddenFromAny(): Boolean {
|
fun IrFunction.isFakeOverriddenFromAny(): Boolean {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JS_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ internal annotation class DoNotIntrinsify
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
@DoNotIntrinsify
|
@DoNotIntrinsify
|
||||||
internal fun charSequenceGet(a: CharSequence, index: Int): Char {
|
internal fun charSequenceGet(a: CharSequence, index: Int): Char {
|
||||||
return if (a is String) {
|
return if (isString(a)) {
|
||||||
Char(a.asDynamic().charCodeAt(index).unsafeCast<Int>())
|
Char(a.asDynamic().charCodeAt(index).unsafeCast<Int>())
|
||||||
} else {
|
} else {
|
||||||
a[index]
|
a[index]
|
||||||
@@ -20,8 +20,8 @@ internal fun charSequenceGet(a: CharSequence, index: Int): Char {
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
@DoNotIntrinsify
|
@DoNotIntrinsify
|
||||||
internal fun charSequenceLength(a: CharSequence): Int {
|
internal fun charSequenceLength(a: CharSequence): Int {
|
||||||
return if (a is String) {
|
return if (isString(a)) {
|
||||||
a.asDynamic().length.unsafeCast<Int>()
|
js("a.length").unsafeCast<Int>()
|
||||||
} else {
|
} else {
|
||||||
a.length
|
a.length
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,12 @@ internal fun charSequenceLength(a: CharSequence): Int {
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
@DoNotIntrinsify
|
@DoNotIntrinsify
|
||||||
internal fun charSequenceSubSequence(a: CharSequence, startIndex: Int, endIndex: Int): CharSequence {
|
internal fun charSequenceSubSequence(a: CharSequence, startIndex: Int, endIndex: Int): CharSequence {
|
||||||
return if (a is String) {
|
return if (isString(a)) {
|
||||||
a.asDynamic().substring(startIndex, endIndex).unsafeCast<String>()
|
a.asDynamic().substring(startIndex, endIndex).unsafeCast<String>()
|
||||||
} else {
|
} else {
|
||||||
a.subSequence(startIndex, endIndex)
|
a.subSequence(startIndex, endIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keeping this function as separate non-inline to intrincify `is` operator
|
||||||
|
internal fun isString(a: CharSequence) = a is String
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fun compareTo(a: dynamic, b: dynamic): Int {
|
|||||||
return compareToDoNotIntrinsicify(a, b)
|
return compareToDoNotIntrinsicify(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use @DoNotIntrincify annotation
|
@DoNotIntrinsify
|
||||||
private fun <T : Comparable<T>> compareToDoNotIntrinsicify(a: Comparable<T>, b: T) =
|
private fun <T : Comparable<T>> compareToDoNotIntrinsicify(a: Comparable<T>, b: T) =
|
||||||
a.compareTo(b)
|
a.compareTo(b)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user