[IR] Refactored Kotlin Mangler API
- Implement abstract Ir-based, Descriptor-based mangler computers and export checkers and corresponding platform specializations - Add runtime verifier which check whether all types of mangler produces the same type of data Note: code migration is not finished yet
This commit is contained in:
+55
-17
@@ -5,25 +5,63 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinManglerImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.isInlined
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.KotlinExportChecker
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.KotlinMangleComputer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.classic.ClassicExportChecker
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.classic.ClassicKotlinManglerImpl
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.classic.ClassicMangleComputer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.DescriptorBasedKotlinManglerImpl
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.DescriptorExportCheckerVisitor
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.DescriptorMangleComputer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.ir.IrBasedKotlinManglerImpl
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.ir.IrExportCheckerVisitor
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.ir.IrMangleComputer
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
|
||||
abstract class AbstractJsMangler : KotlinManglerImpl() {
|
||||
override val IrType.isInlined: Boolean
|
||||
get() = this.isInlined()
|
||||
abstract class AbstractJsManglerIr : IrBasedKotlinManglerImpl() {
|
||||
|
||||
companion object {
|
||||
private val exportChecker = JsIrExportChecker()
|
||||
}
|
||||
|
||||
private class JsIrExportChecker : IrExportCheckerVisitor() {
|
||||
override fun IrDeclaration.isPlatformSpecificExported() = false
|
||||
}
|
||||
|
||||
private class JsIrManglerComputer(builder: StringBuilder) : IrMangleComputer(builder) {
|
||||
override fun copy(): IrMangleComputer = JsIrManglerComputer(builder)
|
||||
}
|
||||
|
||||
override fun getExportChecker(): KotlinExportChecker<IrDeclaration> = exportChecker
|
||||
|
||||
override fun getMangleComputer(prefix: String): KotlinMangleComputer<IrDeclaration> {
|
||||
return JsIrManglerComputer(StringBuilder(256))
|
||||
}
|
||||
}
|
||||
|
||||
object JsMangler : AbstractJsMangler()
|
||||
object JsManglerIr : AbstractJsManglerIr()
|
||||
|
||||
abstract class AbstractJsDescriptorMangler : DescriptorBasedKotlinManglerImpl() {
|
||||
|
||||
companion object {
|
||||
private val exportChecker = JsDescriptorExportChecker()
|
||||
}
|
||||
|
||||
private class JsDescriptorExportChecker : DescriptorExportCheckerVisitor() {
|
||||
override fun DeclarationDescriptor.isPlatformSpecificExported() = false
|
||||
}
|
||||
|
||||
private class JsDescriptorManglerComputer(builder: StringBuilder, prefix: String) : DescriptorMangleComputer(builder, prefix) {
|
||||
override fun copy(): DescriptorMangleComputer = JsDescriptorManglerComputer(builder, specialPrefix)
|
||||
}
|
||||
|
||||
override fun getExportChecker(): KotlinExportChecker<DeclarationDescriptor> = exportChecker
|
||||
|
||||
override fun getMangleComputer(prefix: String): KotlinMangleComputer<DeclarationDescriptor> {
|
||||
return JsDescriptorManglerComputer(StringBuilder(256), prefix)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* JsManglerForBE is a special verison of kotlin mangler used in case when IR is not completely correct from Type Parameter perspective.
|
||||
* I.e. usage of TypeParameter is not in TP's container. It's acceptable if only required to distinguish declaration somehow.
|
||||
*/
|
||||
object JsManglerForBE : AbstractJsMangler() {
|
||||
|
||||
override fun mangleTypeParameter(typeParameter: IrTypeParameter, typeParameterNamer: (IrTypeParameter) -> String): String =
|
||||
typeParameter.name.asString()
|
||||
}
|
||||
object JsManglerDesc : AbstractJsDescriptorMangler()
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.serialization.metadata
|
||||
|
||||
class JsKlibMetadataModuleDescriptor<out T>(
|
||||
val name: String,
|
||||
val imported: List<String>,
|
||||
val data: T
|
||||
)
|
||||
Reference in New Issue
Block a user