STEllAR-GROUP / phylanx

An Asynchronous Distributed C++ Array Processing Toolkit
Boost Software License 1.0
75 stars 76 forks source link

Error from unrelated compilation module #1138

Open stevenrbrandt opened 4 years ago

stevenrbrandt commented 4 years ago

The following code fails to run.

from random import randint
from phylanx import Phylanx

@Phylanx
def f3(n):
    if n < 2:
        return n
    else:
        return fib(n-1)+fib(n-2)+fib(n-3)

@Phylanx
def f4(n):
    if n < 2:
        return n
    else:
        return f4(n-1)+f4(n-2)+f4(n-3)

print("Sources compiled")
fibno = randint(3,5)
res = f4(fibno)
print("f4(%d)=%d" % (fibno, res))

Produces the output below. Note, the string "Sources compiled" prints, but f4 fails to execute because of a missing function in f3 (which is not executed).

Sources compiled
PAPI lmsensors component found...
No lmsensors events found.
Error starting PAPI eventset.
Traceback (most recent call last):
  File "f4.py", line 20, in <module>
    res = f4(fibno)
  File "/home/jovyan/.local/lib/python3.6/site-packages/phylanx-0.0.1-py3.6-linux-x86_64.egg/phylanx/ast/transducer.py", line 162, in __call__
    result = self.backend.call(*mapped_args, **mapped_kwargs)
  File "/home/jovyan/.local/lib/python3.6/site-packages/phylanx-0.0.1-py3.6-linux-x86_64.egg/phylanx/ast/physl.py", line 548, in call
    self._ensure_global_state()
  File "/home/jovyan/.local/lib/python3.6/site-packages/phylanx-0.0.1-py3.6-linux-x86_64.egg/phylanx/ast/physl.py", line 421, in _ensure_global_state
    PhySLFunction.compile()
  File "/home/jovyan/.local/lib/python3.6/site-packages/phylanx-0.0.1-py3.6-linux-x86_64.egg/phylanx/ast/physl.py", line 348, in compile
    func.compile_function()
  File "/home/jovyan/.local/lib/python3.6/site-packages/phylanx-0.0.1-py3.6-linux-x86_64.egg/phylanx/ast/physl.py", line 342, in compile_function
    self.physl._ensure_is_compiled()
  File "/home/jovyan/.local/lib/python3.6/site-packages/phylanx-0.0.1-py3.6-linux-x86_64.egg/phylanx/ast/physl.py", line 439, in _ensure_is_compiled
    self.wrapped_function.__name__, self.__ast__)
RuntimeError: f4.py(9, 15): couldn't find function 'fib' in symbol table: HPX(bad_parameter)
hkaiser commented 4 years ago

Why shouldn't this not be an error? We currently compile all @Phylanx-decorated functions once the first is invoked. Do you think we should delay the compilation until a function is actually invoked?