-- XXX: marks everything in the circuit before this ref as Skip
saveRef :: (Gate g, Monad m) => Ref -> BuilderT g m ()
saveRef ref = do
    markSave ref
    c <- use bs_circ
    mapM_ (skipRec c) (gateArgs (getGate c ref))
  where
    skipRec c ref = do
        markSkip ref
        let g = getGate c ref
        when (gateIsGate g) $
            mapM_ (skipRec c) (gateArgs g)
saveRef :: (Gate g, Monad m) => Ref -> BuilderT g m ()
saveRef ref = do
    markSave ref
    c <- use bs_circ
    mapM_ (skipRec c) (gateArgs (getGate c ref))
  where
    skipRec c ref = do
        markSkip ref
        let g = getGate c ref
        when (gateIsGate g) $
            mapM_ (skipRec c) (gateArgs g)
saveRef ref = do
    markSave ref
    c <- use bs_circ
    mapM_ (skipRec c) (gateArgs (getGate c ref))
  where
    skipRec c ref = do
        markSkip ref
        let g = getGate c ref
        when (gateIsGate g) $
            mapM_ (skipRec c) (gateArgs g)