Review fixes
This commit is contained in:
+1
-5
@@ -55,13 +55,9 @@ internal class KonanLower(val context: Context) {
|
|||||||
phaser.phase(KonanPhase.LOWER_VARARG) {
|
phaser.phase(KonanPhase.LOWER_VARARG) {
|
||||||
VarargInjectionLowering(context).runOnFilePostfix(irFile)
|
VarargInjectionLowering(context).runOnFilePostfix(irFile)
|
||||||
}
|
}
|
||||||
phaser.phase(KonanPhase.LOWER_DELEGATION) {
|
|
||||||
DelegationLowering(context).runOnFilePostfix(irFile)
|
|
||||||
}
|
|
||||||
phaser.phase(KonanPhase.BRIDGES_BUILDING) {
|
phaser.phase(KonanPhase.BRIDGES_BUILDING) {
|
||||||
|
DelegationLowering(context).runOnFilePostfix(irFile)
|
||||||
BridgesBuilding(context).runOnFilePostfix(irFile)
|
BridgesBuilding(context).runOnFilePostfix(irFile)
|
||||||
}
|
|
||||||
phaser.phase(KonanPhase.LOWER_DIRECT_BRIDGES_CALLS) {
|
|
||||||
DirectBridgesCallsLowering(context).runOnFilePostfix(irFile)
|
DirectBridgesCallsLowering(context).runOnFilePostfix(irFile)
|
||||||
}
|
}
|
||||||
phaser.phase(KonanPhase.AUTOBOX) {
|
phaser.phase(KonanPhase.AUTOBOX) {
|
||||||
|
|||||||
-2
@@ -25,8 +25,6 @@ enum class KonanPhase(val description: String,
|
|||||||
/* ... ... */ LOWER_STRING_CONCAT("String concatenation lowering"),
|
/* ... ... */ LOWER_STRING_CONCAT("String concatenation lowering"),
|
||||||
/* ... ... */ LOWER_INITIALIZERS("Initializers lowering"),
|
/* ... ... */ LOWER_INITIALIZERS("Initializers lowering"),
|
||||||
/* ... ... */ BRIDGES_BUILDING("Bridges building"),
|
/* ... ... */ BRIDGES_BUILDING("Bridges building"),
|
||||||
/* ... ... */ LOWER_DELEGATION("Delegation lowering"),
|
|
||||||
/* ... ... */ LOWER_DIRECT_BRIDGES_CALLS("Direct bridges calls lowering"),
|
|
||||||
/* ... */ BITCODE("LLVM BitCode Generation"),
|
/* ... */ BITCODE("LLVM BitCode Generation"),
|
||||||
/* ... ... */ RTTI("RTTI Generation"),
|
/* ... ... */ RTTI("RTTI Generation"),
|
||||||
/* ... ... */ CODEGEN("Code Generation"),
|
/* ... ... */ CODEGEN("Code Generation"),
|
||||||
|
|||||||
+6
-4
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of all implemented interfaces (including those which implemented by a super class)
|
* List of all implemented interfaces (including those which implemented by a super class)
|
||||||
@@ -254,11 +253,14 @@ internal class BridgeDirections(val array: Array<BridgeDirection>) {
|
|||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is BridgeDirections) return false
|
if (other !is BridgeDirections) return false
|
||||||
|
|
||||||
return (Arrays.equals(array, other.array))
|
return array.size == other.array.size
|
||||||
|
&& array.indices.all { array[it] == other.array[it] }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return Arrays.hashCode(array)
|
var result = 0
|
||||||
|
array.forEach { result = result * 31 + it.ordinal }
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +275,7 @@ internal fun FunctionDescriptor.bridgeDirectionsTo(overriddenDescriptor: Functio
|
|||||||
if (!kind.isReal
|
if (!kind.isReal
|
||||||
&& OverridingUtil.overrides(target, overriddenDescriptor)
|
&& OverridingUtil.overrides(target, overriddenDescriptor)
|
||||||
&& ourDirections == target.bridgeDirectionsTo(overriddenDescriptor)) {
|
&& ourDirections == target.bridgeDirectionsTo(overriddenDescriptor)) {
|
||||||
// Bridge is inherited from supers
|
// Bridge is inherited from superclass.
|
||||||
return BridgeDirections(this.valueParameters.size)
|
return BridgeDirections(this.valueParameters.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -1225,7 +1225,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
private fun evaluateGetField(value: IrGetField): LLVMValueRef {
|
private fun evaluateGetField(value: IrGetField): LLVMValueRef {
|
||||||
context.log("evaluateGetField : ${ir2string(value)}")
|
context.log("evaluateGetField : ${ir2string(value)}")
|
||||||
if (value.descriptor.dispatchReceiverParameter != null
|
if (value.descriptor.dispatchReceiverParameter != null
|
||||||
|| value.descriptor is IrImplementingDelegateDescriptorImpl) { // TODO: hack because of IR bug.
|
// TODO: hack because of IR bug: https://github.com/JetBrains/kotlin/tree/rr/dispatch_receiver_for_delegate_descriptor.
|
||||||
|
|| value.descriptor is IrImplementingDelegateDescriptorImpl) {
|
||||||
val thisPtr = evaluateExpression(value.receiver!!)
|
val thisPtr = evaluateExpression(value.receiver!!)
|
||||||
return codegen.loadSlot(
|
return codegen.loadSlot(
|
||||||
fieldPtrOfClass(thisPtr, value.descriptor), value.descriptor.isVar())
|
fieldPtrOfClass(thisPtr, value.descriptor), value.descriptor.isVar())
|
||||||
@@ -1256,7 +1257,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
val valueToAssign = evaluateExpression(value.value)
|
val valueToAssign = evaluateExpression(value.value)
|
||||||
|
|
||||||
if (value.descriptor.dispatchReceiverParameter != null
|
if (value.descriptor.dispatchReceiverParameter != null
|
||||||
|| value.descriptor is IrImplementingDelegateDescriptorImpl) { // TODO: hack because of IR bug.
|
// TODO: hack because of IR bug: https://github.com/JetBrains/kotlin/tree/rr/dispatch_receiver_for_delegate_descriptor.
|
||||||
|
|| value.descriptor is IrImplementingDelegateDescriptorImpl) {
|
||||||
val thisPtr = evaluateExpression(value.receiver!!)
|
val thisPtr = evaluateExpression(value.receiver!!)
|
||||||
codegen.storeAnyGlobal(valueToAssign, fieldPtrOfClass(thisPtr, value.descriptor))
|
codegen.storeAnyGlobal(valueToAssign, fieldPtrOfClass(thisPtr, value.descriptor))
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -299,9 +299,11 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
|
|||||||
|
|
||||||
val dispatchReceiverParameter = descriptor.dispatchReceiverParameter
|
val dispatchReceiverParameter = descriptor.dispatchReceiverParameter
|
||||||
if (dispatchReceiverParameter != null
|
if (dispatchReceiverParameter != null
|
||||||
|| descriptor is IrImplementingDelegateDescriptorImpl) { // TODO: hack because of IR bug.
|
// TODO: hack because of IR bug: https://github.com/JetBrains/kotlin/tree/rr/dispatch_receiver_for_delegate_descriptor.
|
||||||
|
|| descriptor is IrImplementingDelegateDescriptorImpl) {
|
||||||
val containingClass = dispatchReceiverParameter?.containingDeclaration
|
val containingClass = dispatchReceiverParameter?.containingDeclaration
|
||||||
?: descriptor.containingDeclaration // TODO: hack because of IR bug.
|
// TODO: hack because of IR bug: https://github.com/JetBrains/kotlin/tree/rr/dispatch_receiver_for_delegate_descriptor.
|
||||||
|
?: descriptor.containingDeclaration
|
||||||
val classDeclarations = this.classes[containingClass] ?: error(containingClass.toString())
|
val classDeclarations = this.classes[containingClass] ?: error(containingClass.toString())
|
||||||
|
|
||||||
val allFields = classDeclarations.fields
|
val allFields = classDeclarations.fields
|
||||||
|
|||||||
+1
-1
@@ -173,7 +173,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
|||||||
val bridgeOwner = if (!descriptor.kind.isReal
|
val bridgeOwner = if (!descriptor.kind.isReal
|
||||||
&& OverridingUtil.overrides(target, overriddenDescriptor)
|
&& OverridingUtil.overrides(target, overriddenDescriptor)
|
||||||
&& descriptor.bridgeDirectionsTo(overriddenDescriptor).allNotNeeded()) {
|
&& descriptor.bridgeDirectionsTo(overriddenDescriptor).allNotNeeded()) {
|
||||||
target // Bridge is inherited from supers
|
target // Bridge is inherited from superclass.
|
||||||
} else {
|
} else {
|
||||||
descriptor
|
descriptor
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -27,7 +27,7 @@ internal class DirectBridgesCallsLowering(val context: Context) : BodyLoweringPa
|
|||||||
val descriptor = expression.descriptor as? FunctionDescriptor ?: return expression
|
val descriptor = expression.descriptor as? FunctionDescriptor ?: return expression
|
||||||
if (descriptor.modality == Modality.ABSTRACT
|
if (descriptor.modality == Modality.ABSTRACT
|
||||||
|| (expression.superQualifier == null && descriptor.isOverridable)) {
|
|| (expression.superQualifier == null && descriptor.isOverridable)) {
|
||||||
// A virtual call. box/unbox will be in the corresponding bridge.
|
// A virtual call. boxing/unboxing will be in the corresponding bridge.
|
||||||
return expression
|
return expression
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ internal class DirectBridgesCallsLowering(val context: Context) : BodyLoweringPa
|
|||||||
val toCall = if (needBridge) {
|
val toCall = if (needBridge) {
|
||||||
target
|
target
|
||||||
} else {
|
} else {
|
||||||
// Need to call delegating fun.
|
// Need to call delegating function.
|
||||||
context.specialDescriptorsFactory.getBridgeDescriptor(OverriddenFunctionDescriptor(descriptor, target))
|
context.specialDescriptorsFactory.getBridgeDescriptor(OverriddenFunctionDescriptor(descriptor, target))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,10 +81,8 @@ internal class DelegationLowering(val context: Context) : ClassLoweringPass {
|
|||||||
is IrProperty -> {
|
is IrProperty -> {
|
||||||
val getter = transformBridgeToDelegatedMethod(irClass, it.getter)
|
val getter = transformBridgeToDelegatedMethod(irClass, it.getter)
|
||||||
val setter = transformBridgeToDelegatedMethod(irClass, it.setter)
|
val setter = transformBridgeToDelegatedMethod(irClass, it.setter)
|
||||||
if (getter != null || setter != null) {
|
if (getter != null) it.getter = getter
|
||||||
it.getter = getter
|
if (setter != null) it.setter = setter
|
||||||
it.setter = setter
|
|
||||||
}
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
@@ -92,7 +90,7 @@ internal class DelegationLowering(val context: Context) : ClassLoweringPass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: hack because of broken IR for synthesized delegated members.
|
// TODO: hack because of broken IR for synthesized delegated members: https://youtrack.jetbrains.com/issue/KT-16486.
|
||||||
private fun transformBridgeToDelegatedMethod(irClass: IrClass, irFunction: IrFunction?): IrFunction? {
|
private fun transformBridgeToDelegatedMethod(irClass: IrClass, irFunction: IrFunction?): IrFunction? {
|
||||||
if (irFunction == null || irFunction.descriptor.kind != CallableMemberDescriptor.Kind.DELEGATION) return null
|
if (irFunction == null || irFunction.descriptor.kind != CallableMemberDescriptor.Kind.DELEGATION) return null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user