-
Notifications
You must be signed in to change notification settings - Fork 170
Saving LPython's intrinsic modules as pyc
files
#999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@certik Is this PR a good approach for implementing #992 (comment)? |
b.write_string(serialize(m)); | ||
|
||
return b.get_str(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would merge this with LFortran --- I think all LCompilers can then reuse it, just change the extension. I think there is nothing special about LPython's .pyc
compared to LFortran's .mod
, I think they can be exactly identical. It's just ASR that is saved, it's independent of the frontend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one thing different though. Fortran files have specific module symbols. Only those are saved in the .mod
files. However in the case of Python, whole file can be a module. We just have to import something from it and it becomes a module. But if you call it using python
command then it acts as an "executable". So what I have done is if any file is compiled with -c
option of LPython then its ASR (i.e., the full ASR::TranslationUnit_t
) gets saved in a .pyc
file. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can discuss it more. What I had in mind is that a single Python file is exactly 100% equivalent to a single Fortran module file, at the ASR level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Well, there is a difference that Python modules can be nested, but this is something that people have requested for Fortran also to do, so we should allow that at the ASR level in some clean way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Let me try out implementing the rest of the steps I have written in #999 (comment). Let's see if it works till the end.
343f757
to
bcbee61
Compare
@certik Could you please review this? So far I have added support for saving LPython's generated ASR into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine.
My only concern is with the duplication, since we rather want to extend / amend ASR and whatever is needed, and then exactly reuse the saving / loading functionality. It will benefit both LPython and LFortran. In fact, I think we could even mix and match ASR modules, that is, take an LPython .pyc
module and "use" it from LFortran and vice versa. It's a little hard to wrap the head around it, but in libasr
it is "just" ASR, it is not Python and it is not Fortran; or equivalently, it is both Python and Fortran. So rather than saving Python/Fortran, I want to think about it as saving ASR as a module. That's it. So it should be exactly the same code, and if it is not, that would be a concern.
Yes. I agree. I will try to combine the functions (or as much as is common between them) here. Rest I will try to leave the scope of handling differences if any. |
Regarding the behavior --- should LPython always save It seems we almost need two modes:
|
By timestamp you mean two things right, the time at which |
Yes regarding timestamp. Yes, we need to distinguish the two (or three) modes above. For example |
Regarding mix and matching LPython / LFortran, we will (later) version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine. Further improvements can be done once this is merged.
#992 (comment)
For now I just save the ASR of a Python file compiled with
-c
option in.pyc
files. Next steps,.pyc
file generated earlier. If not found then compile and re-save in.pyc
file.