[IR] Set source offsets in SAM lowering
This is needed for debug info generating in K/N
This commit is contained in:
+7
-2
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||||
@@ -104,7 +105,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
val inInlineFunctionScope = allScopes.any { scope -> (scope.irElement as? IrFunction)?.isInline ?: false }
|
val inInlineFunctionScope = allScopes.any { scope -> (scope.irElement as? IrFunction)?.isInline ?: false }
|
||||||
val cache = if (inInlineFunctionScope) inlineCachedImplementations else cachedImplementations
|
val cache = if (inInlineFunctionScope) inlineCachedImplementations else cachedImplementations
|
||||||
val implementation = cache.getOrPut(superType) {
|
val implementation = cache.getOrPut(superType) {
|
||||||
createObjectProxy(superType, inInlineFunctionScope)
|
createObjectProxy(superType, inInlineFunctionScope, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (superType.isNullable() && invokable.type.isNullable()) {
|
return if (superType.isNullable() && invokable.type.isNullable()) {
|
||||||
@@ -135,7 +136,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
|
|
||||||
// Construct a class that wraps an invokable object into an implementation of an interface:
|
// Construct a class that wraps an invokable object into an implementation of an interface:
|
||||||
// class sam$n(private val invokable: F) : Interface { override fun method(...) = invokable(...) }
|
// class sam$n(private val invokable: F) : Interface { override fun method(...) = invokable(...) }
|
||||||
private fun createObjectProxy(superType: IrType, generatePublicWrapper: Boolean): IrClass {
|
private fun createObjectProxy(superType: IrType, generatePublicWrapper: Boolean, createFor: IrElement): IrClass {
|
||||||
val superClass = superType.classifierOrFail.owner as IrClass
|
val superClass = superType.classifierOrFail.owner as IrClass
|
||||||
// The language documentation prohibits casting lambdas to classes, but if it was allowed,
|
// The language documentation prohibits casting lambdas to classes, but if it was allowed,
|
||||||
// the `irDelegatingConstructorCall` in the constructor below would need to be modified.
|
// the `irDelegatingConstructorCall` in the constructor below would need to be modified.
|
||||||
@@ -159,6 +160,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
name = wrapperName
|
name = wrapperName
|
||||||
origin = IrDeclarationOrigin.GENERATED_SAM_IMPLEMENTATION
|
origin = IrDeclarationOrigin.GENERATED_SAM_IMPLEMENTATION
|
||||||
visibility = wrapperVisibility
|
visibility = wrapperVisibility
|
||||||
|
setSourceRange(createFor)
|
||||||
}.apply {
|
}.apply {
|
||||||
createImplicitParameterDeclarationWithWrappedDescriptor()
|
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||||
superTypes += superType
|
superTypes += superType
|
||||||
@@ -170,12 +172,14 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
type = wrappedFunctionType
|
type = wrappedFunctionType
|
||||||
origin = subclass.origin
|
origin = subclass.origin
|
||||||
visibility = Visibilities.PRIVATE
|
visibility = Visibilities.PRIVATE
|
||||||
|
setSourceRange(createFor)
|
||||||
}
|
}
|
||||||
|
|
||||||
subclass.addConstructor {
|
subclass.addConstructor {
|
||||||
origin = subclass.origin
|
origin = subclass.origin
|
||||||
isPrimary = true
|
isPrimary = true
|
||||||
visibility = wrapperVisibility
|
visibility = wrapperVisibility
|
||||||
|
setSourceRange(createFor)
|
||||||
}.apply {
|
}.apply {
|
||||||
val parameter = addValueParameter {
|
val parameter = addValueParameter {
|
||||||
name = field.name
|
name = field.name
|
||||||
@@ -196,6 +200,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
visibility = superMethod.visibility
|
visibility = superMethod.visibility
|
||||||
origin = subclass.origin
|
origin = subclass.origin
|
||||||
isSuspend = superMethod.isSuspend
|
isSuspend = superMethod.isSuspend
|
||||||
|
setSourceRange(createFor)
|
||||||
}.apply {
|
}.apply {
|
||||||
overriddenSymbols += superMethod.symbol
|
overriddenSymbols += superMethod.symbol
|
||||||
dispatchReceiverParameter = subclass.thisReceiver!!.copyTo(this)
|
dispatchReceiverParameter = subclass.thisReceiver!!.copyTo(this)
|
||||||
|
|||||||
Reference in New Issue
Block a user