Skip to content

Commit

Permalink
Merge branch 'master' into 92-missing_callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad authored Nov 30, 2023
2 parents 7131070 + a19235b commit 72610a6
Show file tree
Hide file tree
Showing 23 changed files with 249 additions and 37 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.jython.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.jython.test</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.jython/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.jython</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.jython3.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.jython3.test</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.jython3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.jython3</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ibm.wala.cast.python.client;

import com.ibm.wala.cast.python.ipa.callgraph.PythonSSAPropagationCallGraphBuilder;
import com.ibm.wala.cast.python.loader.PytestLoader;
import com.ibm.wala.cast.python.loader.PytestLoaderFactory;
import com.ibm.wala.classLoader.CallSiteReference;
Expand All @@ -10,7 +9,6 @@
import com.ibm.wala.core.util.strings.Atom;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
Expand All @@ -23,8 +21,6 @@

public class PytestAnalysisEngine<T> extends PythonAnalysisEngine<T> {

private PythonSSAPropagationCallGraphBuilder builder;

private class PytestTargetSelector implements MethodTargetSelector {
private final MethodTargetSelector base;

Expand Down Expand Up @@ -88,12 +84,6 @@ protected void addBypassLogic(IClassHierarchy cha, AnalysisOptions options) {
addSummaryBypassLogic(options, "pytest.xml");
}

@Override
protected PythonSSAPropagationCallGraphBuilder getCallGraphBuilder(
IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
return builder = super.getCallGraphBuilder(cha, options, cache);
}

@Override
public T performAnalysis(PropagationCallGraphBuilder arg0) throws CancelException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value="testTf2"/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.buildship.core.classpathprovider"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.python.ml.test.TestTensorflowModel"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.python.ml.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Djava.util.logging.config.file=logging.properties"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Djava.util.logging.config.file=logging.properties -Dcom.ibm.wala.fixedpoint.impl.verbose=true"/>
</launchConfiguration>
4 changes: 2 additions & 2 deletions com.ibm.wala.cast.python.ml.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.ml.test</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>com.ibm.wala.cast.python.jython.test</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,13 @@ public void testTf2()
testTf2("tf2_test_tensor_list.py", "add", 2, 3, 2, 3);
testTf2("tf2_test_tensor_list2.py", "add", 0, 2);
testTf2("tf2_test_tensor_list3.py", "add", 0, 2);
testTf2(
"tf2_test_model_call.py",
"SequentialModel.__call__",
0,
2); // NOTE: Change to testTf2("tf2_test_model_call.py", "SequentialModel.__call__", 1, 4,
// 2) once
// https://github.com/wala/ML/issues/24 is fixed.
testTf2("tf2_test_model_call.py", "SequentialModel.__call__", 1, 4, 2);
testTf2(
"tf2_test_model_call2.py",
"SequentialModel.call",
0,
2); // NOTE: Change to testTf2("tf2_test_model_call2.py", "SequentialModel.call", 1, 4, 2)
// once
// https://github.com/wala/ML/issues/24 is fixed.
// once https://github.com/wala/ML/issues/106 is fixed.
testTf2("tf2_test_model_call3.py", "SequentialModel.call", 1, 4, 2);
testTf2("tf2_test_model_call4.py", "SequentialModel.__call__", 1, 4, 2);
testTf2("tf2_test_callbacks.py", "get_dataset", 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.ml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.ml</artifactId>
<dependencies>
Expand Down
9 changes: 9 additions & 0 deletions com.ibm.wala.cast.python.test/data/callables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class C:

def __call__(self, x):
return x * x


c = C()
a = c.__call__(5)
assert a == 25
9 changes: 9 additions & 0 deletions com.ibm.wala.cast.python.test/data/callables2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class C:

def __call__(self, x):
return x * x


c = C()
a = c(5)
assert a == 25
9 changes: 9 additions & 0 deletions com.ibm.wala.cast.python.test/data/callables3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class C(object):

def __call__(self, x):
return x * x


c = C()
a = c.__call__(5)
assert a == 25
9 changes: 9 additions & 0 deletions com.ibm.wala.cast.python.test/data/callables4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class C(object):

def __call__(self, x):
return x * x


c = C()
a = c(5)
assert a == 25
13 changes: 13 additions & 0 deletions com.ibm.wala.cast.python.test/data/callables5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class D:
pass


class C(D):

def __call__(self, x):
return x * x


c = C()
a = c.__call__(5)
assert a == 25
13 changes: 13 additions & 0 deletions com.ibm.wala.cast.python.test/data/callables6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class D:
pass


class C(D):

def __call__(self, x):
return x * x


c = C()
a = c(5)
assert a == 25
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python.test</artifactId>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.ibm.wala.cast.python.test;

import static org.junit.Assert.assertTrue;

import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.util.CancelException;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Logger;
import org.junit.Test;

public class TestCallables extends TestPythonCallGraphShape {

private static Logger logger = Logger.getLogger(TestCallables.class.getName());

@Test
public void testCallables()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
final String[] testFileNames = {
"callables.py",
"callables2.py",
"callables3.py",
"callables4.py",
"callables5.py",
"callables6.py"
};

for (String fileName : testFileNames) {
CallGraph CG = process(fileName);
boolean found = false;

for (CGNode node : CG) {
if (node.getMethod()
.getDeclaringClass()
.getName()
.toString()
.equals("Lscript " + fileName)) {

for (Iterator<CGNode> it = CG.getSuccNodes(node); it.hasNext(); ) {
CGNode callee = it.next();

logger.info("Found callee: " + callee.getMethod().getSignature());

if (callee
.getMethod()
.getDeclaringClass()
.getName()
.toString()
.equals("L$script " + fileName + "/C/__call__")) found = true;
}
}
}

assertTrue("Expecting to find __call__ method trampoline in: " + fileName + ".", found);
}
}
}
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ibm.wala</groupId>
<artifactId>ml</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>com.ibm.wala.cast.python</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public abstract class PythonAnalysisEngine<T>

private static final Logger logger = Logger.getLogger(PythonAnalysisEngine.class.getName());

protected PythonSSAPropagationCallGraphBuilder builder;

static {
try {
Class<?> j3 = Class.forName("com.ibm.wala.cast.python.loader.Python3LoaderFactory");
Expand Down Expand Up @@ -286,9 +288,10 @@ public boolean isReferenceType() {

protected void addBypassLogic(IClassHierarchy cha, AnalysisOptions options) {
options.setSelector(
new PythonTrampolineTargetSelector(
new PythonTrampolineTargetSelector<T>(
new PythonConstructorTargetSelector(
new PythonComprehensionTrampolines(options.getMethodTargetSelector()))));
new PythonComprehensionTrampolines(options.getMethodTargetSelector())),
this));

BuiltinFunctions builtins = new BuiltinFunctions(cha);
options.setSelector(builtins.builtinClassTargetSelector(options.getClassTargetSelector()));
Expand Down Expand Up @@ -349,7 +352,11 @@ public int getDefaultValue(SymbolTable symtab, int valueNumber) {

new PythonSuper(cha).handleSuperCalls(builder, options);

return builder;
return this.builder = builder;
}

public PythonSSAPropagationCallGraphBuilder getCachedCallGraphBuilder() {
return this.builder;
}

protected PythonSSAPropagationCallGraphBuilder makeBuilder(
Expand Down
Loading

0 comments on commit 72610a6

Please sign in to comment.