PurityAnalysis: Object.toString hardcoded pure

This commit is contained in:
Tagir Valeev
2017-05-29 15:13:10 +07:00
parent 03403ded9d
commit 60e8eb5948
31 changed files with 514 additions and 23 deletions

View File

@@ -53,7 +53,7 @@ public class BytecodeAnalysisIndex extends ScalarIndexExtension<Bytes> {
private static final ID<Bytes, Void> NAME = ID.create("bytecodeAnalysis");
private static final HKeyDescriptor KEY_DESCRIPTOR = new HKeyDescriptor();
private static final VirtualFileGist<Map<Bytes, HEquations>> ourGist = GistManager.getInstance().newVirtualFileGist(
"BytecodeAnalysisIndex", 4, new HEquationsExternalizer(), new ClassDataIndexer());
"BytecodeAnalysisIndex", 5, new HEquationsExternalizer(), new ClassDataIndexer());
@NotNull
@Override

View File

@@ -556,9 +556,6 @@ final class HardCodedPurity {
// Maybe overloaded and be not pure, but this would be definitely bad code style
// Used in Throwable(Throwable) ctor, so this helps to infer purity of many exception constructors
new Method("java/lang/Throwable", "toString", "()Ljava/lang/String;"),
// Declared in final class StringBuilder
new Method("java/lang/StringBuilder", "toString", "()Ljava/lang/String;"),
new Method("java/lang/StringBuffer", "toString", "()Ljava/lang/String;"),
// Native
new Method("java/lang/Object", "getClass", "()Ljava/lang/Class;"),
new Method("java/lang/Class", "getComponentType", "()Ljava/lang/Class;"),
@@ -596,7 +593,8 @@ final class HardCodedPurity {
}
static boolean isPureMethod(Key key) {
return pureMethods.contains(key.method);
return key.method.methodName.equals("toString") && key.method.methodDesc.equals("()Ljava/lang/String;") ||
pureMethods.contains(key.method);
}
static boolean isOwnedField(FieldInsnNode fieldInsn) {