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

Severe Bug: Output of --show-asr differs from actual ASR constructed after transformation #2621

Closed
kmr-srbh opened this issue Mar 23, 2024 · 3 comments

Comments

@kmr-srbh
Copy link
Contributor

I encountered this bug while working out the fix for #2613 . This bug caused me to wander A LOT trying to find the actual cause of the issue. It was only after executing std::cout << LCompilers::pickle(asr, true, false, false) << std::endl; in asr_to_llvm.cpp that I could see the actual ASR which was being constructed, matching the output I was receiving.

Minimum Reproducible Example

Note: The following example will not work after #2620 is merged.

l: list[str] = ["a", "b", "c"]
print(l[0], "...")
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
...

ASR output for --show-asr

(TranslationUnit
    (SymbolTable
        1
        {
            __main__:
                (Module
                    (SymbolTable
                        2
                        {
                            __main__global_init:
                                (Function
                                    (SymbolTable
                                        3
                                        {
                                            
                                        })
                                    __main__global_init
                                    (FunctionType
                                        []
                                        ()
                                        Source
                                        Implementation
                                        ()
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        []
                                        .false.
                                    )
                                    []
                                    []
                                    [(=
                                        (Var 2 l)
                                        (ListConstant
                                            [(StringConstant
                                                "a"
                                                (Character 1 1 ())
                                            )
                                            (StringConstant
                                                "b"
                                                (Character 1 1 ())
                                            )
                                            (StringConstant
                                                "c"
                                                (Character 1 1 ())
                                            )]
                                            (List
                                                (Character 1 1 ())
                                            )
                                        )
                                        ()
                                    )]
                                    ()
                                    Public
                                    .false.
                                    .false.
                                    ()
                                ),
                            __main__global_stmts:
                                (Function
                                    (SymbolTable
                                        4
                                        {
                                            
                                        })
                                    __main__global_stmts
                                    (FunctionType
                                        []
                                        ()
                                        Source
                                        Implementation
                                        ()
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        []
                                        .false.
                                    )
                                    []
                                    []
                                    [(Print
                                        [(ListItem
                                            (Var 2 l)
                                            (IntegerConstant 0 (Integer 4))
                                            (Character 1 -2 ())
                                            ()
                                        )
                                        (StringConstant
                                            "..."
                                            (Character 1 3 ())
                                        )]
                                        ()
                                        ()
                                    )]
                                    ()
                                    Public
                                    .false.
                                    .false.
                                    ()
                                ),
                            l:
                                (Variable
                                    2
                                    l
                                    []
                                    Local
                                    ()
                                    ()
                                    Default
                                    (List
                                        (Character 1 -2 ())
                                    )
                                    ()
                                    Source
                                    Public
                                    Required
                                    .false.
                                )
                        })
                    __main__
                    []
                    .false.
                    .false.
                ),
            main_program:
                (Program
                    (SymbolTable
                        5
                        {
                            __main__global_init:
                                (ExternalSymbol
                                    5
                                    __main__global_init
                                    2 __main__global_init
                                    __main__
                                    []
                                    __main__global_init
                                    Public
                                ),
                            __main__global_stmts:
                                (ExternalSymbol
                                    5
                                    __main__global_stmts
                                    2 __main__global_stmts
                                    __main__
                                    []
                                    __main__global_stmts
                                    Public
                                )
                        })
                    main_program
                    [__main__]
                    [(SubroutineCall
                        5 __main__global_init
                        2 __main__global_init
                        []
                        ()
                    )
                    (SubroutineCall
                        5 __main__global_stmts
                        2 __main__global_stmts
                        []
                        ()
                    )]
                )
        })
    []
)

Actual ASR after transformation

(TranslationUnit
    (SymbolTable
        1
        {
            __main__:
                (Module
                    (SymbolTable
                        2
                        {
                            __main__global_init:
                                (Function
                                    (SymbolTable
                                        3
                                        {
                                            
                                        })
                                    __main__global_init
                                    (FunctionType
                                        []
                                        ()
                                        Source
                                        Implementation
                                        ()
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        []
                                        .false.
                                    )
                                    []
                                    []
                                    [(=
                                        (Var 2 l)
                                        (ListConstant
                                            [(StringConstant
                                                "a"
                                                (Character 1 1 ())
                                            )
                                            (StringConstant
                                                "b"
                                                (Character 1 1 ())
                                            )
                                            (StringConstant
                                                "c"
                                                (Character 1 1 ())
                                            )]
                                            (List
                                                (Character 1 1 ())
                                            )
                                        )
                                        ()
                                    )]
                                    ()
                                    Public
                                    .false.
                                    .false.
                                    ()
                                ),
                            __main__global_stmts:
                                (Function
                                    (SymbolTable
                                        4
                                        {
                                            
                                        })
                                    __main__global_stmts
                                    (FunctionType
                                        []
                                        ()
                                        Source
                                        Implementation
                                        ()
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        .false.
                                        []
                                        .false.
                                    )
                                    []
                                    []
                                    [(Print
                                        [(StringConstant
                                            "..."
                                            (Character 1 3 ())
                                        )]
                                        ()
                                        ()
                                    )]
                                    ()
                                    Public
                                    .false.
                                    .false.
                                    ()
                                ),
                            l:
                                (Variable
                                    2
                                    l
                                    []
                                    Local
                                    ()
                                    ()
                                    Default
                                    (List
                                        (Character 1 -2 ())
                                    )
                                    ()
                                    Source
                                    Public
                                    Required
                                    .false.
                                )
                        })
                    __main__
                    []
                    .false.
                    .false.
                ),
            main_program:
                (Program
                    (SymbolTable
                        5
                        {
                            __main__global_init:
                                (ExternalSymbol
                                    5
                                    __main__global_init
                                    2 __main__global_init
                                    __main__
                                    []
                                    __main__global_init
                                    Public
                                ),
                            __main__global_stmts:
                                (ExternalSymbol
                                    5
                                    __main__global_stmts
                                    2 __main__global_stmts
                                    __main__
                                    []
                                    __main__global_stmts
                                    Public
                                )
                        })
                    main_program
                    [__main__]
                    [(SubroutineCall
                        5 __main__global_init
                        5 __main__global_init
                        []
                        ()
                    )
                    (SubroutineCall
                        5 __main__global_stmts
                        5 __main__global_stmts
                        []
                        ()
                    )]
                )
        })
    []
)
@Shaikh-Ubaid
Copy link
Collaborator

Thanks for looking into this. I think this is not a bug, but a feature. When you do --show-asr you can see the original ASR that was constructed. This ASR is then passed through several ASR->ASR passes. The backends then receive this transformed ASR.

Therefore the ASR that you see from the output of --show-asr and the ASR that the backends see are different.

To check the ASR that the backends see, you can do --dump-all-passes and you will get some files generated that contain the ASR output after each pass. You can simply check the ASR output after the last pass as that is the ASR that will be seen by the backends.

PS: You can also combine --visualize with --dump-all-passes (or --show-asr) if you want to see ASR visualization.

@Shaikh-Ubaid
Copy link
Collaborator

The ASR being constructed after the passes in the example shared here #2621 (comment) is definitely incorrect. I think we have an issue noted for it here #2613.

@Shaikh-Ubaid
Copy link
Collaborator

I am closing this issue for now.

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 a pull request may close this issue.

2 participants