Effects: add (de)serialization of contracts in metadata
- Introduce new definitions in descriptors.proto - Add new corresponding values in Flags.java - Introduce ContractSerializer and ContractDeserializer, responsible for for conversion ContractDescription <-> ProtoBuf.Contract - Add dependency of 'serialization' module on 'resolution' so that it could see contracts model. Note that here we do a lot of seemingly unnecessary hoops, which in fact necessary to respect existing module system (in particular, to be able to extract ContractDescription declarations from 'descriptors' module to make them invisible from reflection) ========== Effect System introduction: 8/18
This commit is contained in:
@@ -354,6 +354,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
if (old.versionRequirement != new.versionRequirement) return false
|
||||
}
|
||||
|
||||
if (old.hasContract() != new.hasContract()) return false
|
||||
if (old.hasContract()) {
|
||||
if (!checkEquals(old.contract, new.contract)) return false
|
||||
}
|
||||
|
||||
if (old.hasExtension(JvmProtoBuf.methodSignature) != new.hasExtension(JvmProtoBuf.methodSignature)) return false
|
||||
if (old.hasExtension(JvmProtoBuf.methodSignature)) {
|
||||
if (!checkEquals(old.getExtension(JvmProtoBuf.methodSignature), new.getExtension(JvmProtoBuf.methodSignature))) return false
|
||||
@@ -745,6 +750,12 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: ProtoBuf.Contract, new: ProtoBuf.Contract): Boolean {
|
||||
if (!checkEqualsContractEffect(old, new)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: JvmProtoBuf.JvmMethodSignature, new: JvmProtoBuf.JvmMethodSignature): Boolean {
|
||||
if (old.hasName() != new.hasName()) return false
|
||||
if (old.hasName()) {
|
||||
@@ -890,6 +901,27 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: ProtoBuf.Effect, new: ProtoBuf.Effect): Boolean {
|
||||
if (old.hasEffectType() != new.hasEffectType()) return false
|
||||
if (old.hasEffectType()) {
|
||||
if (old.effectType != new.effectType) return false
|
||||
}
|
||||
|
||||
if (!checkEqualsEffectEffectConstructorArgument(old, new)) return false
|
||||
|
||||
if (old.hasConclusionOfConditionalEffect() != new.hasConclusionOfConditionalEffect()) return false
|
||||
if (old.hasConclusionOfConditionalEffect()) {
|
||||
if (!checkEquals(old.conclusionOfConditionalEffect, new.conclusionOfConditionalEffect)) return false
|
||||
}
|
||||
|
||||
if (old.hasKind() != new.hasKind()) return false
|
||||
if (old.hasKind()) {
|
||||
if (old.kind != new.kind) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: JvmProtoBuf.JvmFieldSignature, new: JvmProtoBuf.JvmFieldSignature): Boolean {
|
||||
if (old.hasName() != new.hasName()) return false
|
||||
if (old.hasName()) {
|
||||
@@ -904,6 +936,39 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: ProtoBuf.Expression, new: ProtoBuf.Expression): Boolean {
|
||||
if (old.hasFlags() != new.hasFlags()) return false
|
||||
if (old.hasFlags()) {
|
||||
if (old.flags != new.flags) return false
|
||||
}
|
||||
|
||||
if (old.hasValueParameterReference() != new.hasValueParameterReference()) return false
|
||||
if (old.hasValueParameterReference()) {
|
||||
if (old.valueParameterReference != new.valueParameterReference) return false
|
||||
}
|
||||
|
||||
if (old.hasConstantValue() != new.hasConstantValue()) return false
|
||||
if (old.hasConstantValue()) {
|
||||
if (old.constantValue != new.constantValue) return false
|
||||
}
|
||||
|
||||
if (old.hasIsInstanceType() != new.hasIsInstanceType()) return false
|
||||
if (old.hasIsInstanceType()) {
|
||||
if (!checkEquals(old.isInstanceType, new.isInstanceType)) return false
|
||||
}
|
||||
|
||||
if (old.hasIsInstanceTypeId() != new.hasIsInstanceTypeId()) return false
|
||||
if (old.hasIsInstanceTypeId()) {
|
||||
if (old.isInstanceTypeId != new.isInstanceTypeId) return false
|
||||
}
|
||||
|
||||
if (!checkEqualsExpressionAndArgument(old, new)) return false
|
||||
|
||||
if (!checkEqualsExpressionOrArgument(old, new)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsPackageFunction(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
||||
if (old.functionCount != new.functionCount) return false
|
||||
|
||||
@@ -1154,6 +1219,16 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsContractEffect(old: ProtoBuf.Contract, new: ProtoBuf.Contract): Boolean {
|
||||
if (old.effectCount != new.effectCount) return false
|
||||
|
||||
for(i in 0..old.effectCount - 1) {
|
||||
if (!checkEquals(old.getEffect(i), new.getEffect(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsAnnotationArgumentValueArrayElement(old: ProtoBuf.Annotation.Argument.Value, new: ProtoBuf.Annotation.Argument.Value): Boolean {
|
||||
if (old.arrayElementCount != new.arrayElementCount) return false
|
||||
|
||||
@@ -1164,6 +1239,36 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsEffectEffectConstructorArgument(old: ProtoBuf.Effect, new: ProtoBuf.Effect): Boolean {
|
||||
if (old.effectConstructorArgumentCount != new.effectConstructorArgumentCount) return false
|
||||
|
||||
for(i in 0..old.effectConstructorArgumentCount - 1) {
|
||||
if (!checkEquals(old.getEffectConstructorArgument(i), new.getEffectConstructorArgument(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsExpressionAndArgument(old: ProtoBuf.Expression, new: ProtoBuf.Expression): Boolean {
|
||||
if (old.andArgumentCount != new.andArgumentCount) return false
|
||||
|
||||
for(i in 0..old.andArgumentCount - 1) {
|
||||
if (!checkEquals(old.getAndArgument(i), new.getAndArgument(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsExpressionOrArgument(old: ProtoBuf.Expression, new: ProtoBuf.Expression): Boolean {
|
||||
if (old.orArgumentCount != new.orArgumentCount) return false
|
||||
|
||||
for(i in 0..old.orArgumentCount - 1) {
|
||||
if (!checkEquals(old.getOrArgument(i), new.getOrArgument(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun oldGetIndexOfString(index: Int): Int = getIndexOfString(index, oldStringIndexesMap, oldNameResolver)
|
||||
fun newGetIndexOfString(index: Int): Int = getIndexOfString(index, newStringIndexesMap, newNameResolver)
|
||||
|
||||
@@ -1362,6 +1467,10 @@ fun ProtoBuf.Function.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
|
||||
hashCode = 31 * hashCode + versionRequirement
|
||||
}
|
||||
|
||||
if (hasContract()) {
|
||||
hashCode = 31 * hashCode + contract.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasExtension(JvmProtoBuf.methodSignature)) {
|
||||
hashCode = 31 * hashCode + getExtension(JvmProtoBuf.methodSignature).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
@@ -1701,6 +1810,16 @@ fun ProtoBuf.ValueParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes:
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun ProtoBuf.Contract.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
for(i in 0..effectCount - 1) {
|
||||
hashCode = 31 * hashCode + getEffect(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun JvmProtoBuf.JvmMethodSignature.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
@@ -1837,6 +1956,28 @@ fun ProtoBuf.Annotation.Argument.hashCode(stringIndexes: (Int) -> Int, fqNameInd
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun ProtoBuf.Effect.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
if (hasEffectType()) {
|
||||
hashCode = 31 * hashCode + effectType.hashCode()
|
||||
}
|
||||
|
||||
for(i in 0..effectConstructorArgumentCount - 1) {
|
||||
hashCode = 31 * hashCode + getEffectConstructorArgument(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasConclusionOfConditionalEffect()) {
|
||||
hashCode = 31 * hashCode + conclusionOfConditionalEffect.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasKind()) {
|
||||
hashCode = 31 * hashCode + kind.hashCode()
|
||||
}
|
||||
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun JvmProtoBuf.JvmFieldSignature.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
@@ -1850,3 +1991,37 @@ fun JvmProtoBuf.JvmFieldSignature.hashCode(stringIndexes: (Int) -> Int, fqNameIn
|
||||
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun ProtoBuf.Expression.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
if (hasFlags()) {
|
||||
hashCode = 31 * hashCode + flags
|
||||
}
|
||||
|
||||
if (hasValueParameterReference()) {
|
||||
hashCode = 31 * hashCode + valueParameterReference
|
||||
}
|
||||
|
||||
if (hasConstantValue()) {
|
||||
hashCode = 31 * hashCode + constantValue.hashCode()
|
||||
}
|
||||
|
||||
if (hasIsInstanceType()) {
|
||||
hashCode = 31 * hashCode + isInstanceType.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasIsInstanceTypeId()) {
|
||||
hashCode = 31 * hashCode + isInstanceTypeId
|
||||
}
|
||||
|
||||
for(i in 0..andArgumentCount - 1) {
|
||||
hashCode = 31 * hashCode + getAndArgument(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
for(i in 0..orArgumentCount - 1) {
|
||||
hashCode = 31 * hashCode + getOrArgument(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
return hashCode
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user