Skip to content

Miscellaneous changes #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 19, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PytestLoader(IClassHierarchy cha) {

@Override
protected TranslatorToIR initTranslator(Set<Pair<CAstEntity, ModuleEntry>> topLevelEntities) {
return new PythonCAstToIRTranslator(this, topLevelEntities) {
return new PythonCAstToIRTranslator(this) {

private boolean isPytestEntry(CAstEntity F) {
if (F.getType() instanceof CAstType.Function) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/** Test TF2 APIs. */
public class TestTensorflow2Model extends TestPythonMLCallGraphShape {

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

@Test
public void test()
Expand Down Expand Up @@ -1504,18 +1504,18 @@ private void test(
CallGraph CG = builder.makeCallGraph(builder.getOptions());
assertNotNull(CG);

if (logger.isLoggable(Level.FINE)) {
if (LOGGER.isLoggable(Level.FINE)) {
CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(
((SSAPropagationCallGraphBuilder) builder).getCFAContextInterpreter(),
builder.getPointerAnalysis(),
CG);
logger.fine("Call graph:\n" + CG);
LOGGER.fine("Call graph:\n" + CG);
}

TensorTypeAnalysis analysis = E.performAnalysis(builder);

logger.info("Tensor analysis: " + analysis);
LOGGER.info("Tensor analysis: " + analysis);

// Create a mapping from function signatures to pointer keys.
Map<String, Set<LocalPointerKey>> functionSignatureToPointerKeys = new HashMap<>();
Expand Down Expand Up @@ -1557,7 +1557,7 @@ private void test(
v.add(tensorVariable);
return v;
});
} else logger.warning(() -> "Encountered: " + pointerKey.getClass());
} else LOGGER.warning(() -> "Encountered: " + pointerKey.getClass());
});

final String functionSignature = "script " + filename + "." + functionName + ".do()LRoot;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/
public class TensorFlowTypes extends PythonTypes {

public static final TypeReference TENSORFLOW =
TypeReference.findOrCreate(pythonLoader, TypeName.findOrCreate("Ltensorflow"));

public static final TypeReference DATASET =
TypeReference.findOrCreate(pythonLoader, TypeName.findOrCreate("Ltensorflow/data/Dataset"));

Expand Down
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.test/data/tf2n3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def func2(t):
pass
assert isinstance(t, tf.Tensor)


@tf.function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,32 @@ public void testMulti1()
PropagationCallGraphBuilder builder =
(PropagationCallGraphBuilder) engine.defaultCallGraphBuilder();
CallGraph CG = builder.makeCallGraph(engine.getOptions(), new NullProgressMonitor());
CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(
(SSAContextInterpreter) builder.getContextInterpreter(), builder.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsMulti1);
}

protected static final Object[][] assertionsMulti2 =
new Object[][] {
new Object[] {ROOT, new String[] {"script multi1.py", "script multi2.py"}},
// TODO: Add the following code once https://github.com/wala/ML/issues/168 is fixed:
// new Object[] {"script multi1.py", new String[] {"script multi2.py/silly"}},
// TODO: Add the following code once https://github.com/wala/ML/issues/168 is fixed:
// new Object[] {"script multi2.py/silly", new String[] {"script multi2.py/silly/inner"}},
};

@Test
public void testMulti2()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
PythonAnalysisEngine<?> engine = makeEngine("multi1.py", "multi2.py");
PropagationCallGraphBuilder builder =
(PropagationCallGraphBuilder) engine.defaultCallGraphBuilder();
CallGraph CG = builder.makeCallGraph(engine.getOptions(), new NullProgressMonitor());
CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(
(SSAContextInterpreter) builder.getContextInterpreter(), builder.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsMulti2);
}

protected static final Object[][] assertionsMulti3 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

public class PythonSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraphBuilder {

@SuppressWarnings("unused")
private static final Logger logger =
Logger.getLogger(PythonSSAPropagationCallGraphBuilder.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ private static TypeReference builtinFunction(String name) {
builtinFunctions.put("iter", Either.forRight(2));
// https://docs.python.org/3/library/functions.html#next
builtinFunctions.put("next", Either.forLeft(PythonTypes.object));
// https://docs.python.org/3/library/functions.html#isinstance
builtinFunctions.put("isinstance", Either.forLeft(TypeReference.Boolean));
}

public static Set<String> builtins() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IClassLoader;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.core.util.strings.Atom;
import com.ibm.wala.shrike.shrikeBT.IBinaryOpInstruction;
Expand Down Expand Up @@ -71,21 +70,18 @@ public class PythonCAstToIRTranslator extends AstTranslator {

private final Map<CAstType, TypeName> walaTypeNames = HashMapFactory.make();
private final Set<Pair<Scope, String>> globalDeclSet = new HashSet<>();
private static boolean signleFileAnalysis = true;
private final Set<Pair<CAstEntity, ModuleEntry>> topLevelEntities;
private static boolean singleFileAnalysis = true;

public PythonCAstToIRTranslator(
IClassLoader loader, Set<Pair<CAstEntity, ModuleEntry>> topLevelEntities) {
public PythonCAstToIRTranslator(IClassLoader loader) {
super(loader);
this.topLevelEntities = topLevelEntities;
}

public static boolean isSingleFileAnalysis() {
return signleFileAnalysis;
return singleFileAnalysis;
}

public static void setSingleFileAnalysis(boolean singleFile) {
PythonCAstToIRTranslator.signleFileAnalysis = singleFile;
PythonCAstToIRTranslator.singleFileAnalysis = singleFile;
}

@Override
Expand Down Expand Up @@ -899,7 +895,7 @@ private void handleObjectLiteralAssign(
}

boolean isGlobal(WalkContext context, String varName) {
if (signleFileAnalysis) return false;
if (singleFileAnalysis) return false;
else {
if (context.currentScope().getEntity().getKind() == CAstEntity.SCRIPT_ENTITY) return true;
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected boolean shouldTranslate(CAstEntity entity) {

@Override
protected TranslatorToIR initTranslator(Set<Pair<CAstEntity, ModuleEntry>> topLevelEntities) {
return new PythonCAstToIRTranslator(this, topLevelEntities);
return new PythonCAstToIRTranslator(this);
}

final CoreClass CodeBody =
Expand Down
4 changes: 2 additions & 2 deletions logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ handlers= java.util.logging.ConsoleHandler
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level= FINE
.level= FINEST

############################################################
# Handler specific properties.
Expand All @@ -40,7 +40,7 @@ handlers= java.util.logging.ConsoleHandler
#java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# Example to customize the SimpleFormatter output format
Expand Down
Loading