JVM: do not write trivial SMAPs to classes outside inline funs
where trivial == those that map the file to itself.
This commit is contained in:
@@ -54,7 +54,6 @@ import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.CallableReferenceUtilKt.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConst;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.CLOSURE;
|
||||
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.initDefaultSourceMappingIfNeeded;
|
||||
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.METHOD_FOR_FUNCTION;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
|
||||
@@ -170,7 +169,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
superInterfaceAsmTypes
|
||||
);
|
||||
|
||||
initDefaultSourceMappingIfNeeded(context, this, state);
|
||||
initDefaultSourceMappingIfNeeded();
|
||||
|
||||
v.visitSource(element.getContainingFile().getName(), null);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ import static org.jetbrains.kotlin.codegen.CodegenUtilKt.isNonGenericToArray;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.getDelegatedLocalVariableMetadata;
|
||||
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.initDefaultSourceMappingIfNeeded;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAbi.*;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_GET;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_SET;
|
||||
@@ -228,7 +227,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
v.visitSource(myClass.getContainingKtFile().getName(), null);
|
||||
|
||||
initDefaultSourceMappingIfNeeded(context, this, state);
|
||||
initDefaultSourceMappingIfNeeded();
|
||||
|
||||
writeEnclosingMethod();
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
private NameGenerator inlineNameGenerator;
|
||||
private boolean jvmAssertFieldGenerated;
|
||||
|
||||
private boolean alwaysWriteSourceMap;
|
||||
private SourceMapper sourceMapper;
|
||||
|
||||
public MemberCodegen(
|
||||
@@ -182,8 +183,8 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
|
||||
writeInnerClasses();
|
||||
|
||||
if (sourceMapper != null) {
|
||||
v.visitSMAP(sourceMapper, !state.getLanguageVersionSettings().supportsFeature(LanguageFeature.CorrectSourceMappingSyntax));
|
||||
if (alwaysWriteSourceMap || (sourceMapper != null && !sourceMapper.isTrivial())) {
|
||||
v.visitSMAP(getOrCreateSourceMapper(), !state.getLanguageVersionSettings().supportsFeature(LanguageFeature.CorrectSourceMappingSyntax));
|
||||
}
|
||||
|
||||
v.done();
|
||||
@@ -730,6 +731,19 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
return sourceMapper;
|
||||
}
|
||||
|
||||
protected void initDefaultSourceMappingIfNeeded() {
|
||||
if (state.isInlineDisabled()) return;
|
||||
|
||||
CodegenContext parentContext = context.getParentContext();
|
||||
while (parentContext != null) {
|
||||
if (parentContext.isInlineMethodContext()) {
|
||||
alwaysWriteSourceMap = true;
|
||||
return;
|
||||
}
|
||||
parentContext = parentContext.getParentContext();
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateConstInstance(@NotNull Type thisAsmType, @NotNull Type fieldAsmType) {
|
||||
v.newField(
|
||||
JvmDeclarationOriginKt.OtherOriginFromPure(element), ACC_STATIC | ACC_FINAL | ACC_PUBLIC, JvmAbi.INSTANCE_FIELD,
|
||||
|
||||
@@ -95,6 +95,9 @@ class SourceMapper(val sourceInfo: SourceInfo?) {
|
||||
}
|
||||
}
|
||||
|
||||
val isTrivial: Boolean
|
||||
get() = maxUsedValue == 0 || maxUsedValue == sourceInfo?.linesInFile
|
||||
|
||||
private fun getOrRegisterNewSource(name: String, path: String): FileMapping =
|
||||
fileMappings.getOrPut(name to path) { FileMapping(name, path) }
|
||||
|
||||
|
||||
@@ -565,22 +565,6 @@ class InlineOnlySmapSkipper(codegen: BaseExpressionCodegen) {
|
||||
}
|
||||
}
|
||||
|
||||
fun initDefaultSourceMappingIfNeeded(
|
||||
context: CodegenContext<*>, codegen: MemberCodegen<*>, state: GenerationState
|
||||
) {
|
||||
if (state.isInlineDisabled) return
|
||||
|
||||
var parentContext: CodegenContext<*>? = context.parentContext
|
||||
while (parentContext != null) {
|
||||
if (parentContext.isInlineMethodContext) {
|
||||
//just init default one to one mapping
|
||||
codegen.orCreateSourceMapper
|
||||
break
|
||||
}
|
||||
parentContext = parentContext.parentContext
|
||||
}
|
||||
}
|
||||
|
||||
fun MethodNode.preprocessSuspendMarkers(forInline: Boolean, keepFakeContinuation: Boolean = true) {
|
||||
if (instructions.first == null) return
|
||||
if (!keepFakeContinuation) {
|
||||
|
||||
Reference in New Issue
Block a user