[JS IR BE] Fix @DoNotIntrinsify processing. Reuse it for compareTo

This commit is contained in:
Svyatoslav Kuzmich
2018-09-24 20:24:28 +03:00
parent 12a31637d1
commit 334c776b92
6 changed files with 15 additions and 13 deletions
@@ -134,8 +134,6 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
val jsToString = getInternalFunction("toString")
val jsAnyToString = getInternalFunction("anyToString")
val jsCompareTo = getInternalFunction("compareTo")
// TODO: Use annotations
val compareToDoNotIntrinsicify = getInternalFunction("compareToDoNotIntrinsicify")
val jsEquals = getInternalFunction("equals")
// Coroutines
@@ -343,7 +343,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
}
override fun visitFunction(declaration: IrFunction): IrStatement {
if (declaration.symbol == intrinsics.compareToDoNotIntrinsicify)
if (declaration.hasAnnotation(intrinsics.doNotIntrinsifyAnnotationSymbol))
return declaration
return super.visitFunction(declaration)
}
@@ -355,10 +355,6 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
val symbol = call.symbol
val declaration = symbol.owner
if (declaration.annotations.any { it.superQualifierSymbol == intrinsics.doNotIntrinsifyAnnotationSymbol }) {
return call
}
if (declaration.isDynamic() || declaration.isEffectivelyExternal()) {
when (call.origin) {
IrStatementOrigin.GET_PROPERTY -> {
@@ -336,6 +336,12 @@ fun IrAnnotationContainer.hasAnnotation(name: FqName) =
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!!
fun IrFunction.isFakeOverriddenFromAny(): Boolean {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// WITH_RUNTIME
fun box(): String {
@@ -10,7 +10,7 @@ internal annotation class DoNotIntrinsify
@PublishedApi
@DoNotIntrinsify
internal fun charSequenceGet(a: CharSequence, index: Int): Char {
return if (a is String) {
return if (isString(a)) {
Char(a.asDynamic().charCodeAt(index).unsafeCast<Int>())
} else {
a[index]
@@ -20,8 +20,8 @@ internal fun charSequenceGet(a: CharSequence, index: Int): Char {
@PublishedApi
@DoNotIntrinsify
internal fun charSequenceLength(a: CharSequence): Int {
return if (a is String) {
a.asDynamic().length.unsafeCast<Int>()
return if (isString(a)) {
js("a.length").unsafeCast<Int>()
} else {
a.length
}
@@ -30,9 +30,12 @@ internal fun charSequenceLength(a: CharSequence): Int {
@PublishedApi
@DoNotIntrinsify
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>()
} else {
a.subSequence(startIndex, endIndex)
}
}
// Keeping this function as separate non-inline to intrincify `is` operator
internal fun isString(a: CharSequence) = a is String
+1 -1
View File
@@ -23,7 +23,7 @@ fun compareTo(a: dynamic, b: dynamic): Int {
return compareToDoNotIntrinsicify(a, b)
}
// TODO: Use @DoNotIntrincify annotation
@DoNotIntrinsify
private fun <T : Comparable<T>> compareToDoNotIntrinsicify(a: Comparable<T>, b: T) =
a.compareTo(b)