You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/09/21 00:01:11 UTC

[royale-compiler] branch develop updated: try promoting regular deps to static deps if a class is used in a static initializer or base class. Seems to fix #297

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new 87c5717  try promoting regular deps to static deps if a class is used in a static initializer or base class.  Seems to fix #297
87c5717 is described below

commit 87c5717474513dea8aae73d90d7ece000ba102d8
Author: Alex Harui <ah...@apache.org>
AuthorDate: Thu Sep 20 16:55:51 2018 -0700

    try promoting regular deps to static deps if a class is used in a static initializer or base class.  Seems to fix #297
---
 .../compiler/internal/graph/GoogDepsWriter.java    | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
index 0cace52..dc8f6cb 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
@@ -80,6 +80,7 @@ public class GoogDepsWriter {
 	private ArrayList<GoogDep> dps;
 	private DependencyGraph graph;
 	private CompilerProject project;
+	private ArrayList<String> staticInitializers;
 	
 	private HashMap<String, GoogDep> depMap = new HashMap<String,GoogDep>();
 	private HashMap<String, ICompilationUnit> requireMap = new HashMap<String, ICompilationUnit>();
@@ -238,6 +239,8 @@ public class GoogDepsWriter {
 	
 	private boolean buildDB()
 	{
+		staticInitializers = new ArrayList<String>();
+		
 		graph = new DependencyGraph();
 		if (isGoogClass(mainName))
 		{
@@ -259,6 +262,24 @@ public class GoogDepsWriter {
     
 	private ArrayList<GoogDep> sort()
 	{
+		// first, promote all dependencies of classes used in static initializers to
+		// the level of static dependencies since their constructors will be
+		// run early
+		for (String staticClass: staticInitializers)
+		{
+			GoogDep info = depMap.get(staticClass);
+			if (info != null && info.fileInfo != null && info.fileInfo.deps != null)
+			{
+				if (info.fileInfo.staticDeps == null)
+					info.fileInfo.staticDeps = new ArrayList<String>();
+				for (String dep : info.fileInfo.deps)
+				{
+					if (!info.fileInfo.staticDeps.contains(dep))
+						info.fileInfo.staticDeps.add(dep);
+				}
+			}
+		}
+		
 		ArrayList<GoogDep> arr = new ArrayList<GoogDep>();
 		GoogDep current = depMap.get(mainName);
 		sortFunction(current, arr);
@@ -696,6 +717,7 @@ public class GoogDepsWriter {
 						    					line = line.substring(c + token.length(), c2);
 							        			fi.staticDeps = new ArrayList<String>();
 						    					fi.staticDeps.addAll(Arrays.asList(line.split(",")));
+						    					staticInitializers.addAll(Arrays.asList(line.split(",")));
 						    				}
 						    				else
 						    				{