Native compiler: remove unused hashing code
It was used to compute hashes for class names, but this is no longer
required after c6ac807034.
This commit is contained in:
committed by
Space
parent
39d748dbbb
commit
a471bbc185
-40
@@ -13,7 +13,6 @@ import llvm.*
|
|||||||
import org.jetbrains.kotlin.backend.konan.CachedLibraries
|
import org.jetbrains.kotlin.backend.konan.CachedLibraries
|
||||||
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
|
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
import org.jetbrains.kotlin.backend.konan.hash.GlobalHash
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.llvmSymbolOrigin
|
import org.jetbrains.kotlin.backend.konan.ir.llvmSymbolOrigin
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.konan.CompiledKlibModuleOrigin
|
import org.jetbrains.kotlin.descriptors.konan.CompiledKlibModuleOrigin
|
||||||
@@ -214,45 +213,6 @@ internal interface ContextUtils : RuntimeAware {
|
|||||||
val IrClass.llvmTypeInfoPtr: LLVMValueRef
|
val IrClass.llvmTypeInfoPtr: LLVMValueRef
|
||||||
get() = typeInfoPtr.llvm
|
get() = typeInfoPtr.llvm
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns contents of this [GlobalHash].
|
|
||||||
*
|
|
||||||
* It must be declared identically with [Runtime.globalHashType].
|
|
||||||
*/
|
|
||||||
fun GlobalHash.getBytes(): ByteArray {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
val size = GlobalHash.size
|
|
||||||
assert(size == LLVMStoreSizeOfType(llvmTargetData, runtime.globalHashType))
|
|
||||||
|
|
||||||
return this.bits.getBytes(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns global hash of this string contents.
|
|
||||||
*/
|
|
||||||
val String.globalHashBytes: ByteArray
|
|
||||||
get() = memScoped {
|
|
||||||
val hash = globalHash(stringAsBytes(this@globalHashBytes), memScope)
|
|
||||||
hash.getBytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return base64 representation for global hash of this string contents.
|
|
||||||
*/
|
|
||||||
val String.globalHashBase64: String
|
|
||||||
get() {
|
|
||||||
return base64Encode(globalHashBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
val String.globalHash: ConstValue
|
|
||||||
get() = memScoped {
|
|
||||||
val hashBytes = this@globalHash.globalHashBytes
|
|
||||||
return Struct(runtime.globalHashType, ConstArray(int8Type, hashBytes.map { Int8(it) }))
|
|
||||||
}
|
|
||||||
|
|
||||||
val FqName.globalHash: ConstValue
|
|
||||||
get() = this.toString().globalHash
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
-35
@@ -5,46 +5,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.llvm
|
package org.jetbrains.kotlin.backend.konan.llvm
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.cityHash64
|
import org.jetbrains.kotlin.backend.common.serialization.cityHash64
|
||||||
import org.jetbrains.kotlin.backend.konan.hash.*
|
|
||||||
|
|
||||||
@OptIn(ExperimentalUnsignedTypes::class)
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
internal fun localHash(data: ByteArray): Long {
|
internal fun localHash(data: ByteArray): Long {
|
||||||
return cityHash64(data).toLong()
|
return cityHash64(data).toLong()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun globalHash(data: ByteArray, retValPlacement: NativePlacement): GlobalHash {
|
|
||||||
val res = retValPlacement.alloc<GlobalHash>()
|
|
||||||
memScoped {
|
|
||||||
val bytes = allocArrayOf(data)
|
|
||||||
MakeGlobalHash(bytes, data.size, res.ptr)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun base64Encode(data: ByteArray): String {
|
|
||||||
memScoped {
|
|
||||||
val resultSize = 4 * data.size / 3 + 3 + 1
|
|
||||||
val result = allocArray<ByteVar>(resultSize)
|
|
||||||
val bytes = allocArrayOf(data)
|
|
||||||
EncodeBase64(bytes, data.size, result, resultSize)
|
|
||||||
// TODO: any better way to do that without two copies?
|
|
||||||
return result.toKString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun base64Decode(encoded: String): ByteArray {
|
|
||||||
memScoped {
|
|
||||||
val bufferSize: Int = 3 * encoded.length / 4
|
|
||||||
val result = allocArray<ByteVar>(bufferSize)
|
|
||||||
val resultSize = allocArray<uint32_tVar>(1)
|
|
||||||
resultSize[0] = bufferSize
|
|
||||||
val errorCode = DecodeBase64(encoded, encoded.length, result, resultSize)
|
|
||||||
if (errorCode != 0) throw Error("Non-zero exit code of DecodeBase64: ${errorCode}")
|
|
||||||
val realSize = resultSize[0]
|
|
||||||
return result.readBytes(realSize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class LocalHash(val value: Long) : ConstValue by Int64(value)
|
internal class LocalHash(val value: Long) : ConstValue by Int64(value)
|
||||||
|
|||||||
-1
@@ -28,7 +28,6 @@ class Runtime(bitcodeFile: String) {
|
|||||||
val writableTypeInfoType = getStructTypeOrNull("WritableTypeInfo")
|
val writableTypeInfoType = getStructTypeOrNull("WritableTypeInfo")
|
||||||
val methodTableRecordType = getStructType("MethodTableRecord")
|
val methodTableRecordType = getStructType("MethodTableRecord")
|
||||||
val interfaceTableRecordType = getStructType("InterfaceTableRecord")
|
val interfaceTableRecordType = getStructType("InterfaceTableRecord")
|
||||||
val globalHashType = getStructType("GlobalHash")
|
|
||||||
val associatedObjectTableRecordType = getStructType("AssociatedObjectTableRecord")
|
val associatedObjectTableRecordType = getStructType("AssociatedObjectTableRecord")
|
||||||
|
|
||||||
val objHeaderType = getStructType("ObjHeader")
|
val objHeaderType = getStructType("ObjHeader")
|
||||||
|
|||||||
Reference in New Issue
Block a user