Propagate isExternal flag in Psi2Ir and deserializer
This commit is contained in:
committed by
TeamCityServer
parent
027f656790
commit
b0e0e62c0b
+16
-13
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFileSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -48,7 +49,7 @@ private fun isBuiltInClass(declaration: IrDeclaration): Boolean =
|
||||
fun moveBodilessDeclarationsToSeparatePlace(context: JsIrBackendContext, moduleFragment: IrModuleFragment) {
|
||||
MoveBodilessDeclarationsToSeparatePlaceLowering(context).let { moveBodiless ->
|
||||
moduleFragment.files.forEach {
|
||||
markExternalDeclarations(it)
|
||||
validateIsExternal(it)
|
||||
moveBodiless.lower(it)
|
||||
}
|
||||
}
|
||||
@@ -114,29 +115,31 @@ class MoveBodilessDeclarationsToSeparatePlaceLowering(private val context: JsIrB
|
||||
}
|
||||
}
|
||||
|
||||
fun markExternalDeclarations(packageFragment: IrPackageFragment) {
|
||||
fun validateIsExternal(packageFragment: IrPackageFragment) {
|
||||
for (declaration in packageFragment.declarations) {
|
||||
if (declaration is IrPossiblyExternalDeclaration) {
|
||||
if (declaration.isExternal) {
|
||||
markNestedExternalDeclarations(declaration)
|
||||
}
|
||||
}
|
||||
validateNestedExternalDeclarations(declaration, (declaration as? IrPossiblyExternalDeclaration)?.isExternal ?: false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun markNestedExternalDeclarations(declaration: IrDeclaration) {
|
||||
fun validateNestedExternalDeclarations(declaration: IrDeclaration, isExternalTopLevel: Boolean) {
|
||||
fun IrPossiblyExternalDeclaration.checkExternal() {
|
||||
if (isExternal != isExternalTopLevel) {
|
||||
throw error("isExternal validation failed for declaration ${declaration.render()}")
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration is IrPossiblyExternalDeclaration) {
|
||||
declaration.isExternal = true
|
||||
declaration.checkExternal()
|
||||
}
|
||||
if (declaration is IrProperty) {
|
||||
declaration.getter?.isExternal = true
|
||||
declaration.setter?.isExternal = true
|
||||
declaration.backingField?.isExternal = true
|
||||
declaration.getter?.checkExternal()
|
||||
declaration.setter?.checkExternal()
|
||||
declaration.backingField?.checkExternal()
|
||||
}
|
||||
if (declaration is IrClass) {
|
||||
declaration.declarations.forEach {
|
||||
markNestedExternalDeclarations(it)
|
||||
validateNestedExternalDeclarations(it, isExternalTopLevel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -189,7 +189,7 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
|
||||
val irFunction = with(descriptor) {
|
||||
irFactory.createFunction(
|
||||
startOffset, endOffset, origin, symbol, name, visibility, modality, IrUninitializedType,
|
||||
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect
|
||||
isInline, isEffectivelyExternal(), isTailrec, isSuspend, isOperator, isInfix, isExpect
|
||||
)
|
||||
}
|
||||
irFunction.metadata = DescriptorMetadataSource.Function(descriptor)
|
||||
|
||||
@@ -382,7 +382,7 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa
|
||||
descriptor.run {
|
||||
irFactory.createFunction(
|
||||
offset, offset, memberOrigin, it, name, visibility, modality, returnType,
|
||||
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, true
|
||||
isInline, isEffectivelyExternal(), isTailrec, isSuspend, isOperator, isInfix, isExpect, true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -26,7 +26,7 @@ class DeepCopyIrTreeWithSymbolsForFakeOverrides(typeArguments: Map<IrTypeParamet
|
||||
|
||||
// Make symbol remapper aware of the callsite's type arguments.
|
||||
// Copy IR.
|
||||
val result = irElement.transform(copier, data = null)
|
||||
val result = irElement.transform(if (parent.isEffectivelyExternal()) copierMakingExternal else copier, data = null)
|
||||
|
||||
result.patchDeclarationParents(parent)
|
||||
return result
|
||||
@@ -94,4 +94,11 @@ class DeepCopyIrTreeWithSymbolsForFakeOverrides(typeArguments: Map<IrTypeParamet
|
||||
FakeOverrideTypeRemapper(symbolRemapper, typeArguments),
|
||||
SymbolRenamer.DEFAULT
|
||||
)
|
||||
|
||||
private val copierMakingExternal = FakeOverrideCopier(
|
||||
symbolRemapper,
|
||||
FakeOverrideTypeRemapper(symbolRemapper, typeArguments),
|
||||
SymbolRenamer.DEFAULT,
|
||||
makeExternal = true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
class FakeOverrideCopier(
|
||||
private val symbolRemapper: SymbolRemapper,
|
||||
private val typeRemapper: TypeRemapper,
|
||||
private val symbolRenamer: SymbolRenamer
|
||||
private val symbolRenamer: SymbolRenamer,
|
||||
private val makeExternal: Boolean = false,
|
||||
) : DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper, symbolRenamer) {
|
||||
|
||||
private fun <T : IrFunction> T.transformFunctionChildren(declaration: T): T =
|
||||
@@ -55,7 +56,7 @@ class FakeOverrideCopier(
|
||||
declaration.modality,
|
||||
declaration.returnType,
|
||||
isInline = declaration.isInline,
|
||||
isExternal = false,
|
||||
isExternal = makeExternal,
|
||||
isTailrec = declaration.isTailrec,
|
||||
isSuspend = declaration.isSuspend,
|
||||
isExpect = declaration.isExpect,
|
||||
@@ -78,7 +79,7 @@ class FakeOverrideCopier(
|
||||
isLateinit = declaration.isLateinit,
|
||||
isDelegated = declaration.isDelegated,
|
||||
isExpect = declaration.isExpect,
|
||||
isExternal = false
|
||||
isExternal = makeExternal
|
||||
).apply {
|
||||
transformAnnotations(declaration)
|
||||
this.getter = declaration.getter?.transform()
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun SymbolTable.declareSimpleFunctionWithOverrides(
|
||||
@@ -23,7 +24,7 @@ fun SymbolTable.declareSimpleFunctionWithOverrides(
|
||||
with(descriptor) {
|
||||
irFactory.createFunction(
|
||||
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(this),
|
||||
visibility, modality, IrUninitializedType, isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect
|
||||
visibility, modality, IrUninitializedType, isInline, isEffectivelyExternal(), isTailrec, isSuspend, isOperator, isInfix, isExpect
|
||||
).also { declaration ->
|
||||
declaration.metadata = DescriptorMetadataSource.Function(this)
|
||||
}
|
||||
|
||||
+25
-8
@@ -189,6 +189,18 @@ class IrDeclarationDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private var isEffectivelyExternal = false
|
||||
|
||||
private inline fun withExternalValue(value: Boolean, fn: () -> Unit) {
|
||||
val oldExternalValue = isEffectivelyExternal
|
||||
isEffectivelyExternal = value
|
||||
try {
|
||||
fn()
|
||||
} finally {
|
||||
isEffectivelyExternal = oldExternalValue
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T> withDeserializedIrDeclarationBase(
|
||||
proto: ProtoDeclarationBase,
|
||||
block: (IrSymbol, IdSignature, Int, Int, IrDeclarationOrigin, Long) -> T
|
||||
@@ -287,7 +299,7 @@ class IrDeclarationDeserializer(
|
||||
flags.isCompanion,
|
||||
flags.isInner,
|
||||
flags.isData,
|
||||
flags.isExternal,
|
||||
flags.isExternal || isEffectivelyExternal,
|
||||
flags.isInline,
|
||||
flags.isExpect,
|
||||
flags.isFun,
|
||||
@@ -297,9 +309,11 @@ class IrDeclarationDeserializer(
|
||||
|
||||
superTypes = proto.superTypeList.map { deserializeIrType(it) }
|
||||
|
||||
proto.declarationList
|
||||
.filterNot { isSkippableFakeOverride(it, this) }
|
||||
.mapTo(declarations) { deserializeDeclaration(it) }
|
||||
withExternalValue(isExternal) {
|
||||
proto.declarationList
|
||||
.filterNot { isSkippableFakeOverride(it, this) }
|
||||
.mapTo(declarations) { deserializeDeclaration(it) }
|
||||
}
|
||||
|
||||
thisReceiver = deserializeIrValueParameter(proto.thisReceiver, -1)
|
||||
|
||||
@@ -484,7 +498,7 @@ class IrDeclarationDeserializer(
|
||||
flags.modality,
|
||||
IrUninitializedType,
|
||||
flags.isInline,
|
||||
flags.isExternal,
|
||||
flags.isExternal || isEffectivelyExternal,
|
||||
flags.isTailrec,
|
||||
flags.isSuspend,
|
||||
flags.isOperator,
|
||||
@@ -548,7 +562,7 @@ class IrDeclarationDeserializer(
|
||||
flags.visibility,
|
||||
IrUninitializedType,
|
||||
flags.isInline,
|
||||
flags.isExternal,
|
||||
flags.isExternal || isEffectivelyExternal,
|
||||
flags.isPrimary,
|
||||
flags.isExpect
|
||||
)
|
||||
@@ -570,7 +584,7 @@ class IrDeclarationDeserializer(
|
||||
type,
|
||||
flags.visibility,
|
||||
flags.isFinal,
|
||||
flags.isExternal,
|
||||
flags.isExternal || isEffectivelyExternal,
|
||||
flags.isStatic,
|
||||
)
|
||||
}.usingParent {
|
||||
@@ -615,7 +629,7 @@ class IrDeclarationDeserializer(
|
||||
flags.isConst,
|
||||
flags.isLateinit,
|
||||
flags.isDelegated,
|
||||
flags.isExternal,
|
||||
flags.isExternal || isEffectivelyExternal,
|
||||
flags.isExpect,
|
||||
flags.isFakeOverride
|
||||
)
|
||||
@@ -623,16 +637,19 @@ class IrDeclarationDeserializer(
|
||||
if (proto.hasGetter()) {
|
||||
getter = deserializeIrFunction(proto.getter).also {
|
||||
it.correspondingPropertySymbol = symbol
|
||||
it.isExternal = this.isExternal
|
||||
}
|
||||
}
|
||||
if (proto.hasSetter()) {
|
||||
setter = deserializeIrFunction(proto.setter).also {
|
||||
it.correspondingPropertySymbol = symbol
|
||||
it.isExternal = this.isExternal
|
||||
}
|
||||
}
|
||||
if (proto.hasBackingField()) {
|
||||
backingField = deserializeIrField(proto.backingField).also {
|
||||
it.correspondingPropertySymbol = symbol
|
||||
it.isExternal = this.isExternal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user