From 24d672e820ba4a033fd02f83b2626487bee698c8 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 24 Oct 2024 18:28:28 +0200 Subject: [PATCH] Fix support for multi-dimensional arrays of degree 3 and more in dependency analyzer --- .../org/teavm/dependency/DependencyNode.java | 11 --------- .../dependency/PreciseDependencyAnalyzer.java | 24 +++++++++++++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/teavm/dependency/DependencyNode.java b/core/src/main/java/org/teavm/dependency/DependencyNode.java index 74125e277b..18b8a535c0 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyNode.java +++ b/core/src/main/java/org/teavm/dependency/DependencyNode.java @@ -32,7 +32,6 @@ import org.teavm.model.ValueType; public class DependencyNode implements ValueDependencyInfo { - private static final int DEGREE_THRESHOLD = 2; DependencyAnalyzer dependencyAnalyzer; List 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 @@ private void scheduleSingleType(DependencyType type) { } public void propagate(DependencyType[] newTypes) { - if (degree > DEGREE_THRESHOLD) { - return; - } - if (newTypes.length == 0) { return; } @@ -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; } diff --git a/core/src/main/java/org/teavm/dependency/PreciseDependencyAnalyzer.java b/core/src/main/java/org/teavm/dependency/PreciseDependencyAnalyzer.java index a27513aaf7..fbfcf0e1e4 100644 --- a/core/src/main/java/org/teavm/dependency/PreciseDependencyAnalyzer.java +++ b/core/src/main/java/org/teavm/dependency/PreciseDependencyAnalyzer.java @@ -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) { @@ -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 = ""; + } + } + node = allArrayItemsNode; + } else { + node = createNode(itemTypeFilter); + node.degree = parent.degree + 1; + node.method = parent.method; + if (DependencyAnalyzer.shouldTag) { + node.tag = parent.tag + "["; + } } return node; }