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,
isConstructor: Boolean
): 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 remapper = RegeneratedLambdaFieldRemapper(
@@ -25,7 +25,7 @@ class RootInliningContext(
nameGenerator: NameGenerator,
val callElement: KtElement,
override val callSiteInfo: InlineCallSiteInfo,
val inlineMethodReificator: ReifiedTypeInliner,
val inlineMethodReifier: ReifiedTypeInliner,
typeParameterMappings: TypeParameterMappings
) : InliningContext(
null, expressionMap, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), null, false
@@ -75,11 +75,9 @@ class MethodInliner(
): InlineResult {
//analyze body
var transformedNode = markPlacesForInlineAndRemoveInlinable(node, labelOwner, finallyDeepShift)
if (inliningContext.isInliningLambda &&
inliningContext.lambdaInfo is DefaultLambda &&
inliningContext.lambdaInfo.needReification) {
if (inliningContext.isInliningLambda && isDefaultLambdaWithReification(inliningContext.lambdaInfo!!)) {
//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
@@ -277,9 +275,7 @@ class MethodInliner(
super.visitMethodInsn(opcode, owner, name, desc, itf)
}
}
else if ((!inliningContext.isInliningLambda ||
inliningContext.lambdaInfo is DefaultLambda &&
inliningContext.lambdaInfo.needReification) &&
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
}
@@ -306,6 +302,9 @@ 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()
@@ -26,7 +26,7 @@ class TypeRemapper private constructor(
val parent: TypeRemapper? = null,
val isRootInlineLambda: Boolean = false
) {
private var additionalMappings = hashMapOf<String, String>()
private val additionalMappings = hashMapOf<String, String>()
private val typeParametersMapping = hashMapOf<String, TypeParameter>()
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);
}
@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")
public void testDefaultLambdaInNoInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultLambdaInNoInline.kt");
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")
public void testFunctionReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionReference.kt");
@@ -1027,6 +1039,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
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")
public void testPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyReference.kt");
@@ -973,12 +973,24 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
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")
public void testDefaultLambdaInNoInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/defaultLambdaInNoInline.kt");
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")
public void testFunctionReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/functionReference.kt");
@@ -1027,6 +1039,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
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")
public void testPropertyReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/propertyReference.kt");