Skip to content
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

Fix scoping issue #2161

Merged
merged 10 commits into from
Jul 16, 2023
Merged

Fix scoping issue #2161

merged 10 commits into from
Jul 16, 2023

Conversation

Shaikh-Ubaid
Copy link
Collaborator

fixes #2146

In this PR the main_module is also considered/treated as every other module and added into the ASR Translation_Unit_t as a Module_t.

@Shaikh-Ubaid
Copy link
Collaborator Author

This PR is a continuation of #2160. (I was hoping to send them together but the PR was being huge.).

I will rebase this PR after merging/completion of #2160.

@Shaikh-Ubaid
Copy link
Collaborator Author

Ready.

@certik
Copy link
Contributor

certik commented Jul 15, 2023

Thanks @Shaikh-Ubaid, very useful. @Thirumalai-Shaktivel, @czgdp1807 can you please review this and check if you see any issue with this approach?

This might be a simpler and more robust approach than what we were using so far.

@Shaikh-Ubaid
Copy link
Collaborator Author

Just removed the function move_symbols_from_global_scope() which is unused now, since the pass that uses it was removed.

"The script is invoked as the main module and it has code to execute,\n"
"but `--disable-main` was passed so no code was generated for `main`.\n"
"We are removing all global executable code from ASR.",
diag::Level::Warning, diag::Stage::Semantic, {})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to keep this warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous approach, we were removing the global executable code. I think therefore we were printing the warning that global code is being removed. In the current approach, we do not remove any global code (The global code is present inside the functions global_init() and global_stmts().). When disable main is enabled, we just do not execute the global code (that is, it is present but not executing). Since, there is no loss or removal of code, I guess we need not print the warning.

Comment on lines 121 to 122
/* a_return_var */ (return_var ? return_var_ref : nullptr),
(return_var ? ASR::abiType::BindC : ASR::abiType::Source),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. If a tertiary operator doesn't suit our design, we can use some variable to store the values and pass them here.

@@ -5,16 +5,16 @@ source_filename = "LFortran"
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1

define void @__module__global_symbols__lpython_main_program() {
define void @__module___main_____main____global_statements() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle this name mangling correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I guess we can work on it in a separate PR.

Copy link
Collaborator

@Thirumalai-Shaktivel Thirumalai-Shaktivel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this seems to be more robust, as we handle everything in the ASR itself.
This looks great! Thanks @Shaikh-Ubaid!

@Shaikh-Ubaid
Copy link
Collaborator Author

Thank you so much for the review @Thirumalai-Shaktivel! I appreciate it.

@certik
Copy link
Contributor

certik commented Jul 16, 2023

@Shaikh-Ubaid can you please merge #2160 and then update this branch against master, so that we can see just the changes? I want to see if we need to test it with LFortran as well.

Copy link
Contributor

@certik certik left a 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. Thanks for fixing this @Shaikh-Ubaid. If there is a problem, we'll fix it later.

@Shaikh-Ubaid Shaikh-Ubaid merged commit f8f58d0 into lcompilers:main Jul 16, 2023
9 checks passed
@Shaikh-Ubaid Shaikh-Ubaid deleted the fix_scoping2 branch July 16, 2023 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Declaring a u16 function breaks the % operation
3 participants