Skip to content

Always insert global symbols to _global_symbols module #1732

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

Merged
merged 2 commits into from
Apr 21, 2023

Conversation

czgdp1807
Copy link
Collaborator

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.

LGTM! Thanks for fixing this. This was on my TODO list, but I kept forgetting about it. 
So, from now on, we will always have two symbols in the TranslationUnit. If the program uses an IntrinsicFunction then the TranslationUnit also includes that function in the global scope.

Empty program:

(TranslationUnit
    (SymbolTable
        1
        {
            _global_symbols:
                (Module
                    (SymbolTable
                        3
                        {
                            
                        })
                    _global_symbols
                    []
                    .false.
                    .false.
                ),
            main_program:
                (Program
                    (SymbolTable
                        2
                        {
                            
                        })
                    main_program
                    []
                    []
                )
        })
    []
)

@czgdp1807
Copy link
Collaborator Author

czgdp1807 commented Apr 21, 2023

Thanks for pointing out. I don't create _global_symbols now if global scope doesn't have any user defined symbols. Now the behaviour will be same as main branch when the input file is empty.

@czgdp1807 czgdp1807 marked this pull request as ready for review April 21, 2023 10:31
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 looks good, thanks for fixing it!

@certik certik merged commit eb7b62e into lcompilers:main Apr 21, 2023
@certik
Copy link
Contributor

certik commented Apr 21, 2023

Hm, this PR broke --disable-main, it now always inserts main:

(lp) lpython/integration_tests(main) $ lpython --show-c --disable-main import_order_01.py -I.
#include <inttypes.h>

#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <lfortran_intrinsics.h>

#define ASSERT(cond)                                                           \
    {                                                                          \
        if (!(cond)) {                                                         \
            printf("%s%s", "ASSERT failed: ", __FILE__);                       \
            printf("%s%s", "\nfunction ", __func__);                           \
            printf("%s%d%s", "(), line number ", __LINE__, " at \n");          \
            printf("%s%s", #cond, "\n");                                       \
            exit(1);                                                           \
        }                                                                      \
    }
#define ASSERT_MSG(cond, msg)                                                  \
    {                                                                          \
        if (!(cond)) {                                                         \
            printf("%s%s", "ASSERT failed: ", __FILE__);                       \
            printf("%s%s", "\nfunction ", __func__);                           \
            printf("%s%d%s", "(), line number ", __LINE__, " at \n");          \
            printf("%s%s", #cond, "\n");                                       \
            printf("%s", "ERROR MESSAGE:\n");                                  \
            printf("%s%s", msg, "\n");                                         \
            exit(1);                                                           \
        }                                                                      \
    }


struct dimension_descriptor
{
    int32_t lower_bound, length;
};

// Implementations
int32_t f()
{
    int32_t _lpython_return_variable;
    _lpython_return_variable = 42;
    return _lpython_return_variable;
}

void main1()
{
    int32_t a;
    a = f();
    printf("%d\n", a);
}

int main(int argc, char* argv[])
{
    return 0;
}

Hopefully it can be fixed with a subsequent PR, otherwise we'll need to revert it.

@czgdp1807
Copy link
Collaborator Author

Let me see. Probably a corner case.

certik added a commit to certik/lpython that referenced this pull request Apr 21, 2023
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.

Function dependencies not respected with --disable-main
3 participants