luthfan's Blog

Dealing with conflict and ASR (2nd week)

luthfan
Published: 06/24/2022

Hello again, here's a quick update on my second week with LPython!

What I did this week

It turned out that there were conflicts between my last week's work and the project's upstream, so the first thing I did this week was resolving that conflict. I also found another issue with existing integration tests, so some changes had to be made to make it possible for my work from last week to be submitted.

I also spent time to understand the differences between two AST visitors that build the ASR: a visitor that builds the symbol table and a visitor that transforms the statements.

What is coming up next week

I want to start implementing support to allow the following function declaration with type parameters:

def fun(x: T, y: T) -> T:
  return x+y

Did I get stuck anywhere

I didn't exactly understand the cause of the conflict at the beginning, but consulting with my mentor solved that issue.

View Blog Post

Adding type variable support to LPython (1st week)

luthfan
Published: 06/18/2022

Hello, here is a quick update of my first week with LPython project!

What I did this week

Unfortunately due to a personal issue, I had a very late start. I could not start until Thursday. Spent the day to reintroduce myself to the project and finally started making progress on Friday.

As planned, the first week was to give support for Python's type variable declaration T = TypeVar('T'). The syntax was already extended, so that's a okay. What I had to do then was to support the type variable in the underlying ASR (Abstract Semantic Representation) into which the Python AST will be translated. By the way, ASR is an IR from which we compile the program into lower languages like LLVM.

To do so, what I did was adding a new kind of type to the underlying ASR, the type variable. Then, while scanning through the AST, the type variable declaration T = TypeVar('T') is converted into a variable that is typed with an ASR type variable and then placed into the symbol table of the program, so that later on functions can identify these variables as type variables.

Slight note though, since I'm messing around with the ASR, the code generation for these type variables have to also be added later on.

What is coming up next week

Next week I will have to handle functions with type parameters. One important issue would be how to handle the type check on these functions, because they can't be type checked as usual where the base types are all present.

Did I get stuck anywhere

I was confused on whether to approach the issue by tinkering with the AST or going straight to ASR. However, since the ASR has many utilities for handling symbol table, I decided to go straight with ASR.

View Blog Post