Allow implicit discard of qubits at the end of main
Qubits leftover at the end of main are being discarded anyway, users shouldn't have to do it manually just to satisfy the type checker. This should significantly reduce the need for discard calls - in programs that don't use ancillas.
Note that we still need to generate Hugr discards which is not entirely trivial when considering nested structs, arrays, and lists.
Also, would this be a special case for the qubit type only?
Note that we still need to generate Hugr discards which is not entirely trivial when considering nested structs, arrays, and lists.
Also, would this be a special case for the qubit type only?
I think it should apply to all linear types. An executable should be allowed to exit without having to clean up after itself.
But this makes me wonder if we should change the type checker rather than guppy (so it would need to understand the concept of a main program).
-
If we are doing all linear types, should we have a
__drop__/__leak__implementation that gets called automatically in these cases? (For qubit it would be anoop). -
Seyon mentioned elsewhere to add a
@guppy.entrypointmarker that would trigger this behaviour.
- If we are doing all linear types, should we have a
__drop__/__leak__implementation that gets called automatically in these cases? (For qubit it would be anoop).
Seems a good idea -- for example, an output stream would want to flush itself when dropped. Not sure if we have any non-trivial examples in guppy at the moment?
- Seyon mentioned elsewhere to add a
@guppy.entrypointmarker that would trigger this behaviour.
Yes, better than relying on a function name.