Fix support for multi-dimensional arrays of degree 3 and more in dependency analyzer

This commit is contained in:
Alexey Andreev 2024-10-24 18:28:28 +02:00
parent 18d63863c9
commit 24d672e820
2 changed files with 19 additions and 16 deletions

View File

@ -32,7 +32,6 @@ import org.teavm.model.MethodReference;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
public class DependencyNode implements ValueDependencyInfo { public class DependencyNode implements ValueDependencyInfo {
private static final int DEGREE_THRESHOLD = 2;
DependencyAnalyzer dependencyAnalyzer; DependencyAnalyzer dependencyAnalyzer;
List<DependencyConsumer> followers; List<DependencyConsumer> followers;
TypeSet typeSet; TypeSet typeSet;
@ -58,9 +57,6 @@ public class DependencyNode implements ValueDependencyInfo {
} }
public void propagate(DependencyType type) { public void propagate(DependencyType type) {
if (degree > DEGREE_THRESHOLD) {
return;
}
if (!hasType(type) && filter(type)) { if (!hasType(type) && filter(type)) {
propagateCount++; propagateCount++;
moveToSeparateDomain(); moveToSeparateDomain();
@ -96,10 +92,6 @@ public class DependencyNode implements ValueDependencyInfo {
} }
public void propagate(DependencyType[] newTypes) { public void propagate(DependencyType[] newTypes) {
if (degree > DEGREE_THRESHOLD) {
return;
}
if (newTypes.length == 0) { if (newTypes.length == 0) {
return; return;
} }
@ -314,9 +306,6 @@ public class DependencyNode implements ValueDependencyInfo {
} }
private void connectArrayItemNodes(DependencyNode node) { private void connectArrayItemNodes(DependencyNode node) {
if (degree > DEGREE_THRESHOLD || node.degree > DEGREE_THRESHOLD) {
return;
}
if (!isArray(typeFilter) || !isArray(node.typeFilter)) { if (!isArray(typeFilter) || !isArray(node.typeFilter)) {
return; return;
} }

View File

@ -24,6 +24,9 @@ import org.teavm.model.ReferenceCache;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
public class PreciseDependencyAnalyzer extends DependencyAnalyzer { public class PreciseDependencyAnalyzer extends DependencyAnalyzer {
private DependencyNode allArrayItemsNode;
private static final int DEGREE_THRESHOLD = 2;
public PreciseDependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, public PreciseDependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader,
ServiceRepository services, Diagnostics diagnostics, ReferenceCache referenceCache, ServiceRepository services, Diagnostics diagnostics, ReferenceCache referenceCache,
String[] platformTags) { String[] platformTags) {
@ -80,11 +83,22 @@ public class PreciseDependencyAnalyzer extends DependencyAnalyzer {
ValueType itemTypeFilter = parent.typeFilter instanceof ValueType.Array ValueType itemTypeFilter = parent.typeFilter instanceof ValueType.Array
? ((ValueType.Array) parent.typeFilter).getItemType() ? ((ValueType.Array) parent.typeFilter).getItemType()
: null; : null;
DependencyNode node = createNode(itemTypeFilter); DependencyNode node;
node.degree = parent.degree + 1; if (parent.degree > DEGREE_THRESHOLD) {
node.method = parent.method; if (allArrayItemsNode == null) {
if (DependencyAnalyzer.shouldTag) { allArrayItemsNode = createNode(null);
node.tag = parent.tag + "["; if (DependencyAnalyzer.shouldTag) {
allArrayItemsNode.tag = "<any array item>";
}
}
node = allArrayItemsNode;
} else {
node = createNode(itemTypeFilter);
node.degree = parent.degree + 1;
node.method = parent.method;
if (DependencyAnalyzer.shouldTag) {
node.tag = parent.tag + "[";
}
} }
return node; return node;
} }