IR: make IrMetadataSourceOwner.metadata mutable

To avoid casting to specific Ir*Impl elements at call sites.

Also inherit from IrMetadataSourceOwner only where it's needed: class,
file, function, property. Previously this field was always null and took
some space for things like value parameters, type parameters, etc.
This commit is contained in:
Alexander Udalov
2020-07-07 16:49:57 +02:00
parent 689887c94d
commit dbad81473e
32 changed files with 86 additions and 86 deletions
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
@@ -94,7 +93,7 @@ class Fir2IrVisitor(
it.accept(this@Fir2IrVisitor, data) as? IrConstructorCall
}
(this as IrFileImpl).metadata = FirMetadataSource.File(file, components.session)
metadata = FirMetadataSource.File(file, components.session)
}
}
@@ -39,10 +39,6 @@ abstract class AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrSym
lateinit var typeParameters: List<IrTypeParameter>
override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
override lateinit var parent: IrDeclarationParent
@ObsoleteDescriptorBasedAPI
@@ -54,4 +50,4 @@ abstract class AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrSym
callGenerator.convertToIrConstructorCall(it) as? IrConstructorCall
}
}
}
}
@@ -170,6 +170,10 @@ class Fir2IrLazyClass(
result
}
override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
private fun FirNamedFunctionSymbol.isAbstractMethodOfAny(): Boolean {
val fir = fir
if (fir.modality != Modality.ABSTRACT) return false
@@ -194,4 +198,4 @@ class Fir2IrLazyClass(
typeParameters = typeParameters.transformIfNeeded(transformer, data)
declarations.transform { it.transform(transformer, data) }
}
}
}
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.fir.backend.toIrType
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.symbols.Fir2IrConstructorSymbol
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.types.IrType
@@ -110,6 +107,10 @@ class Fir2IrLazyConstructor(
}
}
override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitConstructor(this, data)
}
@@ -133,4 +134,4 @@ class Fir2IrLazyConstructor(
body = body?.transform(transformer, data)
}
}
}
@@ -150,6 +150,10 @@ class Fir2IrLazyProperty(
)
}
override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitProperty(this, data)
}
@@ -165,4 +169,4 @@ class Fir2IrLazyProperty(
getter = getter?.run { transform(transformer, data) as IrSimpleFunction }
setter = setter?.run { transform(transformer, data) as IrSimpleFunction }
}
}
}
@@ -132,6 +132,10 @@ class Fir2IrLazySimpleFunction(
?.filterIsInstance<IrSimpleFunctionSymbol>().orEmpty()
}
override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitSimpleFunction(this, data)
}
@@ -155,4 +159,4 @@ class Fir2IrLazySimpleFunction(
body = body?.transform(transformer, data)
}
}
}