Skip to content

Commit

Permalink
Activate explicit API mode (#2447)
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev authored Jul 14, 2021
1 parent 10a517b commit 0afdd9a
Show file tree
Hide file tree
Showing 169 changed files with 2,887 additions and 2,836 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package arrow.ank
import org.gradle.api.file.FileCollection
import java.io.File

data class AnkExtension(
public data class AnkExtension(
var source: File? = null,
var target: File? = null,
var classpath: FileCollection? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import org.gradle.api.Project
import org.gradle.api.tasks.JavaExec
import java.util.Properties

class AnkPlugin : Plugin<Project> {
public class AnkPlugin : Plugin<Project> {

companion object {
public companion object {
private const val EXTENSION_NAME = "ank"
private const val TASK_NAME = "runAnk"
}
Expand Down
18 changes: 9 additions & 9 deletions arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/algebra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package arrow.ank

import java.nio.file.Path

data class AnkProcessingContext(
public data class AnkProcessingContext(
val index: Int,
val path: Path
)

interface AnkOps {
public interface AnkOps {

suspend fun createTargetDirectory(source: Path, target: Path): Path
public suspend fun createTargetDirectory(source: Path, target: Path): Path

suspend fun Path.ankFiles(): Sequence<AnkProcessingContext>
public suspend fun Path.ankFiles(): Sequence<AnkProcessingContext>

fun extractCode(content: Sequence<String>): Pair<Sequence<String>, Sequence<Snippet>>
public fun extractCode(content: Sequence<String>): Pair<Sequence<String>, Sequence<Snippet>>

suspend fun compileCode(snippets: Pair<Path, Sequence<Snippet>>, compilerArgs: List<String>): Sequence<Snippet>
public suspend fun compileCode(snippets: Pair<Path, Sequence<Snippet>>, compilerArgs: List<String>): Sequence<Snippet>

fun replaceAnkToLang(content: Sequence<String>, compiledSnippets: Sequence<Snippet>): Sequence<String>
public fun replaceAnkToLang(content: Sequence<String>, compiledSnippets: Sequence<Snippet>): Sequence<String>

suspend fun generateFile(path: Path, newContent: Sequence<String>): Path
public suspend fun generateFile(path: Path, newContent: Sequence<String>): Path

suspend fun printConsole(msg: String): Unit
public suspend fun printConsole(msg: String): Unit
}
4 changes: 2 additions & 2 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 @@ -10,15 +10,15 @@ import kotlin.math.pow
/**
* From https://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
*/
fun Long.humanBytes(): String {
public fun Long.humanBytes(): String {
val unit = 1024
if (this < unit) return toString() + " B"
val exp = (ln(toDouble()) / ln(unit.toDouble())).toInt()
val pre = ("KMGTPE")[exp - 1] + "i"
return String.format("%.1f %sB", this / unit.toDouble().pow(exp.toDouble()), pre)
}

suspend fun ank(source: Path, target: Path, compilerArgs: List<String>, ankOps: AnkOps): Unit = with(ankOps) {
public 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()
val heapMaxSize = Runtime.getRuntime().maxMemory()
Expand Down
22 changes: 11 additions & 11 deletions arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/formatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ private fun fill(ch: Char, len: Int): String {
return sb.toString()
}

const val ANSI_RESET = "\u001B[0m"
const val ANSI_BLACK = "\u001B[30m"
const val ANSI_RED = "\u001B[31m"
const val ANSI_GREEN = "\u001B[32m"
const val ANSI_YELLOW = "\u001B[33m"
const val ANSI_BLUE = "\u001B[34m"
const val ANSI_PURPLE = "\u001B[35m"
const val ANSI_CYAN = "\u001B[36m"
const val ANSI_WHITE = "\u001B[37m"
public const val ANSI_RESET: String = "\u001B[0m"
public const val ANSI_BLACK: String = "\u001B[30m"
public const val ANSI_RED: String = "\u001B[31m"
public const val ANSI_GREEN: String = "\u001B[32m"
public const val ANSI_YELLOW: String = "\u001B[33m"
public const val ANSI_BLUE: String = "\u001B[34m"
public const val ANSI_PURPLE: String = "\u001B[35m"
public const val ANSI_CYAN: String = "\u001B[36m"
public const val ANSI_WHITE: String = "\u001B[37m"

fun colored(color: String, message: String) =
public fun colored(color: String, message: String): String =
"$color$message$ANSI_RESET"

val AnkHeader =
public val AnkHeader: String =
"""
| ::: :::: ::: ::: :::
| :+: :+: :+:+: :+: :+: :+:
Expand Down
46 changes: 23 additions & 23 deletions arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/interpreter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
import kotlin.streams.asSequence

val extensionMappings = mapOf(
public val extensionMappings: Map<String, String> = mapOf(
"java" to "java",
"kotlin" to "kts"
)

val SupportedMarkdownExtensions: Set<String> = setOf(
public val SupportedMarkdownExtensions: Set<String> = setOf(
"markdown",
"mdown",
"mkdn",
Expand All @@ -37,7 +37,7 @@ val SupportedMarkdownExtensions: Set<String> = setOf(
"Rmd"
)

data class CompilationException(
public data class CompilationException(
val path: Path,
val snippet: Snippet,
val underlying: Throwable,
Expand All @@ -46,13 +46,13 @@ data class CompilationException(
override fun toString(): String = msg
}

data class AnkFailedException(val msg: String) : NoStackTrace(msg) {
public data class AnkFailedException(val msg: String) : NoStackTrace(msg) {
override fun toString(): String = msg
}

abstract class NoStackTrace(msg: String) : Throwable(msg, null, false, false)
public abstract class NoStackTrace(msg: String) : Throwable(msg, null, false, false)

data class Snippet(
public data class Snippet(
val fence: String,
val lang: String,
val code: String,
Expand All @@ -65,22 +65,22 @@ data class Snippet(
val isPlaygroundExtension: Boolean = fence.contains(AnkPlaygroundExtension)
)

const val AnkBlock = ":ank"
const val AnkSilentBlock = ":ank:silent"
const val AnkReplaceBlock = ":ank:replace"
const val AnkOutFileBlock = ":ank:outFile"
const val AnkPlayground = ":ank:playground"
const val AnkFailBlock = ":ank:fail"
const val AnkPlaygroundExtension = ":ank:playground:extension"

sealed class SnippetParserState {
data class CollectingCode(val snippet: Snippet) : SnippetParserState()
object Searching : SnippetParserState()
public const val AnkBlock: String = ":ank"
public const val AnkSilentBlock: String = ":ank:silent"
public const val AnkReplaceBlock: String = ":ank:replace"
public const val AnkOutFileBlock: String = ":ank:outFile"
public const val AnkPlayground: String = ":ank:playground"
public const val AnkFailBlock: String = ":ank:fail"
public const val AnkPlaygroundExtension: String = ":ank:playground:extension"

public sealed class SnippetParserState {
public data class CollectingCode(val snippet: Snippet) : SnippetParserState()
public object Searching : SnippetParserState()
}

val interpreter: AnkOps = object : AnkOps {
public val interpreter: AnkOps = object : AnkOps {

override suspend fun printConsole(msg: String): Unit {
public override suspend fun printConsole(msg: String): Unit {
println(msg)
}

Expand All @@ -89,7 +89,7 @@ val interpreter: AnkOps = object : AnkOps {
it.lines().anyMatch { s -> s.contains(AnkBlock) }
}

override suspend fun Path.ankFiles(): Sequence<AnkProcessingContext> =
public override suspend fun Path.ankFiles(): Sequence<AnkProcessingContext> =
withContext(Dispatchers.IO) { Files.walk(this@ankFiles) }
.filter { Files.isDirectory(it).not() }
.filter { path ->
Expand All @@ -100,7 +100,7 @@ val interpreter: AnkOps = object : AnkOps {
AnkProcessingContext(index, path)
}

override suspend fun createTargetDirectory(source: Path, target: Path): Path {
public override suspend fun createTargetDirectory(source: Path, target: Path): Path {
source.toFile().copyRecursively(target.toFile(), overwrite = true)
return target
}
Expand Down Expand Up @@ -140,7 +140,7 @@ val interpreter: AnkOps = object : AnkOps {
return result.second to result.third
}

override suspend fun compileCode(snippets: Pair<Path, Sequence<Snippet>>, compilerArgs: List<String>): Sequence<Snippet> =
public override suspend fun compileCode(snippets: Pair<Path, Sequence<Snippet>>, compilerArgs: List<String>): Sequence<Snippet> =
getEngineCache(snippets.second, compilerArgs).let { engineCache ->
// run each snipped and handle its result
snippets.second.mapIndexed { i, snip ->
Expand Down Expand Up @@ -222,7 +222,7 @@ val interpreter: AnkOps = object : AnkOps {
)
})

override suspend fun generateFile(path: Path, newContent: Sequence<String>): Path =
public override suspend fun generateFile(path: Path, newContent: Sequence<String>): Path =
Files.write(path, newContent.asIterable())

private val engineCache: ConcurrentMap<List<String>, Map<String, ScriptEngine>> = ConcurrentHashMap()
Expand Down
2 changes: 1 addition & 1 deletion arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package arrow.ank

import java.nio.file.Paths

suspend fun main(vararg args: String) =
public suspend fun main(vararg args: String): Unit =
when {
args.size > 1 -> {
ank(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import kotlin.annotation.AnnotationTarget.CLASS
/**
* Empty arrays means "Everything that matches annotated class"
*/
annotation class optics(val targets: Array<OpticsTarget> = emptyArray())
public annotation class optics(val targets: Array<OpticsTarget> = emptyArray())

enum class OpticsTarget {
public enum class OpticsTarget {
ISO, LENS, PRISM, OPTIONAL, DSL
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ package arrow
AnnotationTarget.TYPEALIAS
)
@MustBeDocumented
annotation class synthetic
public annotation class synthetic
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package arrow.continuations

import arrow.continuations.generic.DelimitedScope

fun interface Effect<F> {
fun control(): DelimitedScope<F>
public fun interface Effect<F> {
public fun control(): DelimitedScope<F>

companion object {
suspend inline fun <Eff : Effect<*>, F, A> suspended(
public companion object {
public suspend inline fun <Eff : Effect<*>, F, A> suspended(
crossinline eff: (DelimitedScope<F>) -> Eff,
crossinline just: (A) -> F,
crossinline f: suspend Eff.() -> A,
): F =
Reset.suspended { just(f(eff(this))) }

inline fun <Eff : Effect<*>, F, A> restricted(
public inline fun <Eff : Effect<*>, F, A> restricted(
crossinline eff: (DelimitedScope<F>) -> Eff,
crossinline just: (A) -> F,
crossinline f: suspend Eff.() -> A,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal object Reset {
* use `Either.catch`, `Validated.catch` etc or `e.nonFatalOrThrow()`
* to ensure you're not catching `ShortCircuit`.
*/
suspend fun <A> suspended(block: suspend SuspendedScope<A>.() -> A): A =
public suspend fun <A> suspended(block: suspend SuspendedScope<A>.() -> A): A =
suspendCoroutineUninterceptedOrReturn { cont ->
SuspendMonadContinuation(cont, block)
.startCoroutineUninterceptedOrReturn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ package arrow.continuations.generic
* 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
public expect open class ControlThrowable() : Throwable
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
/**
* Small wrapper that handles invoking the correct continuations and appending continuations from shift blocks
*/
data class SingleShotCont<A, R>(
public data class SingleShotCont<A, R>(
private val continuation: Continuation<A>,
private val shiftFnContinuations: MutableList<Continuation<R>>
) : DelimitedContinuation<A, R> {
override suspend fun invoke(a: A): R = suspendCoroutineUninterceptedOrReturn { resumeShift ->
public override suspend fun invoke(a: A): R = suspendCoroutineUninterceptedOrReturn { resumeShift ->
shiftFnContinuations.add(resumeShift)
continuation.resume(a)
COROUTINE_SUSPENDED
Expand All @@ -53,16 +53,16 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
/**
* Wrapper that handles invoking manually cps transformed continuations
*/
data class CPSCont<A, R>(
public data class CPSCont<A, R>(
private val runFunc: suspend DelimitedScope<R>.(A) -> R
) : DelimitedContinuation<A, R> {
override suspend fun invoke(a: A): R = DelimContScope<R> { runFunc(a) }.invoke()
public override suspend fun invoke(a: A): R = DelimContScope<R> { runFunc(a) }.invoke()
}

/**
* Captures the continuation and set [f] with the continuation to be executed next by the runloop.
*/
override suspend fun <A> shift(f: suspend RestrictedScope<R>.(DelimitedContinuation<A, R>) -> R): A =
public override suspend fun <A> shift(f: suspend RestrictedScope<R>.(DelimitedContinuation<A, R>) -> R): A =
suspendCoroutineUninterceptedOrReturn { continueMain ->
val delCont = SingleShotCont(continueMain, shiftFnContinuations)
require(nextShift == null)
Expand All @@ -73,7 +73,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
/**
* Same as [shift] except we never resume execution because we only continue in [c].
*/
suspend fun <A, B> shiftCPS(f: suspend (DelimitedContinuation<A, B>) -> R, c: suspend DelimitedScope<B>.(A) -> B): Nothing =
public suspend fun <A, B> shiftCPS(f: suspend (DelimitedContinuation<A, B>) -> R, c: suspend DelimitedScope<B>.(A) -> B): Nothing =
suspendCoroutineUninterceptedOrReturn {
require(nextShift == null)
nextShift = suspend { f(CPSCont(c)) }
Expand Down Expand Up @@ -128,6 +128,6 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
@Suppress("ClassName")
internal object EMPTY_VALUE {
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
inline fun <T> unbox(value: Any?): T =
public inline fun <T> unbox(value: Any?): T =
if (value === this) null as T else value as T
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ package arrow.continuations.generic
/**
* Base interface for a continuation
*/
interface DelimitedContinuation<A, R> {
suspend operator fun invoke(a: A): R
public interface DelimitedContinuation<A, R> {
public suspend operator fun invoke(a: A): R
}

/**
* Base interface for our scope.
*/
interface DelimitedScope<R> {
public interface DelimitedScope<R> {

/**
* Exit the [DelimitedScope] with [R]
*/
suspend fun <A> shift(r: R): A
public suspend fun <A> shift(r: R): A
}

interface RestrictedScope<R> : DelimitedScope<R> {
public interface RestrictedScope<R> : DelimitedScope<R> {
/**
* Capture the continuation and pass it to [f].
*/
suspend fun <A> shift(f: suspend RestrictedScope<R>.(DelimitedContinuation<A, R>) -> R): A
public suspend fun <A> shift(f: suspend RestrictedScope<R>.(DelimitedContinuation<A, R>) -> R): A

override suspend fun <A> shift(r: R): A = shift { r }
public override suspend fun <A> shift(r: R): A = shift { r }
}

interface SuspendedScope<R> : DelimitedScope<R>
public interface SuspendedScope<R> : DelimitedScope<R>
Loading

0 comments on commit 0afdd9a

Please sign in to comment.