1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00

Remove copy propagation from the native/WASM and Rust pipelines (#2846)

* Closes #2845 
* Copy propagation is not correct without subsequent adjusting of live
variables. See the comments in #2845.
* Enables JuvixReg transformations in the test suite, which exposes the
bug.
* Adds a test in JuvixAsm crafted specifically to expose this bug.
This commit is contained in:
Łukasz Czajka 2024-06-20 12:44:15 +02:00 committed by GitHub
parent 9e6e8d8a35
commit 285b23742f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 53 additions and 6 deletions

View File

@ -378,5 +378,6 @@ asmToMiniC' = mapError (JuvixError @Asm.AsmError) . Asm.toReg' >=> regToMiniC' .
regToMiniC' :: (Member (Reader Asm.Options) r) => Reg.InfoTable -> Sem r C.MiniCResult
regToMiniC' tab = do
tab' <- Reg.toC tab
e <- ask
return $ C.fromReg (e ^. Asm.optLimits) tab
return $ C.fromReg (e ^. Asm.optLimits) tab'

View File

@ -20,13 +20,11 @@ data PipelineId
type TransformationLikeId = TransformationLikeId' TransformationId PipelineId
-- Note: this works only because for now we mark all variables as live. Liveness
-- information needs to be re-computed after copy propagation.
toCTransformations :: [TransformationId]
toCTransformations = [Cleanup, CopyPropagation]
toCTransformations = [Cleanup]
toRustTransformations :: [TransformationId]
toRustTransformations = [Cleanup, CopyPropagation]
toRustTransformations = [Cleanup]
toCasmTransformations :: [TransformationId]
toCasmTransformations = [Cleanup, CopyPropagation, SSA]

View File

@ -224,5 +224,10 @@ tests =
"Test038: Apply & argsnum"
$(mkRelDir ".")
$(mkRelFile "test038.jva")
$(mkRelFile "out/test038.out")
$(mkRelFile "out/test038.out"),
PosTest
"Test039: Copy propagation"
$(mkRelDir ".")
$(mkRelFile "test039.jva")
$(mkRelFile "out/test039.out")
]

View File

@ -0,0 +1 @@
11

View File

@ -0,0 +1,42 @@
-- Copy propagation
-- This test will fail with the native/WASM backend if copy propagation is
-- performed on JuvixReg without adjusting the live variables.
function f(integer) {
push arg[0];
push 0;
eq;
br {
true: {
push 3;
push 4;
tsave {
tsave {
push tmp[1];
call f;
push tmp[0];
add;
ret;
};
};
};
false: {
push arg[0];
push arg[0];
push arg[0];
push arg[0];
add;
sub;
add;
push 1;
add;
ret;
};
};
}
function main() {
push 0;
tcall f;
}