[LL FIR] skip implicit type resolution for declarations without implicit type

This also fixes non-resolved contract calls in the case
of wrong contract description.
And we can avoid body calculation.

^KT-56551
This commit is contained in:
Dmitrii Gridin
2023-09-19 19:27:12 +02:00
committed by Space Team
parent 7ab8239c6e
commit a128cbc97a
13 changed files with 63 additions and 88 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirImplicitAwa
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirResolveContextCollector
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.ImplicitBodyResolveComputationSession
import org.jetbrains.kotlin.fir.scopes.callableCopySubstitutionForTypeUpdater
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
internal object LLFirImplicitTypesLazyResolver : LLFirLazyResolver(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) {
override fun resolve(
@@ -68,14 +69,30 @@ internal class LLFirImplicitBodyTargetResolver(
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
when (target) {
is FirFunction -> resolve(target, BodyStateKeepers.FUNCTION)
is FirProperty -> resolve(target, BodyStateKeepers.PROPERTY)
is FirVariable -> resolve(target, BodyStateKeepers.VARIABLE)
is FirFunction -> {
if (target.returnTypeRef is FirImplicitTypeRef) {
resolve(target, BodyStateKeepers.FUNCTION)
}
}
is FirProperty -> {
if (target.returnTypeRef is FirImplicitTypeRef || target.backingField?.returnTypeRef is FirImplicitTypeRef) {
resolve(target, BodyStateKeepers.PROPERTY)
}
}
is FirField -> {
if (target.returnTypeRef is FirImplicitTypeRef) {
resolve(target, BodyStateKeepers.FIELD)
}
}
is FirScript -> {
if (target.statements.any { it.isScriptDependentDeclaration }) {
resolve(target, BodyStateKeepers.SCRIPT)
}
}
is FirRegularClass,
is FirTypeAlias,
is FirFile,
@@ -83,6 +100,8 @@ internal class LLFirImplicitBodyTargetResolver(
is FirAnonymousInitializer,
is FirDanglingModifierList,
is FirFileAnnotationsContainer,
is FirEnumEntry,
is FirErrorProperty,
-> {
// No implicit bodies here
}
@@ -1,15 +1,15 @@
BEFORE MODIFICATION:
public final inline [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[Contract description] <
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
>
{
{
kotlin#.contracts#.contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
}
@@ -1,15 +1,15 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] fun x(): R|kotlin/Unit|
[Contract description] <
<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
>
{
{
contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
req#
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
}
@@ -5,7 +5,7 @@ public final [ResolvedTo(BODY_RESOLVE)] fun passLambdaValue([ResolvedTo(BODY_RES
>
{
{
contract#(l#)
<Unresolved name: contract>#(R|<local>/l|)
}
Int(42)
@@ -1,15 +1,15 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] fun x(): R|kotlin/Unit|
[Contract description] <
<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
>
{
{
contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
req#
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
}
@@ -1,15 +1,15 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] fun x(): R|kotlin/Unit|
[Contract description] <
<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
>
{
{
contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
req#
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
}
@@ -2,15 +2,15 @@ BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] var x: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=A] get(): R|kotlin/Int|
[Contract description] <
<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
>
{
{
contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
req#
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
}
@@ -2,15 +2,15 @@ BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] var <no name provided>: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=A] get(): R|kotlin/Int|
[Contract description] <
<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
>
{
{
contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
req#
<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: req> <inline=Unknown> {
^ <Unresolved name: req>#
}
)
}
@@ -245,7 +245,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
LAZY_super<<implicit>>
}
private final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] field $$delegate_0: R|one/Foo| = prop#
private final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
@@ -268,7 +268,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
LAZY_super<<implicit>>
}
private final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] field $$delegate_0: R|one/Foo| = prop#
private final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
@@ -321,7 +321,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedFieldScript.kts
LAZY_super<<implicit>>
}
private final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] field $$delegate_0: R|one/Foo| = prop#
private final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
@@ -351,7 +351,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedFieldScript.kts
LAZY_super<<implicit>>
}
private final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] field $$delegate_0: R|one/Foo| = prop#
private final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
@@ -261,13 +261,7 @@ FILE: [ResolvedTo(IMPORTS)] enumEntry.kt
LAZY_super<R|kotlin/Enum<Foo>|>
}
@R|Anno|[Types]() public final static [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = object : R|Foo| {
private [ResolvedTo(RAW_FIR)] [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
super<R|Foo|>()
}
}
@R|Anno|[Types]() public final static [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = LAZY_EXPRESSION
public final static [ResolvedTo(STATUS)] [ContainingClassKey=Foo] fun values(): R|kotlin/Array<Foo>| {
}
@@ -292,13 +286,7 @@ FILE: [ResolvedTo(IMPORTS)] enumEntry.kt
LAZY_super<R|kotlin/Enum<Foo>|>
}
@R|Anno|[Types]() public final static [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = object : R|Foo| {
private [ResolvedTo(RAW_FIR)] [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
super<R|Foo|>()
}
}
@R|Anno|[Types]() public final static [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = LAZY_EXPRESSION
public final static [ResolvedTo(STATUS)] [ContainingClassKey=Foo] fun values(): R|kotlin/Array<Foo>| {
}
@@ -326,13 +326,7 @@ FILE: [ResolvedTo(IMPORTS)] enumEntryScript.kts
LAZY_super<R|kotlin/Enum<Foo>|>
}
@R|Anno|[Types]() public final static [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = object : R|Foo| {
private [ResolvedTo(RAW_FIR)] [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
super<R|Foo|>()
}
}
@R|Anno|[Types]() public final static [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = LAZY_EXPRESSION
public final static [ResolvedTo(STATUS)] [ContainingClassKey=Foo] fun values(): R|kotlin/Array<Foo>| {
}
@@ -363,13 +357,7 @@ FILE: [ResolvedTo(IMPORTS)] enumEntryScript.kts
LAZY_super<R|kotlin/Enum<Foo>|>
}
@R|Anno|[Types]() public final static [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = object : R|Foo| {
private [ResolvedTo(RAW_FIR)] [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
super<R|Foo|>()
}
}
@R|Anno|[Types]() public final static [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] [ContainingClassKey=Foo] enum entry ResolveMe: R|Foo| = LAZY_EXPRESSION
public final static [ResolvedTo(STATUS)] [ContainingClassKey=Foo] fun values(): R|kotlin/Array<Foo>| {
}
@@ -46,41 +46,21 @@ FILE: [ResolvedTo(IMPORTS)] contract.kt
IMPLICIT_TYPES_BODY_RESOLVE:
FILE: [ResolvedTo(IMPORTS)] contract.kt
public final inline [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun foo([ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[Contract description] <
kotlin#.contracts#.contract#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
}
)
>
{
{
kotlin#.contracts#.contract#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
}
)
public final inline [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun foo([ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] block: R|() -> kotlin/Unit|): R|kotlin/Unit| {
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
block#()
}
ANNOTATIONS_ARGUMENTS_MAPPING:
FILE: [ResolvedTo(IMPORTS)] contract.kt
public final inline [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] fun foo([ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[Contract description] <
kotlin#.contracts#.contract#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
}
)
>
{
{
kotlin#.contracts#.contract#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
}
)
public final inline [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] fun foo([ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] block: R|() -> kotlin/Unit|): R|kotlin/Unit| {
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
block#()
}
@@ -88,15 +68,15 @@ BODY_RESOLVE:
FILE: [ResolvedTo(IMPORTS)] contract.kt
public final inline [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[Contract description] <
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
>
{
{
kotlin#.contracts#.contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
}
@@ -108,15 +88,15 @@ FILE RAW TO BODY:
FILE: [ResolvedTo(BODY_RESOLVE)] contract.kt
public final inline [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[Contract description] <
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(RAW_FIR)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
>
{
{
kotlin#.contracts#.contract#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
callsInPlace#(block#, InvocationKind#.EXACTLY_ONCE#)
Q|kotlin|.<Unresolved name: contracts>#.<Unresolved name: contract>#(<L> = [ResolvedTo(BODY_RESOLVE)] contract@fun <anonymous>(): <ERROR TYPE REF: Unresolved name: callsInPlace> <inline=Unknown> {
^ <Unresolved name: callsInPlace>#(R|<local>/block|, <Unresolved name: InvocationKind>#.<Unresolved name: EXACTLY_ONCE>#)
}
)
}