[IR] Get rid of minor symbol.descriptor usages

This commit is contained in:
Mikhail Glukhikh
2020-05-18 18:25:09 +03:00
parent bf66929b5b
commit 724101cdd2
11 changed files with 14 additions and 17 deletions
@@ -250,7 +250,7 @@ open class DefaultParameterInjector(
val (symbol, params) = parametersForCall(expression) ?: return expression val (symbol, params) = parametersForCall(expression) ?: return expression
for (i in 0 until expression.typeArgumentsCount) { for (i in 0 until expression.typeArgumentsCount) {
log { "${symbol.descriptor}[$i]: ${expression.getTypeArgument(i)}" } log { "$symbol[$i]: ${expression.getTypeArgument(i)}" }
} }
symbol.owner.typeParameters.forEach { log { "${symbol.owner}[${it.index}] : $it" } } symbol.owner.typeParameters.forEach { log { "${symbol.owner}[${it.index}] : $it" } }
@@ -590,7 +590,7 @@ class ExpressionCodegen(
val index = frameMap.getIndex(irSymbol) val index = frameMap.getIndex(irSymbol)
if (index >= 0) if (index >= 0)
return index return index
val dump = if (irSymbol.isBound) irSymbol.owner.dump() else irSymbol.descriptor.toString() val dump = if (irSymbol.isBound) irSymbol.owner.dump() else "??? unbound symbol ???"
throw AssertionError("Non-mapped local declaration: $dump\n in ${irFunction.dump()}") throw AssertionError("Non-mapped local declaration: $dump\n in ${irFunction.dump()}")
} }
@@ -97,7 +97,6 @@ class IrSourceCompilerForInline(
callDefault: Boolean, callDefault: Boolean,
asmMethod: Method asmMethod: Method
): SMAPAndMethodNode { ): SMAPAndMethodNode {
assert(callableDescriptor == callee.symbol.descriptor.original) { "Expected $callableDescriptor got ${callee.descriptor.original}" }
return ClassCodegen.getOrCreate(callee.parentAsClass, codegen.context).generateMethodNode(callee) return ClassCodegen.getOrCreate(callee.parentAsClass, codegen.context).generateMethodNode(callee)
} }
@@ -292,10 +292,8 @@ class IrBuiltIns(
private fun TypeConstructor.makeNullableType() = KotlinTypeFactory.simpleType(Annotations.EMPTY, this, listOf(), true) private fun TypeConstructor.makeNullableType() = KotlinTypeFactory.simpleType(Annotations.EMPTY, this, listOf(), true)
val dataClassArrayMemberHashCodeSymbol = defineOperator("dataClassArrayMemberHashCode", intType, listOf(anyType)) val dataClassArrayMemberHashCodeSymbol = defineOperator("dataClassArrayMemberHashCode", intType, listOf(anyType))
val dataClassArrayMemberHashCode = dataClassArrayMemberHashCodeSymbol.descriptor
val dataClassArrayMemberToStringSymbol = defineOperator("dataClassArrayMemberToString", stringType, listOf(anyNType)) val dataClassArrayMemberToStringSymbol = defineOperator("dataClassArrayMemberToString", stringType, listOf(anyNType))
val dataClassArrayMemberToString = dataClassArrayMemberToStringSymbol.descriptor
fun function(n: Int): IrClassSymbol = functionFactory.functionN(n).symbol fun function(n: Int): IrClassSymbol = functionFactory.functionN(n).symbol
fun suspendFunction(n: Int): IrClassSymbol = functionFactory.suspendFunctionN(n).symbol fun suspendFunction(n: Int): IrClassSymbol = functionFactory.suspendFunctionN(n).symbol
@@ -32,7 +32,7 @@ abstract class IrNoArgumentsCallableReferenceBase(
IrCallableReference { IrCallableReference {
private fun throwNoValueArguments(): Nothing { private fun throwNoValueArguments(): Nothing {
throw UnsupportedOperationException("Property reference ${symbol.descriptor} has no value arguments") throw UnsupportedOperationException("Property reference $symbol has no value arguments")
} }
override fun getValueArgument(index: Int): IrExpression? = throwNoValueArguments() override fun getValueArgument(index: Int): IrExpression? = throwNoValueArguments()
@@ -48,13 +48,13 @@ abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolO
private var _owner: B? = null private var _owner: B? = null
override val owner: B override val owner: B
get() = _owner ?: throw IllegalStateException("Symbol for $descriptor is unbound") get() = _owner ?: throw IllegalStateException("Symbol is unbound")
override fun bind(owner: B) { override fun bind(owner: B) {
if (_owner == null) { if (_owner == null) {
_owner = owner _owner = owner
} else { } else {
throw IllegalStateException("${javaClass.simpleName} for $descriptor is already bound") throw IllegalStateException("${javaClass.simpleName} is already bound")
} }
} }
@@ -157,7 +157,7 @@ open class DeepCopySymbolRemapper(
private fun <T : IrSymbol> Map<T, T>.getDeclared(symbol: T) = private fun <T : IrSymbol> Map<T, T>.getDeclared(symbol: T) =
getOrElse(symbol) { getOrElse(symbol) {
throw IllegalArgumentException("Non-remapped symbol $symbol ${symbol.descriptor}") throw IllegalArgumentException("Non-remapped symbol $symbol")
} }
private fun <T : IrSymbol> Map<T, T>.getReferenced(symbol: T) = private fun <T : IrSymbol> Map<T, T>.getReferenced(symbol: T) =
@@ -196,14 +196,14 @@ open class DeepCopySymbolRemapper(
when (symbol) { when (symbol) {
is IrValueParameterSymbol -> valueParameters.getReferenced(symbol) is IrValueParameterSymbol -> valueParameters.getReferenced(symbol)
is IrVariableSymbol -> variables.getReferenced(symbol) is IrVariableSymbol -> variables.getReferenced(symbol)
else -> throw IllegalArgumentException("Unexpected symbol $symbol ${symbol.descriptor}") else -> throw IllegalArgumentException("Unexpected symbol $symbol")
} }
override fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol = override fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol =
when (symbol) { when (symbol) {
is IrSimpleFunctionSymbol -> functions.getReferenced(symbol) is IrSimpleFunctionSymbol -> functions.getReferenced(symbol)
is IrConstructorSymbol -> constructors.getReferenced(symbol) is IrConstructorSymbol -> constructors.getReferenced(symbol)
else -> throw IllegalArgumentException("Unexpected symbol $symbol ${symbol.descriptor}") else -> throw IllegalArgumentException("Unexpected symbol $symbol")
} }
override fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol = override fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol =
@@ -213,7 +213,7 @@ open class DeepCopySymbolRemapper(
when (symbol) { when (symbol) {
is IrClassSymbol -> classes.getReferenced(symbol) is IrClassSymbol -> classes.getReferenced(symbol)
is IrTypeParameterSymbol -> typeParameters.getReferenced(symbol) is IrTypeParameterSymbol -> typeParameters.getReferenced(symbol)
else -> throw IllegalArgumentException("Unexpected symbol $symbol ${symbol.descriptor}") else -> throw IllegalArgumentException("Unexpected symbol $symbol")
} }
override fun getReferencedTypeAlias(symbol: IrTypeAliasSymbol): IrTypeAliasSymbol = typeAliases.getReferenced(symbol) override fun getReferencedTypeAlias(symbol: IrTypeAliasSymbol): IrTypeAliasSymbol = typeAliases.getReferenced(symbol)
@@ -32,7 +32,7 @@ class ExternalDependenciesGenerator(
fun generateUnboundSymbolsAsDependencies() { fun generateUnboundSymbolsAsDependencies() {
if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) { if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
require(symbolTable.unboundTypeParameters.isEmpty()) { require(symbolTable.unboundTypeParameters.isEmpty()) {
"Unbound type parameters are forbidden: ${symbolTable.unboundTypeParameters.map { it.descriptor }}" "Unbound type parameters are forbidden: ${symbolTable.unboundTypeParameters}"
} }
} }
// There should be at most one DeclarationStubGenerator (none in closed world?) // There should be at most one DeclarationStubGenerator (none in closed world?)
@@ -739,7 +739,7 @@ internal fun IrTypeAliasSymbol.renderTypeAliasFqn(): String =
if (isBound) if (isBound)
StringBuilder().also { owner.renderDeclarationFqn(it) }.toString() StringBuilder().also { owner.renderDeclarationFqn(it) }.toString()
else else
"<unbound $this: ${this.descriptor}>" "<unbound $this>"
internal fun IrClass.renderClassFqn(): String = internal fun IrClass.renderClassFqn(): String =
StringBuilder().also { renderDeclarationFqn(it) }.toString() StringBuilder().also { renderDeclarationFqn(it) }.toString()
@@ -165,7 +165,7 @@ open class SymbolTable(
if (s == null) { if (s == null) {
val new = orElse() val new = orElse()
assert(unboundSymbols.add(new)) { assert(unboundSymbols.add(new)) {
"Symbol for ${new.descriptor} was already referenced" "Symbol for $new was already referenced"
} }
set(d0, new) set(d0, new)
return new return new
@@ -283,7 +283,7 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
private fun IrSymbol.checkBinding(kind: String, irElement: IrElement) { private fun IrSymbol.checkBinding(kind: String, irElement: IrElement) {
if (!isBound) { if (!isBound) {
error("${javaClass.simpleName} $descriptor is unbound @$kind ${irElement.render()}") error("${javaClass.simpleName} descriptor is unbound @$kind ${irElement.render()}")
} else { } else {
val irDeclaration = owner as? IrDeclaration val irDeclaration = owner as? IrDeclaration
if (irDeclaration != null) { if (irDeclaration != null) {
@@ -297,7 +297,7 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
val otherSymbol = symbolForDeclaration.getOrPut(owner) { this } val otherSymbol = symbolForDeclaration.getOrPut(owner) { this }
if (this != otherSymbol) { if (this != otherSymbol) {
error("Multiple symbols for $descriptor @$kind ${irElement.render()}") error("Multiple symbols for descriptor of @$kind ${irElement.render()}")
} }
} }