Skip to content

Commit

Permalink
feat: Upgrade kotlin compiler to v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PranavPurwar committed Jun 28, 2024
1 parent 2a0a6a7 commit f49c67a
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins {
id("com.android.library") version "8.1.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.20-Beta2" apply false
id("com.android.library") version "8.1.4" apply false
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
}
10 changes: 5 additions & 5 deletions kotlinc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
implementation("org.lsposed.hiddenapibypass:hiddenapibypass:4.3")

implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.20-Beta2")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.22")
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
implementation("org.jetbrains.intellij.deps:trove4j:1.0.20200330")
implementation("org.jdom:jdom:2.0.2")

implementation(projects.jaxp)
api(files("libs/kotlin-compiler-1.9.0-RC.jar"))
api(files("libs/kotlin-compiler-2.0.0.jar"))

compileOnly(projects.theUnsafe)
}
Expand All @@ -55,12 +55,12 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "org.cosmic.ide"
artifactId = "kotlinc"
version = "1.9.0-RC"
artifactId = "kotlinc-android"
version = "2.0.0"

pom {
name.set("Kotlin Compiler")
description.set("A port of the Kotlin Compiler to Android")
description.set("A port of the Kotlin Compiler for the Android platform.")
url.set("http://github.com/Cosmic-IDE/kotlinc")
licenses {
license {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.cli.jvm.compiler.jarfs

Expand Down Expand Up @@ -39,7 +30,7 @@ class ByteArrayCharSequence(
override fun toString(): String {
val chars = CharArray(length)

for (i in indices) {
for (i in 0 until length) {
chars[i] = bytes[i + start].toInt().toChar()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.cli.jvm.compiler.jarfs

Expand All @@ -35,29 +19,16 @@ import java.nio.channels.FileChannel

private typealias RandomAccessFileAndBuffer = Pair<RandomAccessFile, MappedByteBuffer>

class FastJarFileSystem private constructor(internal val unmapBuffer: MappedByteBuffer.() -> Unit) :
DeprecatedVirtualFileSystem() {
class FastJarFileSystem private constructor(internal val unmapBuffer: MappedByteBuffer.() -> Unit) : DeprecatedVirtualFileSystem() {
private val myHandlers: MutableMap<String, FastJarHandler> =
ConcurrentFactoryMap.createMap { key: String ->
FastJarHandler(
this@FastJarFileSystem,
key
)
}
ConcurrentFactoryMap.createMap { key: String -> FastJarHandler(this@FastJarFileSystem, key) }

internal val cachedOpenFileHandles: FileAccessorCache<File, RandomAccessFileAndBuffer> =
object : FileAccessorCache<File, RandomAccessFileAndBuffer>(20, 10) {
@Throws(IOException::class)
override fun createAccessor(file: File): RandomAccessFileAndBuffer {
val randomAccessFile = RandomAccessFile(file, "r")
return Pair(
randomAccessFile,
randomAccessFile.channel.map(
FileChannel.MapMode.READ_ONLY,
0,
randomAccessFile.length()
)
)
return Pair(randomAccessFile, randomAccessFile.channel.map(FileChannel.MapMode.READ_ONLY, 0, randomAccessFile.length()))
}

@Throws(IOException::class)
Expand Down Expand Up @@ -87,6 +58,10 @@ class FastJarFileSystem private constructor(internal val unmapBuffer: MappedByte

fun clearHandlersCache() {
myHandlers.clear()
cleanOpenFilesCache()
}

fun cleanOpenFilesCache() {
cachedOpenFileHandles.clear()
}

Expand All @@ -107,12 +82,12 @@ class FastJarFileSystem private constructor(internal val unmapBuffer: MappedByte
}


//private val IS_PRIOR_9_JRE = System.getProperty("java.specification.version", "").startsWith("1.")
// private val IS_PRIOR_9_JRE = System.getProperty("java.specification.version", "").startsWith("1.")

private fun prepareCleanerCallback(): ((ByteBuffer) -> Unit)? {
return try {
// API 26+ already allow using these methods
// if (IS_PRIOR_9_JRE) {
// We can use these on API 26+
// if (IS_PRIOR_9_JRE) {
val directByteBuffer = Class.forName("java.nio.DirectByteBuffer")
if (directByteBuffer.declaredMethods.any { it.name == "cleaner" }.not()) {
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.cli.jvm.compiler.jarfs

import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile
import java.io.File
import java.io.FileNotFoundException
import java.io.RandomAccessFile
import java.nio.channels.FileChannel
import kotlin.collections.HashMap

class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
private val myRoot: VirtualFile?
Expand All @@ -29,16 +22,15 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
init {
val entries: List<ZipEntryDescription>
RandomAccessFile(file, "r").use { randomAccessFile ->
val mappedByteBuffer = randomAccessFile.channel.map(
FileChannel.MapMode.READ_ONLY,
0,
randomAccessFile.length()
)
val mappedByteBuffer = randomAccessFile.channel.map(FileChannel.MapMode.READ_ONLY, 0, randomAccessFile.length())
try {
entries = try {
mappedByteBuffer.parseCentralDirectory()
} catch (e: Exception) {
throw IllegalStateException("Error while reading '${file.path}': $e", e)
// copying the behavior of ArchiveHandler (and therefore ZipHandler)
// TODO: consider propagating to compiler error or warning, but take into account that both javac and K1 simply ignore invalid jars in such cases
Logger.getInstance(this::class.java).warn("Error while reading zip file: ${file.path}: $e", e)
emptyList()
}
cachedManifest =
entries.singleOrNull { StringUtil.equals(MANIFEST_PATH, it.relativePath) }
Expand Down Expand Up @@ -70,10 +62,7 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
}
}

private fun createFile(
entry: ZipEntryDescription,
directories: MutableMap<String, FastJarVirtualFile>
): FastJarVirtualFile {
private fun createFile(entry: ZipEntryDescription, directories: MutableMap<String, FastJarVirtualFile>): FastJarVirtualFile {
val (parentName, shortName) = entry.relativePath.splitPath()

val parentFile = getOrCreateDirectory(parentName, directories)
Expand All @@ -89,10 +78,7 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
)
}

private fun getOrCreateDirectory(
entryName: CharSequence,
directories: MutableMap<String, FastJarVirtualFile>
): FastJarVirtualFile {
private fun getOrCreateDirectory(entryName: CharSequence, directories: MutableMap<String, FastJarVirtualFile>): FastJarVirtualFile {
return directories.getOrPut(entryName.toString()) {
val (parentPath, shortName) = entryName.splitPath()
val parentFile = getOrCreateDirectory(parentPath, directories)
Expand All @@ -118,8 +104,7 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {

fun contentsToByteArray(zipEntryDescription: ZipEntryDescription): ByteArray {
val relativePath = zipEntryDescription.relativePath
if (StringUtil.equals(relativePath, MANIFEST_PATH)) return cachedManifest
?: throw FileNotFoundException("$file!/$relativePath")
if (StringUtil.equals(relativePath, MANIFEST_PATH)) return cachedManifest ?: throw FileNotFoundException("$file!/$relativePath")
return fileSystem.cachedOpenFileHandles[file].use {
synchronized(it) {
it.get().second.contentsToByteArray(zipEntryDescription)
Expand All @@ -128,4 +113,4 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
}
}

private const val MANIFEST_PATH = "META-INF/MANIFEST.MF"
private const val MANIFEST_PATH = "META-INF/MANIFEST.MF"
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* This file is part of Cosmic IDE.
* Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.cli.jvm.compiler.jarfs

Expand Down Expand Up @@ -88,11 +79,7 @@ internal class FastJarVirtualFile(
}

@Throws(IOException::class)
override fun getOutputStream(
requestor: Any,
newModificationStamp: Long,
newTimeStamp: Long
): OutputStream {
override fun getOutputStream(requestor: Any, newModificationStamp: Long, newTimeStamp: Long): OutputStream {
throw UnsupportedOperationException("JarFileSystem is read-only")
}

Expand All @@ -118,4 +105,4 @@ internal class FastJarVirtualFile(
}
}

private val EMPTY_BYTE_ARRAY = ByteArray(0)
private val EMPTY_BYTE_ARRAY = ByteArray(0)
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,4 @@ private fun MappedByteBuffer.parseZip64CentralDirectoryRecordsNumberAndOffset():
return Pair(entriesNumber.toInt(), offsetOfCentralDirectory.toInt())
}

private fun ByteBuffer.getUnsignedShort(offset: Int): Int =
java.lang.Short.toUnsignedInt(getShort(offset))
private fun ByteBuffer.getUnsignedShort(offset: Int): Int = java.lang.Short.toUnsignedInt(getShort(offset))
Loading

0 comments on commit f49c67a

Please sign in to comment.