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

Try Bumping Kotlin to Kotlin 2.0.0-Beta5 #2138

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ err.txt
*.xcuserstate
xcuserdata
kotlin-js-store/
/.kotlin
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ fun Project.configureErrorableEsbuild() {

val esbuildVersion = korge.esbuildVersion
doFirst {
val npmCmd = arrayOf(
File(env.nodeExecutable),
File(env.nodeDir, "lib/node_modules/npm/bin/npm-cli.js").takeIf { it.exists() }
?: File(env.nodeDir, "node_modules/npm/bin/npm-cli.js").takeIf { it.exists() }
?: error("Can't find npm-cli.js in ${env.nodeDir} standard folders")

//val nodeDir = env.nodeBinDir
val nodeDir = env.dir
val file1: File = File(env.nodeExecutable)
val file2: File? = File(nodeDir, "lib/node_modules/npm/bin/npm-cli.js").takeIf { it.exists() }
val file3: File? = File(nodeDir, "node_modules/npm/bin/npm-cli.js").takeIf { it.exists() }
val npmCmd = arrayOf<File>(
file1,
file2
?: file2
?: error("Can't find npm-cli.js in ${nodeDir} standard folders")
)

environment("PATH", ENV_PATH)
Expand Down Expand Up @@ -108,7 +114,11 @@ fun Project.configureErrorableEsbuild() {
dependsOn(compileExecutableKotlinJs)

//println("compileExecutableKotlinJs:" + compileExecutableKotlinJs::class)
val jsPath = compileExecutableKotlinJs.outputFileProperty.get()
//val jsPath = compileExecutableKotlinJs.outputFileProperty.get()
//val jsPath = compileExecutableKotlinJs.destinationDirectory.asFile.get().absolutePath + "/" + compileExecutableKotlinJs.moduleName.get() + ".js"
// @TODO: Check this
val jsPath = compileExecutableKotlinJs.destinationDirectory.asFile.get().absolutePath

val output = File(wwwFolder, "${project.name}.js")
//println("jsPath=$jsPath")
//println("jsPath.parentFile=${jsPath.parentFile}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun Project.configureWasm(projectType: ProjectType, binaryen: Boolean = false) {
}

open class WasmJsCreateIndexTask : DefaultTask() {
private val npmDir: File = project.kotlin.wasmJs().compilations["main"]!!.npmProject.dir
private val npmDir: File = project.kotlin.wasmJs().compilations["main"]!!.npmProject.dir.get().asFile

@TaskAction
fun run() {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/korlibs/root/RootKorlibsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ object RootKorlibsPlugin {
wasmBrowserTest.doFirst {
logger.info("!!!!! wasmBrowserTest PATCH :: $wasmBrowserTest : ${wasmBrowserTest::class.java}")

val npmProjectDir = wasmBrowserTest.compilation.npmProject.dir
val npmProjectDir: File = wasmBrowserTest.compilation.npmProject.dir.get().asFile
val projectName = npmProjectDir.name
val uninstantiatedMjs = File(npmProjectDir, "kotlin/$projectName.uninstantiated.mjs")

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jgit = "5.13.1.202206130422-r"

#kotlin = "1.9.0"
#kotlin = "1.9.10"
kotlin = "1.9.22"
kotlin = "2.0.0-Beta5"
kotlinx-coroutines = "1.8.0-RC"
kotlinx-serialization = "1.6.2"
kotlinx-atomicfu = "0.23.1"
Expand Down
6 changes: 5 additions & 1 deletion korge-core/src/korlibs/io/dynamic/DynApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ val defaultDynApi: DynApi get() = DynamicInternal
// @TODO: We should be able to plug-in a kotlinx-serialization version for this
var dynApi: DynApi = DynamicInternal

internal expect object DynamicInternal : DynApi
internal expect object DynamicInternal : DynApi {
override fun get(instance: Any?, key: String): Any?
override fun set(instance: Any?, key: String, value: Any?)
override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any?
}
1 change: 0 additions & 1 deletion korge-core/src/korlibs/io/lang/Charset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ open class SingleByteCharset(name: String, val conv: String) : BaseSingleByteCha

object ISO_8859_1 : SingleByteCharset("ISO-8859-1", buildString { for (n in 0 until 256) append(n.toChar()) })

@SharedImmutable
expect val UTF8: Charset

class UTF16Charset(val le: Boolean) : Charset("UTF-16-" + (if (le) "LE" else "BE")) {
Expand Down
5 changes: 4 additions & 1 deletion korge-core/src/korlibs/wasm/WASMLib.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import korlibs.io.lang.*
import korlibs.memory.*
import kotlin.coroutines.*

expect open class WASMLib(content: ByteArray) : IWASMLib
expect open class WASMLib(content: ByteArray) : IWASMLib {
override val content: ByteArray
override fun close()
}

interface IWASMLib : Closeable {
val isAvailable: Boolean get() = true
Expand Down
6 changes: 3 additions & 3 deletions korge-core/src@darwin/korlibs/io/dynamic/DynApiNative.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package korlibs.io.dynamic

internal actual object DynamicInternal : DynApi {
override fun get(instance: Any?, key: String): Any? = throw UnsupportedOperationException("DynamicInternal.get")
override fun set(instance: Any?, key: String, value: Any?): Unit = throw UnsupportedOperationException("DynamicInternal.set")
override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? = throw UnsupportedOperationException("DynamicInternal.invoke")
actual override fun get(instance: Any?, key: String): Any? = throw UnsupportedOperationException("DynamicInternal.get")
actual override fun set(instance: Any?, key: String, value: Any?): Unit = throw UnsupportedOperationException("DynamicInternal.set")
actual override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? = throw UnsupportedOperationException("DynamicInternal.invoke")
}
8 changes: 4 additions & 4 deletions korge-core/src@js/korlibs/io/dynamic/DynApiJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package korlibs.io.dynamic
import korlibs.io.jsGlobalDynamic

internal actual object DynamicInternal : DynApi {
override val global: Any get() = jsGlobalDynamic
override val global: Any? get() = jsGlobalDynamic

override fun get(instance: Any?, key: String): Any? = (instance.asDynamic())[key]
override fun set(instance: Any?, key: String, value: Any?) { (instance.asDynamic())[key] = value }
override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? =
actual override fun get(instance: Any?, key: String): Any? = (instance.asDynamic())[key]
actual override fun set(instance: Any?, key: String, value: Any?) { (instance.asDynamic())[key] = value }
actual override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? =
(instance.asDynamic())[key].apply(instance, args)
}
6 changes: 3 additions & 3 deletions korge-core/src@jvmAndroid/korlibs/io/dynamic/DynApiJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ internal actual object DynamicInternal : DynApi {
}
}

override fun get(instance: Any?, key: String): Any? = getBase(instance, key, doThrow = false)
actual override fun get(instance: Any?, key: String): Any? = getBase(instance, key, doThrow = false)

override fun set(instance: Any?, key: String, value: Any?) {
actual override fun set(instance: Any?, key: String, value: Any?) {
if (instance == null) return

val static = instance is Class<*>
Expand All @@ -66,7 +66,7 @@ internal actual object DynamicInternal : DynApi {
return getBase(instance, key, doThrow = true)
}

override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? {
actual override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? {
return invokeBase(instance, key, args, doThrow = false)
}

Expand Down
8 changes: 4 additions & 4 deletions korge-core/src@wasmJs/korlibs/io/dynamic/DynApiJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ private external fun JsAny_set(obj: JsAny, key: String, value: JsAny?)
private external fun JsAny_invoke(obj: JsAny, key: String, args: JsArray<JsAny?>)

internal actual object DynamicInternal : DynApi {
override val global: Any get() = jsGlobal
override val global: Any? get() = jsGlobal

override fun get(instance: Any?, key: String): Any? {
actual override fun get(instance: Any?, key: String): Any? {
if (instance == null) return null
return JsAny_get((instance as JsAny), key)
}
override fun set(instance: Any?, key: String, value: Any?) {
actual override fun set(instance: Any?, key: String, value: Any?) {
if (instance == null) return
return JsAny_set((instance as JsAny), key, value as? JsAny?)
}
override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? =
actual override fun invoke(instance: Any?, key: String, args: Array<out Any?>): Any? =
JsAny_invoke(instance as JsAny, key, jsArrayOf(*args.map { it as? JsAny? }.toTypedArray()))
}
21 changes: 19 additions & 2 deletions korge/src/korlibs/korge/view/Container.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class Container(
/**
* A collection with all the children [View]s.
*/
val children: ContainerCollection = ContainerCollection(this, __children)
val children: ContainerCollection = ContainerCollection(this)

@PublishedApi
override val _children: List<View>? get() = __children
Expand Down Expand Up @@ -415,6 +415,14 @@ open class Container(
if (parent.hasAncestor(child)) invalidOp("Can't addChild to an ancestor")
}

fun addChildrenAt(views: Collection<View>, index: Int) {
// @TODO: Optimize this
var nindex = index
for (v in views) {
addChildAt(v, nindex++)
}
}

/**
* Adds the [view] [View] as a child at a specific [index].
*
Expand Down Expand Up @@ -495,13 +503,22 @@ open class Container(
/**
* Allows to safely interact with the children of a [container] instance.
*/
class ContainerCollection internal constructor(val container: Container, children: List<View>) : MutableCollection<View>, List<View> by children {
class ContainerCollection internal constructor(val container: Container) : BaseMutableList<View>() {
override val size: Int get() = container.numChildren
override fun get(index: Int): View = container.getChildAt(index)
override fun removeAt(index: Int): View = this[index].also { container.removeChildAt(index) }
override fun set(index: Int, element: View): View {
val old = this[index]
container.replaceChild(old, element)
return old
}

override fun contains(element: View): Boolean = element.parent === container
override fun containsAll(elements: Collection<View>): Boolean = elements.all { it.parent === container }
override fun isEmpty(): Boolean = container.numChildren == 0

override fun addAll(index: Int, elements: Collection<View>): Boolean = elements.isNotEmpty().also { container.addChildrenAt(elements, index) }
override fun add(index: Int, element: View) = container.addChildAt(element, index)
override fun add(element: View): Boolean {
container.addChild(element)
return true
Expand Down
18 changes: 14 additions & 4 deletions korlibs-datastructure/src/korlibs/datastructure/BaseCollections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface BaseMap<K, V> : Map<K, V> {
override fun containsValue(value: V): Boolean = values.contains(value)
}

interface BaseMutableList<T> : BaseList<T>, MutableList<T> {
abstract class BaseMutableList<T> : BaseList<T>(), MutableList<T> {
override fun iterator(): MutableIterator<T> = listIterator(0)
override fun listIterator(): MutableListIterator<T> = listIterator(0)
override fun listIterator(index: Int): MutableListIterator<T> = BaseMutableListIterator(this, index)
Expand Down Expand Up @@ -49,7 +49,7 @@ interface BaseMutableList<T> : BaseList<T>, MutableList<T> {
}
}

interface BaseList<T> : List<T> {
abstract class BaseList<T> : List<T> {
override fun containsAll(elements: Collection<T>): Boolean {
val elementsSet = elements.toSet()
for (n in 0 until size) if (this[n] in elementsSet) return true
Expand All @@ -71,7 +71,7 @@ interface BaseList<T> : List<T> {
}
}

open class BaseSubList<T>(val list: List<T>, start: Int, end: Int) : BaseList<T> {
open class BaseSubList<T>(val list: List<T>, start: Int, end: Int) : BaseList<T>() {
var start: Int = start ; protected set
var end: Int = end ; protected set
override val size: Int get() = end - start
Expand All @@ -83,7 +83,17 @@ open class BaseSubList<T>(val list: List<T>, start: Int, end: Int) : BaseList<T>
override fun get(index: Int): T = list[checkIndex(index)]
}

open class BaseSubMutableList<T>(val mlist: MutableList<T>, start: Int, end: Int) : BaseSubList<T>(mlist, start, end), BaseMutableList<T> {
open class BaseSubMutableList<T>(val mlist: MutableList<T>, start: Int, end: Int) : BaseMutableList<T>() {
var start: Int = start ; protected set
var end: Int = end ; protected set
override val size: Int get() = end - start
fun checkIndex(index: Int): Int {
if (index < 0 || index >= size) throw IndexOutOfBoundsException()
return start + index
}

override fun get(index: Int): T = mlist[checkIndex(index)]

override fun add(index: Int, element: T) {
mlist.add(checkIndex(index), element)
end++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ expect class FastArrayList<E> : MutableListEx<E>, RandomAccess {
fun trimToSize()
fun ensureCapacity(minCapacity: Int)

// From MutableListEx
override fun removeRange(fromIndex: Int, toIndex: Int)

// From List

override val size: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class SynchronizedCollection<T>(
open class SynchronizedList<T>(
protected val base: MutableList<T>,
protected val lock: NonRecursiveLock = NonRecursiveLock()
) : BaseMutableList<T> {
) : BaseMutableList<T>() {
override fun clear() = lock { base.clear() }
override fun add(index: Int, element: T) { lock { base.add(index, element) } }
override fun addAll(index: Int, elements: Collection<T>): Boolean = lock { base.addAll(index, elements) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public actual open class FastArrayList<E> internal constructor(
return out
}

override fun removeRange(fromIndex: Int, toIndex: Int) {
actual override fun removeRange(fromIndex: Int, toIndex: Int) {
val count = toIndex - fromIndex
if (count <= 0) return
val array = this.array
Expand Down
2 changes: 1 addition & 1 deletion korlibs-datastructure/src@js/korlibs/datastructure/Js.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public actual open class FastArrayList<E> internal constructor(@PublishedApi int
return false
}

override fun removeRange(fromIndex: Int, toIndex: Int) {
actual override fun removeRange(fromIndex: Int, toIndex: Int) {
jsArray.splice(fromIndex, toIndex - fromIndex)
modCount++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public actual open class FastArrayList<E> internal constructor(
return out
}

override fun removeRange(fromIndex: Int, toIndex: Int) {
actual override fun removeRange(fromIndex: Int, toIndex: Int) {
val count = toIndex - fromIndex
if (count <= 0) return
val array = this.array
Expand Down
4 changes: 3 additions & 1 deletion korlibs-logger/src/korlibs/logger/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,6 @@ internal val miniEnvironmentVariablesUC: Map<String, String> get() {
return _miniEnvironmentVariablesUC!!
}

expect object DefaultLogOutput : Logger.Output
expect object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ actual object Console : BaseConsole() {
}

actual object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?) {
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) {
if (level == Logger.Level.NONE) return
Log.println(when (level) {
Logger.Level.NONE -> Log.VERBOSE
Expand Down
2 changes: 1 addition & 1 deletion korlibs-logger/src@darwin/korlibs/logger/Logger.darwin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ actual object Console : BaseConsole() {
}

actual object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
}

internal actual val miniEnvironmentVariables: Map<String, String> by lazy {
Expand Down
2 changes: 1 addition & 1 deletion korlibs-logger/src@js/korlibs/logger/Logger.js.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ actual object Console : BaseConsole() {
}

actual object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
}

private external val process: dynamic
Expand Down
2 changes: 1 addition & 1 deletion korlibs-logger/src@jvm/korlibs/logger/Logger.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal actual val miniEnvironmentVariables: Map<String, String> by lazy { Syst
actual object DefaultLogOutput : Logger.Output {
private val DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")

override fun output(logger: Logger, level: Logger.Level, msg: Any?) {
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) {
if (logger.nativeLogger == null) {
logger.nativeLogger = java.util.logging.Logger.getLogger(logger.name).also { nativeLogger ->
nativeLogger.useParentHandlers = true
Expand Down
2 changes: 1 addition & 1 deletion korlibs-logger/src@linux/korlibs/logger/Logger.linux.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.cinterop.*
actual object Console : BaseConsole()

actual object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
}

internal actual val miniEnvironmentVariables: Map<String, String> by lazy {
Expand Down
2 changes: 1 addition & 1 deletion korlibs-logger/src@mingw/korlibs/logger/Logger.mingw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import platform.windows.*
actual object Console : BaseConsole()

actual object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
}

internal actual val miniEnvironmentVariables: Map<String, String> by lazy { getEnvs() }
Expand Down
2 changes: 1 addition & 1 deletion korlibs-logger/src@wasmJs/korlibs/logger/Logger.wasm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ actual object Console : BaseConsole() {
}

actual object DefaultLogOutput : Logger.Output {
override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg)
}

internal actual val miniEnvironmentVariables: Map<String, String> by lazy {
Expand Down