[JS IR BE] Move external declarations to a separate IrPackageFragment to not generate code for them
This commit is contained in:
@@ -55,6 +55,8 @@ fun compile(
|
|||||||
ExternalDependenciesGenerator(psi2IrContext.moduleDescriptor, psi2IrContext.symbolTable, psi2IrContext.irBuiltIns)
|
ExternalDependenciesGenerator(psi2IrContext.moduleDescriptor, psi2IrContext.symbolTable, psi2IrContext.irBuiltIns)
|
||||||
.generateUnboundSymbolsAsDependencies(moduleFragment)
|
.generateUnboundSymbolsAsDependencies(moduleFragment)
|
||||||
|
|
||||||
|
MoveExternalDeclarationsToSeparatePlace().lower(moduleFragment.files)
|
||||||
|
|
||||||
context.performInlining(moduleFragment)
|
context.performInlining(moduleFragment)
|
||||||
|
|
||||||
context.lower(moduleFragment.files)
|
context.lower(moduleFragment.files)
|
||||||
|
|||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 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.js.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||||
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.backend.js.lower.inline.addChild
|
||||||
|
import org.jetbrains.kotlin.ir.backend.js.utils.isEffectivelyExternal
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
|
class MoveExternalDeclarationsToSeparatePlace : FileLoweringPass {
|
||||||
|
private val packageFragment = IrExternalPackageFragmentImpl(object : IrExternalPackageFragmentSymbol {
|
||||||
|
override val descriptor: PackageFragmentDescriptor
|
||||||
|
get() = error("Operation is unsupported")
|
||||||
|
|
||||||
|
private var _owner: IrExternalPackageFragment? = null
|
||||||
|
override val owner get() = _owner!!
|
||||||
|
|
||||||
|
override val isBound get() = _owner != null
|
||||||
|
|
||||||
|
override fun bind(owner: IrExternalPackageFragment) {
|
||||||
|
_owner = owner
|
||||||
|
}
|
||||||
|
}, FqName.ROOT)
|
||||||
|
|
||||||
|
override fun lower(irFile: IrFile) {
|
||||||
|
val it = irFile.declarations.iterator()
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
val d = it.next()
|
||||||
|
|
||||||
|
if (d.isEffectivelyExternal()) {
|
||||||
|
it.remove()
|
||||||
|
packageFragment.addChild(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -9,9 +9,11 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
val IrConstructorSymbol.constructedClass get() = descriptor.constructedClass
|
val IrConstructorSymbol.constructedClass get() = descriptor.constructedClass
|
||||||
@@ -46,3 +48,5 @@ fun CallableMemberDescriptor.isFakeOverriddenFromAny(): Boolean {
|
|||||||
}
|
}
|
||||||
return overriddenDescriptors.all { it.isFakeOverriddenFromAny() }
|
return overriddenDescriptors.all { it.isFakeOverriddenFromAny() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun IrDeclaration.isEffectivelyExternal() = descriptor.isEffectivelyExternal()
|
||||||
|
|||||||
@@ -422,6 +422,8 @@ fun MemberDescriptor.isEffectivelyExternal(): Boolean {
|
|||||||
return containingClass != null && containingClass.isEffectivelyExternal()
|
return containingClass != null && containingClass.isEffectivelyExternal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun DeclarationDescriptor.isEffectivelyExternal() = this is MemberDescriptor && this.isEffectivelyExternal()
|
||||||
|
|
||||||
fun isParameterOfAnnotation(parameterDescriptor: ParameterDescriptor): Boolean =
|
fun isParameterOfAnnotation(parameterDescriptor: ParameterDescriptor): Boolean =
|
||||||
parameterDescriptor.containingDeclaration.isAnnotationConstructor()
|
parameterDescriptor.containingDeclaration.isAnnotationConstructor()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user