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

    miha-x64

    02/26/2019, 8:15 AM
    It would be better to work hard on good abstractions and throw all the codegen away.
    m
    • 2
    • 10
  • k

    kevinmost

    02/27/2019, 9:31 PM
    I had asked this in another thread but it got a bit buried; we know that the compiler team is working on a new IR for Kotlin so we can write cross-platform compiler plugins. Is there anywhere that we can track that work? Either a bunch of Youtrack tickets, a branch or directory in the Github repo containing the latest work, etc.
    ➕ 9
    g
    d
    +3
    • 6
    • 19
  • m

    Marc Knaup

    03/02/2019, 12:24 AM
    Can I run the compiler directly from Kotlin in the same JVM?
    k
    t
    • 3
    • 25
  • j

    jw

    03/06/2019, 6:05 PM
    details are in https://youtrack.jetbrains.com/issue/KT-9742
    👍 1
    p
    • 2
    • 1
  • r

    raulraja

    03/08/2019, 12:45 AM
    Does anyone know if
    foo { bar(it) }
    has a performance cost over
    foo(bar)
    allocating an extra lambda? If so is this something the Kotlin compiler already optimizes for?
    u
    d
    • 3
    • 3
  • m

    mp

    03/11/2019, 4:42 PM
    If I sprinkle a few typos in module-info.java, the compiler (via gradle) happily compiles anyway. Meanwhile IntelliJ complains about both the typo and (when the typo is removed) the usual JPMS issues — split packages in dependencies, etc
    u
    • 2
    • 5
  • r

    raulraja

    03/31/2019, 10:53 PM
    Hi, I have a use case where I can optimize a type lookup with a fast
    switch
    based on ints. Does the kotlin compiler ever optimizes
    when
    to become a fast
    switch
    based on ints? If not what is the equivalent in Kotlin of https://www.scala-lang.org/api/current/scala/annotation/switch.html if any? thanks!
    :yes: 1
    • 1
    • 1
  • l

    louiscad

    04/02/2019, 7:46 PM
    No, and I'm happy there's none. It could encourage people to write poor code with the excuse of build speed, that would make maintenance slower instead. kapt is slow though, because it's not incremental yet (unless you already use 1.3.30 with EAP and your kapt dependencies have incremental support), but kapt is mainly Java legacy that is replaced by things like SQLDelight, kotlinx.serialization, delegates, extension functions, coroutines, data classes and more great features that are actually faster than annotation processors to compile.
    g
    • 2
    • 5
  • j

    Jorge Castillo

    04/04/2019, 10:13 AM
    Hi. Working on a KEEP, is it possible to declare new line characters inside the
    DefaultErrorMessages
    and make them work in the inlined errors from the IDE inspections? Since looks like the errors print with new line chars on terminal if you build the project, but the inlined IDE error inspections don’t seem to show new line chars and show everything on a single line.
    u
    • 2
    • 3
  • a

    aerb

    04/07/2019, 6:33 PM
    Hi! Still interested in finding out about compiler performance to feature information if anyone who actually works on the Kotlin team has any familiarity with it.
    g
    t
    • 3
    • 2
  • j

    jlleitschuh

    04/12/2019, 6:52 PM
    Hi, Junit5 team is encountering a weird issue where, in the face of 30+ overloads for a method, there seems to be a weird case where the Kotlin compiler generates a completely invalid call. We are looking at the bytecode and the compiler generates a call to the following method that doesn't exist:
    org/junit/jupiter/api/Assertions.assertEquals:(ILjava/lang/Integer;)V
    https://github.com/junit-team/junit5/issues/1859
    d
    • 2
    • 8
  • p

    Paulius Ruminas

    04/15/2019, 8:22 PM
    Hello, I encountered an unexpected behaviour it this code snippet:
    interface Command<T>
        
    class TestUnitCommand : Command<Unit>
    
    class TestIntCommand : Command<Int>
        
    class TestStringCommand : Command<String>
        
    class Result<T>
        
    inline fun <reified T : Command<R>, reified R : Any> execute(crossinline block: suspend (T) -> R) {}
    
    fun main() {
        execute<TestUnitCommand, Unit> { Result<Unit>() }        // OK
        execute<TestIntCommand, Int> { Result<Int>() }           // Error
        execute<TestStringCommand, String> { Result<String>() }  // Error
    }
    Why does it not error when
    Command
    generic parameter is
    Unit
    ? Does it implicitly not return anything?
    k
    • 2
    • 4
  • c

    colljos

    04/16/2019, 2:07 PM
    Hi, I am trying to compile some Kotlin code under Java 11 which is using an internal JDK api (eg. com.sun). I am therefore required to inform the compiler (Java) that I need to use this internal API by specifying:
    --add-exports java.base/sun.security.x509=UNNAMED-MODULE
    . How does one coax the Kotlin compiler to process/pass this directive?
    u
    • 2
    • 1
  • s

    simon.vergauwen

    04/23/2019, 8:10 AM
    Hi all 👋 I ran into something very weird when trying to check the compiled code for a simple coroutine example. Following 9 lines of Kotlin code result in 12, 402 lines of Java code according to IntellIJ’s decompiler.
    import kotlin.coroutines.Continuation
    import kotlin.coroutines.EmptyCoroutineContext
    import kotlin.coroutines.startCoroutine
    
    val f: suspend () -> String = suspend { "Hello World!" }
    
    fun main() {
      f.startCoroutine(Continuation(EmptyCoroutineContext, ::println))
    }
    Test2Kt$main$$inlined$Continuation$1.java
    a
    • 2
    • 3
  • a

    aerb

    05/04/2019, 7:35 PM
    Hello! I’ve been poking through the compiler source code and have a couple questions. 1) It looks like you are lexing via JFlex instead of Antlr. Is this correct? Any reasons for one over the other? 2) Is the parser implemented by hand? I’ve seen some parsing examples where you can generate a simple parser from grammar rules. Did this not give you enough control?
    i
    m
    • 3
    • 7
  • p

    pardom

    05/06/2019, 4:59 AM
    Hey, all. 👋 I’m writing a Kotlin compiler plugin and I’m trying to get the fully qualified name of a
    KtCallExpression
    . Anyone know how?
    i
    r
    • 3
    • 36
  • p

    pardom

    05/08/2019, 4:16 AM
    Or better, yet. Is it possible to attach the debugger to my plugin?
    s
    • 2
    • 2
  • m

    miha-x64

    05/15/2019, 8:01 AM
    println
    is an inline-function which calls
    System.out.println
    internally. That's how Kotlin function inlining look like.
    m
    i
    +3
    • 6
    • 12
  • k

    kralli

    06/05/2019, 1:29 PM
    So here is what I have found out from reading the sources in the past two days: Generally speaking it is not possible to simply create a synthetic class outside the bounds of existing class, at least there is no officially endorsed way of doing so. However there are several ways to do it, if you really need to. The first way is to obtain the
    CompilerConfiguration
    using the
    CompilerConfigurationExtension
    in order to get hold of the output directory. You can then write your own files using the
    BinaryClassWriter
    . This way is pretty safe and should be stable across future releases. The second method would be to use either the
    AnalysisHandlerExtension
    or the
    CollectAdditionalSourcesExtension
    to access and modify the list of source files. The list of sources is leaking and can simply be casted into a
    MutableList
    . While this can be pretty useful, it is not recommendable, because this will probably be fixed in the future.
    👍 2
    r
    • 2
    • 1
  • p

    pablisco

    06/06/2019, 10:21 PM
    Would it make sense to have equals rely on type checks instead of using the default JVM implementation that uses the instance id? Maybe the compiler could add these default implementations:
    sealed class Location: Serializable {
        object Unknown : Location() {
            override fun equals(other: Any?) = other is Unknown
            override fun hashCode() = toString().hashCode()
            override fun toString(): String = "Location.Unknown"
        }
        data class Known(val lat: Float, val lon: Float) : Location()
    }
    https://stackoverflow.com/a/56485743/458365
    k
    a
    • 3
    • 4
  • r

    raulraja

    06/09/2019, 8:43 PM
    Where is
    TypeResolutionInterceptorExtension
    in the compiler?. I see Jetpack Compose uses that and can’t find that on github.
    • 1
    • 1
  • r

    raulraja

    06/12/2019, 12:05 PM
    I have a compiler plugin where I’m subscribing to the
    org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
    . It does not seem like it’s calling me back so I’m guessing is not using the IR format. Is there a compiler flag or some kind of way to turn IR generation on?. Thanks!
    • 1
    • 1
  • h

    Hanno

    06/12/2019, 12:43 PM
    Hey guys, I'm writing a compiler plugin for fun and I'm generating additional functions in a class. Is there any way to include (in bytecode) generated things in for example the ide (intellij) completion? I mean without writing a custom intellij plugin? I want the ide to use the build for class compilation and the compilation output for Code completion somehow O:-)
    ➕ 3
    r
    i
    s
    • 4
    • 7
  • r

    raulraja

    06/12/2019, 4:00 PM
    What is the best way to obtain an
    IrType
    for a known type given it’s fully qualified name and type arguments? I need to refer to a known type that is not in the
    IrBuiltins
    constants.
    i
    • 2
    • 2
  • j

    jw

    06/13/2019, 3:27 AM
    with 1.3.31 i'm seeing enum `when`'s generating a bunch of if/else's instead of a tableswitch
    :android: 1
    • 1
    • 2
  • r

    raulraja

    06/13/2019, 9:11 PM
    is the
    Kotlin Bytecode Viewer
    actually decompiling binaries or just making a best effort based on the sources presented? I have a compiler plugin injecting stuff in the bytecode that I don’t see in the bytecode viewer. What do people use to debug emitted bytecode when working with compiler plugins? thanks!
    i
    • 2
    • 2
  • r

    raulraja

    06/13/2019, 11:50 PM
    In a compiler plugin in the
    SyntheticResolverExtension
    I’m overriding
    generateSyntheticClasses(PackageFragmentDescriptor, ...)
    and
    addSyntheticSupertypes
    . I’m attempting to add a super type to a class that I generate myself in that pass. For example:
    package x
    interface Foo<A>
    class Bar
    I want to expand to:
    package x
    interface Foo<A>
    class GeneratedClass
    class Bar : Foo<GeneratedClass>
    The issue I’m having is that
    addSyntheticSupertypes
    happens before
    GeneratedClass
    has a valid
    ClasDescriptor
    so when I add the supertype I get:
    Bar : Foo<[ERROR : Unsubstituted type for <ERROR CLASS>]>
    
    e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
    Cause: Error type encountered: [ERROR : Unsubstituted type for <ERROR CLASS>] (ErrorType).
    How can I generate a valid descriptor in that phase for
    GeneratedClass
    or how can I add a supertype to a class given the class the type refers to may not have been generated yet? Is this the wrong phase to do this kind of work?
    d
    k
    • 3
    • 14
  • s

    spierce7

    06/17/2019, 5:52 PM
    What is the state of compiler plugins in Kotlin? I believe the native compiler allows for code generation via IR. What about the JVM and js compilers? Are they compatible with IR yet?
    d
    • 2
    • 3
  • r

    raulraja

    06/18/2019, 3:16 PM
    I have implemented my own extensions for
    PackageFragmentProviderExtension
    and now I’m verifying that all the code is generated properly and I can even import classes and they compile fine from the command line. For example this compiles:
    import sample.GeneratedClass
    And also this:
    Class.forName("sample.GeneratedClass")
    I’m still seeing these issues: 1. This compiles fine only in the command line. IDEA still shows redlines for all the types it can’t find. Does IDEA use automatically the
    PackageFramentDescriptor
    and
    SyntheticResolver
    info or am I missing additional setup to get this to work on IDEA? 2. It only compiles fine with
    import sample.GeneratedClass
    if its in the same module. If I add the compilation result with codegen as dependency in a different module it does not compile but shows instead:
    sample/test.kt: (3, 21): Unresolved reference: GeneratedClass
    Any help is appreciated, thanks!
    k
    d
    +2
    • 5
    • 32
  • p

    pardom

    06/18/2019, 6:48 PM
    Is there a way with
    kotlin-compiler
    and
    kotlin-script-util
    to evaluate a simple expression like
    Foo("bar")
    and get an instance? Kind of a like a
    Class.forName
    evaluator?
    t
    • 2
    • 1
Powered by Linen
Title
p

pardom

06/18/2019, 6:48 PM
Is there a way with
kotlin-compiler
and
kotlin-script-util
to evaluate a simple expression like
Foo("bar")
and get an instance? Kind of a like a
Class.forName
evaluator?
t

tschuchort

06/19/2019, 12:03 AM
I have made a library that can evaluate scripts by compiling them with the K2JVMCompiler. But that's probably too heavy-weight and clunky for you.
View count: 5