[FIR2IR] Set @Metadata when declaring IR symbols

This commit is contained in:
Jinseong Jeon
2020-04-04 01:02:37 +03:00
committed by Mikhail Glukhikh
parent b7e270f1c1
commit 08ca6f5f99
25 changed files with 118 additions and 28 deletions
@@ -208,6 +208,7 @@ class Fir2IrClassifierStorage(
isExpect = regularClass.isExpect, isExpect = regularClass.isExpect,
isFun = false // TODO FirRegularClass.isFun isFun = false // TODO FirRegularClass.isFun
).apply { ).apply {
metadata = MetadataSource.Class(descriptor)
descriptor.bind(this) descriptor.bind(this)
} }
} }
@@ -242,6 +243,7 @@ class Fir2IrClassifierStorage(
isCompanion = false, isInner = false, isData = false, isCompanion = false, isInner = false, isData = false,
isExternal = false, isInline = false, isExpect = false, isFun = false isExternal = false, isInline = false, isExpect = false, isFun = false
).apply { ).apply {
metadata = MetadataSource.Class(descriptor)
descriptor.bind(this) descriptor.bind(this)
setThisReceiver() setThisReceiver()
if (irParent != null) { if (irParent != null) {
@@ -430,7 +430,9 @@ class Fir2IrDeclarationStorage(
isExpect = simpleFunction?.isExpect == true, isExpect = simpleFunction?.isExpect == true,
isFakeOverride = updatedOrigin == IrDeclarationOrigin.FAKE_OVERRIDE, isFakeOverride = updatedOrigin == IrDeclarationOrigin.FAKE_OVERRIDE,
isOperator = simpleFunction?.isOperator == true isOperator = simpleFunction?.isOperator == true
) ).apply {
metadata = MetadataSource.Function(descriptor)
}
} }
result result
}.bindAndDeclareParameters(function, descriptor, irParent, isStatic = simpleFunction?.isStatic == true) }.bindAndDeclareParameters(function, descriptor, irParent, isStatic = simpleFunction?.isStatic == true)
@@ -486,6 +488,7 @@ class Fir2IrDeclarationStorage(
constructor.returnTypeRef.toIrType(), constructor.returnTypeRef.toIrType(),
isInline = false, isExternal = false, isPrimary = isPrimary, isExpect = false isInline = false, isExternal = false, isPrimary = isPrimary, isExpect = false
).apply { ).apply {
metadata = MetadataSource.Function(descriptor)
enterScope(descriptor) enterScope(descriptor)
}.bindAndDeclareParameters(constructor, descriptor, irParent, isStatic = false).apply { }.bindAndDeclareParameters(constructor, descriptor, irParent, isStatic = false).apply {
leaveScope(descriptor) leaveScope(descriptor)
@@ -532,6 +535,7 @@ class Fir2IrDeclarationStorage(
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE, isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
isOperator = false isOperator = false
).apply { ).apply {
metadata = MetadataSource.Function(descriptor)
with(classifierStorage) { with(classifierStorage) {
setTypeParameters( setTypeParameters(
property, ConversionTypeContext( property, ConversionTypeContext(
@@ -585,6 +589,7 @@ class Fir2IrDeclarationStorage(
isExpect = property.isExpect, isExpect = property.isExpect,
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
).apply { ).apply {
metadata = MetadataSource.Property(descriptor)
descriptor.bind(this) descriptor.bind(this)
if (irParent != null) { if (irParent != null) {
parent = irParent parent = irParent
@@ -638,6 +643,7 @@ class Fir2IrDeclarationStorage(
isStatic = field.isStatic, isStatic = field.isStatic,
isFakeOverride = false isFakeOverride = false
).apply { ).apply {
metadata = MetadataSource.Property(descriptor)
descriptor.bind(this) descriptor.bind(this)
fieldCache[field] = this fieldCache[field] = this
} }
@@ -443,7 +443,110 @@ open class WrappedSimpleFunctionDescriptor(
override fun <V : Any?> getUserData(key: CallableDescriptor.UserDataKey<V>?): V? = null override fun <V : Any?> getUserData(key: CallableDescriptor.UserDataKey<V>?): V? = null
override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder<out SimpleFunctionDescriptor> { override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder<out SimpleFunctionDescriptor> {
TODO("not implemented") // Use the original descriptor's copy builder if available.
// make sure that the original descriptor is not `this`. Otherwise, newCopyBuilder ends up with stack overflow.
if (originalDescriptor != this && originalDescriptor is SimpleFunctionDescriptor) {
return (originalDescriptor as SimpleFunctionDescriptor).newCopyBuilder();
}
// Otherwise, return a fake copy builder that will eventually return the same wrapped descriptor.
// TODO: it is unclear whether IR lowering really needs a deep copy (and a fake copy is okay by chance).
return object : FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
override fun setOwner(owner: DeclarationDescriptor): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setModality(modality: Modality): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setVisibility(visibility: Visibility): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setKind(kind: CallableMemberDescriptor.Kind): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setCopyOverrides(copyOverrides: Boolean): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setName(name: Name): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setValueParameters(parameters: MutableList<ValueParameterDescriptor>):
FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setTypeParameters(
parameters: MutableList<TypeParameterDescriptor>
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setReturnType(type: KotlinType): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setExtensionReceiverParameter(
extensionReceiverParameter: ReceiverParameterDescriptor?
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setDispatchReceiverParameter(
dispatchReceiverParameter: ReceiverParameterDescriptor?
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setOriginal(original: CallableMemberDescriptor?): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setSignatureChange(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setPreserveSourceElement(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setDropOriginalInContainingParts(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setHiddenToOvercomeSignatureClash(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setHiddenForResolutionEverywhereBesideSupercalls(): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setAdditionalAnnotations(
additionalAnnotations: Annotations
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun setSubstitution(substitution: TypeSubstitution): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun <V : Any?> putUserData(
userDataKey: CallableDescriptor.UserDataKey<V>,
value: V
): FunctionDescriptor.CopyBuilder<SimpleFunctionDescriptor> {
return this
}
override fun build(): SimpleFunctionDescriptor? {
return this@WrappedSimpleFunctionDescriptor
}
}
} }
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D) = override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D) =
@@ -570,11 +673,11 @@ open class WrappedClassDescriptor(
override fun getSource() = sourceElement override fun getSource() = sourceElement
override fun getConstructors() = owner.declarations.asSequence().filterIsInstance<IrConstructor>().map { it.descriptor }.toList() override fun getConstructors() =
owner.declarations.filterIsInstance<IrConstructor>().filter { !it.origin.isSynthetic }.map { it.descriptor }.toList()
override fun getContainingDeclaration() = (owner.parent as IrSymbolOwner).symbol.descriptor override fun getContainingDeclaration() = (owner.parent as IrSymbolOwner).symbol.descriptor
private val _defaultType: SimpleType by lazy { private val _defaultType: SimpleType by lazy {
TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope, KotlinTypeFactory.EMPTY_REFINED_TYPE_FACTORY) TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope, KotlinTypeFactory.EMPTY_REFINED_TYPE_FACTORY)
} }
@@ -604,9 +707,7 @@ open class WrappedClassDescriptor(
override fun getDeclaredTypeParameters() = owner.typeParameters.map { it.descriptor } override fun getDeclaredTypeParameters() = owner.typeParameters.map { it.descriptor }
override fun getSealedSubclasses(): Collection<ClassDescriptor> { override fun getSealedSubclasses(): Collection<ClassDescriptor> = emptyList()
TODO("not implemented")
}
override fun getOriginal() = this override fun getOriginal() = this
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
+2
View File
@@ -1,3 +1,5 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T> tableView(init: Table<T>.() -> Unit) { fun <T> tableView(init: Table<T>.() -> Unit) {
Table<T>().init() Table<T>().init()
} }
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT // WITH_REFLECT
@@ -1,5 +1,4 @@
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi // !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR, JS, NATIVE // IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,6 +1,5 @@
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi // !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
// !LANGUAGE: +NewInference // !LANGUAGE: +NewInference
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,5 +1,4 @@
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi // !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS, JS_IR, NATIVE // IGNORE_BACKEND: JS, JS_IR, NATIVE
// WITH_REFLECT // WITH_REFLECT
@@ -1,5 +1,4 @@
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi // !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS, JS_IR, NATIVE // IGNORE_BACKEND: JS, JS_IR, NATIVE
// WITH_REFLECT // WITH_REFLECT
@@ -1,5 +1,4 @@
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi // !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS, JS_IR, NATIVE // IGNORE_BACKEND: JS, JS_IR, NATIVE
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE