Minor. Fix review remarks

This commit is contained in:
Mikhael Bogdanov
2017-05-16 14:21:05 +02:00
parent fd561c6cb9
commit d9dc2bd443
9 changed files with 110 additions and 10 deletions
@@ -183,7 +183,7 @@ class AnonymousObjectTransformer(
capturedBuilder: ParametersBuilder, capturedBuilder: ParametersBuilder,
isConstructor: Boolean isConstructor: Boolean
): InlineResult { ): InlineResult {
val typeParametersToReify = inliningContext.root.inlineMethodReificator.reifyInstructions(sourceNode) val typeParametersToReify = inliningContext.root.inlineMethodReifier.reifyInstructions(sourceNode)
val parameters = if (isConstructor) capturedBuilder.buildParameters() else getMethodParametersWithCaptured(capturedBuilder, sourceNode) val parameters = if (isConstructor) capturedBuilder.buildParameters() else getMethodParametersWithCaptured(capturedBuilder, sourceNode)
val remapper = RegeneratedLambdaFieldRemapper( val remapper = RegeneratedLambdaFieldRemapper(
@@ -25,7 +25,7 @@ class RootInliningContext(
nameGenerator: NameGenerator, nameGenerator: NameGenerator,
val callElement: KtElement, val callElement: KtElement,
override val callSiteInfo: InlineCallSiteInfo, override val callSiteInfo: InlineCallSiteInfo,
val inlineMethodReificator: ReifiedTypeInliner, val inlineMethodReifier: ReifiedTypeInliner,
typeParameterMappings: TypeParameterMappings typeParameterMappings: TypeParameterMappings
) : InliningContext( ) : InliningContext(
null, expressionMap, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), null, false null, expressionMap, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), null, false
@@ -75,11 +75,9 @@ class MethodInliner(
): InlineResult { ): InlineResult {
//analyze body //analyze body
var transformedNode = markPlacesForInlineAndRemoveInlinable(node, labelOwner, finallyDeepShift) var transformedNode = markPlacesForInlineAndRemoveInlinable(node, labelOwner, finallyDeepShift)
if (inliningContext.isInliningLambda && if (inliningContext.isInliningLambda && isDefaultLambdaWithReification(inliningContext.lambdaInfo!!)) {
inliningContext.lambdaInfo is DefaultLambda &&
inliningContext.lambdaInfo.needReification) {
//TODO maybe move reification in one place //TODO maybe move reification in one place
inliningContext.root.inlineMethodReificator.reifyInstructions(transformedNode) inliningContext.root.inlineMethodReifier.reifyInstructions(transformedNode)
} }
//substitute returns with "goto end" instruction to keep non local returns in lambdas //substitute returns with "goto end" instruction to keep non local returns in lambdas
@@ -277,9 +275,7 @@ class MethodInliner(
super.visitMethodInsn(opcode, owner, name, desc, itf) super.visitMethodInsn(opcode, owner, name, desc, itf)
} }
} }
else if ((!inliningContext.isInliningLambda || else if ((!inliningContext.isInliningLambda || isDefaultLambdaWithReification(inliningContext.lambdaInfo!!)) &&
inliningContext.lambdaInfo is DefaultLambda &&
inliningContext.lambdaInfo.needReification) &&
ReifiedTypeInliner.isNeedClassReificationMarker(MethodInsnNode(opcode, owner, name, desc, false))) { 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 //we shouldn't process here content of inlining lambda it should be reified at external level except default lambdas
} }
@@ -306,6 +302,9 @@ class MethodInliner(
return resultNode return resultNode
} }
private fun isDefaultLambdaWithReification(lambdaInfo: LambdaInfo) =
lambdaInfo is DefaultLambda && lambdaInfo.needReification
private fun prepareNode(node: MethodNode, finallyDeepShift: Int): MethodNode { private fun prepareNode(node: MethodNode, finallyDeepShift: Int): MethodNode {
node.instructions.resetLabels() node.instructions.resetLabels()
@@ -26,7 +26,7 @@ class TypeRemapper private constructor(
val parent: TypeRemapper? = null, val parent: TypeRemapper? = null,
val isRootInlineLambda: Boolean = false val isRootInlineLambda: Boolean = false
) { ) {
private var additionalMappings = hashMapOf<String, String>() private val additionalMappings = hashMapOf<String, String>()
private val typeParametersMapping = hashMapOf<String, TypeParameter>() private val typeParametersMapping = hashMapOf<String, TypeParameter>()
fun addMapping(type: String, newType: String) { fun addMapping(type: String, newType: String) {
@@ -0,0 +1,20 @@
// FILE: 1.kt
// LANGUAGE_VERSION: 1.2
// SKIP_INLINE_CHECK_IN: inlineFun$default
package test
class A(val value: String) {
fun ok() = value
}
inline fun inlineFun(a: String, lambda: (String) -> A = ::A): A {
return lambda(a)
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun("OK").value
}
@@ -0,0 +1,24 @@
// FILE: 1.kt
package test
fun ok() = "OK"
object A {
fun ok() = "OK"
}
inline fun stub() {}
// FILE: 2.kt
// LANGUAGE_VERSION: 1.2
// SKIP_INLINE_CHECK_IN: inlineFun$default
import test.A.ok
inline fun inlineFun(lambda: () -> String = ::ok): String {
return lambda()
}
fun box(): String {
return inlineFun()
}
@@ -0,0 +1,21 @@
// FILE: 1.kt
package test
object A {
val ok = "OK"
}
inline fun stub() {}
// FILE: 2.kt
// LANGUAGE_VERSION: 1.2
// SKIP_INLINE_CHECK_IN: inlineFun$default
import test.A.ok
inline fun inlineFun(lambda: () -> String = ::ok): String {
return lambda()
}
fun box(): String {
return inlineFun()
}
@@ -973,12 +973,24 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName); doTest(fileName);
} }
@TestMetadata("constuctorReference.kt")
public void testConstuctorReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/constuctorReference.kt");
doTest(fileName);
}
@TestMetadata("defaultLambdaInNoInline.kt") @TestMetadata("defaultLambdaInNoInline.kt")
public void testDefaultLambdaInNoInline() throws Exception { public void testDefaultLambdaInNoInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultLambdaInNoInline.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultLambdaInNoInline.kt");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("functionImportedFromObject.kt")
public void testFunctionImportedFromObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionImportedFromObject.kt");
doTest(fileName);
}
@TestMetadata("functionReference.kt") @TestMetadata("functionReference.kt")
public void testFunctionReference() throws Exception { public void testFunctionReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionReference.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionReference.kt");
@@ -1027,6 +1039,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName); doTest(fileName);
} }
@TestMetadata("propertyImportedFromObject.kt")
public void testPropertyImportedFromObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyImportedFromObject.kt");
doTest(fileName);
}
@TestMetadata("propertyReference.kt") @TestMetadata("propertyReference.kt")
public void testPropertyReference() throws Exception { public void testPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyReference.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyReference.kt");
@@ -973,12 +973,24 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName); doTest(fileName);
} }
@TestMetadata("constuctorReference.kt")
public void testConstuctorReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/constuctorReference.kt");
doTest(fileName);
}
@TestMetadata("defaultLambdaInNoInline.kt") @TestMetadata("defaultLambdaInNoInline.kt")
public void testDefaultLambdaInNoInline() throws Exception { public void testDefaultLambdaInNoInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultLambdaInNoInline.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultLambdaInNoInline.kt");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("functionImportedFromObject.kt")
public void testFunctionImportedFromObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionImportedFromObject.kt");
doTest(fileName);
}
@TestMetadata("functionReference.kt") @TestMetadata("functionReference.kt")
public void testFunctionReference() throws Exception { public void testFunctionReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionReference.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionReference.kt");
@@ -1027,6 +1039,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName); doTest(fileName);
} }
@TestMetadata("propertyImportedFromObject.kt")
public void testPropertyImportedFromObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyImportedFromObject.kt");
doTest(fileName);
}
@TestMetadata("propertyReference.kt") @TestMetadata("propertyReference.kt")
public void testPropertyReference() throws Exception { public void testPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyReference.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyReference.kt");