insertGate :: (Gate g, Ord g, Monad m) => Ref -> g -> BuilderT g m ()
insertGate !ref !gate = do
    refs <- use $ bs_circ . circ_refmap
    when (IM.member (getRef ref) refs) $
        error ("redefinition of ref " ++ show ref)
    bs_circ . circ_refmap . at (getRef ref) ?= gate
    bs_dedup . at gate ?= ref
    mapM_ bumpRefCount (gateArgs gate)
insertGate :: (Gate g, Ord g, Monad m) => Ref -> g -> BuilderT g m ()
insertGate !ref !gate = do
    refs <- use $ bs_circ . circ_refmap
    when (IM.member (getRef ref) refs) $
        error ("redefinition of ref " ++ show ref)
    bs_circ . circ_refmap . at (getRef ref) ?= gate
    bs_dedup . at gate ?= ref
    mapM_ bumpRefCount (gateArgs gate)
insertGate !ref !gate = do
    refs <- use $ bs_circ . circ_refmap
    when (IM.member (getRef ref) refs) $
        error ("redefinition of ref " ++ show ref)
    bs_circ . circ_refmap . at (getRef ref) ?= gate
    bs_dedup . at gate ?= ref
    mapM_ bumpRefCount (gateArgs gate)