Made coroutines and lambdas numbered continuously

This commit is contained in:
Igor Chevdar
2018-09-24 19:22:10 +03:00
parent d9d53d84d8
commit c9632e4f23
3 changed files with 5 additions and 6 deletions
@@ -332,6 +332,9 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
config.librariesWithDependencies(moduleDescriptor)
}
var functionReferenceCount = 0
var coroutineCount = 0
fun needGlobalInit(field: IrField): Boolean {
if (field.descriptor.containingDeclaration !is PackageFragmentDescriptor) return false
// TODO: add some smartness here. Maybe if package of the field is in never accessed
@@ -47,8 +47,6 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
private object DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL : IrDeclarationOriginImpl("FUNCTION_REFERENCE_IMPL")
private var functionReferenceCount = 0
override fun lower(irFile: IrFile) {
irFile.transform(object: IrElementTransformerVoidWithContext() {
@@ -184,7 +182,7 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
functionReferenceClassDescriptor = object : ClassDescriptorImpl(
/* containingDeclaration = */ containingDeclaration,
/* name = */ "${functionDescriptor.name}\$${functionReferenceCount++}".synthesizedName,
/* name = */ "${functionDescriptor.name}\$FUNCTION_REFERENCE\$${context.functionReferenceCount++}".synthesizedName,
/* modality = */ Modality.FINAL,
/* kind = */ ClassKind.CLASS,
/* superTypes = */ superTypes.map { it.toKotlinType() },
@@ -252,8 +252,6 @@ internal class SuspendFunctionsLowering(val context: Context): FileLoweringPass
val coroutineConstructor: IrConstructor,
val invokeSuspendFunction: IrFunction)
private var coroutineId = 0
private val COROUTINES_FQ_NAME = FqName.fromSegments(listOf("kotlin", "coroutines", "experimental"))
private val KOTLIN_FQ_NAME = FqName("kotlin")
@@ -310,7 +308,7 @@ internal class SuspendFunctionsLowering(val context: Context): FileLoweringPass
}
coroutineClassDescriptor = ClassDescriptorImpl(
/* containingDeclaration = */ irFunction.descriptor.containingDeclaration,
/* name = */ "${irFunction.descriptor.name}\$${coroutineId++}".synthesizedName,
/* name = */ "${irFunction.descriptor.name}\$COROUTINE\$${context.coroutineCount++}".synthesizedName,
/* modality = */ Modality.FINAL,
/* kind = */ ClassKind.CLASS,
/* superTypes = */ superTypes.map { it.toKotlinType() },