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

View File

@ -24,6 +24,9 @@ import org.teavm.model.ReferenceCache;
import org.teavm.model.ValueType;
public class PreciseDependencyAnalyzer extends DependencyAnalyzer {
private DependencyNode allArrayItemsNode;
private static final int DEGREE_THRESHOLD = 2;
public PreciseDependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader,
ServiceRepository services, Diagnostics diagnostics, ReferenceCache referenceCache,
String[] platformTags) {
@ -80,12 +83,23 @@ public class PreciseDependencyAnalyzer extends DependencyAnalyzer {
ValueType itemTypeFilter = parent.typeFilter instanceof ValueType.Array
? ((ValueType.Array) parent.typeFilter).getItemType()
: null;
DependencyNode node = createNode(itemTypeFilter);
DependencyNode node;
if (parent.degree > DEGREE_THRESHOLD) {
if (allArrayItemsNode == null) {
allArrayItemsNode = createNode(null);
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;
}