Stabilize deepRecursiveFunction and DeepRecursiveScope
#KT-51848
This commit is contained in:
committed by
Space
parent
728f2bdbea
commit
cf79752c14
@@ -415,8 +415,8 @@ public inline operator fun <T, V> kotlin.reflect.KProperty1<T, V>.getValue(thisR
|
|||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun kotlin.Any?.hashCode(): kotlin.Int
|
public inline fun kotlin.Any?.hashCode(): kotlin.Int
|
||||||
|
|
||||||
@kotlin.SinceKotlin(version = "1.4")
|
@kotlin.SinceKotlin(version = "1.7")
|
||||||
@kotlin.ExperimentalStdlibApi
|
@kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
|
||||||
public operator fun <T, R> kotlin.DeepRecursiveFunction<T, R>.invoke(value: T): R
|
public operator fun <T, R> kotlin.DeepRecursiveFunction<T, R>.invoke(value: T): R
|
||||||
|
|
||||||
public fun kotlin.Double.isFinite(): kotlin.Boolean
|
public fun kotlin.Double.isFinite(): kotlin.Boolean
|
||||||
@@ -1195,15 +1195,15 @@ public final annotation class ContextFunctionTypeParams : kotlin.Annotation {
|
|||||||
public final val count: kotlin.Int { get; }
|
public final val count: kotlin.Int { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.SinceKotlin(version = "1.4")
|
@kotlin.SinceKotlin(version = "1.7")
|
||||||
@kotlin.ExperimentalStdlibApi
|
@kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
|
||||||
public final class DeepRecursiveFunction<T, R> {
|
public final class DeepRecursiveFunction<T, R> {
|
||||||
public constructor DeepRecursiveFunction<T, R>(block: suspend kotlin.DeepRecursiveScope<T, R>.(T) -> R)
|
public constructor DeepRecursiveFunction<T, R>(block: suspend kotlin.DeepRecursiveScope<T, R>.(T) -> R)
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictsSuspension
|
@kotlin.coroutines.RestrictsSuspension
|
||||||
@kotlin.SinceKotlin(version = "1.4")
|
@kotlin.SinceKotlin(version = "1.7")
|
||||||
@kotlin.ExperimentalStdlibApi
|
@kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
|
||||||
public sealed class DeepRecursiveScope<T, R> {
|
public sealed class DeepRecursiveScope<T, R> {
|
||||||
protected constructor DeepRecursiveScope<T, R>()
|
protected constructor DeepRecursiveScope<T, R>()
|
||||||
|
|
||||||
|
|||||||
@@ -378,8 +378,8 @@ public inline operator fun <T, V> kotlin.reflect.KProperty1<T, V>.getValue(thisR
|
|||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun kotlin.Any?.hashCode(): kotlin.Int
|
public inline fun kotlin.Any?.hashCode(): kotlin.Int
|
||||||
|
|
||||||
@kotlin.SinceKotlin(version = "1.4")
|
@kotlin.SinceKotlin(version = "1.7")
|
||||||
@kotlin.ExperimentalStdlibApi
|
@kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
|
||||||
public operator fun <T, R> kotlin.DeepRecursiveFunction<T, R>.invoke(value: T): R
|
public operator fun <T, R> kotlin.DeepRecursiveFunction<T, R>.invoke(value: T): R
|
||||||
|
|
||||||
public fun kotlin.Double.isFinite(): kotlin.Boolean
|
public fun kotlin.Double.isFinite(): kotlin.Boolean
|
||||||
@@ -1166,15 +1166,15 @@ public final annotation class ContextFunctionTypeParams : kotlin.Annotation {
|
|||||||
public final val count: kotlin.Int { get; }
|
public final val count: kotlin.Int { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.SinceKotlin(version = "1.4")
|
@kotlin.SinceKotlin(version = "1.7")
|
||||||
@kotlin.ExperimentalStdlibApi
|
@kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
|
||||||
public final class DeepRecursiveFunction<T, R> {
|
public final class DeepRecursiveFunction<T, R> {
|
||||||
public constructor DeepRecursiveFunction<T, R>(block: suspend kotlin.DeepRecursiveScope<T, R>.(T) -> R)
|
public constructor DeepRecursiveFunction<T, R>(block: suspend kotlin.DeepRecursiveScope<T, R>.(T) -> R)
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictsSuspension
|
@kotlin.coroutines.RestrictsSuspension
|
||||||
@kotlin.SinceKotlin(version = "1.4")
|
@kotlin.SinceKotlin(version = "1.7")
|
||||||
@kotlin.ExperimentalStdlibApi
|
@kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
|
||||||
public sealed class DeepRecursiveScope<T, R> {
|
public sealed class DeepRecursiveScope<T, R> {
|
||||||
protected constructor DeepRecursiveScope<T, R>()
|
protected constructor DeepRecursiveScope<T, R>()
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import kotlin.native.concurrent.SharedImmutable
|
|||||||
* println(depth(deepTree)) // StackOverflowError
|
* println(depth(deepTree)) // StackOverflowError
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* If this `depth` function is called for a `deepTree` it produces [StackOverflowError] because of deep recursion.
|
* If this `depth` function is called for a `deepTree` it produces `StackOverflowError` because of deep recursion.
|
||||||
* However, the `depth` function can be rewritten using `DeepRecursiveFunction` in the following way, and then
|
* However, the `depth` function can be rewritten using `DeepRecursiveFunction` in the following way, and then
|
||||||
* it successfully computes [`depth(deepTree)`][DeepRecursiveFunction.invoke] expression:
|
* it successfully computes [`depth(deepTree)`][DeepRecursiveFunction.invoke] expression:
|
||||||
*
|
*
|
||||||
@@ -67,8 +67,8 @@ import kotlin.native.concurrent.SharedImmutable
|
|||||||
* @param [R] the function result type.
|
* @param [R] the function result type.
|
||||||
* @param block the function body.
|
* @param block the function body.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.4")
|
@SinceKotlin("1.7")
|
||||||
@ExperimentalStdlibApi
|
@WasExperimental(ExperimentalStdlibApi::class)
|
||||||
public class DeepRecursiveFunction<T, R>(
|
public class DeepRecursiveFunction<T, R>(
|
||||||
internal val block: suspend DeepRecursiveScope<T, R>.(T) -> R
|
internal val block: suspend DeepRecursiveScope<T, R>.(T) -> R
|
||||||
)
|
)
|
||||||
@@ -80,8 +80,8 @@ public class DeepRecursiveFunction<T, R>(
|
|||||||
* initial recursive invocation. From inside of [DeepRecursiveScope] use
|
* initial recursive invocation. From inside of [DeepRecursiveScope] use
|
||||||
* [callRecursive][DeepRecursiveScope.callRecursive].
|
* [callRecursive][DeepRecursiveScope.callRecursive].
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.4")
|
@SinceKotlin("1.7")
|
||||||
@ExperimentalStdlibApi
|
@WasExperimental(ExperimentalStdlibApi::class)
|
||||||
public operator fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R =
|
public operator fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R =
|
||||||
DeepRecursiveScopeImpl<T, R>(block, value).runCallLoop()
|
DeepRecursiveScopeImpl<T, R>(block, value).runCallLoop()
|
||||||
|
|
||||||
@@ -93,8 +93,8 @@ public operator fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R =
|
|||||||
* @param [R] function result type.
|
* @param [R] function result type.
|
||||||
*/
|
*/
|
||||||
@RestrictsSuspension
|
@RestrictsSuspension
|
||||||
@SinceKotlin("1.4")
|
@SinceKotlin("1.7")
|
||||||
@ExperimentalStdlibApi
|
@WasExperimental(ExperimentalStdlibApi::class)
|
||||||
public sealed class DeepRecursiveScope<T, R> {
|
public sealed class DeepRecursiveScope<T, R> {
|
||||||
/**
|
/**
|
||||||
* Makes recursive call to this [DeepRecursiveFunction] function putting the call activation frame on the heap,
|
* Makes recursive call to this [DeepRecursiveFunction] function putting the call activation frame on the heap,
|
||||||
@@ -122,14 +122,12 @@ public sealed class DeepRecursiveScope<T, R> {
|
|||||||
|
|
||||||
// ================== Implementation ==================
|
// ================== Implementation ==================
|
||||||
|
|
||||||
@ExperimentalStdlibApi
|
|
||||||
private typealias DeepRecursiveFunctionBlock = suspend DeepRecursiveScope<*, *>.(Any?) -> Any?
|
private typealias DeepRecursiveFunctionBlock = suspend DeepRecursiveScope<*, *>.(Any?) -> Any?
|
||||||
|
|
||||||
@SharedImmutable
|
@SharedImmutable
|
||||||
private val UNDEFINED_RESULT = Result.success(COROUTINE_SUSPENDED)
|
private val UNDEFINED_RESULT = Result.success(COROUTINE_SUSPENDED)
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@ExperimentalStdlibApi
|
|
||||||
private class DeepRecursiveScopeImpl<T, R>(
|
private class DeepRecursiveScopeImpl<T, R>(
|
||||||
block: suspend DeepRecursiveScope<T, R>.(T) -> R,
|
block: suspend DeepRecursiveScope<T, R>.(T) -> R,
|
||||||
value: T
|
value: T
|
||||||
|
|||||||
Reference in New Issue
Block a user