Skip to content

Commit

Permalink
Fix support for multi-dimensional arrays of degree 3 and more in depe…
Browse files Browse the repository at this point in the history
…ndency analyzer
  • Loading branch information
konsoletyper committed Oct 24, 2024
1 parent 18d6386 commit 24d672e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
11 changes: 0 additions & 11 deletions core/src/main/java/org/teavm/dependency/DependencyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.teavm.model.ValueType;

public class DependencyNode implements ValueDependencyInfo {
private static final int DEGREE_THRESHOLD = 2;
DependencyAnalyzer dependencyAnalyzer;
List<DependencyConsumer> followers;
TypeSet typeSet;
Expand All @@ -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();
Expand Down Expand Up @@ -96,10 +92,6 @@ private void scheduleSingleType(DependencyType type) {
}

public void propagate(DependencyType[] newTypes) {
if (degree > DEGREE_THRESHOLD) {
return;
}

if (newTypes.length == 0) {
return;
}
Expand Down Expand Up @@ -314,9 +306,6 @@ private boolean connectWithoutChildNodes(DependencyNode node, DependencyTypeFilt
}

private void connectArrayItemNodes(DependencyNode node) {
if (degree > DEGREE_THRESHOLD || node.degree > DEGREE_THRESHOLD) {
return;
}
if (!isArray(typeFilter) || !isArray(node.typeFilter)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
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) {
Expand Down Expand Up @@ -80,11 +83,22 @@ DependencyNode createArrayItemNode(DependencyNode parent) {
ValueType itemTypeFilter = parent.typeFilter instanceof ValueType.Array
? ((ValueType.Array) parent.typeFilter).getItemType()
: null;
DependencyNode node = createNode(itemTypeFilter);
node.degree = parent.degree + 1;
node.method = parent.method;
if (DependencyAnalyzer.shouldTag) {
node.tag = parent.tag + "[";
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;
}
Expand Down

0 comments on commit 24d672e

Please sign in to comment.