From 4978cecf7a80f711fedefc4d83c72e9d2e4934a2 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 13 Feb 2017 17:48:35 +0300 Subject: [PATCH] Fix several tests. (#234) --- .../kotlin/backend/konan/KonanLower.kt | 6 +- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 3 +- .../src/main/kotlin/kotlin/ranges/Ranges.kt | 119 +++++++++++++++++- 3 files changed, 118 insertions(+), 10 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt index f4fcf308179..55d5d6bc0c4 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt @@ -37,15 +37,15 @@ internal class KonanLower(val context: Context) { phaser.phase(KonanPhase.LOWER_BUILTIN_OPERATORS) { BuiltinOperatorLowering(context).runOnFilePostfix(irFile) } - phaser.phase(KonanPhase.LOWER_TYPE_OPERATORS) { - TypeOperatorLowering(context).runOnFilePostfix(irFile) - } phaser.phase(KonanPhase.LOWER_SHARED_VARIABLES) { SharedVariablesLowering(context).runOnFilePostfix(irFile) } phaser.phase(KonanPhase.LOWER_INITIALIZERS) { InitializersLowering(context).runOnFilePostfix(irFile) } + phaser.phase(KonanPhase.LOWER_TYPE_OPERATORS) { + TypeOperatorLowering(context).runOnFilePostfix(irFile) + } phaser.phase(KonanPhase.LOWER_LOCAL_FUNCTIONS) { LocalDeclarationsLowering(context).runOnFilePostfix(irFile) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index eede8254a63..21cb5433359 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.isNothing +import org.jetbrains.kotlin.types.typeUtil.isTypeParameter import org.jetbrains.kotlin.types.typeUtil.isUnit import org.jetbrains.kotlin.utils.addToStdlib.singletonList @@ -1170,7 +1171,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid context.log("evaluateCast : ${ir2string(value)}") val type = value.typeOperand assert(!KotlinBuiltIns.isPrimitiveType(type) && !KotlinBuiltIns.isPrimitiveType(value.argument.type)) - + assert(!type.isTypeParameter()) val dstDescriptor = TypeUtils.getClassDescriptor(type) // Get class descriptor for dst type. val dstTypeInfo = codegen.typeInfoValue(dstDescriptor!!) // Get TypeInfo for dst type. val srcArg = evaluateExpression(value.argument) // Evaluate src expression. diff --git a/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt b/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt index 12096e272d4..ddd16121b9a 100644 --- a/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt +++ b/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt @@ -330,15 +330,122 @@ public fun Long.coerceIn(range: ClosedRange): Long { /** * Returns a progression that goes over the same range in the opposite direction with the same step. */ -public fun IntProgression.reversed(): IntProgression { - return IntProgression.fromClosedRange(last, first, -step) -} +public fun IntProgression.reversed() = IntProgression.fromClosedRange(last, first, -step) /** * Returns a progression from this value down to the specified [to] value with the step -1. * * The [to] value has to be less than this value. */ -public infix fun Int.downTo(to: Int): IntProgression { - return IntProgression.fromClosedRange(this, to, -1) -} +public infix fun Int.downTo(to: Byte) = IntProgression.fromClosedRange(this, to.toInt(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Long.downTo(to: Byte) = LongProgression.fromClosedRange(this, to.toLong(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Byte.downTo(to: Byte): IntProgression = + IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Short.downTo(to: Byte) = + IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Char.downTo(to: Char): CharProgression = CharProgression.fromClosedRange(this, to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Int.downTo(to: Int) = IntProgression.fromClosedRange(this, to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Long.downTo(to: Int) = LongProgression.fromClosedRange(this, to.toLong(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Byte.downTo(to: Int): IntProgression = + IntProgression.fromClosedRange(this.toInt(), to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Short.downTo(to: Int) = IntProgression.fromClosedRange(this.toInt(), to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Int.downTo(to: Long) = LongProgression.fromClosedRange(this.toLong(), to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Long.downTo(to: Long) = LongProgression.fromClosedRange(this, to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Byte.downTo(to: Long): LongProgression = + LongProgression.fromClosedRange(this.toLong(), to, -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Int.downTo(to: Short) = IntProgression.fromClosedRange(this, to.toInt(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Long.downTo(to: Short) = LongProgression.fromClosedRange(this, to.toLong(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Byte.downTo(to: Short): IntProgression = + IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) + +/** + * Returns a progression from this value down to the specified [to] value with the step -1. + * + * The [to] value has to be less than this value. + */ +public infix fun Short.downTo(to: Short): IntProgression = + IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1)