KT-10670: Debugger: Evaluate Expression/Watches fail for inline function parameter initialized with default value

#KT-10670 Fixed
This commit is contained in:
Michael Bogdanov
2016-01-25 17:15:22 +03:00
parent d4df7aaabc
commit dc2cb401ad
7 changed files with 36 additions and 11 deletions

View File

@@ -2425,7 +2425,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
private CallGenerator getOrCreateCallGenerator(
@NotNull CallableDescriptor descriptor,
@Nullable KtElement callElement,
@Nullable TypeParameterMappings typeParameterMappings
@Nullable TypeParameterMappings typeParameterMappings,
boolean isDefaultCompilation
) {
if (callElement == null) return defaultCallGenerator;
@@ -2437,12 +2438,12 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
if (!isInline) return defaultCallGenerator;
FunctionDescriptor original = DescriptorUtils.unwrapFakeOverride((FunctionDescriptor) descriptor.getOriginal());
return new InlineCodegen(this, state, original, callElement, typeParameterMappings);
return new InlineCodegen(this, state, original, callElement, typeParameterMappings, isDefaultCompilation);
}
@NotNull
protected CallGenerator getOrCreateCallGeneratorForDefaultImplBody(@NotNull FunctionDescriptor descriptor, @Nullable KtNamedFunction function) {
return getOrCreateCallGenerator(descriptor, function, null);
return getOrCreateCallGenerator(descriptor, function, null, true);
}
@NotNull
@@ -2473,8 +2474,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
}
}
return getOrCreateCallGenerator(
resolvedCall.getResultingDescriptor(), resolvedCall.getCall().getCallElement(), mappings
);
resolvedCall.getResultingDescriptor(), resolvedCall.getCall().getCallElement(), mappings, false);
}

View File

@@ -85,6 +85,7 @@ public class InlineCodegen extends CallGenerator {
private final ReifiedTypeInliner reifiedTypeInliner;
@Nullable private final TypeParameterMappings typeParameterMappings;
private final boolean isDefaultCompilation;
private LambdaInfo activeLambda;
@@ -95,11 +96,12 @@ public class InlineCodegen extends CallGenerator {
@NotNull GenerationState state,
@NotNull FunctionDescriptor function,
@NotNull KtElement callElement,
@Nullable TypeParameterMappings typeParameterMappings
@Nullable TypeParameterMappings typeParameterMappings,
boolean isDefaultCompilation
) {
assert InlineUtil.isInline(function) || InlineUtil.isArrayConstructorWithLambda(function) :
"InlineCodegen can inline only inline functions and array constructors: " + function;
this.isDefaultCompilation = isDefaultCompilation;
this.state = state;
this.typeMapper = state.getTypeMapper();
this.codegen = codegen;
@@ -274,7 +276,7 @@ public class InlineCodegen extends CallGenerator {
InliningContext info = new RootInliningContext(
expressionMap, state, codegen.getInlineNameGenerator().subGenerator(jvmSignature.getAsmMethod().getName()),
codegen.getContext(), callElement, getInlineCallSiteInfo(), reifiedTypeInliner, typeParameterMappings
codegen.getContext(), callElement, getInlineCallSiteInfo(), reifiedTypeInliner, typeParameterMappings, isDefaultCompilation
);
MethodInliner inliner = new MethodInliner(node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule,

View File

@@ -370,7 +370,10 @@ public class MethodInliner {
@NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index
) {
if (isInliningLambda || InlineCodegenUtil.GENERATE_SMAP) {
String varSuffix = inliningContext.isRoot() && !InlineCodegenUtil.isFakeLocalVariableForInline(name) ? INLINE_FUN_VAR_SUFFIX : "";
String varSuffix = inliningContext.isRoot() &&
!((RootInliningContext) inliningContext).isDefaultCompilation &&
!InlineCodegenUtil.isFakeLocalVariableForInline(name) ?
INLINE_FUN_VAR_SUFFIX : "";
String varName = !varSuffix.isEmpty() && name.equals("this") ? name + "_" : name;
super.visitLocalVariable(varName + varSuffix, desc, signature, start, end, getNewIndex(index));
}

View File

@@ -28,6 +28,7 @@ public class RootInliningContext extends InliningContext {
public final CodegenContext startContext;
private final InlineCallSiteInfo inlineCallSiteInfo;
public final TypeParameterMappings typeParameterMappings;
public final boolean isDefaultCompilation;
public final KtElement callElement;
public RootInliningContext(
@@ -38,13 +39,15 @@ public class RootInliningContext extends InliningContext {
@NotNull KtElement callElement,
@NotNull InlineCallSiteInfo classNameToInline,
@NotNull ReifiedTypeInliner inliner,
@Nullable TypeParameterMappings typeParameterMappings
@Nullable TypeParameterMappings typeParameterMappings,
boolean isDefaultCompilation
) {
super(null, map, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), inliner, false, false);
this.callElement = callElement;
this.startContext = startContext;
this.inlineCallSiteInfo = classNameToInline;
this.typeParameterMappings = typeParameterMappings;
this.isDefaultCompilation = isDefaultCompilation;
}
@Override

View File

@@ -1,8 +1,11 @@
LineBreakpoint created at remappedParameterInInline.kt:7
LineBreakpoint created at remappedParameterInInline.kt:14
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! remappedParameterInInline.RemappedParameterInInlineKt
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
remappedParameterInInline.kt:7
Compile bytecode for p
remappedParameterInInline.kt:14
Compile bytecode for p
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0

View File

@@ -7,8 +7,16 @@ inline fun watch(p: String, f: (String) -> Int) {
f(p)
}
inline fun inlineDefault(p: Int = 1, f: (Int) -> Unit) {
// EXPRESSION: p
// RESULT: 1: I
//Breakpoint!
f(p)
}
fun main(args: Array<String>) {
val local = "mno"
watch(local) { it.length }
}
inlineDefault { it }
}

View File

@@ -772,6 +772,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
doMultipleBreakpointsTest(fileName);
}
@TestMetadata("remappedParameterInInline.kt")
public void testRemappedParameterInInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/remappedParameterInInline.kt");
doMultipleBreakpointsTest(fileName);
}
@TestMetadata("whenEntry.kt")
public void testWhenEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/whenEntry.kt");