[FIR2IR] Implement JvmBackendClassResolver for boxing optimizer

This commit is contained in:
simon.ogorodnik
2020-03-24 02:22:12 +03:00
parent d71939728a
commit 0afbf25943
10 changed files with 75 additions and 9 deletions
+1
View File
@@ -258,6 +258,7 @@ extra["compilerModules"] = arrayOf(
":compiler:fir:psi2fir",
":compiler:fir:lightTree",
":compiler:fir:fir2ir",
":compiler:fir:fir2ir:jvm-backend",
":compiler:fir:java",
":compiler:fir:jvm",
":compiler:fir:checkers",
@@ -40,13 +40,18 @@ class JvmBackendClassResolverForModuleWithDependencies(
override fun resolveToClassDescriptors(type: Type): List<ClassDescriptor> {
if (type.sort != Type.OBJECT) return emptyList()
val className = type.className
val lastDotIndex = className.lastIndexOf('.')
val packageFQN = if (lastDotIndex >= 0) FqName(className.substring(0, lastDotIndex)) else FqName.ROOT
val classRelativeNameWithDollars = if (lastDotIndex >= 0) className.substring(lastDotIndex + 1) else className
val classFQN = FqName(classRelativeNameWithDollars.replace('$', '.'))
val platformClass = moduleDescriptor.findClassAcrossModuleDependencies(ClassId(packageFQN, classFQN, false)) ?: return emptyList()
val platformClass = moduleDescriptor.findClassAcrossModuleDependencies(type.classId) ?: return emptyList()
return JavaToKotlinClassMap.mapPlatformClass(platformClass) + platformClass
}
}
val Type.classId: ClassId
get() {
val className = this.className
val lastDotIndex = className.lastIndexOf('.')
val packageFQN = if (lastDotIndex >= 0) FqName(className.substring(0, lastDotIndex)) else FqName.ROOT
val classRelativeNameWithDollars = if (lastDotIndex >= 0) className.substring(lastDotIndex + 1) else className
val classFQN = FqName(classRelativeNameWithDollars.replace('$', '.'))
return ClassId(packageFQN, classFQN, false)
}
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2018 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.
*/
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
compileOnly(project(":core:descriptors"))
compileOnly(project(":compiler:fir:cones"))
compileOnly(project(":compiler:fir:resolve"))
compileOnly(project(":compiler:fir:tree"))
compileOnly(project(":compiler:fir:fir2ir"))
compileOnly(project(":compiler:ir.tree"))
compileOnly(project(":compiler:ir.psi2ir"))
compileOnly(project(":compiler:ir.backend.common"))
compileOnly(project(":compiler:backend"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core", "asm-all", rootProject = rootProject) }
}
sourceSets {
"main" { projectDefault() }
}
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2020 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.fir.backend.jvm
import org.jetbrains.kotlin.codegen.JvmBackendClassResolver
import org.jetbrains.kotlin.codegen.classId
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.org.objectweb.asm.Type
class FirJvmBackendClassResolver(val components: Fir2IrComponents) : JvmBackendClassResolver {
override fun resolveToClassDescriptors(type: Type): List<ClassDescriptor> {
if (type.sort != Type.OBJECT) return emptyList()
val symbol = components.session.firSymbolProvider.getClassLikeSymbolByFqName(type.classId) ?: return emptyList()
require(symbol is FirClassSymbol<*>)
return listOf(components.classifierStorage.getIrClassSymbol(symbol).descriptor)
}
}
@@ -204,7 +204,7 @@ class Fir2IrConverter(
}
externalDependenciesGenerator.generateUnboundSymbolsAsDependencies()
return Fir2IrResult(irModuleFragment, symbolTable, sourceManager)
return Fir2IrResult(irModuleFragment, symbolTable, sourceManager, components)
}
}
}
@@ -9,4 +9,4 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val sourceManager: PsiSourceManager)
data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val sourceManager: PsiSourceManager, val components: Fir2IrComponents)
+2
View File
@@ -15,6 +15,8 @@ dependencies {
testCompile(project(":compiler:fir:psi2fir"))
testCompile(project(":compiler:fir:lightTree"))
testCompile(project(":compiler:fir:fir2ir"))
testCompile(project(":compiler:fir:jvm"))
testCompile(project(":compiler:fir:fir2ir:jvm-backend"))
testCompile(project(":compiler:fir:cones"))
testCompile(project(":compiler:fir:resolve"))
testCompile(project(":compiler:fir:checkers"))
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.fir.backend.Fir2IrConverter
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendClassResolver
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
import org.jetbrains.kotlin.fir.createSession
import org.jetbrains.kotlin.fir.resolve.firProvider
@@ -131,7 +132,7 @@ object GenerationUtils {
throw e
}
}
val (moduleFragment, symbolTable, sourceManager) =
val (moduleFragment, symbolTable, sourceManager, components) =
Fir2IrConverter.createModuleFragment(session, firFiles, configuration.languageVersionSettings, signaturer = IdSignatureDescriptor(
JvmManglerDesc()))
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
@@ -143,6 +144,8 @@ object GenerationUtils {
codegenFactory
).isIrBackend(
true
).jvmBackendClassResolver(
FirJvmBackendClassResolver(components)
).build()
generationState.beforeCompile()
+1
View File
@@ -51,6 +51,7 @@ val projectsToShadow by extra(listOf(
":compiler:fir:jvm",
":compiler:fir:psi2fir",
":compiler:fir:fir2ir",
":compiler:fir:fir2ir:jvm-backend",
":compiler:frontend",
":compiler:frontend.common",
":compiler:frontend.java",
+1
View File
@@ -83,6 +83,7 @@ include ":kotlin-build-common",
":compiler:fir:psi2fir",
":compiler:fir:lightTree",
":compiler:fir:fir2ir",
":compiler:fir:fir2ir:jvm-backend",
":compiler:fir:resolve",
":compiler:fir:java",
":compiler:fir:modularized-tests",