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

Remove a bunch of warnings in arrow-2 #3282

Merged
merged 17 commits into from
Nov 8, 2023
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
6 changes: 2 additions & 4 deletions arrow-libs/core/arrow-atomic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ kotlin {
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xexpect-actual-classes"
}
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}

Copy link
Member

@JavierSegoviaCordoba JavierSegoviaCordoba Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend to keep the configureEach

Suggested change
tasks.withType<KotlinCompile>.configureEach {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for this? (Gradle is all magic to me)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, configureEach is lazy, the other isn't. If I remember correctly, it is calling all under the hood.

I hope they mark all of those APIs as deprecated in Gradle 9.

tasks.withType<Test> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
2 changes: 1 addition & 1 deletion arrow-libs/core/arrow-core-retrofit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ tasks.jar {
}
}

tasks.withType<Test> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class EitherCallAdapterFactory : CallAdapter.Factory() {
}
}

private inline fun extractErrorAndReturnType(wrapperType: Type, returnType: ParameterizedType): Pair<Type, Type> {
private fun extractErrorAndReturnType(wrapperType: Type, returnType: ParameterizedType): Pair<Type, Type> {
if (wrapperType !is ParameterizedType) {
val name = parseTypeName(returnType)
throw IllegalArgumentException(
Expand Down
2 changes: 1 addition & 1 deletion arrow-libs/core/arrow-core-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ kotlin {
}
}

tasks.withType<Test> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
2 changes: 1 addition & 1 deletion arrow-libs/core/arrow-core/api/arrow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ public final class arrow/core/raise/RaiseKt {
public static final fun get (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun get (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun getOrElse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun getOrElse (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun getOrElse (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun getOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun getOrNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun ior (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior;
Expand Down
6 changes: 5 additions & 1 deletion arrow-libs/core/arrow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ kotlin {
}

// enables context receivers for Jvm Tests
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}

tasks.named<KotlinCompile>("compileTestKotlinJvm") {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}

tasks.withType<Test> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,7 @@ public inline infix fun <A, B> Either<A, B>.getOrElse(default: (A) -> B): B {
* <!--- KNIT example-either-33.kt -->
* <!--- TEST lines.isEmpty() -->
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun <A> Either<A, A>.merge(): A =
fold(::identity, ::identity)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
else -> head
}

@Suppress("OVERRIDE_BY_INLINE")
@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serras, so is this is actually inlining?

I know Kotlin Std has @InlineOnly, and afaik that forces inlining and removes the method from the binary. At least that's my understanding. So I am wondering, if that exists and my understanding is correct does the compiler ignore this inline or does it still forces inline (but keep it in the binary?)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. The error I was getting was "performance of inline is not significant" (even though the error is called "nothing to inline"). I think we should keep those inline, it feels like each step is not very significant, but in a big code this all adds up.

public override inline fun distinct(): NonEmptyList<A> =
NonEmptyList(all.distinct())

Expand Down Expand Up @@ -340,6 +340,7 @@ public fun <A> nonEmptyListOf(head: A, vararg t: A): NonEmptyList<A> =
NonEmptyList(listOf(head) + t)

@JvmName("nel")
@Suppress("NOTHING_TO_INLINE")
public inline fun <A> A.nel(): NonEmptyList<A> =
NonEmptyList(listOf(this))

Expand All @@ -355,9 +356,11 @@ public inline fun <A, B : Comparable<B>> NonEmptyList<A>.minBy(selector: (A) ->
public inline fun <A, B : Comparable<B>> NonEmptyList<A>.maxBy(selector: (A) -> B): A =
maxByOrNull(selector)!!

@Suppress("NOTHING_TO_INLINE")
public inline fun <T : Comparable<T>> NonEmptyList<T>.min(): T =
minOrNull()!!

@Suppress("NOTHING_TO_INLINE")
public inline fun <T : Comparable<T>> NonEmptyList<T>.max(): T =
maxOrNull()!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlin.coroutines.cancellation.CancellationException
* else -> "Hello"
* }
*
* fun main(args: Array<String>) {
* fun main() {
* val nonFatal: Either<Throwable, String> =
* //sampleStart
* try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package arrow.core
import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.core.raise.RaiseAccumulate
import arrow.core.raise.either
import arrow.core.raise.fold
import kotlin.experimental.ExperimentalTypeInference

Expand Down Expand Up @@ -574,7 +573,7 @@ public fun <A> Sequence<A>.salign(
* @return a tuple containing Sequence with [Either.Left] and another Sequence with its [Either.Right] values.
*/
public fun <A, B> Sequence<Either<A, B>>.separateEither(): Pair<List<A>, List<B>> =
fold(listOf<A>() to listOf<B>()) { (lefts, rights), either ->
fold(listOf<A>() to listOf()) { (lefts, rights), either ->
when (either) {
is Left -> lefts + either.value to rights
is Right -> lefts to rights + either.value
Expand Down Expand Up @@ -637,7 +636,7 @@ public fun <Error, A, B> Sequence<A>.mapOrAccumulate(
* import arrow.core.leftIor
* import arrow.core.unalign
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor()).unalign()
* //sampleEnd
Expand All @@ -662,7 +661,7 @@ public fun <A, B> Sequence<Ior<A, B>>.unalign(): Pair<Sequence<A>, Sequence<B>>
* import arrow.core.leftIor
* import arrow.core.unalign
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf(1, 2, 3).unalign { it.leftIor() }
* //sampleEnd
Expand All @@ -680,7 +679,7 @@ public fun <A, B, C> Sequence<C>.unalign(fa: (C) -> Ior<A, B>): Pair<Sequence<A>
* ```kotlin
* import arrow.core.unweave
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") }
* //sampleEnd
Expand All @@ -700,7 +699,7 @@ public fun <A, B> Sequence<A>.unweave(ffa: (A) -> Sequence<B>): Sequence<B> =
* ```kotlin
* import arrow.core.unzip
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result = sequenceOf("A" to 1, "B" to 2).unzip()
* //sampleEnd
Expand All @@ -720,7 +719,7 @@ public fun <A, B> Sequence<Pair<A, B>>.unzip(): Pair<Sequence<A>, Sequence<B>> =
* ```kotlin
* import arrow.core.unzip
*
* fun main(args: Array<String>) {
* fun main() {
* //sampleStart
* val result =
* sequenceOf("A:1", "B:2", "C:3").unzip { e ->
Expand All @@ -743,7 +742,7 @@ public fun <A, B, C> Sequence<C>.unzip(fc: (C) -> Pair<A, B>): Pair<Sequence<A>,
* ```kotlin
* import arrow.core.widen
*
* fun main(args: Array<String>) {
* fun main() {
* val original: Sequence<String> = sequenceOf("Hello World")
* val result: Sequence<CharSequence> = original.widen()
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public fun <K, A, B> Map<K, A>.zip(other: Map<K, B>): Map<K, Pair<A, B>> =
*
* fun test() {
* mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) {
* key, a, b -> "$a ~ $b"
* _, a, b -> "$a ~ $b"
* } shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2")
* }
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package arrow.core
* else -> "Hello"
* }
*
* fun main(args: Array<String>) {
* fun main() {
* val nonFatal: Either<Throwable, String> =
* //sampleStart
* try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package arrow.core

@Suppress("NOTHING_TO_INLINE")
public inline fun <A> identity(a: A): A = a

/**
Expand All @@ -14,6 +15,7 @@ internal object EmptyValue {
inline fun <A> unbox(value: Any?): A =
if (value === this) null as A else value as A

@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
public inline fun <T> combine(first: Any?, second: T, combine: (T, T) -> T): T =
if (first === EmptyValue) second else combine(first as T, second)
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ import kotlin.jvm.JvmName
* ```kotlin
* val default5: Effect<String, Int> =
* foreign
* .catch { ex: RuntimeException -> -1 }
* .catch { ex: java.sql.SQLException -> -2 }
* .catch { _: RuntimeException -> -1 }
* .catch { _: java.sql.SQLException -> -2 }
* ```
*
* Finally, since `catch` also supports `suspend` we can safely call other `suspend` code and throw `Throwable` into the `suspend` system.
Expand Down Expand Up @@ -456,7 +456,7 @@ import kotlin.jvm.JvmName
* effect<String, Int> {
* bracketCase(
* acquire = { File("build.gradle.kts").bufferedReader() },
* use = { reader: BufferedReader -> raise(error) },
* use = { _: BufferedReader -> raise(error) },
* release = { reader, exitCase ->
* reader.close()
* exit.complete(exitCase)
Expand Down Expand Up @@ -664,11 +664,13 @@ import kotlin.jvm.JvmName
*/
public typealias Effect<Error, A> = suspend Raise<Error>.() -> A

@Suppress("NOTHING_TO_INLINE")
public inline fun <Error, A> effect(@BuilderInference noinline block: suspend Raise<Error>.() -> A): Effect<Error, A> = block

/** The same behavior and API as [Effect] except without requiring _suspend_. */
public typealias EagerEffect<Error, A> = Raise<Error>.() -> A

@Suppress("NOTHING_TO_INLINE")
public inline fun <Error, A> eagerEffect(@BuilderInference noinline block: Raise<Error>.() -> A): EagerEffect<Error, A> = block

public suspend fun <A> Effect<A, A>.merge(): A = merge { invoke() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import kotlin.jvm.JvmName
*
* val error = effect<Error, User> { raise(Error) } // Raise(error)
*
* val a = error.recover<Error, Error, User> { error -> User } // Success(User)
* val b = error.recover<Error, String, User> { error -> raise("other-failure") } // Raise(other-failure)
* val c = error.recover<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
* val a = error.recover<Error, Error, User> { _ -> User } // Success(User)
* val b = error.recover<Error, String, User> { _ -> raise("other-failure") } // Raise(other-failure)
* val c = error.recover<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
* ```
* <!--- KNIT example-effect-error-01.kt -->
*/
Expand Down Expand Up @@ -93,7 +93,7 @@ public fun <Error, A> Effect<Error, A>.catch(): Effect<Error, Result<A>> =
catch({ Result.success(invoke()) }, Result.Companion::failure)
}

public suspend inline infix fun <Error, A> Effect<Error, A>.getOrElse(recover: suspend (error: Error) -> A): A =
public suspend inline infix fun <Error, A> Effect<Error, A>.getOrElse(recover: (error: Error) -> A): A =
recover({ invoke() }) { recover(it) }

/**
Expand All @@ -110,9 +110,9 @@ public suspend inline infix fun <Error, A> Effect<Error, A>.getOrElse(recover: s
*
* val error = effect<Error, User> { raise(Error) } // Raise(error)
*
* val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
* val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
* val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
* val c = error.mapError<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
* val c = error.mapError<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
* ```
* <!--- KNIT example-effect-error-04.kt -->
*/
Expand Down Expand Up @@ -147,7 +147,7 @@ public inline infix fun <Error, A> EagerEffect<Error, A>.getOrElse(recover: (err
*
* val error = eagerEffect<Error, User> { raise(Error) } // Raise(error)
*
* val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
* val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
* val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
* ```
* <!--- KNIT example-effect-error-05.kt -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public interface Raise<in Error> {
*
* either {
* val x = one.bind()
* val y = recover({ left.bind() }) { failure : String -> 1 }
* val y = recover({ left.bind() }) { _ : String -> 1 }
* x + y
* } shouldBe Either.Right(2)
* }
Expand Down Expand Up @@ -325,7 +325,7 @@ public interface Raise<in Error> {
* recover({ raise("failed") }) { str -> str.length } shouldBe 6
*
* either<Int, String> {
* recover({ raise("failed") }) { str -> raise(-1) }
* recover({ raise("failed") }) { _ -> raise(-1) }
* } shouldBe Either.Left(-1)
* }
* ```
Expand Down Expand Up @@ -421,7 +421,7 @@ public inline fun <reified T : Throwable, Error, A> recover(
* -->
* ```kotlin
* fun test() {
* catch({ throw RuntimeException("BOOM") }) { t ->
* catch({ throw RuntimeException("BOOM") }) { _ ->
* "fallback"
* } shouldBe "fallback"
*
Expand Down Expand Up @@ -460,7 +460,7 @@ public inline fun <A> catch(block: () -> A, catch: (throwable: Throwable) -> A):
* -->
* ```kotlin
* fun test() {
* catch({ throw RuntimeException("BOOM") }) { t ->
* catch({ throw RuntimeException("BOOM") }) { _ ->
* "fallback"
* } shouldBe "fallback"
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Error

val error = effect<Error, User> { raise(Error) } // Raise(error)

val a = error.recover<Error, Error, User> { error -> User } // Success(User)
val b = error.recover<Error, String, User> { error -> raise("other-failure") } // Raise(other-failure)
val c = error.recover<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
val a = error.recover<Error, Error, User> { _ -> User } // Success(User)
val b = error.recover<Error, String, User> { _ -> raise("other-failure") } // Raise(other-failure)
val c = error.recover<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Error

val error = effect<Error, User> { raise(Error) } // Raise(error)

val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
val c = error.mapError<Error, Nothing, User> { error -> throw RuntimeException("BOOM") } // Exception(BOOM)
val c = error.mapError<Error, Nothing, User> { _ -> throw RuntimeException("BOOM") } // Exception(BOOM)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ object Error

val error = eagerEffect<Error, User> { raise(Error) } // Raise(error)

val a = error.mapError<Error, String, User> { error -> "some-failure" } // Raise(some-failure)
val a = error.mapError<Error, String, User> { _ -> "some-failure" } // Raise(some-failure)
val b = error.mapError<Error, String, User>(Any::toString) // Raise(Error)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import io.kotest.matchers.shouldBe

fun test() {
mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) {
key, a, b -> "$a ~ $b"
_, a, b -> "$a ~ $b"
} shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fun unsafeFunction(i: Int): String =
else -> "Hello"
}

fun main(args: Array<String>) {
fun main() {
val nonFatal: Either<Throwable, String> =
//sampleStart
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fun unsafeFunction(i: Int): String =
else -> "Hello"
}

fun main(args: Array<String>) {
fun main() {
val nonFatal: Either<Throwable, String> =
//sampleStart
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ val default4: Effect<Nothing, Int> =

val default5: Effect<String, Int> =
foreign
.catch { ex: RuntimeException -> -1 }
.catch { ex: java.sql.SQLException -> -2 }
.catch { _: RuntimeException -> -1 }
.catch { _: java.sql.SQLException -> -2 }

suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ suspend fun main() {
effect<String, Int> {
bracketCase(
acquire = { File("build.gradle.kts").bufferedReader() },
use = { reader: BufferedReader -> raise(error) },
use = { _: BufferedReader -> raise(error) },
release = { reader, exitCase ->
reader.close()
exit.complete(exitCase)
Expand Down
Loading
Loading