FIR: disable synthetic scope, make accessor symbols synthetic

Before this commit, we had two methods to do generally the same synthetic thing.
It's an attempt to keep only one of them.
Accessor symbols are generated in Java use-site member scopes,
at this place we know better whether we are in Java class or not.
However, we have to do this at every use-site level, which is relatively slow.
Also we could encounter problems when accessor function is overridden in Kotlin,
and accessor symbol can still contain reference to Java accessor.
This commit is contained in:
Mikhail Glukhikh
2019-11-21 15:07:22 +03:00
parent 2f9c94bd9e
commit f1eb0dff1f
15 changed files with 23 additions and 20 deletions
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
@@ -20,8 +20,6 @@ import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
interface SyntheticSymbol
class SyntheticPropertySymbol(callableId: CallableId) : FirPropertySymbol(callableId), SyntheticSymbol class SyntheticPropertySymbol(callableId: CallableId) : FirPropertySymbol(callableId), SyntheticSymbol
class FirSyntheticFunctionSymbol( class FirSyntheticFunctionSymbol(
@@ -114,10 +114,7 @@ class MemberScopeTowerLevel(
} }
}.stop() }.stop()
) return ProcessorAction.STOP ) return ProcessorAction.STOP
val withSynthetic = FirSyntheticPropertiesScope(session, scope, ReturnTypeCalculatorWithJump(session, scopeSession)) return ProcessorAction.NEXT
return withSynthetic.processScopeMembers { symbol ->
output.consumeCandidate(symbol, symbol.dispatchReceiverValue(), implicitExtensionReceiver)
}
} }
override fun <T : AbstractFirBasedSymbol<*>> processElementsByName( override fun <T : AbstractFirBasedSymbol<*>> processElementsByName(
@@ -66,5 +66,5 @@ class Foo {
} }
fun test_4(foo: Foo) { fun test_4(foo: Foo) {
foo.x // should be error foo.<!UNRESOLVED_REFERENCE!>x<!> // should be error
} }
@@ -22,5 +22,5 @@ FILE: main.kt
} }
public final fun test_4(foo: R|Foo|): R|kotlin/Unit| { public final fun test_4(foo: R|Foo|): R|kotlin/Unit| {
R|<local>/foo|.R|/Foo.x| R|<local>/foo|.<Unresolved name: x>#
} }
@@ -11,6 +11,6 @@ public class A {
// FILE: main.kt // FILE: main.kt
fun test(a: A) { fun test(a: A) {
val int = a.<!AMBIGUITY!>x<!> // <- should be int val int = a.x // <- should be int
val string = a.getX() val string = a.getX()
} }
@@ -1,5 +1,5 @@
FILE: main.kt FILE: main.kt
public final fun test(a: R|A|): R|kotlin/Unit| { public final fun test(a: R|A|): R|kotlin/Unit| {
lval int: <ERROR TYPE REF: Ambiguity: x, [/A.x, /A.x]> = R|<local>/a|.<Ambiguity: x, [/A.x, /A.x]># lval int: R|kotlin/Int| = R|<local>/a|.R|/A.x|
lval string: R|ft<kotlin/String, kotlin/String?>!| = R|<local>/a|.R|/A.getX|() lval string: R|ft<kotlin/String, kotlin/String?>!| = R|<local>/a|.R|/A.getX|()
} }
@@ -20,11 +20,11 @@ class B : A() {
fun test() { fun test() {
// should be CommandExecutor // should be CommandExecutor
val e = <!AMBIGUITY!>executor<!> val e = executor
} }
} }
fun test(b: B) { fun test(b: B) {
// should be CommandExecutor // should be CommandExecutor
b.<!AMBIGUITY!>executor<!> b.executor
} }
@@ -20,10 +20,10 @@ FILE: main.kt
public get(): R|CommandExecutor| public get(): R|CommandExecutor|
public final fun test(): R|kotlin/Unit| { public final fun test(): R|kotlin/Unit| {
lval e: <ERROR TYPE REF: Ambiguity: executor, [/B.executor, /A.executor]> = <Ambiguity: executor, [/B.executor, /A.executor]># lval e: R|CommandExecutor| = this@R|/B|.R|/B.executor|
} }
} }
public final fun test(b: R|B|): R|kotlin/Unit| { public final fun test(b: R|B|): R|kotlin/Unit| {
R|<local>/b|.<Ambiguity: executor, [/B.executor, /A.executor]># R|<local>/b|.R|/B.executor|
} }
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 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.symbols
interface SyntheticSymbol
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.symbols.impl
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
@@ -35,7 +36,7 @@ class FirConstructorSymbol(
class FirAccessorSymbol( class FirAccessorSymbol(
callableId: CallableId, callableId: CallableId,
val accessorId: CallableId val accessorId: CallableId
) : FirFunctionSymbol<FirSimpleFunction>(callableId) ) : FirFunctionSymbol<FirSimpleFunction>(callableId), SyntheticSymbol
// ------------------------ unnamed ------------------------ // ------------------------ unnamed ------------------------
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
// FILE: lateinit.kt // FILE: lateinit.kt
private lateinit var s: String private lateinit var s: String
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: lateinit.kt // FILE: lateinit.kt
private lateinit var s: String private lateinit var s: String
@@ -10,10 +10,10 @@ FILE fqName:<root> fileName:/Derived.kt
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=null SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: <root>.Base declared in <root>.Base' type=<root>.Base origin=null receiver: GET_VAR '<this>: <root>.Base declared in <root>.Base' type=<root>.Base origin=null
value: CONST Int type=kotlin.Int value=0 value: CONST Int type=kotlin.Int value=0
FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:IrErrorType FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.Int
$this: VALUE_PARAMETER name:<this> type:<root>.Derived $this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun getValue (): IrErrorType declared in <root>.Derived' RETURN type=kotlin.Nothing from='public final fun getValue (): kotlin.Int declared in <root>.Derived'
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Int origin=GET_PROPERTY GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Int origin=GET_PROPERTY
receiver: GET_VAR '<this>: <root>.Base declared in <root>.Base' type=<root>.Base origin=null receiver: GET_VAR '<this>: <root>.Base declared in <root>.Base' type=<root>.Base origin=null
FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, value:kotlin.Int) returnType:kotlin.Unit FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, value:kotlin.Int) returnType:kotlin.Unit
@@ -4,7 +4,7 @@ FILE: Derived.kt
super<R|Base|>() super<R|Base|>()
} }
public final fun getValue(): <ERROR TYPE REF: cycle> { public final fun getValue(): R|kotlin/Int| {
^getValue this@R|/Base|.R|/Base.value| ^getValue this@R|/Base|.R|/Base.value|
} }