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

    Justin Wei

    09/15/2020, 7:42 PM
    Anyone know what docs to read to get started with understanding how kotlin compilation works? I heard that it was a bit complicated and wanted to get a feel for what was going on to see if there's anything I can do about speeding it up over the next few months.
    m
    s
    e
    • 4
    • 10
  • a

    agta1991

    09/18/2020, 9:06 AM
    Hi! Is there any way of generating top level function (like SyntheticResolveExtension) from a Compiler plugin, I want to generate an entry point for an exeutable?
    🇳🇴 1
    s
    • 2
    • 1
  • j

    Jason A. Donenfeld

    09/18/2020, 3:24 PM
    Odd compiler bug: https://pl.kotl.in/0dXZp5RHu try running that
    u
    • 2
    • 1
  • z

    Zach Klippenstein (he/him) [MOD]

    09/19/2020, 12:10 AM
    Question for the team working on the compiler, specifically the new IR backend. Rewriting a compiler backend seems like a huge undertaking, and requires accounting for tons of edge cases in real-world code. Is the team using any real-world codebases to validate? I work on an open source codebase that uses a lot of generics, and I’m finding quite a few bugs with the IR backend. I am happy to keep testing out dev versions and reporting bugs as they come out, but I’m wondering if there would be any interest from anyone on the team to build the project themselves to iterate more quickly? If so, I can provide a branch that builds without IR but fails with IR turned on as a starting point, as well as whatever other support would be helpful.
    ❤️ 5
    d
    r
    l
    • 4
    • 6
  • r

    rnett

    09/19/2020, 7:58 AM
    Is there any non-descriptor way to go between expect/actuals for compile plugins?
    r
    • 2
    • 2
  • k

    kartik1712

    09/19/2020, 1:09 PM
    Hi all! I do not how the kotlin compiler works so this might be a stupid question. I am curious about how kotlin works older JVMs. My question is Kotlin able to leverage the latest developments in Java like
    records
    may be helpful in implementing
    data
    classes.
    h
    j
    • 3
    • 3
  • r

    rnett

    09/20/2020, 2:41 AM
    I'm running into an issue when I try to generate (via IR) a suspend lambda. It fails validation because of duplicated nodes. It seems like during lowering, the body of the lambda is copied into the continuation class's
    invokeSuspend
    , but the original isn't deleted. Gists of the ir dump before lowering and after lowering (when the error happens). Note in the after lowering the original lambda's body on line 192, and the body in the continuation on line 210.
    • 1
    • 1
  • r

    rnett

    09/20/2020, 3:14 AM
    Different problem now: everything compiles fine on JVM, but when I try to use it on JS, I get
    java.lang.IllegalStateException: Not found Idx for public kotlin.collections/mapOf|5848051883920634516[0]
    from the IrLinker. I'm referencing and using
    mapOf(vararg Pair<>)
    which works fine on JVM. The
    compileKotlinJs
    task works fine, it's the
    compileProductionExecutableKotlinJs
    task that fails. It's happening on other methods to. Seems to be just top level functions. Is this a known bug? Poking around in debug in
    KotlinIrLinker.IrDeserializerForFile
    , while the referenced function (in this case,
    to
    ) isn't in
    reversedSignitureIndex
    , it is in
    fileLocalDeserializationState.reachableTopLevels
    , so it is obviously being found somehow.
    r
    s
    b
    • 4
    • 10
  • v

    ventura

    09/21/2020, 10:25 AM
    Questions about the KMM internals should I post here, #kmm, #kotlin-native, #kotlin-multiplatform, or #multiplatform? Basically I need to implement
    desktopMain
    to another OS
    m
    • 2
    • 1
  • f

    FalseHonesty

    09/22/2020, 8:20 PM
    I'm having an interesting compiler issue when upgrading to Kotlin 1.4.0. One of the gradle plugins we use embeds the kotlin compiler to use it for some analyzation, but this turns into an error when upgrading the project. The error we get when building is here: https://hasteb.in/otohideq.sql. Which seems like some sort of stdlib versioning error, but I'm not sure how that could be, as the gradle plugin and its dependents all use the correct version of kotlin (1.4.10). I have looked this error up, but all of the reported issues are using spring boot, has this been encountered elsewhere? The Gradle Plugin responsible for running the embedded compiler is here: https://github.com/FalseHonesty/preprocessor/blob/kotlin-1.4/build.gradle.kts.
    • 1
    • 3
  • r

    rnett

    09/23/2020, 4:17 AM
    Another possible JS related bug: I'm trying to extract the value of a top level constant property (i.e.
    const val prop = "..."
    ). I'm using
    context.referenceProperties(name).single().owner.backingField!!.initalizer!!.expression as IrConst<String>
    and it works fine on JVM, however on JS
    backingField.expression
    is
    IrErrorExpressionImpl: Expression body is not deserialized yet
    . I'll make an issue if this is indeed a bug, but wanted to check its not due to me miss-using something (should I just make an issue in the future?).
    r
    • 2
    • 7
  • n

    Nabil

    09/23/2020, 7:21 PM
    I wonder why
    addGetter
    extension was left on the
    IrProperty
    https://github.com/JetBrains/kotlin/blob/master/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/builders/declarations/declarationBuilders.kt#L107 while
    addSetter
    was removed in https://github.com/JetBrains/kotlin/commit/d1dc938a5d7331ba43fcbb8ce53c3e17ef76a22a#diff-2726c3747ace0a1c93ad82365cf3ff18L114 ? What's the new way to create setters on a generated property since
    1.4.255
    ?
    ➕ 1
    • 1
    • 1
  • p

    PHondogo

    09/25/2020, 6:48 AM
    Hello! I've declared function
    inline fun<reified T> test() {throw AssertionError("Implementing by compiler plugin")}
    In IR generator I want to replace all calls to this function by some expression (using T type literal). For calls with direct literals (for example
    test<Int>()
    ) it works as expected. But when calling from templated function with template parameter it appears to substitute just type parameter. For example
    inline fun<reified T> test2(){test<T>()}
    Is it possible in IR generation phase to transform all actual inlined types?
    m
    s
    • 3
    • 7
  • m

    Manuel Wrage

    09/26/2020, 1:21 PM
    Hey there, I'm working on a compiler plugin which generates new files in the AnalysisHandlerExtension. Everything works fine until I turn on incremental compilation. The problem is that the compiler has no idea about the relation between the generated files and their "originating files". The first compilation works fine. Then when a originating file changes, the compiler only compiles the originating file (Here I create a new generated file). But the compiler starts another compilation round and now compiles both the originating file and the generated file. And this is the problem. The compiler should not trigger another round only to recompile the two files from the previous round. I tried to cache the relations between the files and delete the generated ones, when ever a originating one changes, but this does not work, because the dirty generated files are already in the environment of the compiler. I also tried to manually remove the files via reflection but the compiler can't handle that. Another thing I tried is to just generate the file again, but this causes other issues, because the compiler analysis the old version of the file which may have errors in it. Is there a workaround for my issue?
    r
    • 2
    • 5
  • p

    pablisco

    09/29/2020, 10:36 PM
    Has anyone experienced this? I couldn’t find anything. And the message is not great to know what I’ve done wrong 😅 Using 1.4.10
    m
    • 2
    • 3
  • g

    groostav

    10/05/2020, 7:00 PM
    so, im doing a bit of premature optimization: im writing some kotlin wrappers for guice methods used by a large java codebase. I'm looking to streamline the
    getInstance
    flow. Im looking at something like this:
    inline fun <reified T> Injector.getInstance(): T {
        val targetType = T::class.java
        if(targetType.typeParameters.isEmpty()){
            return getInstance(T::class.java)
        }
        else {
            val targetTypeSpecifically = Key.get(object: TypeLiteral<T>(){})
            return getInstance(targetTypeSpecifically)
        }
    }
    I'm wondering what the compiler does with dead-code-elimination of the type that gets created for
    targetTypeSpecifically
    . For the case where the type isnt generic (we take the true branch) Will that create a new
    Class
    entry at runtime or wont it? Whats the best way for me to test that?
    u
    • 2
    • 9
  • d

    Daniel Svensson

    10/14/2020, 7:25 AM
    Is it possible to turn some Kotlin compiler warnings into errors via a compiler plugin, or compiler plugins don't have access to that? Goal being for example turning unused variables into errors etc.
    g
    d
    s
    • 4
    • 12
  • r

    raulraja

    10/14/2020, 10:30 AM
    Hi, I was wondering if this is a known issue already or I should file one. I expect the program below to not compile because the expression A.B.c can’t be resolved until A is initialised assuming the inner object is path dependent. If the object is not and it’s fully static then
    s
    should not have compiled or become accessible.
    Untitled
    d
    k
    • 3
    • 7
  • m

    Marc Knaup

    10/16/2020, 12:38 AM
    Is it still the case that the bytecode viewer in IDEA doesn’t properly reflect the final Java class output? Simple things like
    (0..10).forEach { … }
    cause an
    IntRange
    and an iterator to be allocated. If I recall correctly calls like that are supposed to be optimized.
    i
    • 2
    • 2
  • c

    coroutinedispatcher

    10/16/2020, 2:32 PM
    I have a question regarding the
    public
    modifier in Kotlin. Since everything is already public by default, is there a use case where you actually need to "force" put that modifier? Basically, at the moment I cannot think of such case, when you need a
    public
    modifier in front of something.
    m
    • 2
    • 3
  • s

    spierce7

    10/16/2020, 2:57 PM
    Is KSP ready right now to be used with multiplatform?
    u
    • 2
    • 2
  • l

    louiscad

    10/19/2020, 7:20 AM
    Do
    const val
    affect/hinder incremental compilation in ways plan
    val
    don't, granted their value don't change, but something else changed in the host class (e.g. a new constant or property)?
    g
    e
    +2
    • 5
    • 42
  • o

    Olivier Notteghem

    10/20/2020, 6:40 PM
    Hi everyone! I would like to track which external dependent classes were used during compilation of some Kotlin files. Output could be similar to jdeps java tool. Is this reasonable to try to achieve this with a Kotlin Compiler Plugin? If so, what would be the best approach? Would we use a class visitor for the compiled classes and extract all used/dependent external classes- or is there a better approach? Thanks in advance!
    j
    j
    • 3
    • 4
  • l

    louiscad

    10/28/2020, 10:44 AM
    Hi, how is it possible that I get this warning during compilation with 1.4.20-M2?
    w: Flag is not supported by this version of the compiler: -XInlineClasses
    g
    e
    • 3
    • 5
  • g

    groostav

    10/28/2020, 11:50 PM
    hmm. Is there a name for a kind've backwards operation for destructure, a kind of implied structuring? eg
    sealed class Configuration {
        data class Customer(val name: String, val age: Int): Configuration()
        data class User(val email: String): Configuration()
    }
    
    class Whatever {
      fun doStuff(config: Configuration): Int {
        //...
      }
    }
    and I would like kotlin to do something automagical with
    w.doStuff("bob", 42) // --calls Customer.<init>, doStuff()
    w.doStuff("<mailto:jane_doe@email.com|jane_doe@email.com>") // calls User.<init>, doStuff()
    I feel like I use sealed-classes as a way to expand a functions capability a lot. Right now (at least 3x in recent memory), I'll add exension functions to call the constructor and the method for you. eg
    fun Whatever.doStuff(name: String, age: Int) = doStuff(Customer(name, age))
    but this is kinda tedious, and i feel like the compiler could do it for me.
    d
    • 2
    • 2
  • z

    Zach Klippenstein (he/him) [MOD]

    11/02/2020, 11:28 PM
    I’m seeing some weird bytecode generated by the new IR backend with kotlin 1.4.20-RC: Some default method overloads (named like
    foo$default
    ) were generated as
    synthetic
    and non-final methods without the IR backend, but are now generated as final and non-synthetic (+final, -synthetic). Does anyone know if this is intentional?
    d
    u
    • 3
    • 8
  • m

    mbonnin

    11/04/2020, 10:31 AM
    I see... Still. Is there a case where
    emptyList<Value>
    would behave differently than
    emptyList<Node>
    ?
    d
    • 2
    • 4
  • m

    mbonnin

    11/04/2020, 10:48 AM
    The fact that list elements implements the 2 same interfaces seems to force
    List<Any>
    there. I guess because it could because
    List<Named>
    is as good of a solution than
    List<Node>
    ? But in the context of
    List<Node>
    , I feel like this could be disambiguated_?_
    d
    • 2
    • 1
  • b

    bjonnh

    11/09/2020, 7:43 PM
    KotlinFrontEndExceptino: Front-end Internal error: Failed to analyze declaration ApplicationSecurity
    • 1
    • 1
  • d

    diesieben07

    11/09/2020, 9:27 PM
    I'm working on a compiler plugin (mostly just experimenting and learning things at the moment). I want to generate some nested classes, which I have managed for one so far. The code looks like this
    class MyModel : Model() {
        val foo by IntField()
    
        // this is generated by my plugin:
        interface EntityI {
            val foo: Int
        }
    }
    Now I also want to generate the following companion object:
    companion object : ModelCompanion<MyModel, EntityI>
    I can create the companion object using
    SyntheticResolveExtension.getSyntheticCompanionObjectNameIfNeeded
    , however inside
    addSyntheticSupertypes
    for the companion object I cannot add the supertype, because
    EntityI
    is not yet resolvable as a descriptor (trying to do so will report a recursion, which does make sense). I understand I need to somehow create a lazy KotlinType (which seems to exist), but I have no idea how I would create it with what I have available in
    addSyntheticSupertypes
    . Any advice?
    s
    m
    • 3
    • 3
Powered by Linen
Title
d

diesieben07

11/09/2020, 9:27 PM
I'm working on a compiler plugin (mostly just experimenting and learning things at the moment). I want to generate some nested classes, which I have managed for one so far. The code looks like this
class MyModel : Model() {
    val foo by IntField()

    // this is generated by my plugin:
    interface EntityI {
        val foo: Int
    }
}
Now I also want to generate the following companion object:
companion object : ModelCompanion<MyModel, EntityI>
I can create the companion object using
SyntheticResolveExtension.getSyntheticCompanionObjectNameIfNeeded
, however inside
addSyntheticSupertypes
for the companion object I cannot add the supertype, because
EntityI
is not yet resolvable as a descriptor (trying to do so will report a recursion, which does make sense). I understand I need to somehow create a lazy KotlinType (which seems to exist), but I have no idea how I would create it with what I have available in
addSyntheticSupertypes
. Any advice?
s

shikasd

11/10/2020, 1:34 AM
Hey, I think you theoretically can create class descriptor before it is requested by compiler, so that you will already have a class to get type from. Essentially, I would do something like a hashmap from outer class to entity descriptor, use it in super types and then provide the same descriptor when requested by compiler methods.
d

diesieben07

11/12/2020, 11:19 AM
Thank you, I will try that
m

Miguel Vera Belmonte

03/05/2021, 1:39 AM
To anyone struggling with this, there's a method to basically search for a class descriptor in your whole classpath without having to create it from scratch:
override fun addSyntheticSupertypes(thisDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) {
        val classDescriptor = thisDescriptor.module
                .findClassAcrossModuleDependencies(ClassId(FqName("<package>"), Name.identifier("<className>")))
}
View count: 2