Implement metadata handling for IR scripts
This commit is contained in:
@@ -116,6 +116,12 @@ object AbstractTypeMapper {
|
||||
return asmType
|
||||
}
|
||||
|
||||
typeConstructor.isScript() -> {
|
||||
val asmType = AsmTypes.JAVA_CLASS_TYPE
|
||||
with(context) { sw?.writeGenericType(type, asmType, mode) }
|
||||
return asmType
|
||||
}
|
||||
|
||||
typeConstructor.isTypeParameter() -> {
|
||||
val typeParameter = typeConstructor as TypeParameterMarker
|
||||
return mapType(context, typeParameter.representativeUpperBound(), mode, null).also { asmType ->
|
||||
|
||||
+2
@@ -210,6 +210,8 @@ class ConeTypeSystemCommonBackendContextForTypeMapping(
|
||||
}
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.isScript(): Boolean = false
|
||||
|
||||
override fun SimpleTypeMarker.isSuspendFunction(): Boolean {
|
||||
require(this is ConeSimpleKotlinType)
|
||||
return isSuspendFunctionType(session)
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -221,6 +222,10 @@ private class IrTypeCheckerContextForTypeMapping(
|
||||
}
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.isScript(): Boolean {
|
||||
return this is IrScriptSymbol
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.isSuspendFunction(): Boolean {
|
||||
require(this is IrSimpleType)
|
||||
return isSuspendFunctionImpl()
|
||||
|
||||
+1
-1
@@ -77,6 +77,7 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext) {
|
||||
}.also { irScriptClass ->
|
||||
irScriptClass.superTypes += context.irBuiltIns.anyType
|
||||
irScriptClass.parent = irFile
|
||||
irScriptClass.metadata = irScript.metadata
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +160,6 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext) {
|
||||
}
|
||||
|
||||
irScriptClass.annotations += (irScriptClass.parent as IrFile).annotations
|
||||
irScriptClass.metadata = (irScriptClass.parent as IrFile).metadata
|
||||
|
||||
irScript.resultProperty?.owner?.let { irResultProperty ->
|
||||
context.state.scriptSpecific.resultFieldName = irResultProperty.name.identifier
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||
import org.jetbrains.kotlin.ir.assertCast
|
||||
import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
@@ -42,6 +43,8 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
||||
|
||||
return context.symbolTable.declareScript(descriptor).buildWithScope { irScript ->
|
||||
|
||||
irScript.metadata = DescriptorMetadataSource.Class(descriptor)
|
||||
|
||||
// A workaround for the JS/REPL backend:
|
||||
// JS backend doesn't save previously executed snippets anywhere, they should be taken for now from the context.symbolTable.listExistedScripts()
|
||||
// on the other hand imported scripts are also stored there so to avoid clashes the imported scripts should be filtered out
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
//NOTE: declarations and statements stored separately
|
||||
abstract class IrScript :
|
||||
IrDeclarationBase(), IrDeclarationWithName,
|
||||
IrDeclarationParent, IrStatementContainer {
|
||||
IrDeclarationParent, IrStatementContainer, IrMetadataSourceOwner {
|
||||
|
||||
abstract override val symbol: IrScriptSymbol
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ class IrScriptImpl(
|
||||
|
||||
override val statements: MutableList<IrStatement> = mutableListOf()
|
||||
|
||||
override var metadata: MetadataSource? = null
|
||||
|
||||
override lateinit var thisReceiver: IrValueParameter
|
||||
|
||||
override lateinit var baseClass: IrType
|
||||
|
||||
@@ -54,6 +54,7 @@ interface TypeSystemCommonBackendContext : TypeSystemContext {
|
||||
interface TypeSystemCommonBackendContextForTypeMapping : TypeSystemCommonBackendContext {
|
||||
fun TypeConstructorMarker.isTypeParameter(): Boolean
|
||||
fun TypeConstructorMarker.defaultType(): KotlinTypeMarker
|
||||
fun TypeConstructorMarker.isScript(): Boolean
|
||||
|
||||
fun SimpleTypeMarker.isSuspendFunction(): Boolean
|
||||
fun SimpleTypeMarker.isKClass(): Boolean
|
||||
|
||||
Reference in New Issue
Block a user