Skip to content

Commit

Permalink
~ ExperimentalStdlibApi
Browse files Browse the repository at this point in the history
  • Loading branch information
elizarov committed May 26, 2020
1 parent 636a855 commit 93a7d91
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libraries/stdlib/src/kotlin/util/DeepRecursive.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import kotlin.coroutines.intrinsics.*
* @param block the function body.
*/
@SinceKotlin("1.4")
@ExperimentalStdlibApi
public class DeepRecursiveFunction<T, R>(
internal val block: suspend DeepRecursiveScope<T, R>.(T) -> R
)
Expand All @@ -79,6 +80,7 @@ public class DeepRecursiveFunction<T, R>(
* [callRecursive][DeepRecursiveScope.callRecursive].
*/
@SinceKotlin("1.4")
@ExperimentalStdlibApi
public operator fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R =
DeepRecursiveScopeImpl<T, R>(block, value).runCallLoop()

Expand All @@ -91,6 +93,7 @@ public operator fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R =
*/
@RestrictsSuspension
@SinceKotlin("1.4")
@ExperimentalStdlibApi
public sealed class DeepRecursiveScope<T, R> {
/**
* Makes recursive call to this [DeepRecursiveFunction] function putting the call activation frame on the heap,
Expand Down Expand Up @@ -118,11 +121,13 @@ public sealed class DeepRecursiveScope<T, R> {

// ================== Implementation ==================

@ExperimentalStdlibApi
private typealias DeepRecursiveFunctionBlock = suspend DeepRecursiveScope<*, *>.(Any?) -> Any?

private val UNDEFINED_RESULT = Result.success(COROUTINE_SUSPENDED)

@Suppress("UNCHECKED_CAST")
@ExperimentalStdlibApi
private class DeepRecursiveScopeImpl<T, R>(
block: suspend DeepRecursiveScope<T, R>.(T) -> R,
value: T
Expand Down

0 comments on commit 93a7d91

Please sign in to comment.