lfortran icon indicating copy to clipboard operation
lfortran copied to clipboard

Refactor ASRBuilder

Open certik opened this issue 1 year ago • 7 comments

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

certik avatar Feb 01 '24 15:02 certik

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".

ubaidsk avatar Feb 07 '24 00:02 ubaidsk

Yes, I think it is, thanks!

certik avatar Feb 07 '24 00:02 certik

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).

gxyd avatar Feb 22 '24 07:02 gxyd

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.

ubaidsk avatar Feb 22 '24 07:02 ubaidsk

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.

ubaidsk avatar Feb 22 '24 07:02 ubaidsk

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.

Pranavchiku avatar Mar 13 '24 09:03 Pranavchiku

Things to explore:

  • Simplifying calling another intrinsic function from another intrinsic function's instantiation (must be instantiated)
  • Using operator overloading +, -, &&, <=, etc. to simplify code

certik avatar Apr 19 '24 16:04 certik

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?

nikabot avatar May 24 '24 03:05 nikabot

Seems good to me, but maybe we should do it after Beta?

ubaidsk avatar May 25 '24 03:05 ubaidsk