Thread
#arrow-meta
    m

    mdepies

    2 years ago
    Is there a good [formal] way for me to compare a reference to a declaration?
    KtSimpleNameExpression
    and
    KtProperty
    raulraja

    raulraja

    2 years ago
    what are the values in those and how do you want to compare them?. I’d need some code to see what you are trying to achieve here.
    m

    mdepies

    2 years ago
    data class Window<T>(
            val size: Int,
            val elements: MutableList<T>) {
        init {
            watch(elements).then {
                while (elements.size > size) elements.removeAt(0)
            }
        }
    }
    I crawl through the code (example above) and record all of the declarations. Then I search for any watch methods and see what is declared as dependencies. I'd like to associate that reference with the correct declaration (I have a list of registered elements)
    Ideally I'd like to know if a given reference is for a given declaration
    raulraja

    raulraja

    2 years ago
    So in your case:
    KtProperty : val elements: MutableList<T>
    And
    KtSimpleNameExpression = elements
    m

    mdepies

    2 years ago
    yeah
    raulraja

    raulraja

    2 years ago
    where elements appears inside
    watch(elements)
    elements has no knowledge that it refers to that at the quote level because there is no notion of lexical scope until resolution starts
    m

    mdepies

    2 years ago
    figured as much
    😞
    raulraja

    raulraja

    2 years ago
    let me take a look at the compiler docs one sec
    An alternative is to use directly the
    TopDownAnalyzerFacadeForJVM
    you can invoke that on
    doAnalysis { ..here.. }
    or also org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler#analyze
    There you can feed it a list of KtFiles. The AnalysisResult object has all the descriptors that include the info you need regarding bound symbols in a scope
    sadly thre is no firendly api for this yet but we will consider providing one in meta to offer analysis a la carte in quotes that hides this complexity
    m

    mdepies

    2 years ago
    am I paying a higher cost in compilation
    doing this out of step - so to speak
    raulraja

    raulraja

    2 years ago
    yes, you are analyzing twice but if you know exactly where to and your gened files to analyze are small it may not be significant
    m

    mdepies

    2 years ago
    ah sure
    where do i get the compilerConfiguration?
    raulraja

    raulraja

    2 years ago
    if you are passing it to the Kotlin Core Environment try with
    org.jetbrains.kotlin.config.CompilerConfiguration#EMPTY
    that flow path follows several additions to it depending on platforms until it gets to the point to pass it into ana;ysis in the other links