Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move code Arrow-Core #2403

Merged
merged 7 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/ank.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package arrow.ank

import arrow.core.Validated
import arrow.core.ValidatedNel
import arrow.core.invalidNel
import arrow.core.sequenceValidated
import arrow.core.validNel
import arrow.fx.coroutines.nonFatalOrThrow
import java.nio.file.Path
import kotlin.math.ln
import kotlin.math.pow
Expand All @@ -21,13 +18,6 @@ fun Long.humanBytes(): String {
return String.format("%.1f %sB", this / unit.toDouble().pow(exp.toDouble()), pre)
}

suspend fun <A> Validated.Companion.catchNel(f: suspend () -> A): ValidatedNel<Throwable, A> =
try {
f().validNel()
} catch (e: Throwable) {
e.nonFatalOrThrow().invalidNel()
}

suspend fun ank(source: Path, target: Path, compilerArgs: List<String>, ankOps: AnkOps): Unit = with(ankOps) {
printConsole(colored(ANSI_PURPLE, AnkHeader))
val heapSize = Runtime.getRuntime().totalMemory()
Expand Down
4 changes: 3 additions & 1 deletion arrow-libs/ank/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ kotlin.incremental=true
# Kotlin Test configuration
#Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise
kotlintest.parallelism=1
kotlin.stdlib.default.dependency=false

# Reason: https://youtrack.jetbrains.com/issue/KT-46847
# kotlin.stdlib.default.dependency=false
7 changes: 3 additions & 4 deletions arrow-libs/core/arrow-annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ plugins {
apply from: "$SUB_PROJECT_MPP"
apply from: "$DOC_CREATION"
apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER"
apply from: "$ANIMALSNIFFER_MPP"

kotlin {
sourceSets {
jvmMain {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
api "io.kindedj:kindedj:$KINDEDJ_VERSION"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion arrow-libs/core/arrow-continuations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ apply from: "$SUB_PROJECT_MPP"
apply from: "$TEST_COVERAGE"
apply from: "$DOC_CREATION"
apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER"
apply from: "$ANIMALSNIFFER_MPP"
apply plugin: 'kotlinx-atomicfu'

kotlin {
sourceSets {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
}
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package arrow.continuations.generic

/**
* A [Throwable] class intended for control flow.
* Instance of [ControlThrowable] should **not** be caught,
* and `arrow.core.NonFatal` does not catch this [Throwable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable].
*/
expect open class ControlThrowable() : Throwable
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
override suspend fun <A> shift(f: suspend RestrictedScope<R>.(DelimitedContinuation<A, R>) -> R): A =
suspendCoroutineUninterceptedOrReturn { continueMain ->
val delCont = SingleShotCont(continueMain, shiftFnContinuations)
assert(nextShift == null)
require(nextShift == null)
nextShift = suspend { this.f(delCont) }
COROUTINE_SUSPENDED
}
Expand All @@ -75,7 +75,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
*/
suspend fun <A, B> shiftCPS(f: suspend (DelimitedContinuation<A, B>) -> R, c: suspend DelimitedScope<B>.(A) -> B): Nothing =
suspendCoroutineUninterceptedOrReturn {
assert(nextShift == null)
require(nextShift == null)
nextShift = suspend { f(CPSCont(c)) }
COROUTINE_SUSPENDED
}
Expand Down Expand Up @@ -116,7 +116,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
// we can return directly if we never suspended/called shift
else return@invoke it as R
}
assert(resultVar !== EMPTY_VALUE)
require(resultVar !== EMPTY_VALUE)
// We need to finish the partially evaluated shift blocks by passing them our result.
// This will update the result via the continuations that now finish up
for (c in shiftFnContinuations.asReversed()) c.resume(resultVar as R)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ internal open class MultiShotDelimContScope<R>(val f: suspend RestrictedScope<R>
suspendCoroutineUninterceptedOrReturn { continueMain ->
val c = MultiShotCont(continueMain, f, stack, shiftFnContinuations)
val s: suspend RestrictedScope<R>.() -> R = { this.func(c) }
assert(nextShift.compareAndSet(null, s))
require(nextShift.compareAndSet(null, s))
COROUTINE_SUSPENDED
}

suspend fun <A, B> shiftCPS(func: suspend DelimitedScope<R>.(DelimitedContinuation<A, B>) -> R, c: suspend DelimitedScope<B>.(A) -> B): Nothing =
suspendCoroutine {
val s: suspend DelimitedScope<R>.() -> R = { func(CPSCont(c)) }
assert(nextShift.compareAndSet(null, s))
require(nextShift.compareAndSet(null, s))
}

// This assumes RestrictSuspension or at least assumes the user to never reference the parent scope in f.
Expand Down Expand Up @@ -115,7 +115,7 @@ internal open class MultiShotDelimContScope<R>(val f: suspend RestrictedScope<R>
}
} else return@invoke it as R
}
assert(resultVar.value != null)
require(resultVar.value != null)
for (c in shiftFnContinuations.asReversed()) c.resume(resultVar.value!!)
return resultVar.value!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package arrow.continuations.generic

/** Represents a unique identifier using object equality. */
internal class Token {
override fun toString(): String = "Token(${Integer.toHexString(hashCode())})"
@ExperimentalUnsignedTypes
override fun toString(): String = "Token(${hashCode().toUInt().toString(16)})"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

package arrow.continuations.generic

/**
* A [Throwable] class intended for control flow.
* Instance of [ControlThrowable] should **not** be caught,
* Instance of [ControlThrowable.kt] should **not** be caught,
* and `arrow.core.NonFatal` does not catch this [Throwable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable.kt].
*/
open class ControlThrowable : Throwable() {
actual open class ControlThrowable : Throwable() {
override fun fillInStackTrace(): Throwable = this
}
35 changes: 12 additions & 23 deletions arrow-libs/core/arrow-core-retrofit/build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.jvm"
id "org.jlleitschuh.gradle.ktlint"
}

apply from: "$SUB_PROJECT_MPP"
apply from: "$SUB_PROJECT"
apply from: "$TEST_COVERAGE"
apply from: "$DOC_CREATION"
apply from: "$PUBLICATION_MPP"
apply from: "$PUBLICATION"
apply from: "$ANIMALSNIFFER"

kotlin {
sourceSets {
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
compileOnly project(":arrow-core")
compileOnly "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
}
}

jvmTest {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
runtimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION"
implementation project(":arrow-core-test")
implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
implementation "com.squareup.okhttp3:mockwebserver:$MOCKWEBSERVER_VERSION"
}
}
}
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
compileOnly project(":arrow-core")
compileOnly "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
testCompileOnly "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION"
testImplementation project(":arrow-core-test")
testImplementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
testImplementation "com.squareup.okhttp3:mockwebserver:$MOCKWEBSERVER_VERSION"
}
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-core-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ apply from: "$PUBLICATION"
apply from: "$ANIMALSNIFFER"

dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
api project(":arrow-core")
api project(":arrow-continuations")
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION"
Expand Down
12 changes: 8 additions & 4 deletions arrow-libs/core/arrow-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ apply from: "$SUB_PROJECT_MPP"
apply from: "$TEST_COVERAGE"
apply from: "$DOC_CREATION"
apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER"
apply from: "$ANIMALSNIFFER_MPP"

kotlin {
sourceSets {
jvmMain {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
compileOnly "org.codehaus.mojo:animal-sniffer-annotations:1.19"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
api project(":arrow-continuations")
api project(":arrow-annotations")
}
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
}
}

jvmTest {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package arrow.core

@PublishedApi
internal expect object ArrowCoreInternalException : RuntimeException
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.typeclasses.Monoid
import arrow.typeclasses.Semigroup
import kotlin.jvm.JvmName
import kotlin.jvm.JvmStatic

/**
*
Expand Down
Loading