You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The solution: unless x is declared as x: Constant[i32] (we currently do not support it, but we could), then any initialization must be assigned to it using Assignment, not as "value" in the Variable_t, because then you can't assign to it later (we should check this in verify). Above x still has 3, not 5. For Constant[i32] you have to assign to it right away, and then you can't change it.
Well, first all the variables are declared. So declaration and initialisation of b happens before x = 5 is executed. This is not a bug I think. It is incorrect behaviour for Python. LLVM backend was initially written for Fortran (where you have to declare all the variables together before using them). To fix this, I think we can do an ASR pass where all the initialisations at declarations can be converted to assignments in the body. Then Fortran, Python would behave in the same way. Let me know what you think.
Another condition: the runtime value of symbolic_value must be a compile time constant. 3+3, 3, and constants (we don't have those yet) and expressions using those, are all constants. Everything else is not a constant, and the frontend must generate an Assignment statement instead.
Activity
czgdp1807 commentedon Jun 20, 2022
czgdp1807 commentedon Jun 20, 2022
Well, first all the variables are declared. So declaration and initialisation of
bhappens beforex = 5is executed. This is not a bug I think. It is incorrect behaviour for Python. LLVM backend was initially written for Fortran (where you have to declare all the variables together before using them). To fix this, I think we can do an ASR pass where all the initialisations at declarations can be converted to assignments in the body. Then Fortran, Python would behave in the same way. Let me know what you think.certik commentedon Jun 20, 2022
So the confusion stems from
The
valueis a compile time value, essentially implying the variable is a constant, so the value is assigned once and never changes.The
symbolic_valueis an initial value of the variable, that can change later.certik commentedon Jun 20, 2022
I think the bug is in the frontend, assigning the initialization to
valueinstead ofsymbolic_value.certik commentedon Jun 20, 2022
Another condition: the runtime value of
symbolic_valuemust be a compile time constant. 3+3, 3, and constants (we don't have those yet) and expressions using those, are allconstants. Everything else is not a constant, and the frontend must generate anAssignmentstatement instead.Smit-create commentedon Aug 31, 2022
This seems to be fixed now: