JVM: remove a redundant DefaultLambda field

and add a comment explaining one branch of the inliner... Better than
nothing, I guess?
This commit is contained in:
pyos
2021-06-27 22:31:28 +02:00
committed by max-kammerer
parent 100d2d629c
commit 91cf1a1a4d
2 changed files with 11 additions and 14 deletions
@@ -73,10 +73,7 @@ abstract class ExpressionLambda : LambdaInfo() {
}
}
class DefaultLambda(info: ExtractedDefaultLambda, sourceCompiler: SourceCompilerForInline) : LambdaInfo() {
val needReification = info.needReification // TODO: remove this
override val lambdaClassType: Type = info.type
override val isSuspend: Boolean get() = false // TODO: it should probably be true sometimes, but it never was
override val isBoundCallableReference: Boolean
@@ -92,10 +92,6 @@ class MethodInliner(
): InlineResult {
//analyze body
var transformedNode = markPlacesForInlineAndRemoveInlinable(node, returnLabels, finallyDeepShift)
if (inliningContext.isInliningLambda && isDefaultLambdaWithReification(inliningContext.lambdaInfo!!)) {
//TODO maybe move reification in one place
inliningContext.root.inlineMethodReifier.reifyInstructions(transformedNode)
}
//substitute returns with "goto end" instruction to keep non local returns in lambdas
val end = linkedLabel()
@@ -321,10 +317,17 @@ class MethodInliner(
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf)
}
} else if ((!inliningContext.isInliningLambda || isDefaultLambdaWithReification(inliningContext.lambdaInfo!!)) &&
ReifiedTypeInliner.isNeedClassReificationMarker(MethodInsnNode(opcode, owner, name, desc, false))
) {
//we shouldn't process here content of inlining lambda it should be reified at external level except default lambdas
} else if (ReifiedTypeInliner.isNeedClassReificationMarker(MethodInsnNode(opcode, owner, name, desc, false))) {
// Consider this arrangement:
// inline fun <reified T> f(x: () -> Unit = { /* uses `T` in a local class */ }) = x()
// inline fun <reified V> g() = f<...> { /* uses `V` in a local class */ }
// When inlining `f` into `g`, we need to erase class reification markers from `f` and the default lambda
// (they will be recreated by `handleAnonymousObjectRegeneration` above if `T` is instantiated with another
// reified type parameter), but not from the lambda passed to `f` in `g` (as reified type parameters inside
// it do not belong to `f`, thus we cannot substitute them yet).
if (inliningContext.isInliningLambda && inliningContext.lambdaInfo !is DefaultLambda) {
super.visitMethodInsn(opcode, owner, name, desc, itf)
}
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf)
}
@@ -349,9 +352,6 @@ class MethodInliner(
return resultNode
}
private fun isDefaultLambdaWithReification(lambdaInfo: LambdaInfo) =
lambdaInfo is DefaultLambda && lambdaInfo.needReification
private fun prepareNode(node: MethodNode, finallyDeepShift: Int): MethodNode {
node.instructions.resetLabels()