From 09b3f18a2cd1f1393a622ff07a4b3111c3d5ba88 Mon Sep 17 00:00:00 2001 From: Mirko Sertic Date: Wed, 5 Apr 2017 17:36:53 +0200 Subject: [PATCH] #258 WASM: Unreferenced but exported methods are removed by dep checker (#259) WASM: automatically mark as reachable methods of reachable classes which are exported to WASM via `@Export` annotation See #258 --- .../java/org/teavm/backend/wasm/WasmTarget.java | 2 +- .../wasm/generate/WasmDependencyListener.java | 16 +++++++++++++++- .../org/teavm/dependency/DependencyChecker.java | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java index 92a18b5e7..7df10fbee 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -689,4 +689,4 @@ public class WasmTarget implements TeaVMTarget { return new VirtualTableProvider(classes, virtualMethods); } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/WasmDependencyListener.java b/core/src/main/java/org/teavm/backend/wasm/generate/WasmDependencyListener.java index dfb21fd15..522660888 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/WasmDependencyListener.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/WasmDependencyListener.java @@ -20,6 +20,7 @@ import org.teavm.dependency.DependencyAgent; import org.teavm.dependency.MethodDependency; import org.teavm.diagnostics.Diagnostics; import org.teavm.interop.DelegateTo; +import org.teavm.interop.Export; import org.teavm.model.AnnotationReader; import org.teavm.model.CallLocation; import org.teavm.model.ClassHolder; @@ -31,6 +32,19 @@ import org.teavm.model.MethodHolder; import org.teavm.model.MethodReader; public class WasmDependencyListener extends AbstractDependencyListener implements ClassHolderTransformer { + + @Override + public void classReached(DependencyAgent agent, String className, CallLocation location) { + super.classReached(agent, className, location); + + for (MethodReader reader : agent.getClassSource().get(className).getMethods()) { + AnnotationReader annotation = reader.getAnnotations().get(Export.class.getName()); + if (annotation != null) { + agent.linkMethod(reader.getReference(), null).use(); + } + } + } + @Override public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { AnnotationReader delegateAnnot = method.getMethod().getAnnotations().get(DelegateTo.class.getName()); @@ -57,4 +71,4 @@ public class WasmDependencyListener extends AbstractDependencyListener implement } } } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/teavm/dependency/DependencyChecker.java b/core/src/main/java/org/teavm/dependency/DependencyChecker.java index 9d743e888..da8ed4647 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/core/src/main/java/org/teavm/dependency/DependencyChecker.java @@ -575,4 +575,4 @@ public class DependencyChecker implements DependencyInfo { public void addBootstrapMethodSubstitutor(MethodReference method, BootstrapMethodSubstitutor substitutor) { bootstrapMethodSubstitutors.put(method, substitutor); } -} +} \ No newline at end of file