Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@kmr-srbh

Description

@kmr-srbh

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
                        []
                        ()
                    )]
                )
        })
    []
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions