Open katat opened 1 month ago
This change in another PR should prevent the folding on zz + zz
above, since the folding would only occur on the generic variables.
If it is not generic variable, the constant value still can be propagated even it is not folded at AST level.
So after that change, it seems this issue became non-issue.
Therefore, these two lines are not necessary anymore.
Constant folding is needed to resolve the concrete sizes for the arrays. The MAST phase uses the propagated constants to resolved the generic parameters, such as
Most of the time it is trivial to just fold the constant variables with the resolved values. But here is a case to take care with different rule:
Because the AST for
zz = zz + zz
is changed tozz = 4
after the constant folding, it won't represent the correct AST anymore. The value ofzz
should be changed after each iteration in the for loop. But after constant folding is done over it, the value ofzz
is always the same.There is a PR to do a temporary fix by treat the mutable variable as non constant. But this is not ideal, because there can be cases like:
So if
len
is treated as a non constant variable, the case above won't work also.I think the root problem is due to the case of recursive mutation in a for loop. Therefore, one idea is to skip constant folding for mutable variable if it is within a for loop scope.