Temporary disable line numbers generation for default values from expect declarations

Proper SMAP support for default values from expect declarations is required.
 Default value in expect declaration could has line number that
 exceed line count in actual file that causes an error

  #KT-23739 Fixed
  #KT-29174 Open
This commit is contained in:
Mikhael Bogdanov
2019-01-09 16:31:00 +01:00
parent c725f4ce32
commit 306a982722
9 changed files with 97 additions and 26 deletions
@@ -89,6 +89,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.org.objectweb.asm.commons.Method;
import java.util.*;
import java.util.function.Supplier;
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isInt;
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
@@ -1432,12 +1433,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
});
}
public boolean isShouldMarkLineNumbers() {
return shouldMarkLineNumbers;
}
public void setShouldMarkLineNumbers(boolean shouldMarkLineNumbers) {
this.shouldMarkLineNumbers = shouldMarkLineNumbers;
public <T> T runWithShouldMarkLineNumbers(boolean enable, Supplier<T> operation) {
boolean originalStatus = shouldMarkLineNumbers;
this.shouldMarkLineNumbers = enable;
try {
return operation.get();
} finally {
this.shouldMarkLineNumbers = originalStatus;
}
}
public void markStartLineNumber(@NotNull KtElement element) {
@@ -1313,8 +1313,14 @@ public class FunctionCodegen {
Label loadArg = new Label();
iv.ifeq(loadArg);
StackValue.local(parameterIndex, type, parameterDescriptor.getType())
.store(loadStrategy.genValue(parameterDescriptor, codegen), iv);
CallableDescriptor containingDeclaration = parameterDescriptor.getContainingDeclaration();
codegen.runWithShouldMarkLineNumbers(
!(containingDeclaration instanceof MemberDescriptor) || !((MemberDescriptor) containingDeclaration).isExpect(),
() -> {
StackValue.local(parameterIndex, type, parameterDescriptor.getType())
.store(loadStrategy.genValue(parameterDescriptor, codegen), iv);
return null;
});
iv.mark(loadArg);
}
@@ -323,30 +323,27 @@ fun FqName.topLevelClassInternalName() = JvmClassName.byClassId(ClassId(parent()
fun FqName.topLevelClassAsmType(): Type = Type.getObjectType(topLevelClassInternalName())
fun initializeVariablesForDestructuredLambdaParameters(codegen: ExpressionCodegen, valueParameters: List<ValueParameterDescriptor>) {
val savedIsShouldMarkLineNumbers = codegen.isShouldMarkLineNumbers
// Do not write line numbers until destructuring happens
// (otherwise destructuring variables will be uninitialized in the beginning of lambda)
codegen.isShouldMarkLineNumbers = false
codegen.runWithShouldMarkLineNumbers(false) {
for (parameterDescriptor in valueParameters) {
if (parameterDescriptor !is ValueParameterDescriptorImpl.WithDestructuringDeclaration) continue
for (parameterDescriptor in valueParameters) {
if (parameterDescriptor !is ValueParameterDescriptorImpl.WithDestructuringDeclaration) continue
for (entry in parameterDescriptor.destructuringVariables.filterOutDescriptorsWithSpecialNames()) {
codegen.myFrameMap.enter(entry, codegen.typeMapper.mapType(entry.type))
}
for (entry in parameterDescriptor.destructuringVariables.filterOutDescriptorsWithSpecialNames()) {
codegen.myFrameMap.enter(entry, codegen.typeMapper.mapType(entry.type))
val destructuringDeclaration =
(DescriptorToSourceUtils.descriptorToDeclaration(parameterDescriptor) as? KtParameter)?.destructuringDeclaration
?: error("Destructuring declaration for descriptor $parameterDescriptor not found")
codegen.initializeDestructuringDeclarationVariables(
destructuringDeclaration,
TransientReceiver(parameterDescriptor.type),
codegen.findLocalOrCapturedValue(parameterDescriptor) ?: error("Local var not found for parameter $parameterDescriptor")
)
}
val destructuringDeclaration =
(DescriptorToSourceUtils.descriptorToDeclaration(parameterDescriptor) as? KtParameter)?.destructuringDeclaration
?: error("Destructuring declaration for descriptor $parameterDescriptor not found")
codegen.initializeDestructuringDeclarationVariables(
destructuringDeclaration,
TransientReceiver(parameterDescriptor.type),
codegen.findLocalOrCapturedValue(parameterDescriptor) ?: error("Local var not found for parameter $parameterDescriptor")
)
}
codegen.isShouldMarkLineNumbers = savedIsShouldMarkLineNumbers
}
fun <D : CallableDescriptor> D.unwrapFrontendVersion() = unwrapInitialDescriptorForSuspendFunction()
@@ -0,0 +1,40 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: JVM_IR
// FILE: common.kt
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
// A LOT OF LINES
expect inline fun <T> get(p: String = "OK"): String
// FILE: platform.kt
actual inline fun <T> get(p: String): String {
return p
}
fun box(): String {
return get<String>()
}
@@ -15855,6 +15855,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
}
@TestMetadata("kt23739.kt")
public void testKt23739() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt");
}
@TestMetadata("superCall.kt")
public void testSuperCall() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
@@ -15859,6 +15859,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testKt23239() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
}
@TestMetadata("kt23739.kt")
public void testKt23739() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt");
}
}
}
@@ -15860,6 +15860,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
}
@TestMetadata("kt23739.kt")
public void testKt23739() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt");
}
@TestMetadata("superCall.kt")
public void testSuperCall() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
@@ -12275,6 +12275,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
}
@TestMetadata("kt23739.kt")
public void testKt23739() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt");
}
@TestMetadata("superCall.kt")
public void testSuperCall() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
@@ -13325,6 +13325,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
}
@TestMetadata("kt23739.kt")
public void testKt23739() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23739.kt");
}
@TestMetadata("superCall.kt")
public void testSuperCall() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");