[FIR2IR] Use signature composer to read external callables

This commit is contained in:
Mikhail Glukhikh
2020-06-01 12:20:35 +03:00
parent 9ea69b4b3c
commit 8c422fbfc7
3 changed files with 24 additions and 8 deletions
@@ -874,6 +874,11 @@ class Fir2IrDeclarationStorage(
is FirSimpleFunction, is FirAnonymousFunction -> {
getCachedIrFunction(firDeclaration)?.let { return it.symbol }
val irParent = findIrParent(firDeclaration)
symbolTable.referenceSimpleFunctionIfAny(signatureComposer.composeSignature(firDeclaration))?.let { irFunctionSymbol ->
val irFunction = irFunctionSymbol.owner
functionCache[firDeclaration] = irFunction
return irFunctionSymbol
}
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply {
setAndModifyParent(irParent)
@@ -891,6 +896,11 @@ class Fir2IrDeclarationStorage(
is FirProperty -> {
propertyCache[fir]?.let { return it.symbol }
val irParent = findIrParent(fir)
symbolTable.referencePropertyIfAny(signatureComposer.composeSignature(fir))?.let { irPropertySymbol ->
val irProperty = irPropertySymbol.owner
propertyCache[fir] = irProperty
return irPropertySymbol
}
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
createIrProperty(fir, irParent, origin = parentOrigin).apply {
setAndModifyParent(irParent)
@@ -633,6 +633,9 @@ open class SymbolTable(
override fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol =
propertySymbolTable.referenced(descriptor) { createPropertySymbol(descriptor) }
fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? =
propertySymbolTable.get(sig)
override fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol =
propertySymbolTable.run {
if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(descriptor, sig) }
@@ -718,6 +721,9 @@ open class SymbolTable(
override fun referenceSimpleFunction(descriptor: FunctionDescriptor) =
simpleFunctionSymbolTable.referenced(descriptor) { createSimpleFunctionSymbol(descriptor) }
fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? =
simpleFunctionSymbolTable.get(sig)
override fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol {
return simpleFunctionSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) } else
@@ -6,27 +6,27 @@ FILE fqName:<root> fileName:/enhancedNullabilityInForLoop.kt
BLOCK_BODY
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_0 type:kotlin.collections.MutableIterator<<root>.P?> [val]
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=FOR_LOOP_ITERATOR
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=FOR_LOOP_ITERATOR
$this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<<root>.P?>? declared in <root>.J' type=kotlin.collections.List<<root>.P?>? origin=null
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testForInListUnused' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:x type:<root>.P? [val]
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=FOR_LOOP_NEXT
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testForInListUnused' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
FUN name:testForInListDestructured visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_1 type:kotlin.collections.MutableIterator<<root>.P?> [val]
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=FOR_LOOP_ITERATOR
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=FOR_LOOP_ITERATOR
$this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<<root>.P?>? declared in <root>.J' type=kotlin.collections.List<<root>.P?>? origin=null
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_1: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testForInListDestructured' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:<destruct> type:<root>.P? [val]
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=FOR_LOOP_NEXT
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_1: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testForInListDestructured' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
VAR name:x type:kotlin.Int [val]
CALL 'public final fun component1 (): kotlin.Int declared in <root>.P' type=kotlin.Int origin=null
@@ -37,14 +37,14 @@ FILE fqName:<root> fileName:/enhancedNullabilityInForLoop.kt
FUN name:testDesugaredForInList visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:iterator type:kotlin.collections.MutableIterator<<root>.P?> [val]
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
$this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<<root>.P?>? declared in <root>.J' type=kotlin.collections.List<<root>.P?>? origin=null
WHILE label=null origin=WHILE_LOOP
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null
$this: GET_VAR 'val iterator: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testDesugaredForInList' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
body: BLOCK type=kotlin.Unit origin=WHILE_LOOP
VAR name:x type:<root>.P? [val]
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=null
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=null
$this: GET_VAR 'val iterator: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testDesugaredForInList' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
FUN name:testForInArrayUnused visibility:public modality:FINAL <> (j:<root>.J) returnType:kotlin.Unit
VALUE_PARAMETER name:j index:0 type:<root>.J
@@ -65,14 +65,14 @@ FILE fqName:<root> fileName:/enhancedNullabilityInForLoop.kt
BLOCK_BODY
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_3 type:kotlin.collections.MutableIterator<<root>.P?> [val]
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=FOR_LOOP_ITERATOR
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableList> [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<<root>.P?> origin=FOR_LOOP_ITERATOR
$this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<<root>.P?>? declared in <root>.J' type=kotlin.collections.List<<root>.P?>? origin=null
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_3: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testForInListUse' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:x type:<root>.P? [val]
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=FOR_LOOP_NEXT
CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=<root>.P? origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_3: kotlin.collections.MutableIterator<<root>.P?> [val] declared in <root>.testForInListUse' type=kotlin.collections.MutableIterator<<root>.P?> origin=null
CALL 'public final fun use (s: <root>.P): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
s: GET_VAR 'val x: <root>.P? [val] declared in <root>.testForInListUse' type=<root>.P? origin=null