IR: rename {name,fqName}Safe -> {name,fqName}ForIrSerialization
These properties have a very specific detail in their behavior, in that the constructor's name is set to be "<init>". While this is OK for the IR serialization, this may not always be expected in other cases, and their rather common names (`name`, `fqNameSafe`) suggested that these properties could be used in generic contexts. Change all usages outside IR serialization to use `IrDeclarationWithName.name` and nullable `IrDeclarationWithName.fqNameWhenAvailable` instead
This commit is contained in:
+8
-8
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.util.fqNameSafe
|
||||
import org.jetbrains.kotlin.ir.util.name
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -33,11 +33,11 @@ internal val BUILT_IN_UNIQ_ID_GAP = 2 * BUILT_IN_FUNCTION_ARITY_COUNT * BUILT_IN
|
||||
internal val BUILT_IN_UNIQ_ID_CLASS_OFFSET = BUILT_IN_FUNCTION_CLASS_COUNT * BUILT_IN_FUNCTION_ARITY_COUNT
|
||||
|
||||
internal fun isBuiltInFunction(value: IrDeclaration): Boolean = when (value) {
|
||||
is IrSimpleFunction -> value.name.asString() == "invoke" && (value.parent as? IrClass)?.let { isBuiltInFunction(it) } == true
|
||||
is IrClass -> {
|
||||
val fqn = value.parent.fqNameSafe
|
||||
functionalPackages.any { it == fqn } && value.name.asString().let { functionPattern.matcher(it).find() }
|
||||
}
|
||||
is IrSimpleFunction ->
|
||||
value.name.asString() == "invoke" && (value.parent as? IrClass)?.let { isBuiltInFunction(it) } == true
|
||||
is IrClass ->
|
||||
value.fqNameWhenAvailable?.parent() in functionalPackages &&
|
||||
value.name.asString().let { functionPattern.matcher(it).find() }
|
||||
else -> false
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ internal fun builtInFunctionId(value: IrDeclaration): Long = when (value) {
|
||||
value.run { valueParameters.size + builtInOffset(value) * BUILT_IN_FUNCTION_ARITY_COUNT }.toLong()
|
||||
}
|
||||
is IrClass -> {
|
||||
BUILT_IN_UNIQ_ID_CLASS_OFFSET + builtInFunctionId(value.declarations.first { it.name.asString() == "invoke" })
|
||||
BUILT_IN_UNIQ_ID_CLASS_OFFSET + builtInFunctionId(value.declarations.first { it.nameForIrSerialization.asString() == "invoke" })
|
||||
}
|
||||
else -> error("Only class or function is expected")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user