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
  • r

    ralf

    05/20/2020, 3:42 AM
    Is somebody aware of tiny Kotlin compiler plugin that generates new code with the
    PackageFragmentProviderExtension
    ? I’m always looking at the Android Synthetic implementation, but it’s quite complicated. My goal is only to generate a new top level property without a setter in a new package. I see good examples how to generate the property here: https://github.com/JetBrains/kotlin/blob/5636227857545fb11ae2790fca55934b0f88a468/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt Only the PackageFragmentProvider code is extremely confusing.
    s
    • 2
    • 6
  • r

    rnett

    05/21/2020, 11:32 PM
    I'm trying to do a relatively simple transform where I turn annotated function params into another type, and delegate the original param out of them as a var, like
    fun test(x: @Watched Int)
    -->
    fun test(x$watch: Watcher<Int>){ var x by x$watch ...
    This is easy enough on the IR side, but I get "Can't assign to a var" errors, and when I suppress them,
    Not a variable: value-parameter x: @com.rnett.klairvoyant.Watched <http://kotlin.Int|kotlin.Int>
    errors from
    org.jetbrains.kotlin.psi2ir
    classes. Is there a way to intercept this phase or another way around this? I'm trying to avoid editing the PSI because it looks like a pain after looking at arrow-meta.
    s
    r
    • 3
    • 13
  • j

    Johann Beleites

    05/22/2020, 8:36 AM
    Hey everyone. I found myself in various discussions about the performance of Kotlin vs Java recently. Typically, the argument goes along the lines that since Kotlin generally uses older bytecode features, it is less performant than current Java versions, say Java 11. Now I have a hard time finding current information on 1) which modern bytecode features Kotlin does use and 2) how Kotlin's performance compares to Java's. Without digging through the compiler source code, can anyone point me to resources that provide an overview of which bytecode features Kotlin uses to implement certain features? Potentially also (current, Java 11+) resources that compare the performance between the two? Or, in other words, which benefits do I get (if any) by increasing the Java target version to anything above 8 when compiling Kotlin code?
    m
    • 2
    • 2
  • p

    PHondogo

    05/22/2020, 9:49 AM
    Hello! I have my CommandLineProcessor defined like
    class CliProcessor : CommandLineProcessor {
    
        override val pluginId = "my.test"
    
        override val pluginOptions: Collection<AbstractCliOption> = listOf(
                CliOption(
                        "myTest",
                        "<1|2>",
                        "Test option"
                )
        )
    
        override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) {
            super.processOption(option, value, configuration)
            // DO smth
        }
    }
    How can I pass my option from command line? I'm passing it this way
    private fun setKotlinCompilerArgs(options: KotlinCommonOptions) {
        options.freeCompilerArgs += "-myTest=1"
    }
    I've tried several variants: --myTest=1, myTest=1, myTest:1, -myTest:1 But every time got error:
    e: Invalid argument: -myTest=1
    Please help me to find out right way.
    s
    • 2
    • 3
  • m

    mp

    05/27/2020, 2:02 AM
    I have a project (kotlin 1.3.72) in which updating from ktor 1.3.1 to 1.3.2 causes a catastrophic degradation in compiler performance. Compiles normally take about 20s, but I've been waiting about 8m so far with 1.3.2. Profile shows inline code gen is taking basically all the CPU time, and much of that is spent in asm's
    Frame.merge()
    .
    kotlinc.svg
    d
    • 2
    • 4
  • r

    Rachel

    05/29/2020, 11:53 AM
    Hi! Please, I don't know if I understand the organization in YouTrack 🙏 Please, could someone confirm if this change https://youtrack.jetbrains.com/issue/KT-37255 is going to be available for
    1.4-M3
    ? It seems it solves the issue with the backend IR which is broken since 1.3.7x: https://youtrack.jetbrains.com/issue/KT-37482 Thanks in advance!
    g
    s
    t
    • 4
    • 11
  • r

    russhwolf

    06/02/2020, 4:50 PM
    Does something special need to be configured to hook into the analysis phase on Native? Messing around with this sample https://github.com/nhachicha/sample-KMP-compiler-plugin/ and while the
    IrGenerationExtension
    in there runs fine on JVM and native, when I add a
    AnalysisHandlerExtension
    it's only being run on JVM.
    👀 3
    s
    • 2
    • 6
  • d

    Daniel Svensson

    06/05/2020, 6:37 PM
    I was thinking about
    foo.let(Bar::method)
    vs
    foo.let { Bar.method(it) }
    in terms of compiler speed, thinking that the function reference opens up to fewer possibilities compared to a block, and it could have a slight, but measurable compilation speedup if used a lot. Generating a 1000 long file with identical
    .let { .. }
    and another file with
    .let(func::ref)
    resulted in
    .let { ... }
    being consistently slightly faster with 7.125 seconds vs 7.882 seconds. One hypothesis is that the function reference version is transformed to the block version during compilation, perhaps someone here knows more of the compiler internals to pitch in on that. As expected identical byte code is generated in both cases. When I then tried with Kotlin 1.4 M2, it turned out that the
    .let { ... }
    version had become slower, and has now consistently the exact same compilation speed as the function reference. Which is the reason to why I signed up to this slack 🙂 Was hoping for the opposite as 1.4 is touted to improve compilation speed (but it's not like it's life or death which style is preferred 🙂 ).
    d
    • 2
    • 4
  • d

    Daren Klamer

    06/08/2020, 2:06 AM
    hello everyone, is there a compiler api example for kotlin anywhere? im working on an integration tool that allows you to write classes/scripts in groovy and wanted to add kotlin to it withou resorting to the
    kotlinc
    command.
    g
    • 2
    • 35
  • d

    dephinera

    06/09/2020, 7:15 PM
    Hey, everyone, Any references you can suggest for reading about the Kotlin AST and modifying it? I'm starting with my first kotlin compiler plugin and it feels like I threw myself right in the deep...
    m
    • 2
    • 3
  • a

    Ahmed Mourad

    06/12/2020, 2:11 PM
    Hi everyone, can someone recommend any good compiler courses/books/playlists that would help with building compiler plugins?
    s
    • 2
    • 2
  • r

    Rohan Maity

    06/15/2020, 3:12 AM
    Hello , I have to do bytecode transformation , Now currently , all classes are final by default in kotlin(or not open) If I extend a non-open class ,
    kotlinc
    fails . Is there any way to bypass that failure ? Any way I can tweak
    kotlinc
    to turn off the failure ?
    r
    r
    t
    • 4
    • 5
  • a

    Ahmed Mourad

    06/15/2020, 6:09 PM
    Hi, I'm trying to change the visibility on certain functions from
    public
    to lower values. So, I created this a synthetic resolver with this method:
    override fun generateSyntheticMethods(
        thisDescriptor: ClassDescriptor,
        name: Name,
        bindingContext: BindingContext,
        fromSupertypes: List<SimpleFunctionDescriptor>,
        result: MutableCollection<SimpleFunctionDescriptor>
    ) {
    
        /* ... */
        result.elementAt(methodIndex).let { descriptor ->
            val replacement = descriptor.createCustomCopy {
                it.newCopyBuilder().setVisibility(newVisibility)
            }
            result.remove(descriptor)
            result.add(replacement)
        }
    }
    This works for if
    newVisibility
    is
    private
    and
    protected
    but does not work if it's
    internal
    and gives this error:
    Exception in thread "main" java.lang.NoSuchMethodError: dev.ahmedmourad.sample.SomeClass.functionName$ModuleName(Ljava/lang/String;)Ldev/ahmedmourad/sample/SomeClass;
    	at dev.ahmedmourad.sample.MainKt.main(Main.kt:25)
    	at dev.ahmedmourad.sample.MainKt.main(Main.kt)
    I know that the
    internal
    modifier doesn't exist in the JVM and that synthetic methods are used to simulate it, so I guess I need to create a synthetic method whenever I change access to
    internal
    , how and where do I do that?
    r
    • 2
    • 1
  • d

    Daren Klamer

    06/17/2020, 12:49 PM
    hi everyone, is there an API i can use to compile a kotlin file? I am able to use the scripting api but that creates extra classes to do with scripting which i dont want
    s
    h
    t
    • 4
    • 5
  • t

    turansky

    06/25/2020, 12:54 AM
    How to add
    @Suppress
    for
    IrTypeOperatorCall
    by compiler plugin?
    external interface INode
    
    // before
    val isNode = i is INode
    
    // after
    val isNode = @Suppress(
        "UNCHECKED_CAST_TO_EXTERNAL_INTERFACE",
        "USELESS_IS_CHECK"
    ) i is INode
    ✔️ 1
    d
    • 2
    • 21
  • f

    Fudge

    06/26/2020, 12:21 PM
    How can I get the declaration of a
    KtElement
    using the kotlin compiler api? When I try to access `getReference()`/`getReferences()` all I get is null / empty list. I'm assuming there's some extra configuration I need to do, because calls to resolve references go through this call:
    ServiceManager.getService(KotlinReferenceProvidersService::class.java) ?: NO_REFERENCES_SERVICE
    And the left hand side is always null.
    s
    • 2
    • 21
  • b

    bloder

    06/30/2020, 3:52 AM
    How can I repeat multiple times analysis phase? I have many extensions registered for analysis phase and in some I'm returning
    RetryWithAdditionalRoots
    but it rewinds only one time, I've already tried build these retry returning with different additional files but still repeating only one time, is this expected by Kotlin compiler? Is there a way that I can retry multiple times?
    s
    • 2
    • 7
  • d

    Daren Klamer

    07/07/2020, 10:36 AM
    does anyone have any sample code that can be used to traverse over the ast of a kotlin file?
    r
    • 2
    • 1
  • d

    Daren Klamer

    07/07/2020, 11:09 AM
    any idea how i get kotlin to visit a file, passing in my own visitor?
    r
    • 2
    • 29
  • p

    PHondogo

    07/09/2020, 1:37 PM
    Hello! How can i generate lambda function at comiler ir phase? I'm transforming function body and want to assign lambda to variable. That lambda must be my generated lambda. I found IrFunctionImpl class that i can use for that, but it has parameter of FunctionDescriptor. But to create it, i need to specify containing declaration, but in M3 links to frontend structures were removed or deprecated.
    r
    • 2
    • 11
  • s

    shikasd

    07/09/2020, 2:19 PM
    Hey, as mentioned above, in current version of compiler (1.4-M3) many links to descriptors from IR have been deprecated. I am curious, what is a recommended way of passing data from frontend to backend in the current implementation? Before, I was using
    BindingContext
    with custom slices as a source of such information, but it was mostly relying on certain descriptors being in place. As I see, I still can do same kind of manipulations with them, but as they are deprecated, is there any other means achieve similar results?
    r
    p
    • 3
    • 12
  • p

    PHondogo

    07/10/2020, 8:54 PM
    Previously (M2) in IrGenerationExtension I was able to scan all module dependecies using ModuleDescriptor.allDependencyModules, select needed classes, reference them using pluginContext.symbolTable.referenceClass(ClassDescriptor) and generate needed expressions with them. How can I do it in M3 in IR phase? Now in M3 it complains with list of unbound symbols. I need all IrClasses from dependency modules. It would be even better to scan using only Ir structures without use of Descriptors.
    s
    • 2
    • 5
  • p

    PHondogo

    07/11/2020, 7:59 PM
    Hello! While scanning all packages using ModuleDescriptor.getSubPackagesOf I've faced a problem. Suppose we have packages like below x x.y x.y.z.SomeClass x.z.SomeClass When call getSubPackageOf(FqName("x")) it will return only x.z package. x.y package will not be returned. I guess cause it don't have any nonpackage declarations (classes, variables,functions). But how than I can find out that x.y.z package exists to scan it?
    t
    • 2
    • 2
  • g

    groostav

    07/11/2020, 10:50 PM
    blargwargl, im doing some code gen for java, i have this on stack
    ... double1, double2, double3, arrayRef
    where double1..3 are primative double types, and arrayRef is a DoubleArray. I want to put these doubles into the array.
    DASTORE
    expects
    arrayRef, index, value.
    Problem is, i cant swap double3 and arrayRef. double3 is a category2, and arrayRef is a category 1. There is no DUP bytecode for this swap where the stack has got a category 1 type on top, and a category 2 type below. kotlinc (and javac) are both smart enough to know the array will need to be created before pushing these values to the stack, so they push their array on the stack and then pus the values to store into that array on stack. Smart. Can i really not do this without a local variable? Am I missing something?
    • 1
    • 1
  • r

    ralf

    07/12/2020, 12:09 AM
    Heads up: Kotlin compiler plugins compiled with Kotlin 1.3 can’t be used in projects using Kotlin 1.4 M3 (M2 is fine). I filed a ticket and added a sample to reproduce the issue: https://youtrack.jetbrains.com/issue/KT-40214
    t
    j
    • 3
    • 7
  • t

    turansky

    07/12/2020, 8:43 PM
    How to convert
    IrClass
    (companion object) to
    IrExpression
    or
    IrValueSymbol
    ?
    ✔️ 1
    p
    • 2
    • 5
  • j

    jdemeulenaere

    07/14/2020, 2:04 PM
    Edit: Problem was fixed by pointing JDK_16 to an actual Java 6 JDK, not a Java 8 one. Hi all! I'm trying to compile
    kotlin-scripting-jvm-host
    from the 1.4-M3 source but the
    ./gradlew :kotlin-stdlib:compileKotlin
    task fails. I'm on a clean branch with tag
    build-1.4-M3-release-207
    (the one that was apparently used to compile the compiler jar available at the bottom of https://github.com/JetBrains/kotlin/releases/tag/v1.3.72) . It fails with the error below. Any idea what's going on?
    > Task :kotlin-annotations-jvm:processResources NO-SOURCE
    > Task :kotlin-annotations-jvm:classes
    > Task :kotlin-annotations-jvm:inspectClassesForKotlinIC
    > Task :kotlin-annotations-jvm:jar
    > Task :prepare:build.version:writeStdlibVersion UP-TO-DATE
    > Task :kotlin-stdlib-common:compileKotlinCommon UP-TO-DATE
    > Task :kotlin-stdlib-common:processResources NO-SOURCE
    > Task :kotlin-stdlib-common:classes UP-TO-DATE
    > Task :kotlin-stdlib-common:inspectClassesForKotlinIC UP-TO-DATE
    > Task :kotlin-stdlib-common:jar UP-TO-DATE
    > Task :kotlin-stdlib:compileKotlin
    e: /usr/local/google/code/kotlin/libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt: (98, 9): 'getTypeName' hides member of supertype 'Type' and needs 'override' modifier
    e: /usr/local/google/code/kotlin/libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt: (102, 9): Class 'TypeVariableImpl' is not abstract and does not implement abstract member public abstract fun <T : Annotation!> getAnnotation(p0: Class<T!>!): T! defined in java.lang.reflect.TypeVariable
    > Task :kotlin-stdlib:compileKotlin FAILED
    Build time for tasks:
    Compiling kotlin: 52.33s (90.48% of total time)
    Uncategorized: 4.89s (8.46% of total time)
    FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':kotlin-stdlib:compileKotlin'.
    • 1
    • 1
  • s

    shikasd

    07/16/2020, 12:54 AM
    Hi, I was playing around with compiler api on new js IR backend and it seems like declarations from current module get duplicated if I try to reference them in the linker. E.g. if I have class
    A
    in my module and I used
    IrPluginContext.referenceClass(FqName("A"))
    in my extension, I get the following exception (in thread):
    r
    • 2
    • 8
  • j

    Jan Skrasek

    07/16/2020, 8:28 AM
    Kotlin Symbol Processing API is this an Google initiative? Is it somehow coordinated with JetBrains?
    f
    • 2
    • 1
  • d

    diego-gomez-olvera

    07/22/2020, 12:18 PM
    Hello! I have a class A and a class B (that extends A) which I would like to deprecate with
    ERROR
    , would it be possible to do it simultaneously? Class B complains about the usage of A
    m
    • 2
    • 2
Powered by Linen
Title
d

diego-gomez-olvera

07/22/2020, 12:18 PM
Hello! I have a class A and a class B (that extends A) which I would like to deprecate with
ERROR
, would it be possible to do it simultaneously? Class B complains about the usage of A
m

Marc Knaup

07/26/2020, 5:43 PM
@Suppress("DEPRECATION_ERROR")
on
B
d

diego-gomez-olvera

07/27/2020, 10:33 AM
thanks!
View count: 4