[FIR2IR] Properly approximate intersection types during fir2ir conversion

^KT-62544 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-10-16 13:19:40 +03:00
committed by Space Team
parent 8c6da9fddb
commit 9366847e96
52 changed files with 450 additions and 803 deletions
@@ -0,0 +1,170 @@
FILE fqName:<root> fileName:/Modality.kt
CLASS INTERFACE name:Substitutable modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Substitutable<T of <root>.Substitutable>
TYPE_PARAMETER name:T index:0 variance:out superTypes:[<root>.DeclarationDescriptorNonRoot] reified:false
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:ResolutionPart modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.ResolutionPart
CONSTRUCTOR visibility:public <> () returnType:<root>.ResolutionPart [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ResolutionPart modality:ABSTRACT visibility:public superTypes:[kotlin.Any]'
FUN name:process visibility:public modality:ABSTRACT <> ($this:<root>.ResolutionPart, $receiver:<root>.KotlinResolutionCandidate) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.ResolutionPart
$receiver: VALUE_PARAMETER name:<this> type:<root>.KotlinResolutionCandidate
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:KotlinResolutionCandidate modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.KotlinResolutionCandidate
CONSTRUCTOR visibility:public <> (resolvedCall:<root>.Atom) returnType:<root>.KotlinResolutionCandidate [primary]
VALUE_PARAMETER name:resolvedCall index:0 type:<root>.Atom
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:KotlinResolutionCandidate modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:resolvedCall visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:resolvedCall type:<root>.Atom visibility:private [final]
EXPRESSION_BODY
GET_VAR 'resolvedCall: <root>.Atom declared in <root>.KotlinResolutionCandidate.<init>' type=<root>.Atom origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-resolvedCall> visibility:public modality:FINAL <> ($this:<root>.KotlinResolutionCandidate) returnType:<root>.Atom
correspondingProperty: PROPERTY name:resolvedCall visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.KotlinResolutionCandidate
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-resolvedCall> (): <root>.Atom declared in <root>.KotlinResolutionCandidate'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resolvedCall type:<root>.Atom visibility:private [final]' type=<root>.Atom origin=null
receiver: GET_VAR '<this>: <root>.KotlinResolutionCandidate declared in <root>.KotlinResolutionCandidate.<get-resolvedCall>' type=<root>.KotlinResolutionCandidate origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:Atom modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Atom
CONSTRUCTOR visibility:public <> (candidateDescriptor:<root>.CallableDescriptor) returnType:<root>.Atom [primary]
VALUE_PARAMETER name:candidateDescriptor index:0 type:<root>.CallableDescriptor
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Atom modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:candidateDescriptor visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:candidateDescriptor type:<root>.CallableDescriptor visibility:private [final]
EXPRESSION_BODY
GET_VAR 'candidateDescriptor: <root>.CallableDescriptor declared in <root>.Atom.<init>' type=<root>.CallableDescriptor origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-candidateDescriptor> visibility:public modality:FINAL <> ($this:<root>.Atom) returnType:<root>.CallableDescriptor
correspondingProperty: PROPERTY name:candidateDescriptor visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Atom
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-candidateDescriptor> (): <root>.CallableDescriptor declared in <root>.Atom'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:candidateDescriptor type:<root>.CallableDescriptor visibility:private [final]' type=<root>.CallableDescriptor origin=null
receiver: GET_VAR '<this>: <root>.Atom declared in <root>.Atom.<get-candidateDescriptor>' type=<root>.Atom origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS OBJECT name:Owner modality:FINAL visibility:public superTypes:[<root>.ResolutionPart]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Owner
CONSTRUCTOR visibility:private <> () returnType:<root>.Owner [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.ResolutionPart'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Owner modality:FINAL visibility:public superTypes:[<root>.ResolutionPart]'
FUN name:process visibility:public modality:OPEN <> ($this:<root>.Owner, $receiver:<root>.KotlinResolutionCandidate) returnType:kotlin.String
overridden:
public abstract fun process (): kotlin.String declared in <root>.ResolutionPart
$this: VALUE_PARAMETER name:<this> type:<root>.Owner
$receiver: VALUE_PARAMETER name:<this> type:<root>.KotlinResolutionCandidate
BLOCK_BODY
VAR name:candidateDescriptor type:<root>.CallableDescriptor [val]
CALL 'public final fun <get-candidateDescriptor> (): <root>.CallableDescriptor declared in <root>.Atom' type=<root>.CallableDescriptor origin=GET_PROPERTY
$this: CALL 'public final fun <get-resolvedCall> (): <root>.Atom declared in <root>.KotlinResolutionCandidate' type=<root>.Atom origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.KotlinResolutionCandidate declared in <root>.Owner.process' type=<root>.KotlinResolutionCandidate origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: WHEN type=kotlin.Boolean origin=ANDAND
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.MemberDescriptor
GET_VAR 'val candidateDescriptor: <root>.CallableDescriptor declared in <root>.Owner.process' type=<root>.CallableDescriptor origin=null
then: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: CALL 'public abstract fun getModality (): @[FlexibleNullability] <root>.Modality? declared in <root>.MemberDescriptor' type=@[FlexibleNullability] <root>.Modality? origin=GET_PROPERTY
$this: TYPE_OP type=<root>.MemberDescriptor origin=IMPLICIT_CAST typeOperand=<root>.MemberDescriptor
TYPE_OP type=<root>.DeclarationDescriptor origin=IMPLICIT_CAST typeOperand=<root>.DeclarationDescriptor
GET_VAR 'val candidateDescriptor: <root>.CallableDescriptor declared in <root>.Owner.process' type=<root>.CallableDescriptor origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Boolean type=kotlin.Boolean value=false
then: BLOCK type=kotlin.Unit origin=null
RETURN type=kotlin.Nothing from='public open fun process (): kotlin.String declared in <root>.Owner'
CONST String type=kotlin.String value="OK"
RETURN type=kotlin.Nothing from='public open fun process (): kotlin.String declared in <root>.Owner'
CONST String type=kotlin.String value="FAIL"
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.ResolutionPart
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in <root>.ResolutionPart
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in <root>.ResolutionPart
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS OBJECT name:Final modality:FINAL visibility:public superTypes:[<root>.Modality]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Final
CONSTRUCTOR visibility:private <> () returnType:<root>.Final [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Final modality:FINAL visibility:public superTypes:[<root>.Modality]'
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.Modality
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in <root>.Modality
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in <root>.Modality
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,71 @@
interface Substitutable<out T : DeclarationDescriptorNonRoot> {
}
abstract class ResolutionPart {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
abstract fun KotlinResolutionCandidate.process(): String
}
class KotlinResolutionCandidate {
constructor(resolvedCall: Atom) /* primary */ {
super/*Any*/()
/* <init>() */
}
val resolvedCall: Atom
field = resolvedCall
get
}
class Atom {
constructor(candidateDescriptor: CallableDescriptor) /* primary */ {
super/*Any*/()
/* <init>() */
}
val candidateDescriptor: CallableDescriptor
field = candidateDescriptor
get
}
object Owner : ResolutionPart {
private constructor() /* primary */ {
super/*ResolutionPart*/()
/* <init>() */
}
override fun KotlinResolutionCandidate.process(): String {
val candidateDescriptor: CallableDescriptor = <this>.<get-resolvedCall>().<get-candidateDescriptor>()
when {
when {
candidateDescriptor is MemberDescriptor -> EQEQ(arg0 = candidateDescriptor /*as DeclarationDescriptor */ /*as MemberDescriptor */.getModality(), arg1 = null).not()
else -> false
} -> { // BLOCK
return "OK"
}
}
return "FAIL"
}
}
object Final : Modality {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
-1
View File
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// TARGET_BACKEND: JVM
// FILE: Modality.java
public interface Modality
@@ -132,8 +132,8 @@ FILE fqName:<root> fileName:/candidateSymbol.kt
FUN name:foo visibility:public modality:FINAL <> (candidate:<root>.Candidate) returnType:kotlin.Unit
VALUE_PARAMETER name:candidate index:0 type:<root>.Candidate
BLOCK_BODY
VAR name:me type:<root>.FirSymbolOwner<*> [val]
CALL 'public final fun <get-fir> (): E of <root>.AbstractFirBasedSymbol declared in <root>.AbstractFirBasedSymbol' type=<root>.FirSymbolOwner<*> origin=GET_PROPERTY
VAR name:me type:kotlin.Any [val]
CALL 'public final fun <get-fir> (): E of <root>.AbstractFirBasedSymbol declared in <root>.AbstractFirBasedSymbol' type=kotlin.Any origin=GET_PROPERTY
$this: CALL 'public final fun <get-symbol> (): <root>.AbstractFirBasedSymbol<*> declared in <root>.Candidate' type=<root>.AbstractFirBasedSymbol<*> origin=GET_PROPERTY
$this: GET_VAR 'candidate: <root>.Candidate declared in <root>.foo' type=<root>.Candidate origin=null
WHEN type=kotlin.Unit origin=IF
@@ -141,12 +141,12 @@ FILE fqName:<root> fileName:/candidateSymbol.kt
if: WHEN type=kotlin.Boolean origin=ANDAND
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.FirCallableMemberDeclaration<*>
GET_VAR 'val me: <root>.FirSymbolOwner<*> declared in <root>.foo' type=<root>.FirSymbolOwner<*> origin=null
GET_VAR 'val me: kotlin.Any declared in <root>.foo' type=kotlin.Any origin=null
then: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: CALL 'public abstract fun <get-symbol> (): <root>.AbstractFirBasedSymbol<F of <root>.FirCallableMemberDeclaration> declared in <root>.FirCallableMemberDeclaration' type=<root>.AbstractFirBasedSymbol<out <root>.FirCallableMemberDeclaration<*>> origin=GET_PROPERTY
$this: TYPE_OP type=<root>.FirCallableMemberDeclaration<*> origin=IMPLICIT_CAST typeOperand=<root>.FirCallableMemberDeclaration<*>
GET_VAR 'val me: <root>.FirSymbolOwner<*> declared in <root>.foo' type=<root>.FirSymbolOwner<*> origin=null
GET_VAR 'val me: kotlin.Any declared in <root>.foo' type=kotlin.Any origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
@@ -41,7 +41,7 @@ interface FirCallableMemberDeclaration<F : FirCallableMemberDeclaration<F>> : Fi
}
fun foo(candidate: Candidate) {
val me: FirSymbolOwner<*> = candidate.<get-symbol>().<get-fir>()
val me: Any = candidate.<get-symbol>().<get-fir>()
when {
when {
me is FirCallableMemberDeclaration<*> -> EQEQ(arg0 = me /*as FirCallableMemberDeclaration<*> */.<get-symbol>(), arg1 = null).not()
@@ -50,3 +50,4 @@ fun foo(candidate: Candidate) {
}
}
}