Closed paulcadman closed 1 week ago
The comment at https://github.com/anoma/juvix/blob/main/src/Juvix/Compiler/Reg/Data/TransformationId.hs#L25 is not correct. In fact, copy propagation cannot be used in the C pipeline without adjusting the live variables afterwards. It's not true that all variables are considered live: only the ones representing the current stack in JuvixAsm. Consider the situation when a stack was bigger before and then popped, e.g. the top of it got translated to a variable tmp[n+1]
which was later assigned to tmp[n]
, then there was a call with variables up to tmp[n]
saved (but not tmp[n+1]
), then tmp[n]
is used. After copy propagation tmp[n+1]
is used after the call instead of tmp[n]
, but because the live variables for the call (which are supposed to be saved) didn't get adjusted, this is not correct - tmp[n+1]
contains an unspecified value.
Copy propagation should be removed from the C pipeline until we have liveness computation in JuvixReg. I'll add a test which exposes this in the test suite.
Actually, our test suite catches this, but we just didn't run the JuvixReg transformations when compiling in the test suite (in contrast to compiling via CLI). In the tests, we used regToMiniC'
(https://github.com/anoma/juvix/blob/main/src/Juvix/Compiler/Pipeline.hs#L379), which doesn't call Reg.toC
unlike regToMiniC
(https://github.com/anoma/juvix/blob/main/src/Juvix/Compiler/Pipeline.hs#L344) used in the CLI. So copy propagation was never performed in the tests.
To Reproduce
main
or the commit 235d88f3037abbe12b980d9994c6dc742e7b590c (i.e the commit for #2828 - Copy propagation in JuvixReg)This is an out-of-memory error.
Running without copy-propagation works
The juvix-stdlib test suite runs successfully, and only uses a small amount of memory if it run with the copy-propagation transformation disabled (either by using the commit immediately before the copy-propagation PR, or by manually removing the
CopyPropogation
transformationId from thetoCTransformations
list in the Juvix reg pipeline definition.