Compare commits

...

6 Commits

Author SHA1 Message Date
Ilya Gorbunov
9e4a06e942 Revert tests temporarily 2021-02-10 03:33:16 +03:00
zhelenskiy
7ae252b1a0 More accurate naive test generation 2021-02-08 18:26:20 +03:00
zhelenskiy
b3131ac8ef ULong test is provided 2021-02-08 17:35:18 +03:00
zhelenskiy
0aeeaf288d Useless assertion is removed 2021-02-08 17:27:34 +03:00
zhelenskiy
de9dcc4179 Collection instance for Char, (U)Int, (U)Long Progressions 2021-02-08 15:45:55 +03:00
Dmitriy Novozhilov
f80857c16a Fix broken compilation after changing kotlin compiler configuration form
Problem was introduced at 391f5315
2021-02-06 23:15:26 +03:00
10 changed files with 136 additions and 48 deletions

View File

@@ -18,6 +18,9 @@
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="72" />
</MarkdownNavigatorCodeStyleSettings>
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
<codeStyleSettings language="HTML">
<indentOptions>
<option name="INDENT_SIZE" value="2" />
@@ -101,4 +104,4 @@
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
</codeStyleSettings>
</code_scheme>
</component>
</component>

1
.idea/misc.xml generated
View File

@@ -12,6 +12,7 @@
<item index="2" class="java.lang.String" itemvalue="org.gradle.api.tasks.options.Option" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>

View File

@@ -18,7 +18,7 @@ public open class CharProgression
start: Char,
endInclusive: Char,
step: Int
) : Iterable<Char> {
) : Collection<Char> {
init {
if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero.")
if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.")
@@ -42,7 +42,7 @@ public open class CharProgression
override fun iterator(): CharIterator = CharProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is CharProgression && (isEmpty() && other.isEmpty() ||
@@ -53,6 +53,18 @@ public open class CharProgression
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
override val size: Int
get() = if (isEmpty()) 0 else (last - first) / step + 1
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: Char): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step == 0
step < 0 && value <= first && value >= last -> (first - value) % (-step) == 0
else -> false
}
override fun containsAll(elements: Collection<Char>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**
* Creates CharProgression within the specified bounds of a closed range.
@@ -75,7 +87,7 @@ public open class IntProgression
start: Int,
endInclusive: Int,
step: Int
) : Iterable<Int> {
) : Collection<Int> {
init {
if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero.")
if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.")
@@ -99,7 +111,7 @@ public open class IntProgression
override fun iterator(): IntIterator = IntProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is IntProgression && (isEmpty() && other.isEmpty() ||
@@ -110,6 +122,18 @@ public open class IntProgression
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
override val size: Int
get() = if (isEmpty()) 0 else (last - first) / step + 1
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: Int): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step == 0
step < 0 && value <= first && value >= last -> (first - value) % (-step) == 0
else -> false
}
override fun containsAll(elements: Collection<Int>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**
* Creates IntProgression within the specified bounds of a closed range.
@@ -132,7 +156,7 @@ public open class LongProgression
start: Long,
endInclusive: Long,
step: Long
) : Iterable<Long> {
) : Collection<Long> {
init {
if (step == 0L) throw kotlin.IllegalArgumentException("Step must be non-zero.")
if (step == Long.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Long.MIN_VALUE to avoid overflow on negation.")
@@ -156,7 +180,7 @@ public open class LongProgression
override fun iterator(): LongIterator = LongProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is LongProgression && (isEmpty() && other.isEmpty() ||
@@ -167,6 +191,18 @@ public open class LongProgression
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
override val size: Int
get() = if (isEmpty()) 0 else ((last - first) / step + 1).toIntExactOrNull() ?: Int.MAX_VALUE
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: Long): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step == 0L
step < 0 && value <= first && value >= last -> (first - value) % (-step) == 0L
else -> false
}
override fun containsAll(elements: Collection<Long>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**
* Creates LongProgression within the specified bounds of a closed range.

View File

@@ -49,6 +49,9 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) {
" if (isEmpty()) -1 else (31 * (31 * ${hashLong("first")} + ${hashLong("last")}) + ${hashLong("step")}).toInt()"
}
val sizeBody = "if (isEmpty()) 0 else " +
"(last - first) / step + 1".let { if (kind == LONG) "($it).toIntExactOrNull() ?: Int.MAX_VALUE" else it }
out.println(
"""/**
* A progression of values of type `$t`.
@@ -59,7 +62,7 @@ public open class $progression
start: $t,
endInclusive: $t,
step: $incrementType
) : Iterable<$t> {
) : Collection<$t> {
init {
$checkZero
$checkMin
@@ -83,7 +86,7 @@ public open class $progression
override fun iterator(): ${t}Iterator = ${t}ProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is $progression && (isEmpty() && other.isEmpty() ||
@@ -93,6 +96,18 @@ public open class $progression
override fun toString(): String = ${"if (step > 0) \"\$first..\$last step \$step\" else \"\$first downTo \$last step \${-step}\""}
override val size: Int
get() = $sizeBody
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: $t): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step == $zero
step < 0 && value <= first && value >= last -> (first - value) % (-step) == $zero
else -> false
}
override fun containsAll(elements: Collection<$t>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**
* Creates $progression within the specified bounds of a closed range.

View File

@@ -513,6 +513,14 @@ class UnsignedRangeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
fun hashCodeConversion(name: String, isSigned: Boolean = false) =
if (type == UnsignedType.ULONG) "($name xor ($name ${if (isSigned) "u" else ""}shr 32))" else name
val sizeBody = """
when {
isEmpty() -> 0UL
step > 0 -> (last - first) / step.toULong() + 1UL
step < 0 -> (first - last) / (-step).toULong() + 1UL
else -> error("Invariant is broken: step cannot be 0")
}.let { if (it > Int.MAX_VALUE.toULong()) Int.MAX_VALUE else it.toInt() }
"""
out.println(
"""
@@ -556,7 +564,7 @@ internal constructor(
start: $elementType,
endInclusive: $elementType,
step: $stepType
) : Iterable<$elementType> {
) : Collection<$elementType> {
init {
if (step == 0.to$stepType()) throw kotlin.IllegalArgumentException("Step must be non-zero.")
if (step == $stepMinValue) throw kotlin.IllegalArgumentException("Step must be greater than $stepMinValue to avoid overflow on negation.")
@@ -580,7 +588,7 @@ internal constructor(
override fun iterator(): ${elementType}Iterator = ${elementType}ProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is ${elementType}Progression && (isEmpty() && other.isEmpty() ||
@@ -590,6 +598,19 @@ internal constructor(
if (isEmpty()) -1 else (31 * (31 * ${hashCodeConversion("first")}.toInt() + ${hashCodeConversion("last")}.toInt()) + ${hashCodeConversion("step", isSigned = true)}.toInt())
override fun toString(): String = if (step > 0) "${'$'}first..${'$'}last step ${'$'}step" else "${'$'}first downTo ${'$'}last step ${'$'}{-step}"
override val size: Int
get() = $sizeBody
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: $elementType): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step.toULong() == 0UL
step < 0 && value <= first && value >= last -> (first - value) % (-step).toULong() == 0UL
else -> false
}
override fun containsAll(elements: Collection<$elementType>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**

View File

@@ -109,15 +109,6 @@
<text resource-bundle="messages/KotlinBundle" key="kotlin.compiler.js.option.generate.sourcemaps"/>
</properties>
</component>
<component id="6484c" class="javax.swing.JLabel" binding="labelForSourceMapPrefix">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e65e6"/>
<text resource-bundle="messages/KotlinBundle" key="add.prefix.to.paths.in.source.map"/>
</properties>
</component>
<component id="e65e6" class="javax.swing.JTextField" binding="sourceMapPrefix">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
@@ -150,7 +141,7 @@
</component>
</children>
</grid>
<grid id="483d4" binding="scriptPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="483d4" binding="scriptPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="9" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="true"/>
@@ -165,39 +156,20 @@
<children>
<component id="71c3f" class="javax.swing.JTextField" binding="scriptTemplatesField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="56390" class="javax.swing.JLabel" binding="scriptTemplatesClasspathLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="644d9"/>
<text resource-bundle="messages/KotlinBundle" key="script.templates.classpath"/>
</properties>
</component>
<component id="644d9" class="javax.swing.JTextField" binding="scriptTemplatesClasspathField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="ae60b" class="javax.swing.JLabel" binding="scriptTemplatesLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<labelFor value="71c3f"/>
<text resource-bundle="messages/KotlinBundle" key="script.template.classes"/>
</properties>
</component>
</children>
</grid>
<grid id="1ee7c" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 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.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 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.
*/

View File

@@ -49,7 +49,7 @@ internal constructor(
start: UInt,
endInclusive: UInt,
step: Int
) : Iterable<UInt> {
) : Collection<UInt> {
init {
if (step == 0.toInt()) throw kotlin.IllegalArgumentException("Step must be non-zero.")
if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.")
@@ -73,7 +73,7 @@ internal constructor(
override fun iterator(): UIntIterator = UIntProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is UIntProgression && (isEmpty() && other.isEmpty() ||
@@ -83,6 +83,26 @@ internal constructor(
if (isEmpty()) -1 else (31 * (31 * first.toInt() + last.toInt()) + step.toInt())
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
override val size: Int
get() =
when {
isEmpty() -> 0UL
step > 0 -> (last - first) / step.toULong() + 1UL
step < 0 -> (first - last) / (-step).toULong() + 1UL
else -> error("Invariant is broken: step cannot be 0")
}.let { if (it > Int.MAX_VALUE.toULong()) Int.MAX_VALUE else it.toInt() }
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: UInt): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step.toULong() == 0UL
step < 0 && value <= first && value >= last -> (first - value) % (-step).toULong() == 0UL
else -> false
}
override fun containsAll(elements: Collection<UInt>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**

View File

@@ -49,7 +49,7 @@ internal constructor(
start: ULong,
endInclusive: ULong,
step: Long
) : Iterable<ULong> {
) : Collection<ULong> {
init {
if (step == 0.toLong()) throw kotlin.IllegalArgumentException("Step must be non-zero.")
if (step == Long.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Long.MIN_VALUE to avoid overflow on negation.")
@@ -73,7 +73,7 @@ internal constructor(
override fun iterator(): ULongIterator = ULongProgressionIterator(first, last, step)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
public override fun isEmpty(): Boolean = if (step > 0) first > last else first < last
override fun equals(other: Any?): Boolean =
other is ULongProgression && (isEmpty() && other.isEmpty() ||
@@ -83,6 +83,26 @@ internal constructor(
if (isEmpty()) -1 else (31 * (31 * (first xor (first shr 32)).toInt() + (last xor (last shr 32)).toInt()) + (step xor (step ushr 32)).toInt())
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
override val size: Int
get() =
when {
isEmpty() -> 0UL
step > 0 -> (last - first) / step.toULong() + 1UL
step < 0 -> (first - last) / (-step).toULong() + 1UL
else -> error("Invariant is broken: step cannot be 0")
}.let { if (it > Int.MAX_VALUE.toULong()) Int.MAX_VALUE else it.toInt() }
override fun contains(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") /* for the backward compatibility with old names */ value: ULong): Boolean = when {
this.isEmpty() -> false
step > 0 && value >= first && value <= last -> (value - first) % step.toULong() == 0UL
step < 0 && value <= first && value >= last -> (first - value) % (-step).toULong() == 0UL
else -> false
}
override fun containsAll(elements: Collection<ULong>): Boolean = if (this.isEmpty()) elements.isEmpty() else elements.all { it in this }
companion object {
/**