[EE-IR] Fragment Compiler Entrypoint in IR Backend

This commit introduces a new entrypoint for the IR backend, and starts
the work of accomodating the evaluator in psi2ir.

The evaluator expects a certain class and method structure of the
compiled fragment, but PSI is only supplied for the actual fragment.

So, to that end, this commit introduces a new "front end" of psi2ir
that "synthesizes" the module, class and method structure around the
fragment before calling into the existing psi2ir pipeline to obtain
the IR for the fragment.

The primary complication so far is handling the captured variables of
the fragment: they are mapped to parameters of the method surrounding
the fragment, and passed as arguments on evaluation. Hence, the IR
translation of the fragment needs to remap captured variables to the
appropriate parameter, in essentially all places they can be referred
to in the fragment (and hence in psi2ir). This commit introduces a
decorated symbol table that intercepts symbol look-ups and remaps as
appropriate.

Other cases that dispatches based on descriptor (see
`CallGenerator.kt`) needs other metadata to generate correct code.

It also introduces a shim in DeserializedContainerSource in the psi2ir
pipeline to facilitate facade class generation for the code that is
being debugged (which are generated as "external ir declarations").

Finally, in passing we resolve a small leftover from previous
refactoring that left an asssertion re. allowing IR to _assign_ to
parameters of methods.
This commit is contained in:
Kristoffer Andersen
2021-08-13 14:51:26 +02:00
committed by Alexander Udalov
parent 783c3d1500
commit 247cbffbac
19 changed files with 421 additions and 25 deletions
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
interface FacadeClassSource {
val className: JvmClassName
val facadeClassName: JvmClassName?
}
@@ -20,15 +20,15 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
class JvmPackagePartSource(
val className: JvmClassName,
val facadeClassName: JvmClassName?,
override val className: JvmClassName,
override val facadeClassName: JvmClassName?,
packageProto: ProtoBuf.Package,
nameResolver: NameResolver,
override val incompatibility: IncompatibleVersionErrorData<JvmMetadataVersion>? = null,
override val isPreReleaseInvisible: Boolean = false,
override val abiStability: DeserializedContainerAbiStability = DeserializedContainerAbiStability.STABLE,
val knownJvmBinaryClass: KotlinJvmBinaryClass? = null
) : DeserializedContainerSource {
) : DeserializedContainerSource, FacadeClassSource {
constructor(
kotlinClass: KotlinJvmBinaryClass,
packageProto: ProtoBuf.Package,