https://kotlinlang.org logo
Docs
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
  • e

    elect

    10/16/2021, 9:58 AM
    what's the most updated resource for someone approaching writing a compiler plugin for the first time? I saw the

    famous video▾

    from Kevin Most at KotlinConf '18 Then I saw this blog entry, and this with Arrow Meta.. or I could go completely in my own trying to modify and existing plugin what would you suggest me to follow?
    p
    h
    +2
    • 5
    • 16
  • s

    suresh

    10/21/2021, 4:53 PM
    Hi, i know kotlin is a null safe language, but jvm has recently (JDK14) added Helpful NPE (for NullPointer exceptions thrown by JVM https://openjdk.java.net/jeps/358) which will describe precisely which variable is null. Can we get the same message in the NPE thrown by kotlin compiler in the following scenario?
    r
    • 2
    • 3
  • a

    Alejandro Serrano Mena

    10/21/2021, 8:16 PM
    hi! I’m trying to develop a plug-in with the new FIR infrastructure, and I have a couple of questions: • in order for the plug-in to work, we need to scrape information from all functions in the CLASSPATH with a certain attribute: is the
    FirTypeAttributeExtension
    ensured to be run over all possible functions before the next steps in the analysis continue; if not, what is the best way to perform this? • the analysis works in two stages; what is the best way for a FIR plug-in to introduce several stages? thanks very much in advance!
    d
    • 2
    • 12
  • m

    Mikhail Bolotov

    10/22/2021, 6:41 PM
    Hi everyone! I have a question regarding type inference of a lamda. Why does compiler infers different type depends of whether a lambda is used as an argument or initialize a variable? Is this the expected behavior? This thing also breaks the inline refactoring making it a changing semantic one.
    fun <S> create(code: () -> S): S {
        println("string")
        return code()
    }
    
    fun create(code: () -> Unit) {
        println("unit")
    }
    
    fun main() {
        create { "a" } // prints unit
        val a = { "a" }
        create(a) // prints string
    }
    j
    e
    • 3
    • 58
  • j

    jw

    10/28/2021, 3:09 AM
    is there any way to have the compiler dump IR from the CLI or API? i think a great addition to the Kotlin support on godbolt would be the IR output in addition to Java bytecode
    s
    s
    • 3
    • 18
  • d

    Dave

    10/28/2021, 2:23 PM
    Hi, I'm writing (trying) a kotlin compiler plugin, which uses the IrGenerationExtension. I am trying to access dependencies of the module, and to iterate the declarations (Classes, etc) in each depended on module. How should I do this? I tried `
    moduleFragment.descriptor.allDependencyModules
    but it does not seem to give me the depended on modules? I also tried `
    (pluginContext.symbolTable as SymbolTable).forEachPublicSymbol {
    but I only get the symbols from the current module. some pointers in the right direction for either of these would be great, thanks
    r
    a
    s
    • 4
    • 17
  • a

    Alejandro Serrano Mena

    10/29/2021, 2:18 PM
    hi! what is the status of using a FIR plugin? we are doing some investigation, and would like to know how to specify that we want to use our plug-in in the build, and in the IDE :thank-you:
    d
    • 2
    • 1
  • j

    Justin Tullgren

    11/02/2021, 9:10 PM
    Did i understand the k2 talk from today correctly in that if we are explicit with our return types we can expect a potential performance boost in compilation in the future?
    j
    p
    f
    • 4
    • 5
  • e

    elect

    11/04/2021, 8:06 AM
    I wonder if this is the right place, however I'm feeding
    kotlinc
    this way (via gradle
    project.exe
    ):
    [C:\Users\elect\IdeaProjects\lwjgl3\bin2\libs\kotlinc\bin\kotlinc.bat, -d, C:\Users\elect\IdeaProjects\lwjgl3\bin2\classes\generator, -jvm-target, 1.8, -module-name, generator, -progressive, -version, -Xlambdas=indy, -Xno-call-assertions, -Xno-param-assertions, -Xreport-perf, C:\Users\elect\IdeaProjects\lwjgl3\modules\generator\src\main\kotlin]
    And I see on the output:
    info: kotlinc-jvm 1.5.31 (JRE 11.0.9.1+1-LTS)
    warning: advanced option value is passed in an obsolete form. Please use the '=' character to specify the value: -Xlambdas=...
    Which is weird, because I'm actually using that form.. This is on Windows though, on Linux no issues..
    u
    • 2
    • 3
  • c

    Chachako

    11/06/2021, 5:14 PM
    Hello everyone, I’m a novice at kotlin compiler. I’m trying to write a compiler plugin. I want to change the
    val
    of property to
    var
    in
    IrElementTransformerVoid.visitPropertyNew
    , but I found that
    isVar
    is a immutable value. What should I do?
    s
    l
    +3
    • 6
    • 14
  • c

    Chachako

    11/07/2021, 5:47 PM
    How should I return multi expressions in
    IrGenerationExtension.visitCall
    ?
    s
    • 2
    • 5
  • d

    Deactivated User

    11/10/2021, 1:50 PM
    ❓ I have been working on a gradle plugin to support including IR plugins in gradle submodules for a project, without requiring separate gradle plugins. Similar to what KSP does, but for arbitrary IR plugins. It is working already, but I have not published it to central yet. Do you know if there is anything already for that or some efforts in that direction, to avoid doing it twice?
    r
    j
    • 3
    • 6
  • r

    ralf

    11/10/2021, 11:01 PM
    Maybe someone knows before I file a ticket. I have a compiler plugin that currently supports the IR and old backend. It uses
    IrGenerationExtension
    for the IR implementation and
    ExpressionCodegenExtension
    . When KAPT is enabled in the stub generating task I see the
    ExpressionCodegenExtension
    being called rather than the IR implementation. Is the stub generating task not using the IR backend and still relies on the old backend? I’ve tested with
    1.5.31
    and
    1.6.0-RC2
    .
    u
    • 2
    • 4
  • g

    groostav

    11/10/2021, 11:05 PM
    was there ever a discussion about trying to avoid autoboxing in the case where you have a data type like
    public class DoubleArrayList(): AbstractList<Double> {
      public operator fun get(index: Int): Double //I want the signature (I)D. 
      // I do NOT want the signature (I)Ljava/lang/Double;
    }
    ? I cant help but feel like with all the sophistication of inline classes, kotlins type unification and etc, I could finally have a
    List<Double>
    that doesnt do an enormous amount of boxing/unboxing. Like, why not generate a function
    get()
    that's
    (I)Lj/l/Double;
    and a function
    get_$D()
    that's
    (I)D
    , and where the compiler can be certain ahead of time that we're calling DoubleArrayList's
    get
    , it generates code for`get_$D` instead of
    get()
    ? Again, I know theres a good reason, im just curious. I'm doing some profiling of my app right now, which itself delegates most work to some (fairly recent) fortran code, but it does have some hot loops on the VM, and most are related to poor performance of
    Map<String, Double>
    and
    List<Double>
    Some of those are architectural but, it would be nice if i could flip a kind of switch to say "stop using
    Double[]
    as your backing data types and start using
    double[]
    " to see how that helps performance
    e
    j
    • 3
    • 17
  • g

    Glen

    11/11/2021, 12:41 AM
    Hello everyone, a noob about compiler plugins here. Please, I have question: Is it possible to write a compiler plugin that targets a language or platform not officially supported by the Kotlin compiler? If so, how does one start? Thanks.
    e
    • 2
    • 2
  • k

    Karel Petránek

    11/11/2021, 12:53 AM
    Hi, I’m writing a simple compiler plugin to do slight modifications in the generated code for our JS target. I’m invoking the
    compileProductionLibraryKotlinJs
    task and it seems JS gets compiled twice - once into a klib where the compiler plugin is called correctly and later into a JS library where the compiler plugin is not invoked at all. This means that my changes are visible in the klib but not in the resulting JS library code. Is this an expected behavior? Can I get the IR plugin to execute every time a JS compilation is running? It also seems inefficient to run it twice (I don’t necessarily need the klib...). I’m on Kotlin 1.5.31, Gradle 7.2. My Gradle configuration:
    js(IR) {
        moduleName = "facemoji-core"
        browser {
            webpackTask {
                output.libraryTarget = "commonjs-module"
            }
        }
        binaries.library()
    
        compilations.all {
            kotlinOptions {
                freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.ExperimentalStdlibApi -Xopt-in=kotlin.RequiresOptIn"
            }
        }
    }
    s
    • 2
    • 12
  • g

    galex

    11/11/2021, 10:29 AM
    Hello, I’d link to build a replacement to
    android-kotlin-extensions
    ! I love it and I don’t want to use
    ViewBinding
    as we have lots and lots of layout and running its annotation processor is making the project quite unstable. So the question is, where do I start for the core of its functionality, meaning adding a Hashmap to any class that uses it, and call
    findViewById
    on the first use of a property? 😄
    t
    • 2
    • 2
  • n

    Nathan Bedell

    11/12/2021, 1:15 AM
    Hi, does anyone know how to obtain a
    ModuleDescriptor
    from a
    KtFile
    in version 1.5.0 of the
    kotlin-compiler-embeddable
    ? I'm working on a compiler plugin, and using some utilities from forge that require a
    ModuleDescriptor
    in their API, but I can't figure out how to properly construct one from a
    KtFile
    .
    • 1
    • 1
  • h

    holgerbrandl

    11/12/2021, 8:31 AM
    Hi, why is a SAM implementation producing different compiler outputs depending on if object or lambda style notation are being used?
    fun interface SmthgSAMGeneric<T> {
        fun foo(): (T, T) -> String
    }
    
     val samAsObject = object : SmthgSAMGeneric<String> {
            override fun foo(): (String, String) -> String {
                return { s: String, s2: String -> "42" }
            }
        }
    
    val inlineSam = SmthgSAMGeneric<String> {
        { s: String, s2: String -> "42" }
    }
    See also https://github.com/EsotericSoftware/kryo/issues/867
    b
    d
    • 3
    • 5
  • z

    Zac Sweers

    11/16/2021, 8:47 PM
    Was
    KType.javaType
    intentionally left out of the 1.6 API promotions to stable or an oversight? Seems surprising to see that not included with the
    typeOf()
    promotions Edit: filed a request here in case it helps https://youtrack.jetbrains.com/issue/KT-49743
    b
    • 2
    • 1
  • n

    nikolaymetchev

    11/17/2021, 12:21 PM
    Not sure where to start. Let me know if this is a known issue and if I should just file a bug.
    b
    • 2
    • 3
  • h

    Hakob Astvacatryan

    11/19/2021, 2:30 PM
    Hi folks, is there a way to get furthest parent KtClassOrObject from KtClassOrObject?
    s
    • 2
    • 3
  • t

    Tyron Scott

    11/21/2021, 4:52 PM
    Hi, are there instructions on how to compile the embeddable version of the compiler? I would like to experiment with some stuffs and run it on an android environment.
    d
    • 2
    • 1
  • c

    Claude Brisson

    11/23/2021, 12:17 PM
    I'm trying to compile and test the kotlin compiler, but I alsways get plenty of tests failing after a while with StackOverflowErrors, I'm guessing it is a memory exhaustion problem but I don't know how to overcome it. I tried running the tests in sequential mode with things like:
    org.gradle.workers.max=1
    kotlin.test.junit5.maxParallelForks=1
    kotlin.parallel.tasks.in.project=false
    org.gradle.parallel=false
    in my gradle.properfies file, but it just made the tests much slower and the same errors appeared. The command I am running is:
    ./gradlew -Porg.gradle.java.installations.auto-detect=false compilerTest
    . Maybe it's too wide a task, but how to refine it? Especially, how would I specifically test tweaks to the lexer and the parser? Thanks for your help.
    d
    • 2
    • 12
  • r

    Rob Elliot

    11/23/2021, 8:50 PM
    Just hit this again, this time trying to do this:
    typealias Result<F : Throwable, S> = Either<F, S>
    Still curious what the reason for
    Bounds are not allowed on type alias parameters
    is.
    k
    • 2
    • 1
  • c

    Chachako

    11/24/2021, 12:22 PM
    I saw parcelize has a new commit of FIR. I still don’t quite understand the difference between FIR and IR. Who can solve my doubts? In addition, does the plugin implemented with Fir need to open
    useFir
    in Gradle before it can be used?
    d
    • 2
    • 9
  • z

    Zac Sweers

    11/24/2021, 6:09 PM
    been doing some kotlin 1.6.0 compilation profiling and it's not looking good. Anyone else seeing similar? incremental abi change in a library and app and incremental build • 39s before, 58s after incremental change in just a feature project • 36s before, 55s after
    😕 2
    a
    • 2
    • 4
  • m

    mcpiroman

    11/26/2021, 9:27 AM
    What is 'EE' as in '[EE-IR] Support Inline functions'?
    u
    • 2
    • 1
  • m

    mbonnin

    11/26/2021, 9:32 AM
    Can I get a warning on unused
    @OptIn(SomeExperimentalApi::class)
    usages? It's quite easy to leave them cluttering the codebase after the declarations have been promoted to stable (or something else is used).
    m
    c
    • 3
    • 3
  • j

    Johann Beleites

    12/03/2021, 1:57 PM
    I am using the embeddable Kotlin compiler to analyze code and obtain the
    BindingContext
    . Now this takes quite a while and I know the compiler is doing a lot of work in that time. Is it possible to run the compiler multi-threaded, so that I can make use of multiple cores when available and hence speed up the analysis?
    d
    • 2
    • 2
Powered by Linen
Title
j

Johann Beleites

12/03/2021, 1:57 PM
I am using the embeddable Kotlin compiler to analyze code and obtain the
BindingContext
. Now this takes quite a while and I know the compiler is doing a lot of work in that time. Is it possible to run the compiler multi-threaded, so that I can make use of multiple cores when available and hence speed up the analysis?
d

dmitriy.novozhilov

12/03/2021, 4:40 PM
Not yet Multithread ananylysis is a part of K2 compiler (and FIR frontend) which is not ready yet
👍 2
j

Johann Beleites

12/03/2021, 4:55 PM
Thanks for the info - looking forward to K2 even more now!
View count: 7