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.

DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (11 rendered)

Cache calls from 1 backend

Signals

Log messages