KT-37024 Optimized delegated property metadata generation in inline fun
This commit is contained in:
@@ -4587,10 +4587,16 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
// We can use the $$delegatedProperties array as in non-inline functions and upon inlining, detect elements at what indices
|
||||
// of that array are used in the inline function body, load the corresponding initializing bytecode from <clinit> of the
|
||||
// container class (where the PropertyReferenceNImpl instance is created), copy and adapt it at the call site
|
||||
//noinspection ConstantConditions
|
||||
StackValue value = context.getFunctionDescriptor().isInline()
|
||||
? generatePropertyReference(variable.getDelegate(), variableDescriptor, variableDescriptor, null)
|
||||
: PropertyCodegen.getDelegatedPropertyMetadata(variableDescriptor, bindingContext);
|
||||
StackValue value;
|
||||
if (PropertyCodegen.isDelegatedPropertyWithOptimizedMetadata(variableDescriptor, bindingContext)) {
|
||||
value = PropertyCodegen.getOptimizedDelegatedPropertyMetadataValue();
|
||||
} else if (context.getFunctionDescriptor().isInline()) {
|
||||
//noinspection ConstantConditions
|
||||
value = generatePropertyReference(variable.getDelegate(), variableDescriptor, variableDescriptor, null);
|
||||
}
|
||||
else {
|
||||
value = PropertyCodegen.getDelegatedPropertyMetadata(variableDescriptor, bindingContext);
|
||||
}
|
||||
value.put(K_PROPERTY_TYPE, null, v);
|
||||
metadataVar.storeSelector(K_PROPERTY_TYPE, null, v);
|
||||
}
|
||||
|
||||
@@ -564,13 +564,24 @@ public class PropertyCodegen {
|
||||
return codegen.invokeFunction(resolvedCall, receiver);
|
||||
}
|
||||
|
||||
public static boolean isDelegatedPropertyWithOptimizedMetadata(
|
||||
@NotNull VariableDescriptorWithAccessors descriptor,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
return Boolean.TRUE == bindingContext.get(DELEGATED_PROPERTY_WITH_OPTIMIZED_METADATA, descriptor);
|
||||
}
|
||||
|
||||
public static @NotNull StackValue getOptimizedDelegatedPropertyMetadataValue() {
|
||||
return StackValue.constant(null, K_PROPERTY_TYPE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StackValue getDelegatedPropertyMetadata(
|
||||
@NotNull VariableDescriptorWithAccessors descriptor,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
if (Boolean.TRUE == bindingContext.get(DELEGATED_PROPERTY_WITH_OPTIMIZED_METADATA, descriptor)) {
|
||||
return StackValue.constant(null, K_PROPERTY_TYPE);
|
||||
if (isDelegatedPropertyWithOptimizedMetadata(descriptor, bindingContext)) {
|
||||
return getOptimizedDelegatedPropertyMetadataValue();
|
||||
}
|
||||
|
||||
Type owner = bindingContext.get(DELEGATED_PROPERTY_METADATA_OWNER, descriptor);
|
||||
|
||||
Generated
+5
@@ -8735,6 +8735,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt37204.kt")
|
||||
public void testKt37204() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4138.kt")
|
||||
public void testKt4138() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
val log = StringBuilder()
|
||||
|
||||
inline fun test() {
|
||||
val localLazy by lazy {
|
||||
log.append("localLazy;")
|
||||
"v;"
|
||||
}
|
||||
log.append("test;")
|
||||
log.append(localLazy)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
val t = log.toString()
|
||||
if (t != "test;localLazy;v;")
|
||||
throw AssertionError(t)
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -9880,6 +9880,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt37204.kt")
|
||||
public void testKt37204() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4138.kt")
|
||||
public void testKt4138() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
|
||||
+5
@@ -9880,6 +9880,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt37204.kt")
|
||||
public void testKt37204() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4138.kt")
|
||||
public void testKt4138() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
|
||||
+5
@@ -8735,6 +8735,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt37204.kt")
|
||||
public void testKt37204() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4138.kt")
|
||||
public void testKt4138() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
|
||||
Generated
+7
-2
@@ -5729,8 +5729,8 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionIsAs.kt")
|
||||
public void testSuspendFunctionIsAs_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt", "kotlin.coroutines");
|
||||
public void testSuspendFunctionIsAs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendInlineSuspendFinally.kt")
|
||||
@@ -7470,6 +7470,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt37204.kt")
|
||||
public void testKt37204() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4138.kt")
|
||||
public void testKt4138() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
|
||||
+7
-2
@@ -5729,8 +5729,8 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionIsAs.kt")
|
||||
public void testSuspendFunctionIsAs_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt", "kotlin.coroutines");
|
||||
public void testSuspendFunctionIsAs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendInlineSuspendFinally.kt")
|
||||
@@ -7470,6 +7470,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt37204.kt")
|
||||
public void testKt37204() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt37204.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4138.kt")
|
||||
public void testKt4138() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
|
||||
Reference in New Issue
Block a user