Skip to content
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

Potentially redundant global read in IR stemming from __init__.py #203

Open
khatchad opened this issue Jul 3, 2024 · 1 comment
Open
Labels
cleanup question Further information is requested

Comments

@khatchad
Copy link
Collaborator

khatchad commented Jul 3, 2024

If there is an import statement in an __init__.py file that imports a module in a subpackage, then we'll have two global reads of the same module. The first one is from the one that is imported automatically and the other from the explicit import call. We could reuse the automatic one. Right now, there are two identical ones.

The potentially redundant read occurs here:

int idx = context.cfg().getCurrentInstruction();
FieldReference global = makeGlobalRef("script " + scriptName + ".py");
context.cfg().addInstruction(new AstGlobalRead(idx, resultVal, global));

This issue can be exercised by running the following test case:

https://github.com/ponder-lab/ML/blob/d2946f69704a20bb575ea3bdcade2f43bed7f27a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java#L2611-L2621

That results in the following IR for https://github.com/ponder-lab/ML/blob/d2946f69704a20bb575ea3bdcade2f43bed7f27a/com.ibm.wala.cast.python.test/data/proj51/src/__init__.py:

callees of node __init__.py : []

IR of node 2, context CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]
<Code body of function Lscript src/__init__.py>
CFG:
BB0[-1..-2]
    -> BB1
BB1[0..96]
    -> BB2
BB2[-1..-2]
Instructions:
BB0
BB1
0   global:global script src/__init__.py = v1<no information>
1   putfield v1.< PythonLoader, LRoot, src, <PythonLoader,LRoot> > = v1__init__.py [1:0] -> [1:21]
2   v3 = global:global script src/module.py  __init__.py [1:0] -> [1:21]
3   putfield v1.< PythonLoader, LRoot, module, <PythonLoader,LRoot> > = v3__init__.py [1:0] -> [1:21]
...
95   v240 = global:global script src/module.py__init__.py [1:0] -> [1:21] [240=[f]]
96   v242 = fieldref v240.v239:#f            __init__.py [1:0] -> [1:21] [242=[f]240=[f]]
BB2

Note that v3 and v240 have the same value, though the results seem to differ in the printing (I wonder if that's from the PA?).

@khatchad khatchad added question Further information is requested cleanup labels Jul 3, 2024
@khatchad
Copy link
Collaborator Author

khatchad commented Jul 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant