There might be a clash between getter name and box function name
This commit is contained in:
+5
-6
@@ -12,10 +12,7 @@ import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.*
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
@@ -44,6 +41,8 @@ private fun KonanSymbols.getTypeConversionImpl(
|
||||
}?.symbol
|
||||
}
|
||||
|
||||
internal object DECLARATION_ORIGIN_INLINE_CLASS_SPECIAL_FUNCTION : IrDeclarationOriginImpl("INLINE_CLASS_SPECIAL_FUNCTION")
|
||||
|
||||
internal val Context.getBoxFunction: (IrClass) -> IrSimpleFunction by Context.lazyMapMember { inlinedClass ->
|
||||
assert(inlinedClass.isUsedAsBoxClass())
|
||||
assert(inlinedClass.parent is IrFile) { "Expected top level inline class" }
|
||||
@@ -63,7 +62,7 @@ internal val Context.getBoxFunction: (IrClass) -> IrSimpleFunction by Context.la
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
IrFunctionImpl(
|
||||
startOffset, endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
DECLARATION_ORIGIN_INLINE_CLASS_SPECIAL_FUNCTION,
|
||||
IrSimpleFunctionSymbolImpl(descriptor),
|
||||
Name.special("<${inlinedClass.name}-box>"),
|
||||
Visibilities.PUBLIC,
|
||||
@@ -114,7 +113,7 @@ internal val Context.getUnboxFunction: (IrClass) -> IrSimpleFunction by Context.
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
IrFunctionImpl(
|
||||
startOffset, endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
DECLARATION_ORIGIN_INLINE_CLASS_SPECIAL_FUNCTION,
|
||||
IrSimpleFunctionSymbolImpl(descriptor),
|
||||
Name.special("<${inlinedClass.name}-unbox>"),
|
||||
Visibilities.PUBLIC,
|
||||
|
||||
-6
@@ -95,12 +95,6 @@ val IrDeclaration.parentDeclarationsWithSelf: Sequence<IrDeclaration>
|
||||
|
||||
fun IrClass.companionObject() = this.declarations.filterIsInstance<IrClass>().atMostOne { it.isCompanion }
|
||||
|
||||
val IrDeclaration.isGetter get() = this is IrSimpleFunction && this == this.correspondingProperty?.getter
|
||||
|
||||
val IrDeclaration.isSetter get() = this is IrSimpleFunction && this == this.correspondingProperty?.setter
|
||||
|
||||
val IrDeclaration.isAccessor get() = this.isGetter || this.isSetter
|
||||
|
||||
fun buildSimpleAnnotation(irBuiltIns: IrBuiltIns, startOffset: Int, endOffset: Int,
|
||||
annotationClass: IrClass, vararg args: String): IrConstructorCall {
|
||||
val constructor = annotationClass.constructors.single()
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -401,7 +402,7 @@ private class InlineClassTransformer(private val context: Context) : IrBuildingT
|
||||
startOffset,
|
||||
endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
descriptor,
|
||||
IrPropertySymbolImpl(descriptor),
|
||||
irField.name,
|
||||
irField.visibility,
|
||||
Modality.FINAL,
|
||||
|
||||
+3
-1
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.konan.ir.*
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanMangler.functionName
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanMangler.symbolName
|
||||
import org.jetbrains.kotlin.backend.konan.lower.DECLARATION_ORIGIN_BRIDGE_METHOD
|
||||
import org.jetbrains.kotlin.backend.konan.lower.bridgeTarget
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
@@ -646,7 +647,8 @@ internal object DataFlowIR {
|
||||
}
|
||||
|
||||
private val IrFunction.isSpecial get() =
|
||||
name.asString().let { it.startsWith("<bridge-") || it.endsWith("-box>") || it.endsWith("-unbox>") }
|
||||
origin == DECLARATION_ORIGIN_INLINE_CLASS_SPECIAL_FUNCTION
|
||||
|| origin is DECLARATION_ORIGIN_BRIDGE_METHOD
|
||||
|
||||
private fun mapPropertyInitializer(irField: IrField): FunctionSymbol {
|
||||
functionMap[irField]?.let { return it }
|
||||
|
||||
+2
-4
@@ -1047,10 +1047,8 @@ internal object Devirtualization {
|
||||
}
|
||||
}
|
||||
|
||||
private val specialNames = listOf("-box>", "-unbox>")
|
||||
|
||||
// TODO: do it more reliably.
|
||||
private fun IrExpression.isBoxOrUnboxCall() = (this is IrCall && symbol.owner.name.asString().let { name -> specialNames.any { name.endsWith(it) } })
|
||||
private fun IrExpression.isBoxOrUnboxCall() =
|
||||
(this is IrCall && symbol.owner.origin == DECLARATION_ORIGIN_INLINE_CLASS_SPECIAL_FUNCTION)
|
||||
|
||||
private fun devirtualize(irModule: IrModuleFragment, context: Context, externalModulesDFG: ExternalModulesDFG,
|
||||
devirtualizedCallSites: Map<IrCall, DevirtualizedCallSite>) {
|
||||
|
||||
@@ -2357,9 +2357,16 @@ standaloneTest("args0") {
|
||||
|
||||
standaloneTest("devirtualization_lateinitInterface") {
|
||||
goldValue = "42\n"
|
||||
flags = ["-opt"]
|
||||
source = "codegen/devirtualization/lateinitInterface.kt"
|
||||
}
|
||||
|
||||
standaloneTest("devirtualization_getter_looking_as_box_function") {
|
||||
goldValue = "box\n"
|
||||
flags = ["-opt"]
|
||||
source = "codegen/devirtualization/getter_looking_as_box_function.kt"
|
||||
}
|
||||
|
||||
standaloneTest("multiargs") {
|
||||
arguments = ["AAA", "BB", "C"]
|
||||
multiRuns = true
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo(val box: String = "box")
|
||||
|
||||
fun main() {
|
||||
println(Foo().box)
|
||||
}
|
||||
Reference in New Issue
Block a user