From f1eb0dff1fe281cef487fd9c9a73dbbca72daf00 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 21 Nov 2019 15:07:22 +0300 Subject: [PATCH] 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. --- .../jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt | 1 + .../org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt | 2 -- .../org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt | 5 +---- .../testData/resolve/problems/javaAccessorConversion.kt | 2 +- .../testData/resolve/problems/javaAccessorConversion.txt | 2 +- .../testData/resolve/problems/javaFieldVsAccessor.kt | 2 +- .../testData/resolve/problems/javaFieldVsAccessor.txt | 2 +- .../resolve/problems/syntheticsVsNormalProperties.kt | 4 ++-- .../resolve/problems/syntheticsVsNormalProperties.txt | 4 ++-- .../org/jetbrains/kotlin/fir/symbols/SyntheticSymbol.kt | 8 ++++++++ .../kotlin/fir/symbols/impl/FirFunctionSymbol.kt | 3 ++- .../box/properties/lateinit/topLevel/accessorException.kt | 1 - .../lateinit/topLevel/accessorForTopLevelLateinit.kt | 1 - .../irText/expressions/jvmInstanceFieldReference.fir.txt | 4 ++-- .../multiModule/fieldAccessFromDerived/jvm/Derived.txt | 2 +- 15 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/SyntheticSymbol.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index 3146f54b956..aeec397c29f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.* 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.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index 0d853ea58be..22a8a4da209 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt @@ -20,8 +20,6 @@ import org.jetbrains.kotlin.fir.symbols.* import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.name.Name -interface SyntheticSymbol - class SyntheticPropertySymbol(callableId: CallableId) : FirPropertySymbol(callableId), SyntheticSymbol class FirSyntheticFunctionSymbol( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt index 996d118be34..c847c85015d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt @@ -114,10 +114,7 @@ class MemberScopeTowerLevel( } }.stop() ) return ProcessorAction.STOP - val withSynthetic = FirSyntheticPropertiesScope(session, scope, ReturnTypeCalculatorWithJump(session, scopeSession)) - return withSynthetic.processScopeMembers { symbol -> - output.consumeCandidate(symbol, symbol.dispatchReceiverValue(), implicitExtensionReceiver) - } + return ProcessorAction.NEXT } override fun > processElementsByName( diff --git a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt index 8d6f9c02b78..8c0d2a54fd0 100644 --- a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt +++ b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt @@ -66,5 +66,5 @@ class Foo { } fun test_4(foo: Foo) { - foo.x // should be error + foo.x // should be error } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt index c0b9f7f41a0..38437443800 100644 --- a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt +++ b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt @@ -22,5 +22,5 @@ FILE: main.kt } public final fun test_4(foo: R|Foo|): R|kotlin/Unit| { - R|/foo|.R|/Foo.x| + R|/foo|.# } diff --git a/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.kt b/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.kt index def51571152..5c568c02749 100644 --- a/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.kt +++ b/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.kt @@ -11,6 +11,6 @@ public class A { // FILE: main.kt fun test(a: A) { - val int = a.x // <- should be int + val int = a.x // <- should be int val string = a.getX() } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.txt b/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.txt index f5be316b83f..261a6dbb0d6 100644 --- a/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.txt +++ b/compiler/fir/resolve/testData/resolve/problems/javaFieldVsAccessor.txt @@ -1,5 +1,5 @@ FILE: main.kt public final fun test(a: R|A|): R|kotlin/Unit| { - lval int: = R|/a|.# + lval int: R|kotlin/Int| = R|/a|.R|/A.x| lval string: R|ft!| = R|/a|.R|/A.getX|() } diff --git a/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt b/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt index b848027a55e..27fa05cbe70 100644 --- a/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt +++ b/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt @@ -20,11 +20,11 @@ class B : A() { fun test() { // should be CommandExecutor - val e = executor + val e = executor } } fun test(b: B) { // should be CommandExecutor - b.executor + b.executor } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.txt b/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.txt index 62910e0ace2..3b586149cbd 100644 --- a/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.txt +++ b/compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.txt @@ -20,10 +20,10 @@ FILE: main.kt public get(): R|CommandExecutor| public final fun test(): R|kotlin/Unit| { - lval e: = # + lval e: R|CommandExecutor| = this@R|/B|.R|/B.executor| } } public final fun test(b: R|B|): R|kotlin/Unit| { - R|/b|.# + R|/b|.R|/B.executor| } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/SyntheticSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/SyntheticSymbol.kt new file mode 100644 index 00000000000..b6c2f596d13 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/SyntheticSymbol.kt @@ -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 \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt index ece8cd57851..89e02fd23cd 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.symbols.impl import org.jetbrains.kotlin.fir.declarations.* 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.name.FqName import org.jetbrains.kotlin.name.Name @@ -35,7 +36,7 @@ class FirConstructorSymbol( class FirAccessorSymbol( callableId: CallableId, val accessorId: CallableId -) : FirFunctionSymbol(callableId) +) : FirFunctionSymbol(callableId), SyntheticSymbol // ------------------------ unnamed ------------------------ diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt index e93ce3f1f74..16bc04a0a8b 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME // FILE: lateinit.kt private lateinit var s: String diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt index 092b7fddd4d..caa3418f5b5 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorForTopLevelLateinit.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // FILE: lateinit.kt private lateinit var s: String diff --git a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt index 8f72d757c6b..3abf4b6e49f 100644 --- a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt +++ b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt @@ -10,10 +10,10 @@ FILE fqName: fileName:/Derived.kt SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=null receiver: GET_VAR ': .Base declared in .Base' type=.Base origin=null value: CONST Int type=kotlin.Int value=0 - FUN name:getValue visibility:public modality:FINAL <> ($this:.Derived) returnType:IrErrorType + FUN name:getValue visibility:public modality:FINAL <> ($this:.Derived) returnType:kotlin.Int $this: VALUE_PARAMETER name: type:.Derived BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun getValue (): IrErrorType declared in .Derived' + RETURN type=kotlin.Nothing from='public final fun getValue (): kotlin.Int declared in .Derived' GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Int origin=GET_PROPERTY receiver: GET_VAR ': .Base declared in .Base' type=.Base origin=null FUN name:setValue visibility:public modality:FINAL <> ($this:.Derived, value:kotlin.Int) returnType:kotlin.Unit diff --git a/idea/testData/fir/multiModule/fieldAccessFromDerived/jvm/Derived.txt b/idea/testData/fir/multiModule/fieldAccessFromDerived/jvm/Derived.txt index f78d20aadad..559624e728d 100644 --- a/idea/testData/fir/multiModule/fieldAccessFromDerived/jvm/Derived.txt +++ b/idea/testData/fir/multiModule/fieldAccessFromDerived/jvm/Derived.txt @@ -4,7 +4,7 @@ FILE: Derived.kt super() } - public final fun getValue(): { + public final fun getValue(): R|kotlin/Int| { ^getValue this@R|/Base|.R|/Base.value| }