From 25398734926d819a2843d4f250a3451c6ff31050 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 12 Mar 2019 18:08:59 +0100 Subject: [PATCH] Remove CommonBackendContext.getClass This function is unused in backend.common (and actually throws exception in Native), therefore it makes sense to move it down to subtypes --- .../backend/common/CommonBackendContext.kt | 2 -- .../kotlin/ir/backend/js/JsIrBackendContext.kt | 17 ++++++++--------- .../kotlin/backend/jvm/JvmBackendContext.kt | 17 +++++------------ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendContext.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendContext.kt index 6f6aed9271b..233818c7aff 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendContext.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendContext.kt @@ -20,8 +20,6 @@ interface LoggingContext { interface CommonBackendContext : BackendContext, LoggingContext { override val ir: Ir - fun getClass(fqName: FqName): ClassDescriptor - fun report(element: IrElement?, irFile: IrFile?, message: String, isError: Boolean) val configuration: CompilerConfiguration diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index e3d7f85bb13..34cc472b4e0 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.ir.backend.js.utils.OperatorNames import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol @@ -182,16 +183,12 @@ class JsIrBackendContext( // classes forced to be loaded - val primitiveClassesObject = symbolTable.referenceClass( - getClass(FqName.fromSegments(listOf("kotlin", "reflect", "js", "internal", "PrimitiveClasses"))) - ) + val primitiveClassesObject = getIrClass(FqName("kotlin.reflect.js.internal.PrimitiveClasses")) - val throwableClass = symbolTable.referenceClass(getClass(JsIrBackendContext.KOTLIN_PACKAGE_FQN.child(Name.identifier("Throwable")))) + val throwableClass = getIrClass(JsIrBackendContext.KOTLIN_PACKAGE_FQN.child(Name.identifier("Throwable"))) - val primitiveCompanionObjects = primitivesWithImplicitCompanionObject().associate { - it to symbolTable.referenceClass( - getClass(JS_INTERNAL_PACKAGE_FQNAME.child(Name.identifier("${it.identifier}CompanionObject"))) - ) + val primitiveCompanionObjects = primitivesWithImplicitCompanionObject().associateWith { + getIrClass(JS_INTERNAL_PACKAGE_FQNAME.child(Name.identifier("${it.identifier}CompanionObject"))) } val coroutineImpl = ir.symbols.coroutineImpl @@ -275,9 +272,11 @@ class JsIrBackendContext( internal fun getJsInternalClass(name: String): ClassDescriptor = findClass(internalPackage.memberScope, Name.identifier(name)) - override fun getClass(fqName: FqName): ClassDescriptor = + internal fun getClass(fqName: FqName): ClassDescriptor = findClass(module.getPackage(fqName.parent()).memberScope, fqName.shortName()) + private fun getIrClass(fqName: FqName): IrClassSymbol = symbolTable.referenceClass(getClass(fqName)) + internal fun getJsInternalFunction(name: String): SimpleFunctionDescriptor = findFunctions(internalPackage.memberScope, Name.identifier(name)).single() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt index 437e69d9862..2454fe498f3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi2ir.PsiSourceManager -import org.jetbrains.kotlin.resolve.scopes.MemberScope class JvmBackendContext( val state: GenerationState, @@ -50,20 +49,14 @@ class JvmBackendContext( } } - private fun find(memberScope: MemberScope, className: String): ClassDescriptor { - return find(memberScope, Name.identifier(className)) - } - - private fun find(memberScope: MemberScope, name: Name): ClassDescriptor { - return memberScope.getContributedClassifier(name, NoLookupLocation.FROM_BACKEND) as ClassDescriptor - } - private fun getJvmInternalClass(name: String): ClassDescriptor { - return find(state.module.getPackage(FqName("kotlin.jvm.internal")).memberScope, name) + return getClass(FqName("kotlin.jvm.internal").child(Name.identifier(name))) } - override fun getClass(fqName: FqName): ClassDescriptor { - return find(state.module.getPackage(fqName.parent()).memberScope, fqName.shortName()) + private fun getClass(fqName: FqName): ClassDescriptor { + return state.module.getPackage(fqName.parent()).memberScope.getContributedClassifier( + fqName.shortName(), NoLookupLocation.FROM_BACKEND + ) as ClassDescriptor? ?: error("Class is not found: $fqName") } fun getIrClass(fqName: FqName): IrClassSymbol {