Week 9

Summarizing where I had left off last week, I had just started working on framing a symbolic ASR pass. The goal behind framing such an ASR->ASR pass is that, currently we’ve added support for dealing with symbolic expressions & operations for the C backend only. Hence the next step here should be to lift this symbolic support from the C backend and extend its functionality to all other backends like LLVM. This is where the pass comes in.

Talking about the tasks completed in this regard

  • Added a test based on the basic_new_stack function through the following PR
  • Then Ubaid who’s a fellow developer at LFortran and I discovered the CI fails to catch errors and is passing faultily. Hence we ended up fixing that through the following PR
  • Added support for using ccall() for SymEngine and other libraries through the following PR. Hence we finally had a correct working test example to refer to while framing the ASR pass.
$ cat integration_tests/symbolics_07.py                    
from lpython import ccall, CPtr
import os

@ccall(header="symengine/cwrapper.h", py_mod="symengine", py_mod_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_new_heap() -> CPtr:

@ccall(header="symengine/cwrapper.h", py_mod="symengine", py_mod_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_const_pi(x: CPtr) -> None:

@ccall(header="symengine/cwrapper.h", py_mod="symengine", py_mod_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_str(x: CPtr) -> str:

def main0():
    x: CPtr = basic_new_heap()
    s: str = basic_str(x)
    assert s == "pi"


$ python integration_tests/symbolics_07.py                    

$ lpython integration_tests/symbolics_07.py --enable-symengine --backend c
  • Added the llvm_sym backend for testing symbolic operations through the llvm backend through the following PR. Hence now we could do something like the following
(lf) anutosh491@spbhat68:~/lpython/lpython/integration_tests$ ./run_tests.py -b llvm_sym
-- Configuring done
-- Generating done
-- Build files have been written to: /home/anutosh491/lpython/lpython/integration_tests/_lpython-tmp-test-llvm_sym
+ make -j8
[ 50%] Generating symbolics_07.o
[100%] Linking C executable symbolics_07
[100%] Built target symbolics_07
+ ctest -j8 --output-on-failure
Test project /home/anutosh491/lpython/lpython/integration_tests/_lpython-tmp-test-llvm_sym
    Start 1: symbolics_07
1/1 Test #1: symbolics_07 .....................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 1

Label Time Summary:
c_sym          =   0.01 sec*proc (1 test)
cpython_sym    =   0.01 sec*proc (1 test)
llvm_sym       =   0.01 sec*proc (1 test)
  • Added tests based on basic_new_stack function through the following PR. We used an approach where we would have a placeholder variable and then intialize memory for our CPtr variable using the pointer & p_c_pointer functions.
  • Started implementing the Symbolic ASR pass through the following PR.

As y’all can see, now that we have the working examples for printing out the pi variable using functions/operations implemented in LPython itself, we can start working on the ASR pass now. As I haven’t framed an ASR pass from scratch before I am still working on it with the help of Thirumalai Shaktivel and Shaikh Ubaid. They are helping me understand terminologies like CallReplacerOnExpressionsVisitor, BaseExprReplacer and other terms which would come in while implementing the pass.

I am still working on framing the above pass and hopefully I should be having a concrete implementation by the end of the coming week.

Talking about my plans for the next week.

  • Have a concrete implementation for the pass we discussed in this blog.

Thank You for going through the blog. I hope you like it. Stick around for what’s next to come. Moving into Week 10!


Mumbai, Maharashtra, India