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

Missing decorated functions whose decorators simply return the function #190

Open
khatchad opened this issue Apr 30, 2024 · 4 comments
Open
Labels
bug Something isn't working decorators

Comments

@khatchad
Copy link
Collaborator

Description

Related to #189.

Consider the following code:

import tensorflow as tf


def mama(fun):
    return fun


@mama
def raffi(x):
    assert isinstance(x, tf.Tensor)


raffi(tf.constant(1))

The function raffi() is missing from the CG.

Regression

Reverting 2a6e522 fixes the problem.

When there's no inner function in the decorator, somehow, visiting entire decorator doesn't work. Visiting just the internal decorator (the child) works. It would seem that the decorator is missing from the PA:

BB1
...
101   v244 = new <PythonLoader,Lscript tf2_test_decorated_method3.py/mama>@101<no information> [244=[mama]]
...
104   v4 = new <PythonLoader,Lscript tf2_test_decorated_method3.py/raffi>@104<no information> [4=[raffi]]
105   v249 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v244 @105 exception:v250tf2_test_decorated_method3.py [1:0] -> [13:21] [244=[mama]]
BB2
106   v18 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v249,v4 @106 exception:v251tf2_test_decorated_method3.py [1:0] -> [13:21] [18=[raffi]4=[raffi]]
...
BB3
111   v252 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v18,v253 @111 exception:v258tf2_test_decorated_method3.py [13:0] -> [13:21] [18=[raffi]]
[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v4] --> [SMIK:SITE_IN_NODE{<Code body of function Lscript tf2_test_decorated_method3.py>:Lscript tf2_test_decorated_method3.py/raffi in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]}@creator:Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]]

[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v18] --> []

[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v249] --> []
@khatchad khatchad added decorators bug Something isn't working labels Apr 30, 2024
@khatchad
Copy link
Collaborator Author

khatchad commented Apr 30, 2024

If I put the fix back, we get:

BB1
...
101   v244 = new <PythonLoader,Lscript tf2_test_decorated_method3.py/mama>@101<no information> [244=[mama]]
...
104   v4 = new <PythonLoader,Lscript tf2_test_decorated_method3.py/raffi>@104<no information> [4=[raffi]]
105   v249 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v244 @105 exception:v250tf2_test_decorated_method3.py [1:0] -> [13:21] [244=[mama]]
BB2
106   v18 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v244,v4 @106 exception:v251tf2_test_decorated_method3.py [1:0] -> [13:21] [18=[raffi]244=[mama]4=[raffi]]
...
BB3
111   v252 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v18,v253 @111 exception:v258tf2_test_decorated_method3.py [13:0] -> [13:21] [18=[raffi]]
[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v4] --> [SMIK:SITE_IN_NODE{<Code body of function Lscript tf2_test_decorated_method3.py>:Lscript tf2_test_decorated_method3.py/raffi in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]}@creator:Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]]

[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v18] --> [SMIK:SITE_IN_NODE{<Code body of function Lscript tf2_test_decorated_method3.py>:Lscript tf2_test_decorated_method3.py/raffi in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]}@creator:Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]]

[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v249] --> []

@khatchad
Copy link
Collaborator Author

Something looks to be wrong with instruction 105. When there's an embedded function, I am seeing the variable point to it. Otherwise, it's blank.

@khatchad
Copy link
Collaborator Author

The crux of the problem is that this is the decorator:

callees of node mama : []

IR of node 4, context CallStringContext: [ script tf2_test_decorated_method3.py.do()LRoot;@105 ]
<Code body of function Lscript tf2_test_decorated_method3.py/mama>
CFG:
BB0[-1..-2]
    -> BB1
BB1[0..0]
    -> BB2
BB2[-1..-2]
Instructions:
BB0
BB1
0   return v2                                tf2_test_decorated_method3.py [5:4] -> [5:14] [2=[fun]]
BB2

Here's the call to the decorator:

105   v249 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v244 @105 exception:v250tf2_test_decorated_method3.py [1:0] -> [13:21] [244=[mama]]

We don't pass it anything until later:

106   v18 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v249,v4 @106 exception:v251tf2_test_decorated_method3.py [1:0] -> [13:21] [18=[raffi]4=[raffi]]

But we have this:

[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v249] --> []

But we do have this:

[Node: <Code body of function Lscript tf2_test_decorated_method3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v244] --> [SITE_IN_NODE{<Code body of function Lscript tf2_test_decorated_method3.py>:Lscript tf2_test_decorated_method3.py/mama in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]}]

If the decorator returned itself (v1), it would work.

@khatchad
Copy link
Collaborator Author

khatchad commented May 2, 2024

This works in Jython 2, probably because decorators are not supported and consequently ignored there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working decorators
Projects
None yet
Development

No branches or pull requests

1 participant