JVM: do not write trivial SMAPs to any classes
Even ones inside inline functions. This was a backwards compatibility
hack for Kotlin 1.4, where the inliner would crash if it attempted to
regenerate an anonymous object with no SMAP; that has been fixed in 1.5,
and ever since then trivial SMAPs could be inferred from line number
markers in methods.
There are three kinds of changes to tests in this commit:
* Some SMAPs are gone entirely - self-explanatory.
* Some SMAPs have narrower line ranges - that's because the old SMAP
had the range for the entire file, while the new one only maps up to
the last line number used in the class. There should be no
difference in behavior.
* Some "source file name" markers are removed in continuation objects
- continuations don't have any line numbers, so there's no debugging
information anyway. The actual source information is in the
containing class.
This commit is contained in:
committed by
Space Cloud
parent
fc992274bb
commit
e5ad035039
@@ -151,12 +151,16 @@ public abstract class AbstractClassBuilder implements ClassBuilder {
|
||||
|
||||
@Override
|
||||
public void visitSMAP(@NotNull SourceMapper smap, boolean backwardsCompatibleSyntax) {
|
||||
if (!GENERATE_SMAP) return;
|
||||
|
||||
List<FileMapping> fileMappings = smap.getResultMappings();
|
||||
if (fileMappings.isEmpty()) return;
|
||||
|
||||
visitSource(fileMappings.get(0).getName(), SMAPBuilder.INSTANCE.build(fileMappings, backwardsCompatibleSyntax));
|
||||
if (GENERATE_SMAP && !smap.isTrivial()) {
|
||||
List<FileMapping> fileMappings = smap.getResultMappings();
|
||||
visitSource(fileMappings.get(0).getName(), SMAPBuilder.INSTANCE.build(fileMappings, backwardsCompatibleSyntax));
|
||||
} else {
|
||||
SourceInfo sourceInfo = smap.getSourceInfo();
|
||||
if (sourceInfo == null) return;
|
||||
String fileName = sourceInfo.getSourceFileName();
|
||||
if (fileName == null) return;
|
||||
visitSource(fileName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -181,8 +181,6 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
superInterfaceAsmTypes
|
||||
);
|
||||
|
||||
initDefaultSourceMappingIfNeeded();
|
||||
|
||||
v.visitSource(element.getContainingFile().getName(), null);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,8 +242,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
v.visitSource(myClass.getContainingKtFile().getName(), null);
|
||||
|
||||
initDefaultSourceMappingIfNeeded();
|
||||
|
||||
writeEnclosingMethod();
|
||||
|
||||
AnnotationCodegen.forClass(v.getVisitor(), this, state).genAnnotations(descriptor, null, null);
|
||||
|
||||
@@ -92,7 +92,6 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
private NameGenerator inlineNameGenerator;
|
||||
private boolean jvmAssertFieldGenerated;
|
||||
|
||||
private boolean alwaysWriteSourceMap;
|
||||
private SourceMapper sourceMapper;
|
||||
|
||||
public MemberCodegen(
|
||||
@@ -187,10 +186,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
|
||||
writeInnerClasses();
|
||||
|
||||
if (alwaysWriteSourceMap || (sourceMapper != null && !sourceMapper.isTrivial())) {
|
||||
v.visitSMAP(getOrCreateSourceMapper(), !state.getLanguageVersionSettings().supportsFeature(LanguageFeature.CorrectSourceMappingSyntax));
|
||||
}
|
||||
|
||||
v.visitSMAP(getOrCreateSourceMapper(), !state.getLanguageVersionSettings().supportsFeature(LanguageFeature.CorrectSourceMappingSyntax));
|
||||
v.done(state.getConfig().getGenerateSmapCopyToAnnotation());
|
||||
}
|
||||
|
||||
@@ -749,25 +745,11 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
@NotNull
|
||||
public SourceMapper getOrCreateSourceMapper() {
|
||||
if (sourceMapper == null) {
|
||||
// note: this is used in InlineCodegen and the element is always physical (KtElement) there
|
||||
sourceMapper = new SourceMapper(SourceInfo.Companion.createFromPsi((KtElement)element, getClassName()));
|
||||
sourceMapper = new SourceMapper(element instanceof KtElement ? SourceInfo.Companion.createFromPsi((KtElement)element, getClassName()) : null);
|
||||
}
|
||||
return sourceMapper;
|
||||
}
|
||||
|
||||
protected void initDefaultSourceMappingIfNeeded() {
|
||||
if (state.getConfig().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,
|
||||
|
||||
Reference in New Issue
Block a user