#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
This commit is contained in:
Mirko Sertic 2017-04-05 17:36:53 +02:00 committed by Alexey Andreev
parent 74eda7e63c
commit 09b3f18a2c
3 changed files with 17 additions and 3 deletions

View File

@ -689,4 +689,4 @@ public class WasmTarget implements TeaVMTarget {
return new VirtualTableProvider(classes, virtualMethods);
}
}
}

View File

@ -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
}
}
}
}
}

View File

@ -575,4 +575,4 @@ public class DependencyChecker implements DependencyInfo {
public void addBootstrapMethodSubstitutor(MethodReference method, BootstrapMethodSubstitutor substitutor) {
bootstrapMethodSubstitutors.put(method, substitutor);
}
}
}