hax icon indicating copy to clipboard operation
hax copied to clipboard

Loops without side effect

Open W95Psp opened this issue 1 year ago • 7 comments

Currently, extracting a loop whose body performs no side effect results in the following error:

error[HAX0001]: (FunctionalizeLoops) something is not implemented yet.
                Loop without mutation?

This error comes from the phase FunctionalizeLoops, which --for now-- assumes purity. Under the assumption things are pure, a loop without side effect is a no op; such a loop is useless but should be supported anyway. Also, some backend might use FunctionalizeLoops without assuming purity.

Examples of loops without side effect

for i in i..10 {
   // empty body
}

for i in i..10 {
   f(i)
}

W95Psp avatar Jan 02 '24 13:01 W95Psp

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Dec 17 '24 02:12 github-actions[bot]

It seems like this still reproduce, but I recall you did something around this @maximebuyse: do you remember something as well?

W95Psp avatar Dec 17 '24 06:12 W95Psp

It seems like this still reproduce, but I recall you did something around this @maximebuyse: do you remember something as well?

Yes, the case I fixed is when the only side effect is a return.

maximebuyse avatar Dec 17 '24 08:12 maximebuyse

We also run into this issue when translating ElectionGuard

cmester0 avatar Jan 03 '25 09:01 cmester0

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Mar 06 '25 01:03 github-actions[bot]

Lets allow this, maybe add a warning.

franziskuskiefer avatar Mar 06 '25 12:03 franziskuskiefer

What's the state of this? We run into this in libcrux code.

franziskuskiefer avatar May 16 '25 07:05 franziskuskiefer

Sorry Franziskus, I missed that comment. @maximebuyse I think we wanted to fix this at some point, this should not be too complicated, what do you think?

W95Psp avatar May 19 '25 09:05 W95Psp

Sorry Franziskus, I missed that comment. @maximebuyse I think we wanted to fix this at some point, this should not be too complicated, what do you think?

Yes, I can try to find the time for that this week.

maximebuyse avatar May 19 '25 09:05 maximebuyse

I think the title is also a little misleading as the same error is thrown when there's something panicking in the loop. For example, adding an assert!(i < 10); to the example throws the same error.

franziskuskiefer avatar May 19 '25 10:05 franziskuskiefer

Indeed, I agree: from a Rust perspective, an assert (that is, a conditional panic) can be seen as a side effect.

However, in hax, panics are not effectful: a panic is translated to a point in the program where we have to provide a proof that this point is unreachable. Similarly, every function in hax is supposed to be faithful to its signature: if the signature is pure, then the function is assumed to be pure. So if a loop body calls a function f that actually writes to disk, this error will show up.

W95Psp avatar May 19 '25 10:05 W95Psp