FIR: introduce callable member symbols & initial member scopes

Initial member scopes cover top-level, class-level, and  supers

Ad-hock version of call resolve was introduced to test them
NB: after this commit, total Kotlin resolve test cannot finish
because of scope problems in type resolve transformer

Related to KT-24078
#KT-24083 Fixed
This commit is contained in:
Mikhail Glukhikh
2019-01-25 15:29:21 +03:00
parent 95678a4d64
commit bec62acf5b
58 changed files with 540 additions and 72 deletions
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
// NB: with className == null we are at top level
data class CallableId(val packageName: FqName, val className: FqName?, val callableName: Name) {
constructor(packageName: FqName, callableName: Name): this(packageName, null, callableName)
override fun toString(): String {
return buildString {
append(packageName.asString().replace('.', '/'))
append("/")
if (className != null) {
append(className)
append(".")
}
append(callableName)
}
}
}
interface ConeCallableSymbol : ConeSymbol {
val callableId: CallableId
}
interface ConePropertySymbol : ConeCallableSymbol
interface ConeFunctionSymbol : ConeCallableSymbol {
val parameters: List<ConeKotlinType>
}
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.fir.java.symbols.JavaClassSymbol
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.load.java.JavaClassFinder
import org.jetbrains.kotlin.name.ClassId
@@ -19,6 +20,10 @@ class JavaSymbolProvider(
val project: Project,
private val searchScope: GlobalSearchScope
) : AbstractFirSymbolProvider() {
override fun getCallableSymbols(callableId: CallableId): List<ConeSymbol> {
// TODO
return emptyList()
}
override fun getSymbolByFqName(classId: ClassId): ConeSymbol? {
return classCache.lookupCacheOrCalculate(classId) {
@@ -20,9 +20,8 @@ import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.references.FirExplicitSuperReference
import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference
import org.jetbrains.kotlin.fir.references.FirExplicitThisReference
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.FirType
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.impl.*
@@ -250,6 +249,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val firProperty = FirMemberPropertyImpl(
session,
this,
FirPropertySymbol(callableIdForName(nameAsSafeName)),
nameAsSafeName,
visibility,
modality,
@@ -359,6 +359,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val firConstructor = FirPrimaryConstructorImpl(
session,
this ?: owner,
FirFunctionSymbol(callableIdForClassConstructor()),
this?.visibility ?: Visibilities.UNKNOWN,
this?.hasExpectModifier() ?: false,
this?.hasActualModifier() ?: false,
@@ -432,6 +433,14 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val currentClassId get() = ClassId(packageFqName, className, false)
fun callableIdForName(name: Name) =
if (className == FqName.ROOT) CallableId(packageFqName, name)
else CallableId(packageFqName, className, name)
fun callableIdForClassConstructor() =
if (className == FqName.ROOT) CallableId(packageFqName, Name.special("<anonymous-init>"))
else CallableId(packageFqName, className, className.shortName())
var className: FqName = FqName.ROOT
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Unit): FirElement {
@@ -546,6 +555,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
FirMemberFunctionImpl(
session,
function,
FirFunctionSymbol(callableIdForName(function.nameAsSafeName)),
function.nameAsSafeName,
function.visibility,
function.modality,
@@ -621,6 +631,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
val firConstructor = FirConstructorImpl(
session,
this,
FirFunctionSymbol(callableIdForClassConstructor()),
visibility,
hasExpectModifier(),
hasActualModifier(),
@@ -686,6 +697,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
FirMemberPropertyImpl(
session,
property,
FirPropertySymbol(callableIdForName(name)),
name,
property.visibility,
property.modality,
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.service
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
@@ -15,6 +16,8 @@ interface FirSymbolProvider {
fun getSymbolByFqName(classId: ClassId): ConeSymbol?
fun getCallableSymbols(callableId: CallableId): List<ConeSymbol>
fun getPackage(fqName: FqName): FqName? // TODO: Replace to symbol sometime
companion object {
@@ -6,12 +6,20 @@
package org.jetbrains.kotlin.fir.resolve.impl
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
class FirCompositeSymbolProvider(val providers: List<FirSymbolProvider>) : FirSymbolProvider {
override fun getCallableSymbols(callableId: CallableId): List<ConeSymbol> {
for (provider in providers) {
val symbols = provider.getCallableSymbols(callableId)
if (symbols.isNotEmpty()) return symbols
}
return emptyList()
}
override fun getPackage(fqName: FqName): FqName? {
return providers.firstNotNullResult { it.getPackage(fqName) }
@@ -10,11 +10,16 @@ import org.jetbrains.kotlin.fir.dependenciesWithoutSelf
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
import org.jetbrains.kotlin.fir.service
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
class FirDependenciesSymbolProviderImpl(val session: FirSession) : AbstractFirSymbolProvider() {
override fun getCallableSymbols(callableId: CallableId): List<ConeSymbol> {
// TODO
return emptyList()
}
private val dependencyProviders by lazy {
val moduleInfo = session.moduleInfo ?: return@lazy emptyList()
@@ -11,10 +11,10 @@ import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.deserialization.FirTypeDeserializer
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.fir.symbols.LibraryClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FictitiousFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.builtins.BuiltInsBinaryVersion
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
@@ -27,6 +27,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
import java.io.InputStream
class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider {
override fun getCallableSymbols(callableId: CallableId): List<ConeSymbol> {
// TODO
return emptyList()
}
private class BuiltInsPackageFragment(stream: InputStream, val fqName: FqName) {
lateinit var version: BuiltInsBinaryVersion
@@ -9,10 +9,7 @@ import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.resolve.FirProvider
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner
import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
@@ -31,6 +28,10 @@ class FirProviderImpl(val session: FirSession) : FirProvider {
return (getFirClassifierByFqName(classId) as? FirSymbolOwner<*>)?.symbol
}
override fun getCallableSymbols(callableId: CallableId): List<ConeSymbol> {
return (callableMap[callableId] ?: emptyList()).filterIsInstance<FirSymbolOwner<*>>().map { it.symbol }
}
override fun getFirClassifierContainerFile(fqName: ClassId): FirFile {
return classifierContainerFileMap[fqName] ?: error("Couldn't find container for $fqName")
}
@@ -61,12 +62,29 @@ class FirProviderImpl(val session: FirSession) : FirProvider {
classifierMap[classId] = typeAlias
classifierContainerFileMap[classId] = file
}
override fun visitCallableMember(callableMember: FirCallableMember) {
val callableId = when (containerFqName) {
FqName.ROOT -> CallableId(packageName, callableMember.name)
else -> CallableId(packageName, containerFqName, callableMember.name)
}
callableMap.merge(callableId, listOf(callableMember)) { a, b -> a + b }
}
override fun visitNamedFunction(namedFunction: FirNamedFunction) {
visitCallableMember(namedFunction)
}
override fun visitProperty(property: FirProperty) {
visitCallableMember(property)
}
})
}
private val fileMap = mutableMapOf<FqName, List<FirFile>>()
private val classifierMap = mutableMapOf<ClassId, FirMemberDeclaration>()
private val classifierContainerFileMap = mutableMapOf<ClassId, FirFile>()
private val callableMap = mutableMapOf<CallableId, List<FirNamedDeclaration>>()
override fun getFirFilesByPackage(fqName: FqName): List<FirFile> {
return fileMap[fqName].orEmpty()
@@ -16,16 +16,16 @@ import org.jetbrains.kotlin.fir.types.ConeClassErrorType
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: Boolean) : FirAbstractTreeTransformer() {
protected var towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
protected inline fun <T> withScopeCleanup(crossinline l: () -> T): T {
val scopeBefore = towerScope
val scopes = towerScope.scopes
val sizeBefore = scopes.size
val sizeBefore = towerScope.scopes.size
val result = l()
towerScope = scopeBefore
assert(scopes.size >= sizeBefore)
scopes.subList(sizeBefore + 1, scopes.size).clear()
val size = towerScope.scopes.size
assert(size >= sizeBefore)
repeat(size - sizeBefore) {
towerScope.scopes.let { it.removeAt(it.size - 1) }
}
return result
}
@@ -0,0 +1,64 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.resolve.transformers
import org.jetbrains.kotlin.fir.FirNamedReference
import org.jetbrains.kotlin.fir.FirResolvedCallableReference
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
import org.jetbrains.kotlin.fir.scopes.FirPosition
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
import org.jetbrains.kotlin.fir.scopes.impl.FirTopLevelDeclaredMemberScope
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
import org.jetbrains.kotlin.fir.visitors.compose
class FirAccessResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority = true) {
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
return withScopeCleanup {
towerScope.scopes += FirTopLevelDeclaredMemberScope(file, file.session)
super.transformFile(file, data)
}
}
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult<FirDeclaration> {
return withScopeCleanup {
lookupSuperTypes(regularClass).asReversed().mapNotNullTo(towerScope.scopes) {
val symbol = it.symbol
if (symbol is FirClassSymbol) {
FirClassDeclaredMemberScope(symbol.fir, symbol.fir.session)
} else {
null
}
}
towerScope.scopes += FirClassDeclaredMemberScope(regularClass, regularClass.session)
super.transformRegularClass(regularClass, data)
}
}
override fun transformNamedReference(namedReference: FirNamedReference, data: Nothing?): CompositeTransformResult<FirNamedReference> {
if (namedReference is FirResolvedCallableReference) return namedReference.compose()
val name = namedReference.name
var symbol: ConeCallableSymbol? = null
towerScope.processClassifiersByName(name, FirPosition.OTHER) {
symbol = it as? ConeCallableSymbol
// I'm lucky today!!! (the first symbol we have found is the one we need)
it is ConeCallableSymbol
}
val callableSymbol = symbol ?: return FirErrorNamedReference(
namedReference.session, namedReference.psi, "Unresolved name: $name"
).compose()
return FirResolvedCallableReferenceImpl(
namedReference.session, namedReference.psi,
name, callableSymbol
).compose()
}
}
@@ -13,7 +13,8 @@ class FirTotalResolveTransformer {
val transformers: List<FirTransformer<Nothing?>> = listOf(
FirImportResolveTransformer(),
FirTypeResolveTransformer(),
FirStatusResolveTransformer()
FirStatusResolveTransformer(),
FirAccessResolveTransformer()
)
fun processFile(firFile: FirFile) {
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.scopes.impl
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.scopes.FirPosition
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.name.Name
class FirClassDeclaredMemberScope(
klass: FirRegularClass,
session: FirSession,
lookupInFir: Boolean = true
) : FirAbstractProviderBasedScope(session, lookupInFir) {
private val classId = klass.symbol.classId
override fun processClassifiersByName(
name: Name,
position: FirPosition,
processor: (ConeSymbol) -> Boolean
): Boolean {
val symbols = provider.getCallableSymbols(CallableId(classId.packageFqName, classId.relativeClassName, name))
for (symbol in symbols) {
if (!processor(symbol)) {
return false
}
}
return true
}
}
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.scopes.impl
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.scopes.FirPosition
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.name.Name
class FirTopLevelDeclaredMemberScope(
file: FirFile,
session: FirSession,
lookupInFir: Boolean = true
) : FirAbstractProviderBasedScope(session, lookupInFir) {
private val packageFqName = file.packageFqName
override fun processClassifiersByName(
name: Name,
position: FirPosition,
processor: (ConeSymbol) -> Boolean
): Boolean {
val symbols = provider.getCallableSymbols(CallableId(packageFqName, name))
for (symbol in symbols) {
if (!processor(symbol)) {
return false
}
}
return true
}
}
+2 -2
View File
@@ -8,8 +8,8 @@ FILE: lists.kt
}
public final function convert R|kotlin/collections/List<kotlin/String>|.(): R|MyStringList| {
return@@@convert STUB
return@@@convert as/R|MyStringList|(this#)
}
public final function ret(l: R|kotlin/collections/MutableList<kotlin/String>|): R|MyMutableStringList| {
return@@@ret STUB
return@@@ret as/R|MyMutableStringList|(this#)
}
+2 -2
View File
@@ -7,9 +7,9 @@ FILE: derivedClass.kt
}
<T : R|kotlin/Any|> public final class Derived : R|Base<T>| {
public constructor(x: R|T|): super<R|Base<T>|>()
public constructor(x: R|T|): super<R|Base<T>|>(R|/Base.x|)
}
<T : R|kotlin/Any|> public final function create(x: R|T|): R|Derived<T>| {
return@@@create STUB
return@@@create <Unresolved name: Derived>#(<Unresolved name: x>#)
}
+4 -4
View File
@@ -16,19 +16,19 @@ FILE: enum.kt
public get(): R|Some|
public final enum entry FIRST : R|SomeEnum| {
public constructor(): super<R|SomeEnum|>()
public constructor(): super<R|SomeEnum|>(<Unresolved name: O1>#)
public final override function check(y: R|Some|): R|kotlin/Boolean| {
return@@@check STUB
return@@@check Boolean(true)
}
}
public final enum entry SECOND : R|SomeEnum| {
public constructor(): super<R|SomeEnum|>()
public constructor(): super<R|SomeEnum|>(<Unresolved name: O2>#)
public final override function check(y: R|Some|): R|kotlin/Boolean| {
return@@@check STUB
return@@@check ==(<Unresolved name: y>#, <Unresolved name: O2>#)
}
}
@@ -28,33 +28,33 @@ FILE: enums.kt
internal get(): R|kotlin/Double|
public final enum entry MERCURY : R|Planet| {
public constructor(): super<R|Planet|>()
public constructor(): super<R|Planet|>(Double(1.0), Double(2.0))
public final override function sayHello(): R|kotlin/Unit| {
return@@@sayHello STUB
<Unresolved name: println>#(String(Hello!!!))
}
}
public final enum entry VENERA : R|Planet| {
public constructor(): super<R|Planet|>()
public constructor(): super<R|Planet|>(Double(3.0), Double(4.0))
public final override function sayHello(): R|kotlin/Unit| {
return@@@sayHello STUB
<Unresolved name: println>#(String(Ola!!!))
}
}
public final enum entry EARTH : R|Planet| {
public constructor(): super<R|Planet|>()
public constructor(): super<R|Planet|>(Double(5.0), Double(6.0))
public final override function sayHello(): R|kotlin/Unit| {
return@@@sayHello STUB
<Unresolved name: println>#(String(Privet!!!))
}
}
public final property g(val): R|kotlin/Double| = STUB
public final property g(val): R|kotlin/Double| = <Unresolved name: div>#(<Unresolved name: times>#(<Unresolved name: G>#, R|/Planet.m|), <Unresolved name: times>#(R|/Planet.r|, R|/Planet.r|))
public get(): R|kotlin/Double|
public abstract function sayHello(): R|kotlin/Unit|
@@ -62,7 +62,7 @@ FILE: enums.kt
public final companion object Companion {
public constructor(): super<R|kotlin/Any|>()
public final const property G(val): R|error: Not supported: FirImplicitTypeImpl| = STUB
public final const property G(val): R|error: Not supported: FirImplicitTypeImpl| = Double(6.67E-11)
public get(): R|error: Not supported: FirImplicitTypeImpl|
}
@@ -4,9 +4,9 @@ FILE: noPrimaryConstructor.kt
public get(): R|kotlin/String|
public constructor(x: R|kotlin/String|): super<R|kotlin/Any|>() {
return STUB
this#.R|/NoPrimary.x| = R|/NoPrimary.x|
}
public constructor(): this<R|NoPrimary|>()
public constructor(): this<R|NoPrimary|>(String())
}
@@ -9,19 +9,18 @@ FILE: simpleClass.kt
public final class SomeClass : R|SomeInterface| {
public constructor(): super<R|kotlin/Any|>()
private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = STUB
private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = Int(42)
private get(): R|error: Not supported: FirImplicitTypeImpl|
public final override function foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String| {
return@@@foo STUB
return@@@foo <Unresolved name: plus>#(<Unresolved name: plus>#(<Unresolved name: y>#, <Unresolved name: x>#), R|/SomeClass.baz|)
}
public final override property bar(var): R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
return STUB
return Boolean(true)
}
public set(value: R|kotlin/Boolean|): R|kotlin/Unit| {
return STUB
}
public final lateinit property fau(var): R|kotlin/Double|
@@ -15,11 +15,11 @@ FILE: typeParameters.kt
public constructor(): super<R|AbstractList<kotlin/Int>|>()
public final override function get(index: R|kotlin/Int|): R|kotlin/Int| {
return@@@get STUB
return@@@get Int(42)
}
public final override function concat(other: R|List<kotlin/Int>|): R|List<kotlin/Int>| {
return@@@concat STUB
return@@@concat this#
}
}
+2 -3
View File
@@ -1,12 +1,11 @@
FILE: functionTypes.kt
<T> public final function simpleRun(f: R|(T) -> kotlin/Unit|): R|kotlin/Unit| {
return@@@simpleRun STUB
return@@@simpleRun <Unresolved name: f>#()
}
<T, R> public final function simpleMap R|kotlin/collections/List<T>|.(f: R|(T) -> R|): R|R| {
return@@@simpleMap STUB
}
<T> public final function simpleWith(t: R|T|, f: R|T.() -> kotlin/Unit|): R|kotlin/Unit| {
return@@@simpleWith STUB
return@@@simpleWith <Unresolved name: t>#.<Unresolved name: f>#()
}
<T, R> public abstract interface KMutableProperty1 : R|KProperty1<T, R>|, R|KMutableProperty<R>| {
}
+1 -1
View File
@@ -2,7 +2,7 @@ FILE: genericFunctions.kt
public abstract interface Any {
}
<reified T : R|Any|> public final inline function safeAs R|Any|.(): R|T| {
return@@@safeAs STUB
return@@@safeAs as?/R|T|(this#)
}
public abstract class Summator {
public constructor(): super<R|Any|>()
@@ -5,7 +5,7 @@ FILE: Annotations.kt
@R|annotations/Simple|() public abstract function foo(@R|annotations/WithString|(String(abc)) arg: @R|annotations/Simple|() R|kotlin/Double|): R|kotlin/Unit|
@R|annotations/Complex|(STUB, STUB) public abstract property v(val): R|kotlin/String|
@R|annotations/Complex|(<Unresolved name: WithInt>#(Int(7)), <Unresolved name: WithString>#(String())) public abstract property v(val): R|kotlin/String|
public get(): R|kotlin/String|
}
@@ -16,15 +16,15 @@ FILE: Annotations.kt
public get(): R|kotlin/Char|
public final override function foo(arg: R|kotlin/Double|): R|kotlin/Unit| {
return@@@foo STUB
}
public final override property v(val): R|kotlin/String|
@R|annotations/Simple|() public get(): R|kotlin/String| {
return STUB
return String()
}
@R|annotations/WithString|(String(constructor)) public constructor(): this<R|test/Second|>()
@R|annotations/WithString|(String(constructor)) public constructor(): this<R|test/Second|>(Char(
))
}
@R|annotations/WithInt|(Int(24)) @R|annotations/VeryComplex|(Float(3.14), Double(6.67E-11), Boolean(false), Long(123456789012345), Null(null)) @R|annotations/WithInt|(Int(24)) @R|annotations/VeryComplex|(Float(3.14), Double(6.67E-11), Boolean(false), Long(123456789012345), Null(null)) public final typealias Third = @R|annotations/Simple|() R|test/Second|
+2 -2
View File
@@ -10,12 +10,12 @@ FILE: nestedClass.kt
public constructor(): super<R|kotlin/Any|>()
public final class Derived : R|Base| {
public constructor(s: R|kotlin/String|): super<R|Base|>()
public constructor(s: R|kotlin/String|): super<R|Base|>(R|/Base.s|)
}
public final object Obj : R|Base| {
public constructor(): super<R|Base|>()
public constructor(): super<R|Base|>(String())
}
@@ -0,0 +1,3 @@
fun foo() = 1
fun bar() = foo()
@@ -0,0 +1,7 @@
FILE: simple.kt
public final function foo(): R|error: Not supported: FirImplicitTypeImpl| {
return@@@foo Int(1)
}
public final function bar(): R|error: Not supported: FirImplicitTypeImpl| {
return@@@bar R|/foo|()
}
@@ -0,0 +1,9 @@
open class A {
open fun foo() {}
}
class B : A() {
fun bar() {
foo()
}
}
@@ -0,0 +1,16 @@
FILE: superMember.kt
public open class A {
public constructor(): super<R|kotlin/Any|>()
public open function foo(): R|kotlin/Unit| {
}
}
public final class B : R|A| {
public constructor(): super<R|A|>()
public final function bar(): R|kotlin/Unit| {
R|/A.foo|()
}
}
+3 -4
View File
@@ -9,19 +9,18 @@ FILE: simpleClass.kt
public final class SomeClass : R|SomeInterface| {
public constructor(): super<R|kotlin/Any|>()
private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = STUB
private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = Int(42)
private get(): R|error: Not supported: FirImplicitTypeImpl|
public final override function foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String| {
return@@@foo STUB
return@@@foo <Unresolved name: plus>#(<Unresolved name: plus>#(<Unresolved name: y>#, <Unresolved name: x>#), R|/SomeClass.baz|)
}
public final override property bar(var): R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
return STUB
return Boolean(true)
}
public set(value: R|kotlin/Boolean|): R|kotlin/Unit| {
return STUB
}
public final property fau(var): R|kotlin/Double|
@@ -1,7 +1,6 @@
FILE: concurrent.kt
@R|kotlin/jvm/Volatile|() public final property xx(var): R|kotlin/Int| = STUB
@R|kotlin/jvm/Volatile|() public final property xx(var): R|kotlin/Int| = Int(2)
public get(): R|kotlin/Int|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
@R|kotlin/jvm/Synchronized|() public final function foo(): R|kotlin/Unit| {
return@@@foo STUB
}
+14 -3
View File
@@ -1,13 +1,24 @@
FILE: functionX.kt
public final property x(val): R|kotlin/jvm/functions/Function0<kotlin/Int>| = STUB
public final property x(val): R|kotlin/jvm/functions/Function0<kotlin/Int>| = function R|error: Not supported: FirImplicitTypeImpl|.<anonymous>(): R|error: Not supported: FirImplicitTypeImpl| {
return {
Int(42)
}
}
public get(): R|kotlin/jvm/functions/Function0<kotlin/Int>|
public final property y(val): R|kotlin/Function1<kotlin/String, kotlin/String>| = STUB
public final property y(val): R|kotlin/Function1<kotlin/String, kotlin/String>| = function R|error: Not supported: FirImplicitTypeImpl|.<anonymous>(): R|error: Not supported: FirImplicitTypeImpl| {
return {
<Unresolved name: it>#
}
}
public get(): R|kotlin/Function1<kotlin/String, kotlin/String>|
public final class MyFunction : R|kotlin/Function2<kotlin/Int, kotlin/String, kotlin/Unit>| {
public constructor(): super<R|kotlin/Any|>()
public final override function invoke(p1: R|kotlin/Int|, p2: R|kotlin/String|): R|kotlin/Unit| {
return@@@invoke STUB
}
}
@@ -1,5 +1,5 @@
FILE: reflectionClass.kt
public final property javaClass(val): R|java/lang/Class<kotlin/String>| = STUB
public final property javaClass(val): R|java/lang/Class<kotlin/String>| = <getClass>(<Unresolved name: String>#).<Unresolved name: java>#
public get(): R|java/lang/Class<kotlin/String>|
public final property kotlinClass(val): R|kotlin/reflect/KClass<kotlin/String>| = STUB
public final property kotlinClass(val): R|kotlin/reflect/KClass<kotlin/String>| = <getClass>(<Unresolved name: String>#)
public get(): R|kotlin/reflect/KClass<kotlin/String>|
+1 -1
View File
@@ -1,3 +1,3 @@
FILE: treeSet.kt
public final property x(val): R|java/util/SortedSet<kotlin/Int>| = STUB
public final property x(val): R|java/util/SortedSet<kotlin/Int>| = <Unresolved name: TreeSet>#()
public get(): R|java/util/SortedSet<kotlin/Int>|
@@ -1,5 +1,5 @@
FILE: typeParameterInPropertyReceiver.kt
<T : R|kotlin/Any|> public final property self R|T|.(val): R|T|
public get(): R|T| {
return STUB
return this#
}
@@ -29,7 +29,7 @@ abstract class AbstractFirResolveTestCase : AbstractFirResolveWithSessionTestCas
.uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project))
val session = createSession(scope)
val builder = RawFirBuilder(session, stubMode = true)
val builder = RawFirBuilder(session, stubMode = false)
val transformer = FirTotalResolveTransformer()
return ktFiles.map {
@@ -242,4 +242,27 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
runTest("compiler/fir/resolve/testData/resolve/multifile/TypeAliasExpansion.kt");
}
}
@TestMetadata("compiler/fir/resolve/testData/resolve/references")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class References extends AbstractFirResolveTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInReferences() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/resolve/references"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/references/simple.kt");
}
@TestMetadata("superMember.kt")
public void testSuperMember() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/references/superMember.kt");
}
}
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.name.Name
@BaseTransformedType
interface FirNamedReference : FirReference {
val name: Name
@@ -695,6 +695,12 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
print("${namedReference.name}#")
}
override fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference) {
print("R|")
print(resolvedCallableReference.callableSymbol.callableId)
print("|")
}
override fun visitThisReference(thisReference: FirThisReference) {
print("this")
val labelName = thisReference.labelName
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
import org.jetbrains.kotlin.fir.visitors.FirVisitor
interface FirResolvedCallableReference : FirNamedReference {
val callableSymbol: ConeCallableSymbol
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitResolvedCallableReference(this, data)
}
@@ -6,11 +6,14 @@
package org.jetbrains.kotlin.fir.declarations
import org.jetbrains.kotlin.fir.VisitedSupertype
import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner
import org.jetbrains.kotlin.fir.types.FirType
import org.jetbrains.kotlin.fir.visitors.FirVisitor
// Good name needed (something with receiver, type parameters, return type, and name)
interface FirCallableMember : @VisitedSupertype FirDeclaration, FirMemberDeclaration, FirTypedDeclaration {
interface FirCallableMember :
@VisitedSupertype FirDeclaration, FirMemberDeclaration,
FirTypedDeclaration, FirSymbolOwner<FirCallableMember> {
val isOverride: Boolean get() = status.isOverride
val receiverType: FirType?
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirCallableMember
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.transformSingle
import org.jetbrains.kotlin.fir.types.FirType
import org.jetbrains.kotlin.fir.visitors.FirTransformer
@@ -19,6 +20,7 @@ import org.jetbrains.kotlin.name.Name
abstract class FirAbstractCallableMember(
session: FirSession,
psi: PsiElement?,
final override val symbol: FirBasedSymbol<FirCallableMember>,
name: Name,
visibility: Visibility,
modality: Modality?,
@@ -30,6 +32,7 @@ abstract class FirAbstractCallableMember(
) : FirAbstractMemberDeclaration(session, psi, name, visibility, modality, isExpect, isActual), FirCallableMember {
init {
symbol.bind(this)
status.isOverride = isOverride
}
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirConstructor
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.transformInplace
import org.jetbrains.kotlin.fir.transformSingle
import org.jetbrains.kotlin.fir.types.FirType
@@ -23,13 +24,14 @@ import org.jetbrains.kotlin.name.Name
open class FirConstructorImpl(
session: FirSession,
psi: PsiElement?,
symbol: FirFunctionSymbol,
visibility: Visibility,
isExpect: Boolean,
isActual: Boolean,
delegatedSelfType: FirType,
final override var delegatedConstructor: FirDelegatedConstructorCall?
) : FirAbstractCallableMember(
session, psi, NAME, visibility, Modality.FINAL,
session, psi, symbol, NAME, visibility, Modality.FINAL,
isExpect, isActual, isOverride = false, receiverType = null, returnType = delegatedSelfType
), FirConstructor {
override val valueParameters = mutableListOf<FirValueParameter>()
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirNamedFunction
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.transformInplace
import org.jetbrains.kotlin.fir.transformSingle
import org.jetbrains.kotlin.fir.types.FirType
@@ -22,6 +23,7 @@ import org.jetbrains.kotlin.name.Name
class FirMemberFunctionImpl(
session: FirSession,
psi: PsiElement?,
symbol: FirFunctionSymbol,
name: Name,
visibility: Visibility,
modality: Modality?,
@@ -37,7 +39,7 @@ class FirMemberFunctionImpl(
receiverType: FirType?,
returnType: FirType
) : FirAbstractCallableMember(
session, psi, name, visibility, modality,
session, psi, symbol, name, visibility, modality,
isExpect, isActual, isOverride, receiverType, returnType
), FirNamedFunction, FirModifiableFunction {
init {
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.transformSingle
import org.jetbrains.kotlin.fir.types.FirType
import org.jetbrains.kotlin.fir.visitors.FirTransformer
@@ -21,6 +22,7 @@ import org.jetbrains.kotlin.name.Name
class FirMemberPropertyImpl(
session: FirSession,
psi: PsiElement?,
symbol: FirPropertySymbol,
name: Name,
visibility: Visibility,
modality: Modality?,
@@ -37,7 +39,7 @@ class FirMemberPropertyImpl(
override var setter: FirPropertyAccessor,
override var delegate: FirExpression?
) : FirAbstractCallableMember(
session, psi, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType
session, psi, symbol, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType
), FirProperty {
init {
status.isConst = isConst
@@ -9,14 +9,16 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.types.FirType
class FirPrimaryConstructorImpl(
session: FirSession,
psi: PsiElement?,
symbol: FirFunctionSymbol,
visibility: Visibility,
isExpect: Boolean,
isActual: Boolean,
delegatedSelfType: FirType,
delegatedConstructor: FirDelegatedConstructorCall?
) : FirConstructorImpl(session, psi, visibility, isExpect, isActual, delegatedSelfType, delegatedConstructor)
) : FirConstructorImpl(session, psi, symbol, visibility, isExpect, isActual, delegatedSelfType, delegatedConstructor)
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.references
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.fir.FirAbstractElement
import org.jetbrains.kotlin.fir.FirResolvedCallableReference
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
import org.jetbrains.kotlin.name.Name
class FirResolvedCallableReferenceImpl(
session: FirSession,
psi: PsiElement?,
override val name: Name,
override val callableSymbol: ConeCallableSymbol
) : FirAbstractElement(session, psi), FirResolvedCallableReference
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.impl
import org.jetbrains.kotlin.fir.declarations.FirCallableMember
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
class FirFunctionSymbol(override val callableId: CallableId) : ConeFunctionSymbol, AbstractFirBasedSymbol<FirCallableMember>() {
override val parameters: List<ConeKotlinType>
get() = emptyList()
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.impl
import org.jetbrains.kotlin.fir.declarations.FirCallableMember
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol
class FirPropertySymbol(override val callableId: CallableId) : ConePropertySymbol, AbstractFirBasedSymbol<FirCallableMember>()
@@ -136,10 +136,14 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
return transformElement(reference, data)
}
open fun <E : FirReference> transformNamedReference(namedReference: E, data: D): CompositeTransformResult<E> {
open fun transformNamedReference(namedReference: FirNamedReference, data: D): CompositeTransformResult<FirNamedReference> {
return transformReference(namedReference, data)
}
open fun transformResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: D): CompositeTransformResult<FirNamedReference> {
return transformNamedReference(resolvedCallableReference, data)
}
open fun <E : FirReference> transformSuperReference(superReference: E, data: D): CompositeTransformResult<E> {
return transformReference(superReference, data)
}
@@ -580,6 +584,10 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
return transformRegularClass(regularClass, data)
}
final override fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: D): CompositeTransformResult<FirElement> {
return transformResolvedCallableReference(resolvedCallableReference, data)
}
final override fun visitResolvedDeclarationStatus(resolvedDeclarationStatus: FirResolvedDeclarationStatus, data: D): CompositeTransformResult<FirElement> {
return transformResolvedDeclarationStatus(resolvedDeclarationStatus, data)
}
@@ -140,6 +140,10 @@ abstract class FirVisitor<out R, in D> {
return visitReference(namedReference, data)
}
open fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: D): R {
return visitNamedReference(resolvedCallableReference, data)
}
open fun visitSuperReference(superReference: FirSuperReference, data: D): R {
return visitReference(superReference, data)
}
@@ -140,6 +140,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitReference(namedReference, null)
}
open fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference) {
visitNamedReference(resolvedCallableReference, null)
}
open fun visitSuperReference(superReference: FirSuperReference) {
visitReference(superReference, null)
}
@@ -580,6 +584,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitRegularClass(regularClass)
}
final override fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: Nothing?) {
visitResolvedCallableReference(resolvedCallableReference)
}
final override fun visitResolvedDeclarationStatus(resolvedDeclarationStatus: FirResolvedDeclarationStatus, data: Nothing?) {
visitResolvedDeclarationStatus(resolvedDeclarationStatus)
}
@@ -1,4 +1,4 @@
FILE: user.kt
public final function foo(hello: R|hello/Hello|): R|kotlin/String| {
return@@@foo STUB
return@@@foo <Unresolved name: hello>#.<Unresolved name: msg>#
}
@@ -0,0 +1,5 @@
expect open class A() {
fun foo()
}
open class B : A()
@@ -0,0 +1,11 @@
FILE: common.kt
public open expect class A {
public constructor(): super<R|kotlin/Any|>()
public final function foo(): R|kotlin/Unit|
}
public open class B : R|A| {
public constructor(): super<R|A|>()
}
+19
View File
@@ -0,0 +1,19 @@
actual open class A {
actual fun foo() {}
fun bar() {}
}
class C : B() {
fun test() {
foo()
bar()
}
}
class D : A() {
fun test() {
foo()
bar()
}
}
+29
View File
@@ -0,0 +1,29 @@
FILE: jvm.kt
public open actual class A {
public constructor(): super<R|kotlin/Any|>()
public final actual function foo(): R|kotlin/Unit| {
}
public final function bar(): R|kotlin/Unit| {
}
}
public final class C : R|B| {
public constructor(): super<R|B|>()
public final function test(): R|kotlin/Unit| {
R|/A.foo|()
<Unresolved name: bar>#()
}
}
public final class D : R|A| {
public constructor(): super<R|A|>()
public final function test(): R|kotlin/Unit| {
R|/A.foo|()
<Unresolved name: bar>#()
}
}
@@ -68,7 +68,7 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() {
for (module in project.allModules().drop(1)) {
val session = createSession(module, provider)
val builder = RawFirBuilder(session, stubMode = true)
val builder = RawFirBuilder(session, stubMode = false)
val psiManager = PsiManager.getInstance(project)
val ideaModuleInfo = session.moduleInfo.cast<IdeaModuleInfo>()
@@ -33,4 +33,9 @@ public class FirMultiModuleResolveTestGenerated extends AbstractFirMultiModuleRe
public void testBasic() throws Exception {
runTest("idea/testData/fir/multiModule/basic/");
}
@TestMetadata("mppMembers")
public void testMppMembers() throws Exception {
runTest("idea/testData/fir/multiModule/mppMembers/");
}
}