IR: close over the set of captured type parameters
This commit is contained in:
+12
-15
@@ -55,7 +55,7 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
}
|
||||
|
||||
private class ClosureBuilder(val owner: IrDeclaration) {
|
||||
val capturedValues = mutableSetOf<IrValueSymbol>()
|
||||
private val capturedValues = mutableSetOf<IrValueSymbol>()
|
||||
private val declaredValues = mutableSetOf<IrValueDeclaration>()
|
||||
private val includes = mutableSetOf<ClosureBuilder>()
|
||||
|
||||
@@ -70,15 +70,16 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
* variables declared in the node.
|
||||
*/
|
||||
fun buildClosure(): Closure {
|
||||
val result = mutableSetOf<IrValueSymbol>().apply { addAll(capturedValues) }
|
||||
includes.forEach { builder ->
|
||||
if (!builder.processed) {
|
||||
builder.processed = true
|
||||
builder.buildClosure().capturedValues.filterTo(result) { isExternal(it.owner) }
|
||||
val subClosure = builder.buildClosure()
|
||||
subClosure.capturedValues.filterTo(capturedValues) { isExternal(it.owner) }
|
||||
subClosure.capturedTypeParameters.filterTo(capturedTypeParameters) { isExternal(it) }
|
||||
}
|
||||
}
|
||||
// TODO: We can save the closure and reuse it.
|
||||
return Closure(result.toList(), capturedTypeParameters.toList())
|
||||
return Closure(capturedValues.toList(), capturedTypeParameters.toList())
|
||||
}
|
||||
|
||||
|
||||
@@ -110,18 +111,14 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
|
||||
fun seeType(type: IrType) {
|
||||
if (type !is IrSimpleType) return
|
||||
(type.classifier as? IrTypeParameterSymbol)?.let { typeParameterSymbol ->
|
||||
val typeParameter = typeParameterSymbol.owner
|
||||
if (isExternal(typeParameter))
|
||||
capturedTypeParameters.add(typeParameter)
|
||||
val classifier = type.classifier
|
||||
if (classifier is IrTypeParameterSymbol && isExternal(classifier.owner) && capturedTypeParameters.add(classifier.owner))
|
||||
classifier.owner.superTypes.forEach(::seeType)
|
||||
type.arguments.forEach {
|
||||
(it as? IrTypeProjection)?.type?.let(::seeType)
|
||||
}
|
||||
for (arg in type.arguments) {
|
||||
(arg as? IrTypeProjection)?.let { seeType(arg.type) }
|
||||
}
|
||||
type.abbreviation?.let { abbreviation ->
|
||||
for (arg in abbreviation.arguments) {
|
||||
(arg as? IrTypeProjection)?.let { seeType(arg.type) }
|
||||
}
|
||||
type.abbreviation?.arguments?.forEach {
|
||||
(it as? IrTypeProjection)?.type?.let(::seeType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user