https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
compiler
  • t

    Ty Smith

    01/30/2020, 3:47 AM
    Because of KAPT's performance at our size, I've implemented a similar solution to https://www.droidcon.com/media-detail?video=380953207, where we use Javac to process .class files for annotations coming from kotlinc. It's giving us pretty significant build wins and we're willing to work with the constraints like not referencing generating code directly within the same target. One problem we've run into with some of our APs is the use of SOURCE retained annotations, so I've been experimenting with a kotlin compiler plugin to rewrite the SOURCE retention to CLASS on annotation definitions. However, through my digging, I've only figured out how to rewrite the ones we define per target, but not consume as jars (3rd party deps, downstream java deps, etc..). I have two questions I'm hoping someone could give context on or point me towards some resources to help. 1. Is there a way to set a new Class Builder Mode that's used for the default compiler execution, not an explicit call from another plugin like KAPT? This would allow us to set the mode to retain source annotations (like kapt does) and solve the issue, but it doesn't seem like the overrideClassBuilderMode() method is called on a plugin extension using ClassBuilderInteceptorExtension. 2. If 1 is not feasible, is it possible to adjust the retention policy at the consumer callsite of an annotation as opposed to just the definition? If both are not feasible, I plan on doing some bytecode rewriting all the jars in our build pipeline to adjust source retained ones to class, and combine that with the version I have now that rewrites our own defined versions. This seems overweight though, so hoping I'm overlooking something more simple.
    z
    • 2
    • 2
  • b

    bnorm

    02/04/2020, 5:40 PM
    Is it possible, from a compiler plugin, to get the original source code for the call site of a function? Is this something being considered/possible for the new IR compiler plugins? I've been poking around in the Kotlin repository trying to figure out if an idea I have for a plugin is even possible. I found
    org.jetbrains.kotlin.ir.SourceManager
    but I'm not sure if that can be used to read the source file given an
    IrCall
    .
    f
    z
    s
    • 4
    • 5
  • r

    Rohan Maity

    02/06/2020, 11:29 AM
    My compiler plugin Component registrar is not being accepted by K2JVMCompiler()
    java.lang.RuntimeException: Compilation failed. java.lang.ClassCastException: Cannot cast io.quarkus.allopen.cli.QuarkusComponentRegistrar to org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
    How could I make it work ?
    t
    • 2
    • 4
  • f

    Foso

    02/06/2020, 2:12 PM
    Is there already a way to enable the IR Backend for KotlinJs?
    b
    p
    • 3
    • 7
  • p

    PHondogo

    02/14/2020, 10:11 AM
    Hello! What I should return from KotlinGradleSubplugin.getPluginArtifact if I implement kotlin compiler plugin in buildSrc gradle section?
    t
    s
    • 3
    • 10
  • r

    redrield

    02/15/2020, 12:47 AM
    Is there a way that a compiler plugin can take the resolved generic types from certain values, and replace them with different generics (assuming the replacement conforms to type bounds) before code analysis?
    s
    r
    • 3
    • 15
  • m

    mbonnin

    02/16/2020, 3:55 PM
    I just got this:
    Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'withLock$default' into
    public suspend inline fun <T> kotlinx.coroutines.sync.Mutex.`withLock$default`(owner: kotlin.Any?, action: () -> T, `$mask0`: <http://kotlin.Int|kotlin.Int>, `$handler`: kotlin.Any?, `$completion`: kotlin.coroutines.Continuation<T>): kotlin.Any? defined in kotlinx.coroutines.sync
    I'm currently trying out jetpack compose dev04 and Android Studio canary so I don't mind the occasional exception but is it worth reporting it somewhere ?
    f
    l
    • 3
    • 10
  • r

    raulraja

    02/17/2020, 12:57 PM
    Does anyone know if there is a way within the compiler apis to evaluate a KtExpression that does not require instantiating and bringing in the script-utils with the ScriptEngineFactory?
    s
    • 2
    • 5
  • d

    Dominaezzz

    02/18/2020, 10:17 AM
    So I'm paying around with IR and I've generated a simple function. When the Kotlin compiler runs and I export the project JAR, I can see my function in the JAR. Yay! But if I look at the class files in the build folder it's nowhere to be found. Also I can't use the function from the test sources. What am I missing?
    s
    • 2
    • 8
  • c

    Corbin McNeely-Smith

    02/18/2020, 5:16 PM
    I'm currently fixing up the kotlin bazel integration -- is there a way to exit the compiler after the analysis phase? I'm attempting to the use the kotlin jvm-abi-plugin to generate abis for downstream compilation.
    r
    t
    • 3
    • 5
  • c

    Corbin McNeely-Smith

    02/20/2020, 9:09 PM
    Has anyone had the experience of invoking K2JVMCompiler with a plugin and getting this error:
    java.lang.NoClassDefFoundError: org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    	at <http://java.net|java.net>.URLClassLoader.defineClass(URLClassLoader.java:468)
    	at <http://java.net|java.net>.URLClassLoader.access$100(URLClassLoader.java:74)
    	at <http://java.net|java.net>.URLClassLoader$1.run(URLClassLoader.java:369)
    	at <http://java.net|java.net>.URLClassLoader$1.run(URLClassLoader.java:363)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at <http://java.net|java.net>.URLClassLoader.findClass(URLClassLoader.java:362)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:75)
    	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:82)
    	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:75)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    As you can see it's running in a subset class loader that was seeded with the compiler jar -- but it can't find the class that is most certainly in the jar. (double checked, in fact) Tried add the jar explicitly to the cp, as well as passing it .as a plugin (bit of a hail mary, that.) Any advice?
    c
    • 2
    • 3
  • l

    louiscad

    02/22/2020, 1:03 PM
    Hi, is HMPP ready to be tried in 1.3.70 EAP 3? I'd like to try it for the #splitties libraries
    d
    d
    • 3
    • 5
  • t

    turastory

    02/26/2020, 5:01 AM
    I’m curious about how the kotlin compiler works with coroutines. Currently I’m looking the official kotlin repository(https://github.com/JetBrains/kotlin), but there are a lot of modules and it’s hard to figure out where to start. Could you guys give me some guidance?
    ➕ 1
    r
    • 2
    • 6
  • p

    PHondogo

    03/02/2020, 6:46 PM
    Hello, I have inline function with reified type. How can i get real type in Kotlin compiler plugin at
    override fun visitCall(expression: IrCall, data: Unit): IrElement
    ?
    s
    • 2
    • 3
  • z

    Zach Klippenstein (he/him) [MOD]

    03/02/2020, 8:41 PM
    There are a number of open issues with the Kotlin IntelliJ plugin about an error “PSI and index do not match”: - https://youtrack.jetbrains.com/issue/KT-32042 - https://youtrack.jetbrains.com/issue/KT-34759 - https://youtrack.jetbrains.com/issue/KT-34524 These issues are causing IntelliJ/Android Studio to effectively become a simple text editor for a large number of our developers. Is there anything we can do to help debug and/or prioritize a fix? I would try diving into the plugin codebase to fix it myself, but I won’t have bandwidth to do so for at least a few more weeks.
    👀 1
    • 1
    • 1
  • p

    PHondogo

    03/03/2020, 7:51 PM
    Hello! I've switched to 1.3.70 and got error in my compiler plugin when calling
    IrType.isInterface
    , got
    java.lang.IllegalStateException: Symbol for deserialized  class Any is unbound.
    As i understand this cause when getting owner from symbol of other module. 
    Please advice me how to solve it.
    l
    r
    • 3
    • 6
  • a

    Almas Shagdarov

    03/05/2020, 5:45 AM
    Hi everyOne. Does kotlin support java 5(version 49)?
    f
    • 2
    • 1
  • j

    jw

    03/06/2020, 9:13 PM
    is this where i ask about kotlinx-metadata-jvm? How do I write out a modified KmModule read with KotlinModuleMetadata?
    e
    • 2
    • 2
  • p

    PHondogo

    03/07/2020, 1:42 PM
    Hello! I'm using Kotlin 1.3.70. When I compile kotlin-js with
    -Xir-produce-js
    I got a lot of compilation error from jsTest that it can't find symbols that located in jsMain. Without setting this flag all compiles well. Please advise me how can i compile my Kotlin code to js using IR? P.S. it is the same for browser{} and nodejs{}
    s
    • 2
    • 9
  • p

    PHondogo

    03/08/2020, 7:55 AM
    Hello! I have such code (Kotlin jvm):
    fun main() { 
          embeddedServer(Netty, port = 8080, host = "127.0.0.1") {
            routing {
                get("/") {
                    call.respondHtml {
                        head {
                            title("Hello from Ktor!")
                        }
                        body {
                            +"${hello()} from Ktor. Check me value: ${Sample().checkMe()}"
                            div {
                                id = "js-response"
                                +"Loading..."
                            }
                            script(src = "/static/test_js.js") {}
                        }
                    }
                }
                static("/static") {
                    resource("test_js.js")
                }
            }
        }.start(wait = true)
    }
    After compiling it with
    useIR=false
    it works ok, but after compiling it with
    useIR=true
    it throws execption on `call.respondHtml {`: java.lang.NoSuchMethodError: 'java.lang.Object io.ktor.html.RespondHtmlKt.respondHtml$default(io.ktor.application.ApplicationCall, io.ktor.http.HttpStatusCode, kotlin.jvm.functions.Function1, int, java.lang.Object, kotlin.coroutines.Continuation)' Please, advice me how can I make it work with
    useIR=true
    .
    u
    • 2
    • 2
  • d

    Drew Hamilton

    03/08/2020, 11:48 AM
    I’m trying to brute force my way through writing a compiler plugin (JVM only for now), but I’m stuck now because I can’t find an
    InstructionAdapter.ireturn()
    function. How do I write the JVM
    IRETURN
    (integer return) bytecode into my generated code?
    r
    s
    • 3
    • 9
  • j

    jimn

    03/10/2020, 3:18 AM
    is this a bug ? intellij/kotlinc dont complain
    Untitled
    l
    • 2
    • 2
  • b

    betterclever

    03/10/2020, 12:09 PM
    In my multi-module gradle project with mixed source sets, when I make a small change to a Kotlin source file, compileKotlin is very fast. But when I am changing a Java source file, it take very long. It looks to me that kotlin compiler is compiling whole kotlin source code. Is this a known behavior? If not, can someone tell me any resource so I can profile kotlinc to know better what is going on?
    • 1
    • 1
  • b

    betterclever

    03/11/2020, 4:34 PM
    Can someone tell here how to debug the compiler 🙏 ?
    s
    • 2
    • 3
  • r

    raulraja

    03/17/2020, 7:52 PM
    Also all
    owner
    property in the IR nodes are now null whereas before they always contained the pointer to the
    symbol
    s
    r
    • 3
    • 20
  • s

    spierce7

    03/23/2020, 5:00 AM
    What's the best way for me to learn how to write a compiler plug in? I've tried looking at it a few times in the past but could never figure out what was going on in the IR.
    s
    b
    • 3
    • 4
  • r

    raulraja

    03/23/2020, 1:53 PM
    Hi!, When generating code with IR which seems ok in 1.3.61 it produces binaries that when loaded at runtime result in this kinds of exceptions related to
    kotlin.internal.ir.Intrinsic
    . I suppose this is an issue in code generation and not that I actually need an IR runtime to run that code and it’s missing as dependency. Is that the case? Or does anyone else know where this may be coming from? Any help is appreciated, thanks!
    Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/internal/ir/Intrinsic
    	at consumer.MainKt.<clinit>(main.kt:5)
    Caused by: java.lang.ClassNotFoundException: kotlin.internal.ir.Intrinsic
    	at <http://java.net|java.net>.URLClassLoader.findClass(URLClassLoader.java:382)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	... 1 more
    s
    • 2
    • 29
  • m

    Manuel Wrage

    03/25/2020, 3:53 PM
    Hi, I have a problem while writing a compiler plugin. My goal is to collect functions with a specific annotation and create a class for each of them. The problem is that the class needs to be placed inside a different package than the actual function and i have no idea how to do this. Is this even possible with current apis?
    s
    r
    • 3
    • 7
  • h

    Hadi Lashkari

    03/27/2020, 8:13 AM
    Hi guys! I tried to create a Kotlin compiler plugin to generate a simple method, but I cannot figure out how to resolve that method! I asked about it couple of weeks ago https://stackoverflow.com/questions/60532779/unresolved-reference-in-generated-method-by-a-kotlin-compiler-plugin without answer! Any idea to solve it would be appreciated. Thanks.
    s
    • 2
    • 7
  • m

    mp

    04/04/2020, 5:35 PM
    On one of my ktor projects, updating the ktor dependency from 1.3.1 to 1.3.2 hugely increases the compile time. Normally
    ./gradlew classes
    takes 40-50s from a clean workspace with ktor 1.3.1. I've been waiting 8 minutes so far on 1.3.2... Is this a known issue?
    w
    • 2
    • 6
Powered by Linen
Title
m

mp

04/04/2020, 5:35 PM
On one of my ktor projects, updating the ktor dependency from 1.3.1 to 1.3.2 hugely increases the compile time. Normally
./gradlew classes
takes 40-50s from a clean workspace with ktor 1.3.1. I've been waiting 8 minutes so far on 1.3.2... Is this a known issue?
svg flame graph of the compiler from async profiler (
./profiler.sh -e itimer -f ~/kotlinc.svg -d 30 (pid)
)
kotlinc.svg
This is with kotlin 1.3.71
20 min and counting; I think I'll stick with 1.3.1 for now...
w

wasyl

04/04/2020, 7:53 PM
For me such long builds were often a symptom of memory issues — the GC would be taking so much time it doesn’t allow task to finish. Did you try a clean daemon?
m

mp

04/05/2020, 7:14 PM
yes, that's with a clean daemon each time.
The profile shows the issue isn't GC; C++ stack traces would be dominant if that was happening
👍 1
View count: 4