Review fixes

This commit is contained in:
Igor Chevdar
2017-02-22 12:38:20 +03:00
parent 041fff596d
commit 3ac3b1e7ca
7 changed files with 21 additions and 23 deletions
@@ -55,13 +55,9 @@ internal class KonanLower(val context: Context) {
phaser.phase(KonanPhase.LOWER_VARARG) {
VarargInjectionLowering(context).runOnFilePostfix(irFile)
}
phaser.phase(KonanPhase.LOWER_DELEGATION) {
DelegationLowering(context).runOnFilePostfix(irFile)
}
phaser.phase(KonanPhase.BRIDGES_BUILDING) {
DelegationLowering(context).runOnFilePostfix(irFile)
BridgesBuilding(context).runOnFilePostfix(irFile)
}
phaser.phase(KonanPhase.LOWER_DIRECT_BRIDGES_CALLS) {
DirectBridgesCallsLowering(context).runOnFilePostfix(irFile)
}
phaser.phase(KonanPhase.AUTOBOX) {
@@ -25,8 +25,6 @@ enum class KonanPhase(val description: String,
/* ... ... */ LOWER_STRING_CONCAT("String concatenation lowering"),
/* ... ... */ LOWER_INITIALIZERS("Initializers lowering"),
/* ... ... */ BRIDGES_BUILDING("Bridges building"),
/* ... ... */ LOWER_DELEGATION("Delegation lowering"),
/* ... ... */ LOWER_DIRECT_BRIDGES_CALLS("Direct bridges calls lowering"),
/* ... */ BITCODE("LLVM BitCode Generation"),
/* ... ... */ RTTI("RTTI Generation"),
/* ... ... */ CODEGEN("Code Generation"),
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.util.*
/**
* 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 (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 {
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
&& OverridingUtil.overrides(target, overriddenDescriptor)
&& ourDirections == target.bridgeDirectionsTo(overriddenDescriptor)) {
// Bridge is inherited from supers
// Bridge is inherited from superclass.
return BridgeDirections(this.valueParameters.size)
}
@@ -1225,7 +1225,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
private fun evaluateGetField(value: IrGetField): LLVMValueRef {
context.log("evaluateGetField : ${ir2string(value)}")
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!!)
return codegen.loadSlot(
fieldPtrOfClass(thisPtr, value.descriptor), value.descriptor.isVar())
@@ -1256,7 +1257,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
val valueToAssign = evaluateExpression(value.value)
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!!)
codegen.storeAnyGlobal(valueToAssign, fieldPtrOfClass(thisPtr, value.descriptor))
}
@@ -299,9 +299,11 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
val dispatchReceiverParameter = descriptor.dispatchReceiverParameter
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
?: 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 allFields = classDeclarations.fields
@@ -173,7 +173,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
val bridgeOwner = if (!descriptor.kind.isReal
&& OverridingUtil.overrides(target, overriddenDescriptor)
&& descriptor.bridgeDirectionsTo(overriddenDescriptor).allNotNeeded()) {
target // Bridge is inherited from supers
target // Bridge is inherited from superclass.
} else {
descriptor
}
@@ -27,7 +27,7 @@ internal class DirectBridgesCallsLowering(val context: Context) : BodyLoweringPa
val descriptor = expression.descriptor as? FunctionDescriptor ?: return expression
if (descriptor.modality == Modality.ABSTRACT
|| (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
}
@@ -39,7 +39,7 @@ internal class DirectBridgesCallsLowering(val context: Context) : BodyLoweringPa
val toCall = if (needBridge) {
target
} else {
// Need to call delegating fun.
// Need to call delegating function.
context.specialDescriptorsFactory.getBridgeDescriptor(OverriddenFunctionDescriptor(descriptor, target))
}
@@ -81,10 +81,8 @@ internal class DelegationLowering(val context: Context) : ClassLoweringPass {
is IrProperty -> {
val getter = transformBridgeToDelegatedMethod(irClass, it.getter)
val setter = transformBridgeToDelegatedMethod(irClass, it.setter)
if (getter != null || setter != null) {
it.getter = getter
it.setter = setter
}
if (getter != null) it.getter = getter
if (setter != null) it.setter = setter
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? {
if (irFunction == null || irFunction.descriptor.kind != CallableMemberDescriptor.Kind.DELEGATION) return null