Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Udalov udalov

View GitHub Profile
@udalov
udalov / jvm-ir-via-external-file.patch
Last active Dec 16, 2019
Enable JVM IR backend via external file
View jvm-ir-via-external-file.patch
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt
index 3371edf18c8..5b72262ebfc 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiJavaModule
import com.intellij.psi.search.DelegatingGlobalSearchScope
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.ProjectScope
+import com.sun.management.HotSpotDiagnosticMXBean
import org.jetbrains.kotlin.analyzer.AnalysisResult
@udalov
udalov / bootstrap-ir.py
Last active Sep 12, 2019
Test compilation of the Kotlin project with JVM IR
View bootstrap-ir.py
#!/usr/bin/env python3
import atexit, os, re, shutil, subprocess, sys, time
from pathlib import Path
def to_str(buf):
return "".join(map(chr, buf))
def dump_stdout_stderr(f, result):
f.write("=== STDOUT ===\n\n")
@udalov
udalov / nested-classes-in-annotations.md
Created Sep 20, 2018
Nested classes in annotations KEEP draft
View nested-classes-in-annotations.md

Support nested classes in annotations

Discussion of this proposal is held in this issue.

Goal

Support nested classes, including companion objects, in annotation classes:

annotation class MyAnnotation(val value: Kind) {
    enum class Kind { FIRST, SECOND }
@udalov
udalov / loadOriginName.kt
Last active Mar 1, 2018
Load name of the original anonymous/synthetic class which was copied during inline (KT-21320)
View loadOriginName.kt
import org.jetbrains.kotlin.serialization.jvm.*
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun loadOriginName(className: String) {
val metadata = Class.forName(className).declaredAnnotations
.filter { it.annotationClass.qualifiedName == "kotlin.Metadata" }
.single() as Metadata
if (metadata.k == 3 && metadata.d1.isNotEmpty()) {
// Synthetic classes generated for lambdas/coroutines
@udalov
udalov / getKType.kt
Last active Jun 19, 2020
DEPRECATED example how to obtain KType instance from reified T. Please use "typeOf" since 1.3.40!
View getKType.kt
import java.lang.reflect.*
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.KTypeProjection
import kotlin.reflect.KVariance
import kotlin.reflect.full.createType
// --- Interface ---
inline fun <reified T : Any> getKType(): KType =
@udalov
udalov / spec-bound-calref.md
Last active Apr 8, 2016
Spec: bound callable references
View spec-bound-calref.md

Summary

Support "bound callable references" and "bound class literals".

Motivation / use cases

  • It's painful to write lambdas every time
  • There's currently no way to reference an object member, which is sort of inconsistent with the fact that it's possible to reference static Java members
  • It's present in Java and its absence in Kotlin is rather inconvenient
  • 42 votes on KT-6947: Callable reference with expression on the left hand side

@udalov
udalov / spec-sealed-data.md
Created Mar 28, 2016
Spec: sealed + data
View spec-sealed-data.md

Summary

Allow data classes as sealed class subclasses.

sealed class Base {
    data class Derived(...) : Base()
}

Motivation / use cases

View keybase.md

Keybase proof

I hereby claim:

  • I am udalov on github.
  • I am udalov (https://keybase.io/udalov) on keybase.
  • I have a public key whose fingerprint is 40BF FCAA AA01 B591 916C AAB6 8DA6 620F 79E0 B972

To claim this, I am signing this object:

@udalov
udalov / api.kt
Last active Aug 29, 2015
Sketch of a more type-safe reflection API for Kotlin
View api.kt
@file:suppress("UNCHECKED_CAST", "BASE_WITH_NULLABLE_UPPER_BOUND", "UNUSED_PARAMETER")
interface KElement
// Class, package, type
interface KDeclarationContainer : KElement {
val allMembers: Collection<KElement>
}
View break java
class A { void foo() {} }
class a { }
public class Main {
public static void main(String[] args) {
new A().foo();
}
}
You can’t perform that action at this time.