Skip to content

Commit

Permalink
Merge branch 'main' into sampengilly/ior-accumulate
Browse files Browse the repository at this point in the history
  • Loading branch information
sampengilly committed Apr 24, 2024
2 parents 8b52481 + 132de8c commit bc81e87
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/githubpages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: ./gradlew -Pversion=${{ github.event.release.tag_name }} dokkaHtmlMultiModule -Pgithubpages=true

- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ jobs:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/arrow-2' }}

- name: JVM (Kotlin 2.0) tests
run: ./gradlew jvmTest -Pkotlin_version=2.0.0-Beta3 -Pksp_version=2.0.0-Beta3-1.0.17 -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0
run: ./gradlew jvmTest -Pkotlin_version=2.0.0-RC1 -Pksp_version=2.0.0-RC1-1.0.20 -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0

- name: Upload reports
if: failure()
Expand Down
9 changes: 5 additions & 4 deletions arrow-libs/core/arrow-core-retrofit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply(from = property("ANIMALSNIFFER"))
dependencies {
compileOnly(libs.kotlin.stdlib)
compileOnly(projects.arrowCore)
compileOnly(libs.squareup.retrofit)
compileOnly(libs.squareup.retrofit.lib)

testImplementation(projects.arrowCore)
testImplementation(libs.kotest.frameworkEngine)
Expand All @@ -30,10 +30,11 @@ dependencies {
testCompileOnly(libs.kotlin.reflect)
testRuntimeOnly(libs.kotest.runnerJUnit5)
testImplementation(libs.squareup.okhttpMockWebServer)
testImplementation(libs.squareup.retrofitConverterGson)
testImplementation(libs.squareup.retrofitConverterMoshi)
testImplementation(libs.squareup.retrofit.converter.gson)
testImplementation(libs.squareup.retrofit.converter.moshi)
testImplementation(libs.kotlinx.serializationJson)
testImplementation(libs.jakewharton.retrofitConverterKotlinxSerialization)
testImplementation(libs.squareup.retrofit.converter.kotlinxSerialization)
testImplementation(libs.squareup.moshi.kotlin)
}

tasks.jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import arrow.core.left
import arrow.core.right
import arrow.retrofit.adapter.either.EitherCallAdapterFactory
import arrow.retrofit.adapter.mock.ResponseMock
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import io.kotest.core.spec.style.StringSpec
import io.kotest.core.spec.style.stringSpec
import io.kotest.matchers.shouldBe
Expand All @@ -20,6 +21,7 @@ import okhttp3.mockwebserver.SocketPolicy
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import retrofit2.converter.moshi.MoshiConverterFactory
import java.net.SocketException
import java.net.SocketTimeoutException
Expand All @@ -28,8 +30,9 @@ import java.util.concurrent.TimeUnit
@ExperimentalSerializationApi
class NetworkEitherCallAdapterTestSuite : StringSpec({
include(networkEitherCallAdapterTests(GsonConverterFactory.create()))
include(networkEitherCallAdapterTests(MoshiConverterFactory.create()))
include(networkEitherCallAdapterTests(Json.asConverterFactory("application/json".toMediaType())))
val moshi = Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build()
include(networkEitherCallAdapterTests(MoshiConverterFactory.create(moshi)))
})

private fun networkEitherCallAdapterTests(
Expand Down
1 change: 0 additions & 1 deletion arrow-libs/core/arrow-core/api/arrow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,6 @@ public abstract interface annotation class arrow/core/raise/RaiseDSL : java/lang
public final class arrow/core/raise/RaiseKt {
public static final fun _fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun _foldOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun _foldUnsafe (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun _merge (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun catch (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,13 @@ public inline fun <Error, A, B> fold(
* This method should never be wrapped in `try`/`catch` as it will not throw any unexpected errors,
* it will only result in [CancellationException], or fatal exceptions such as `OutOfMemoryError`.
*/
@OptIn(DelicateRaiseApi::class)
@JvmName("_fold")
public inline fun <Error, A, B> fold(
@BuilderInference block: Raise<Error>.() -> A,
catch: (throwable: Throwable) -> B,
recover: (error: Error) -> B,
transform: (value: A) -> B,
): B {
contract {
callsInPlace(catch, AT_MOST_ONCE)
callsInPlace(recover, AT_MOST_ONCE)
callsInPlace(transform, AT_MOST_ONCE)
}
return foldUnsafe(block, catch, recover) {
if (it is Function<*> || it is Lazy<*> || it is Sequence<*>)
throw IllegalStateException(
"""
Returning a lazy computation or closure from 'fold' breaks the context scope, and may lead to leaked exceptions on later execution.
Make sure all calls to 'raise' and 'bind' occur within the lifecycle of nullable { }, either { } or similar builders.
See Arrow documentation on 'Typed errors' for further information.
""".trimIndent()
)
transform(it)
}
}

/**
* Similar to [fold], but does *not* check for
* potential lazy return types which break the
* [Raise] context barrier.
*/
@JvmName("_foldUnsafe")
@OptIn(DelicateRaiseApi::class)
public inline fun <Error, A, B> foldUnsafe(
@BuilderInference block: Raise<Error>.() -> A,
catch: (throwable: Throwable) -> B,
recover: (error: Error) -> B,
transform: (value: A) -> B,
): B {
contract {
callsInPlace(catch, AT_MOST_ONCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,4 @@ class NullableSpec : StringSpec({
one + two
} shouldBe 3
}

"Detects potential leaked exceptions" {
shouldThrow<IllegalStateException> {
nullable { lazy { raise(null) } }
}
}

"Unsafe leakage of exceptions" {
val l: Lazy<Int> = foldUnsafe<String, Lazy<Int>, Lazy<Int>?>(
{ lazy { raise("problem") } }, { throw it }, { null }, { it }
).shouldNotBeNull()
shouldThrow<IllegalStateException> {
l.value
}
}
})
58 changes: 0 additions & 58 deletions arrow-libs/fx/arrow-fx-stm/api/arrow-fx-stm.api
Original file line number Diff line number Diff line change
Expand Up @@ -239,64 +239,6 @@ public final class arrow/fx/stm/internal/BlockedIndefinitely : java/lang/Throwab
public fun <init> ()V
}

public abstract class arrow/fx/stm/internal/Branch {
}

public final class arrow/fx/stm/internal/Branch$Branches : arrow/fx/stm/internal/Branch {
public fun <init> (Larrow/fx/stm/internal/Hamt;)V
public final fun component1 ()Larrow/fx/stm/internal/Hamt;
public final fun copy (Larrow/fx/stm/internal/Hamt;)Larrow/fx/stm/internal/Branch$Branches;
public static synthetic fun copy$default (Larrow/fx/stm/internal/Branch$Branches;Larrow/fx/stm/internal/Hamt;ILjava/lang/Object;)Larrow/fx/stm/internal/Branch$Branches;
public fun equals (Ljava/lang/Object;)Z
public final fun getSub ()Larrow/fx/stm/internal/Hamt;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/stm/internal/Branch$Leaf : arrow/fx/stm/internal/Branch {
public fun <init> (I[Ljava/lang/Object;)V
public final fun component1 ()I
public final fun component2 ()[Ljava/lang/Object;
public final fun copy (I[Ljava/lang/Object;)Larrow/fx/stm/internal/Branch$Leaf;
public static synthetic fun copy$default (Larrow/fx/stm/internal/Branch$Leaf;I[Ljava/lang/Object;ILjava/lang/Object;)Larrow/fx/stm/internal/Branch$Leaf;
public fun equals (Ljava/lang/Object;)Z
public final fun getHash ()I
public final fun getValue ()[Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/stm/internal/Hamt {
public static final field Companion Larrow/fx/stm/internal/Hamt$Companion;
public fun <init> (Larrow/fx/stm/TVar;)V
public final fun component1 ()Larrow/fx/stm/TVar;
public final fun copy (Larrow/fx/stm/TVar;)Larrow/fx/stm/internal/Hamt;
public static synthetic fun copy$default (Larrow/fx/stm/internal/Hamt;Larrow/fx/stm/TVar;ILjava/lang/Object;)Larrow/fx/stm/internal/Hamt;
public fun equals (Ljava/lang/Object;)Z
public final fun getBranches ()Larrow/fx/stm/TVar;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/stm/internal/Hamt$Companion {
public final fun new (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class arrow/fx/stm/internal/HamtKt {
public static final field ARR_SIZE I
public static final field DEPTH_STEP I
public static final field MASK I
public static final fun alterHamtWithHash (Larrow/fx/stm/STM;Larrow/fx/stm/internal/Hamt;ILkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Z
public static final fun atDepth (II)I
public static final fun clearHamt (Larrow/fx/stm/STM;Larrow/fx/stm/internal/Hamt;)V
public static final fun index (I)I
public static final fun indexAtDepth (II)I
public static final fun lookupHamtWithHash (Larrow/fx/stm/STM;Larrow/fx/stm/internal/Hamt;ILkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun newHamt (Larrow/fx/stm/STM;)Larrow/fx/stm/internal/Hamt;
public static final fun nextDepth (I)I
public static final fun pair (Larrow/fx/stm/STM;IILarrow/fx/stm/internal/Branch;ILarrow/fx/stm/internal/Branch;)Larrow/fx/stm/internal/Hamt;
}

public final class arrow/fx/stm/internal/RetryException : java/lang/Throwable {
public static final field INSTANCE Larrow/fx/stm/internal/RetryException;
public fun fillInStackTrace ()Ljava/lang/Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public interface STM {
* - When committing the value inside the [TVar], at the time of calling [write], has to be the
* same as the current value otherwise the transaction will retry
*/
public fun <A> TVar<A>.write(a: A): Unit
public fun <A> TVar<A>.write(a: A)

/**
* Modify the value of a [TVar]
Expand Down Expand Up @@ -683,7 +683,7 @@ public interface STM {
*
* @see TSemaphore.tryAcquire for a version that does not retry.
*/
public fun TSemaphore.acquire(n: Int): Unit {
public fun TSemaphore.acquire(n: Int) {
val curr = v.read()
check(curr - n >= 0)
v.write(curr - n)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ public interface STM {
*
* > This function has to access both [TVar]'s and thus may lead to increased contention, use sparingly.
*/
public fun <A> TQueue<A>.removeAll(pred: (A) -> Boolean): Unit {
public fun <A> TQueue<A>.removeAll(pred: (A) -> Boolean) {
reads.modify { it.filter(pred) }
writes.modify { it.filter(pred) }
}
Expand Down Expand Up @@ -1332,7 +1332,7 @@ public interface STM {
* ```
* <!--- KNIT example-stm-46.kt -->
*/
public fun <K, V> TMap<K, V>.insert(k: K, v: V): Unit {
public fun <K, V> TMap<K, V>.insert(k: K, v: V) {
alterHamtWithHash(hamt, hashFn(k), { it.first == k }) { k to v }
}

Expand Down Expand Up @@ -1397,8 +1397,8 @@ public interface STM {
* ```
* <!--- KNIT example-stm-49.kt -->
*/
public fun <K, V> TMap<K, V>.update(k: K, fn: (V) -> V): Unit {
alterHamtWithHash(hamt, hashFn(k), { it.first == k }) { it?.second?.let(fn)?.let { k to it } }
public fun <K, V> TMap<K, V>.update(k: K, fn: (V) -> V) {
alterHamtWithHash(hamt, hashFn(k), { it.first == k }) { it?.second?.let(fn)?.let { r -> k to r } }
}

/**
Expand All @@ -1420,7 +1420,7 @@ public interface STM {
* ```
* <!--- KNIT example-stm-50.kt -->
*/
public fun <K, V> TMap<K, V>.remove(k: K): Unit {
public fun <K, V> TMap<K, V>.remove(k: K) {
alterHamtWithHash(hamt, hashFn(k), { it.first == k }) { null }
}

Expand Down Expand Up @@ -1466,7 +1466,7 @@ public interface STM {
* ```
* <!--- KNIT example-stm-52.kt -->
*/
public fun <A> TSet<A>.insert(a: A): Unit {
public fun <A> TSet<A>.insert(a: A) {
alterHamtWithHash(hamt, hashFn(a), { it == a }) { a }
}

Expand Down Expand Up @@ -1509,7 +1509,7 @@ public interface STM {
* ```
* <!--- KNIT example-stm-54.kt -->
*/
public fun <A> TSet<A>.remove(a: A): Unit {
public fun <A> TSet<A>.remove(a: A) {
alterHamtWithHash(hamt, hashFn(a), { it == a }) { null }
}
}
Expand Down

0 comments on commit bc81e87

Please sign in to comment.