[FIR2IR] Add primitive signature composer & use it for external classes
This commit is contained in:
@@ -354,6 +354,14 @@ class Fir2IrClassifierStorage(
|
|||||||
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) {
|
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) {
|
||||||
return createIrClass(firClass).symbol
|
return createIrClass(firClass).symbol
|
||||||
}
|
}
|
||||||
|
val signature = signatureComposer.composeSignature(firClass)
|
||||||
|
symbolTable.referenceClassIfAny(signature)?.let { irClassSymbol ->
|
||||||
|
val irClass = irClassSymbol.owner
|
||||||
|
classCache[firClass as FirRegularClass] = irClass
|
||||||
|
processClassHeader(firClass, irClass)
|
||||||
|
declarationStorage.preCacheBuiltinClassMembers(firClass, irClass)
|
||||||
|
return irClassSymbol
|
||||||
|
}
|
||||||
// TODO: remove all this code and change to unbound symbol creation
|
// TODO: remove all this code and change to unbound symbol creation
|
||||||
val classId = firClassSymbol.classId
|
val classId = firClassSymbol.classId
|
||||||
val parentId = classId.outerClassId
|
val parentId = classId.outerClassId
|
||||||
|
|||||||
@@ -18,4 +18,5 @@ interface Fir2IrComponents {
|
|||||||
val classifierStorage: Fir2IrClassifierStorage
|
val classifierStorage: Fir2IrClassifierStorage
|
||||||
val declarationStorage: Fir2IrDeclarationStorage
|
val declarationStorage: Fir2IrDeclarationStorage
|
||||||
val typeConverter: Fir2IrTypeConverter
|
val typeConverter: Fir2IrTypeConverter
|
||||||
|
val signatureComposer: Fir2IrSignatureComposer
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.backend
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
|
import org.jetbrains.kotlin.fir.signaturer.FirBasedSignatureComposer
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
|
|
||||||
@@ -19,4 +20,6 @@ class Fir2IrComponentsStorage(
|
|||||||
override lateinit var classifierStorage: Fir2IrClassifierStorage
|
override lateinit var classifierStorage: Fir2IrClassifierStorage
|
||||||
override lateinit var declarationStorage: Fir2IrDeclarationStorage
|
override lateinit var declarationStorage: Fir2IrDeclarationStorage
|
||||||
override lateinit var typeConverter: Fir2IrTypeConverter
|
override lateinit var typeConverter: Fir2IrTypeConverter
|
||||||
|
|
||||||
|
override val signatureComposer = FirBasedSignatureComposer()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
|
|
||||||
|
interface Fir2IrSignatureComposer {
|
||||||
|
fun composeSignature(declaration: FirDeclaration): IdSignature
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.signaturer
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
|
import org.jetbrains.kotlin.fir.backend.Fir2IrSignatureComposer
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.fir.render
|
||||||
|
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||||
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
|
|
||||||
|
class FirBasedSignatureComposer : Fir2IrSignatureComposer {
|
||||||
|
|
||||||
|
class SignatureBuilder : FirVisitorVoid() {
|
||||||
|
var hashId: Long? = null
|
||||||
|
var mask = 0L
|
||||||
|
|
||||||
|
private fun setExpected(f: Boolean) {
|
||||||
|
mask = mask or IdSignature.Flags.IS_EXPECT.encode(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitElement(element: FirElement) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitRegularClass(regularClass: FirRegularClass) {
|
||||||
|
setExpected(regularClass.isExpect)
|
||||||
|
//platformSpecificClass(descriptor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun composeSignature(declaration: FirDeclaration): IdSignature {
|
||||||
|
val builder = SignatureBuilder()
|
||||||
|
declaration.accept(builder)
|
||||||
|
if (declaration is FirRegularClass && declaration.visibility != Visibilities.LOCAL) {
|
||||||
|
val classId = declaration.classId
|
||||||
|
return IdSignature.PublicSignature(classId.packageFqName, classId.relativeClassName, builder.hashId, builder.mask)
|
||||||
|
}
|
||||||
|
throw AssertionError("Unsupported FIR declaration in signature composer: ${declaration.render()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -421,6 +421,9 @@ open class SymbolTable(
|
|||||||
override fun referenceClass(descriptor: ClassDescriptor) =
|
override fun referenceClass(descriptor: ClassDescriptor) =
|
||||||
classSymbolTable.referenced(descriptor) { createClassSymbol(descriptor) }
|
classSymbolTable.referenced(descriptor) { createClassSymbol(descriptor) }
|
||||||
|
|
||||||
|
fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? =
|
||||||
|
classSymbolTable.get(sig)
|
||||||
|
|
||||||
override fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol =
|
override fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol =
|
||||||
classSymbolTable.run {
|
classSymbolTable.run {
|
||||||
if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(descriptor, sig) }
|
if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(descriptor, sig) }
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
class MyCollection<T>: Collection<T> {
|
class MyCollection<T>: Collection<T> {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// SKIP_JDK6
|
// SKIP_JDK6
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
class MyCollection<T> : Collection<List<Iterator<T>>> {
|
class MyCollection<T> : Collection<List<Iterator<T>>> {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
class Queue<T>(override val size: Int) : Collection<T> {
|
class Queue<T>(override val size: Int) : Collection<T> {
|
||||||
override fun contains(element: T): Boolean = TODO()
|
override fun contains(element: T): Boolean = TODO()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
Vendored
-1
@@ -1,5 +1,4 @@
|
|||||||
// !LANGUAGE: +InlineClasses
|
// !LANGUAGE: +InlineClasses
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
inline class UInt(val x: Int)
|
inline class UInt(val x: Int)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
open class A1 {
|
open class A1 {
|
||||||
open val size: Int = 56
|
open val size: Int = 56
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// SKIP_JDK6
|
// SKIP_JDK6
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ FILE fqName:<root> fileName:/dataClassesGeneric.kt
|
|||||||
$this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name:<this> type:<root>.Test2<T of <root>.Test2>
|
$this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name:<this> type:<root>.Test2<T of <root>.Test2>
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in <root>.Test2'
|
RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in <root>.Test2'
|
||||||
CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null
|
CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Number' type=kotlin.Int origin=null
|
||||||
$this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of <root>.Test2 visibility:private [final]' type=T of <root>.Test2 origin=null
|
$this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of <root>.Test2 visibility:private [final]' type=T of <root>.Test2 origin=null
|
||||||
receiver: GET_VAR '<this>: <root>.Test2<T of <root>.Test2> declared in <root>.Test2.hashCode' type=<root>.Test2<T of <root>.Test2> origin=null
|
receiver: GET_VAR '<this>: <root>.Test2<T of <root>.Test2> declared in <root>.Test2.hashCode' type=<root>.Test2<T of <root>.Test2> origin=null
|
||||||
FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:<root>.Test2<T of <root>.Test2>) returnType:kotlin.String
|
FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:<root>.Test2<T of <root>.Test2>) returnType:kotlin.String
|
||||||
|
|||||||
Reference in New Issue
Block a user