Interpreter: Cache CGC results instead of re-executing them
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mars |
Fix Released
|
Low
|
Matt Giuca |
Bug Description
Each time a computable global constant is mentioned, it is fully executed. Since CGCs (unlike nullary functions) are by definition constants, their value should be the same every time, and they should not perform side-effects. Therefore, the interpreter should cache their value after the first reference, and on subsequent references, simply re-use the same value.
This technically does *not* change the Mars language, as CGCs have always been specified as constants, but it will change the behaviour of some programs if they use impure constructs. Firstly CGCs which perform IO will change their behaviour to only execute the IO once. Secondly, CGCs which return objects (like arrays) will now return the same array reference each time, so impure array mutation constructs will actually mutate the global constant.
One reason to make this change is to force the upcoming uniqueness analysis to account for shared references to global constants.
Related branches
Changed in mars: | |
status: | Fix Committed → Fix Released |
Fixed in trunk r1068.