Refactor ASRBuilder
Right now the ASR builder is at https://github.com/lfortran/lfortran/blob/dca110d46606d068dbca0fb334b4bf612ab4011d/src/libasr/pass/intrinsic_function_registry.h#L220
It needs to be refactored:
- [x] Dedicated header file (https://github.com/lfortran/lfortran/pull/3261)
- [ ] No macros
- [ ] Improve the interface to be as simple/concise as possible
- [ ] For most common expressions it computes the compile time value automatically
See also: https://github.com/lfortran/lfortran/pull/3274/files#r1474626737
Is the first part in this issue completed in https://github.com/lfortran/lfortran/pull/3261? We currently have a separate header file "src/libasr/asr_builder.h".
Yes, I think it is, thanks!
I find the issue interesting, can I maybe think about working on parts of it? @Shaikh-Ubaid , any suggestions? (I can pick something else from "ASR refactoring" if you are working on this issue).
I find the issue interesting, can I maybe think about working on parts of it? @Shaikh-Ubaid , any suggestions? (I can pick something else from "ASR refactoring" if you are working on this issue).
Sure, I am glad you are interested in this. We can work on this together. Go ahead and submit a PR. As of now, I am more focused on stdlib and can join you in the next week.
We need to make the class ASRBuilder a nice utility to help us easily and rapidly build ASR nodes. For example, for adding two numbers (let's say 5 and 2 of kind 4) I am imagining the code could be like:
ASRBuilder b(al, loc);
b.addInt(b.int(5, 4), b.int(2, 4));
I think the design would come out naturally. There are three things to be tackled as per https://github.com/lfortran/lfortran/issues/3277#issue-2112749568
- No macros
- Improve interface
- Auto-compute compile-time values when possible
I think improving interface can be done gradually as we work on this issue. Auto-computing compile-time values can be handled later when we already have some utility functions. So, for now to get started, I think we can focus on removing the macros.
I think this is right time to go ahead and remove macros, I tried a small one and is pain to do. The rate at which intrinsic function are being implemented, this will be a lot of debt if postponed for later.
Things to explore:
- Simplifying calling another intrinsic function from another intrinsic function's instantiation (must be instantiated)
- Using operator overloading +, -, &&, <=, etc. to simplify code
Like ASR.asdl, we can have Intrinsics.asdl, represent each intrinsics as nodes, members as arguments, result as the last argument and generate create_intrinsics, ...
@certik Would it be worth a try?
Seems good to me, but maybe we should do it after Beta?