Changes after code review

This commit is contained in:
Alexander Gorshenev
2019-03-14 20:17:23 +03:00
committed by alexander-gorshenev
parent f8be378a65
commit ee7660065b
18 changed files with 268 additions and 792 deletions
+9 -14
View File
@@ -74,11 +74,6 @@ message IrDeclarationOrigin {
}
}
message Name {
required String name = 1;
required bool is_special = 2;
}
/* ------ Top Level---------------------------------------------- */
message IrDeclarationContainer {
@@ -99,7 +94,7 @@ message IrFile {
}
message IrModule {
required Name name = 1;
required String name = 1;
repeated IrFile file = 2;
required IrSymbolTable symbol_table = 3;
required IrTypeTable type_table = 4;
@@ -526,7 +521,7 @@ message IrFunction {
}
message IrFunctionBase {
required Name name = 1;
required String name = 1;
required Visibility visibility = 2;
required bool is_inline = 3;
required bool is_external = 4;
@@ -548,7 +543,7 @@ message IrConstructor {
message IrField {
required IrSymbol symbol = 1;
optional IrExpression initializer = 2;
required Name name = 3;
required String name = 3;
required Visibility visibility = 4;
required bool is_final = 5;
required bool is_external = 6;
@@ -558,7 +553,7 @@ message IrField {
message IrProperty {
optional DescriptorReference descriptor_reference = 1; // IrProperty doesn't have a symbol at all. Preserve this rudiment for now.
required Name name = 2;
required String name = 2;
required Visibility visibility = 3;
required ModalityKind modality = 4;
required bool is_var = 5;
@@ -572,7 +567,7 @@ message IrProperty {
}
message IrVariable {
required Name name = 1;
required String name = 1;
required IrSymbol symbol = 2;
required IrTypeIndex type = 3;
required bool is_var = 4;
@@ -599,7 +594,7 @@ enum ModalityKind { // It is ModalityKind to not clash with Modality in descript
message IrValueParameter {
required IrSymbol symbol = 1;
required Name name = 2;
required String name = 2;
required int32 index = 3;
required IrTypeIndex type = 4;
optional IrTypeIndex vararg_element_type = 5;
@@ -610,7 +605,7 @@ message IrValueParameter {
message IrTypeParameter {
required IrSymbol symbol = 1;
required Name name = 2;
required String name = 2;
required int32 index = 3;
required IrTypeVariance variance = 4;
repeated IrTypeIndex super_type = 5;
@@ -623,7 +618,7 @@ message IrTypeParameterContainer {
message IrClass {
required IrSymbol symbol = 1;
required Name name = 2;
required String name = 2;
required ClassKind kind = 3;
required Visibility visibility = 4;
required ModalityKind modality = 5;
@@ -643,7 +638,7 @@ message IrEnumEntry {
required IrSymbol symbol = 1;
optional IrExpression initializer = 2;
optional IrDeclaration corresponding_class = 3;
required Name name = 4;
required String name = 4;
}
message IrAnonymousInit {
@@ -64,9 +64,7 @@ private const val INDEX_HEADER_SIZE = 4 // sizeof(Int).
class CombinedIrFileWriter(val declarationCount: Int) {
private var currentDeclaration = 0
private var currentPosition = 0
private val file = Files.createTempFile("ir", "").toFile().also {
it.deleteOnExit()
}
private val file = Files.createTempFile("ir", "").toFile()
private val randomAccessFile = RandomAccessFile(file.path, "rw")
init {
@@ -178,7 +178,7 @@ class NaiveSourceBasedFileEntryImpl(override val name: String, val lineStartOffs
override fun getColumnNumber(offset: Int): Int {
assert(offset != UNDEFINED_OFFSET)
if (offset == SYNTHETIC_OFFSET) return 0
var lineNumber = getLineNumber(offset)
val lineNumber = getLineNumber(offset)
return offset - lineStartOffsets[lineNumber]
}
@@ -22,20 +22,17 @@ class DescriptorTable {
abstract class DeclarationTable(val builtIns: IrBuiltIns, val descriptorTable: DescriptorTable, mangler: KotlinMangler): KotlinMangler by mangler {
private val table = mutableMapOf<IrDeclaration, UniqId>()
val debugIndex = mutableMapOf<UniqId, String>()
val descriptors = descriptorTable
abstract protected var currentIndex: Long
protected var initialized: Boolean = false
protected abstract var currentIndex: Long
open fun loadKnownBuiltins() {
open fun loadKnownBuiltins(): Long {
builtIns.knownBuiltins.forEach {
table.put(it, UniqId(currentIndex++, false))
}
initialized = true
return currentIndex
}
fun uniqIdByDeclaration(value: IrDeclaration) = table.getOrPut(value) {
if (!initialized) error("DeclarationTable has not been initialized")
computeUniqIdByDeclaration(value)
}
@@ -28,7 +28,7 @@ abstract class DescriptorReferenceDeserializer(
protected fun getContributedDescriptors(packageFqNameString: String, name: String): Collection<DeclarationDescriptor> {
val packageFqName = packageFqNameString.let {
if (it == "<root>") FqName.ROOT else FqName(it)
}// TODO: whould we store an empty string in the protobuf?
}// TODO: would we store an empty string in the protobuf?
val contributedName = if (name.startsWith("<get-") || name.startsWith("<set-")) {
name.substring(5, name.length - 1) // FIXME: rework serialization format.
@@ -31,9 +31,6 @@ import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrDeclarator.D
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrType.KindCase.*
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrVarargElement.VarargElementCase
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrTypeArgument.KindCase.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.Variance
@@ -55,9 +52,9 @@ abstract class IrModuleDeserializer(
abstract fun deserializeString(proto: KotlinIr.String): String
abstract fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase): IrLoopBase
private fun deserializeName(proto: KotlinIr.Name): Name {
val name = deserializeString(proto.name)
return if (proto.isSpecial) Name.special(name) else Name.identifier(name)
private fun deserializeName(proto: KotlinIr.String): Name {
val name = deserializeString(proto)
return Name.guessByFirstCharacter(name)
}
private fun deserializeTypeArguments(proto: KotlinIr.TypeArguments): List<IrType> {
@@ -88,12 +88,7 @@ open class IrModuleSerializer(
return proto.build()
}
fun serializeName(name: Name): KotlinIr.Name {
val proto = KotlinIr.Name.newBuilder()
.setName(serializeString(name.toString()))
.setIsSpecial(name.isSpecial)
return proto.build()
}
fun serializeName(name: Name): KotlinIr.String = serializeString(name.toString())
/* ------- IrSymbols -------------------------------------------------------- */
@@ -27,11 +27,11 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
import java.io.File
abstract class KotlinIrLinker(
currentModule: ModuleDescriptor,
logger: LoggingContext,
builtIns: IrBuiltIns,
symbolTable: SymbolTable,
private val forwardModuleDescriptor: ModuleDescriptor?)
private val forwardModuleDescriptor: ModuleDescriptor?,
val firstKnownBuiltinsIndex: Long)
: IrModuleDeserializer(logger, builtIns, symbolTable),
DescriptorUniqIdAware {
@@ -50,9 +50,18 @@ abstract class KotlinIrLinker(
abstract protected val descriptorReferenceDeserializer: DescriptorReferenceDeserializer
private val descriptorToDirectoryMap = mutableMapOf<ModuleDescriptor, File>()
protected val indexAfterKnownBuiltins = loadKnownBuiltinSymbols()
private fun irDirectory(m: ModuleDescriptor): File = descriptorToDirectoryMap[m]!!
fun loadKnownBuiltinSymbols(): Long {
var currentIndex = firstKnownBuiltinsIndex
builtIns.knownBuiltins.forEach {
require(it is IrFunction)
deserializedSymbols.put(UniqIdKey(null, UniqId(currentIndex, isLocal = false)), it.symbol)
assert(symbolTable.referenceSimpleFunction(it.descriptor) == it.symbol)
currentIndex++
}
return currentIndex
}
private fun referenceDeserializedSymbol(proto: KotlinIr.IrSymbolData, descriptor: DeclarationDescriptor?): IrSymbol = when (proto.kind) {
KotlinIr.IrSymbolKind.ANONYMOUS_INIT_SYMBOL ->
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.backend.common.serialization.*
import org.jetbrains.kotlin.backend.common.serialization.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.*
@@ -21,7 +21,7 @@ internal val DeclarationDescriptor.isExpectMember: Boolean
internal val DeclarationDescriptor.isSerializableExpectClass: Boolean
get() = this is ClassDescriptor && ExpectedActualDeclarationChecker.shouldGenerateExpectClass(this)
tailrec internal fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
internal tailrec fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
return if (this is PackageFragmentDescriptor) this
else this.containingDeclaration!!.findPackage()
}
@@ -1,10 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir.backend.common.serialization
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name