 +      3 -> IdSig <$> get bh
 +      4 -> FixSig <$> get bh
 +      5 -> InlineSig <$> get bh <*> get bh
-+      -- 6 = MinimalSig, 7 = SCCFunSig, 8 = CompleteMatchSig
-+      -- not supported yet
-+      _ -> panic "Binary Sig.get: unknown tag"
++      6 -> SpecSig <$> get bh <*> get bh <*> get bh
++      7 -> SpecInstSig <$> get bh <*> get bh
++      8 -> SCCFunSig <$> get bh <*> get bh <*> get bh
++      9 -> CompleteMatchSig <$> get bh <*> get bh <*> get bh
++      10 -> MinimalSig <$> get bh <*> get bh
++      _ -> getPanic "Sig"
 +
 +instance Binary (FixitySig GhcSe) where
 +  put_ bh s = case s of
-+    FixitySig a b -> putByte bh 0 >> put_ bh a >> put_ bh b
-+  get bh = do
-+    tag <- getByte bh
-+    case tag of
-+      0 -> FixitySig <$> get bh <*> get bh
-+      _ -> panic "Binary FixitySig.get: unknown tag"
-+
++    FixitySig a b -> put_ bh a >> put_ bh b
++  get bh = FixitySig <$> get bh <*> get bh
 +
 +instance Binary (HsBindLR GhcSe GhcSe) where
 +  put_ bh b = case b of

+
+import BasicTypes
+import Binary
+import GhcPrelude
+import HsBinds
+import HsDecls

+import PlaceHolder
+import RdrName
+import SeName
+import SrcLoc
+import TcEvidence (HsWrapper(WpHole))
+
+putPanic :: String -> String -> a
+putPanic tyName conName =
+  panic ("Binary " ++ tyName ++ ".put: " ++ conName ++ " not supported")
+
+getPanic :: String -> a
+getPanic tyName =
+  panic ("Binary " ++ tyName ++ ".get: unknown (or unsupported) tag")
+
+-- * Binary instances
+
+instance Binary (HsExpr GhcSe) where
+  put_ bh e = case e of
+    HsVar a ->
+      putByte bh 0 >> put_ bh a
+    HsUnboundVar a ->
+      putByte bh 1 >> put_ bh a
+    HsRecFld a ->
+      putByte bh 2 >> put_ bh a
+    HsOverLabel a b ->
+      putByte bh 3 >> put_ bh a >> put_ bh b
+    HsIPVar a ->
+      putByte bh 4 >> put_ bh a
+    HsOverLit a ->
+      putByte bh 5 >> put_ bh a
+    HsLit a ->
+      putByte bh 6 >> put_ bh a
+    HsLam a ->
+      putByte bh 7 >> put_ bh a
+    HsLamCase a ->
+      putByte bh 8 >> put_ bh a
+    HsApp a b ->
+      putByte bh 9 >> put_ bh a >> put_ bh b
+    HsAppType a b ->
+      putByte bh 10 >> put_ bh a >> put_ bh b
+    OpApp a b c d ->
+      putByte bh 11 >> put_ bh a >> put_ bh b >> put_ bh c
+                    >> put_ bh d
+    NegApp a b ->
+      putByte bh 12 >> put_ bh a >> put_ bh b
+    HsPar a ->
+      putByte bh 13 >> put_ bh a
+    SectionL a b ->
+      putByte bh 14 >> put_ bh a >> put_ bh b
+    SectionR a b ->
+      putByte bh 15 >> put_ bh a >> put_ bh b
+    ExplicitTuple a b ->
+      putByte bh 16 >> put_ bh a >> put_ bh b
+    ExplicitSum a b c d ->
+      putByte bh 17 >> put_ bh a >> put_ bh b >> put_ bh c
+                    >> put_ bh d
+    HsCase a b ->
+      putByte bh 18 >> put_ bh a >> put_ bh b
+    HsIf a b c d ->
+      putByte bh 19 >> put_ bh a >> put_ bh b >> put_ bh c
+                    >> put_ bh d
+    HsMultiIf a b ->
+      putByte bh 20 >> put_ bh a >> put_ bh b
+    HsLet a b ->
+      putByte bh 21 >> put_ bh a >> put_ bh b
+    HsDo a b c ->
+      putByte bh 22 >> put_ bh a >> put_ bh b >> put_ bh c
+    ExplicitList a b c ->
+      putByte bh 23 >> put_ bh a >> put_ bh b >> put_ bh c
+    RecordCon a _b _c d ->
+      putByte bh 24 >> put_ bh a >> put_ bh d
+    RecordUpd a b c d e f ->
+      putByte bh 25 >> put_ bh a >> put_ bh b >> put_ bh c
+                    >> put_ bh d >> put_ bh e >> put_ bh f
+    ExprWithTySig a b ->
+      putByte bh 26 >> put_ bh a >> put_ bh b
+    ArithSeq _a b c ->
+      putByte bh 27 >> put_ bh b >> put_ bh c
+    EWildPat ->
+      putByte bh 28
+    EAsPat a b ->
+      putByte bh 29 >> put_ bh a >> put_ bh b
+    EViewPat a b ->
+      putByte bh 30 >> put_ bh a >> put_ bh b
+    ELazyPat a ->
+      putByte bh 31 >> put_ bh a
+    HsStatic a b ->
+      putByte bh 32 >> put_ bh a >> put_ bh b
+    HsProc a b ->
+      putByte bh 33 >> put_ bh a >> put_ bh b
+    HsBinTick a b c ->
+      putByte bh 34 >> put_ bh a >> put_ bh b >> put_ bh c
+    HsTickPragma a b c d ->
+      putByte bh 35 >> put_ bh a >> put_ bh b >> put_ bh c
+                    >> put_ bh d
+    HsSpliceE a ->
+      putByte bh 36 >> put_ bh a
+    HsSCC a b c ->
+      putByte bh 37 >> put_ bh a >> put_ bh b >> put_ bh c
+    HsCoreAnn a b c ->
+      putByte bh 38 >> put_ bh a >> put_ bh b >> put_ bh c
+    HsBracket a ->
+      putByte bh 39 >> put_ bh a
+    HsConLikeOut {} -> putPanic "HsExpr" "HsConLikeOut"
+    HsAppTypeOut {} -> putPanic "HsExpr" "HsAppTypeOut"
+    ExplicitPArr {} -> putPanic "HsExpr" "ExplicitPArr"
+    ExprWithTySigOut {} -> putPanic "HsExpr" "ExprWithTySigOut"
+    PArrSeq {} -> putPanic "HsExpr" "PArrSeq"
+    HsRnBracketOut {} -> putPanic "HsExpr" "HsRnBracketOut"
+    HsTcBracketOut {} -> putPanic "HsExpr" "HsTcBracketOut"
+    HsArrApp {} -> putPanic "HsExpr" "HsArrApp"
+    HsArrForm {} -> putPanic "HsExpr" "HsArrForm"
+    HsTick {} -> putPanic "HsExpr" "HsTick"
+    HsWrap {} -> putPanic "HsExpr" "HsWrap"
+  get bh = do
+    tag <- getByte bh
+    case tag of
+      0  -> HsVar <$> get bh
+      1  -> HsUnboundVar <$> get bh
+      2  -> HsRecFld <$> get bh
+      3  -> HsOverLabel <$> get bh <*> get bh
+      4  -> HsIPVar <$> get bh
+      5  -> HsOverLit <$> get bh
+      6  -> HsLit <$> get bh
+      7  -> HsLam <$> get bh
+      8  -> HsLamCase <$> get bh
+      9  -> HsApp <$> get bh <*> get bh
+      10 -> HsAppType <$> get bh <*> get bh
+      11 -> OpApp <$> get bh <*> get bh <*> get bh <*> get bh
+      12 -> NegApp <$> get bh <*> get bh
+      13 -> HsPar <$> get bh
+      14 -> SectionL <$> get bh <*> get bh
+      15 -> SectionR <$> get bh <*> get bh
+      16 -> ExplicitTuple <$> get bh <*> get bh
+      17 -> ExplicitSum <$> get bh <*> get bh <*> get bh <*> get bh
+      18 -> HsCase <$> get bh <*> get bh
+      19 -> HsIf <$> get bh <*> get bh <*> get bh <*> get bh
+      20 -> HsMultiIf <$> get bh <*> get bh
+      21 -> HsLet <$> get bh <*> get bh
+      22 -> HsDo <$> get bh <*> get bh <*> get bh
+      23 -> ExplicitList <$> get bh <*> get bh <*> get bh
+      24 -> RecordCon <$> get bh <*> pure PlaceHolder <*> pure noPostTcExpr
+                      <*> get bh
+      25 -> RecordUpd <$> get bh <*> get bh <*> get bh
+                      <*> get bh <*> get bh <*> get bh
+      26 -> ExprWithTySig <$> get bh <*> get bh
+      27 -> ArithSeq <$> pure noPostTcExpr <*> get bh <*> get bh
+      28 -> pure EWildPat
+      29 -> EAsPat <$> get bh <*> get bh
+      30 -> EViewPat <$> get bh <*> get bh
+      31 -> ELazyPat <$> get bh
+      32 -> HsStatic <$> get bh <*> get bh
+      33 -> HsProc <$> get bh <*> get bh
+      34 -> HsBinTick <$> get bh <*> get bh <*> get bh
+      35 -> HsTickPragma <$> get bh <*> get bh <*> get bh <*> get bh
+      36 -> HsSpliceE <$> get bh
+      37 -> HsSCC <$> get bh <*> get bh <*> get bh
+      38 -> HsCoreAnn <$> get bh <*> get bh <*> get bh
+      39 -> HsBracket <$> get bh
+      _  -> getPanic "HsExpr"
+
+instance Binary (HsBracket GhcSe) where
+  put_ bh b = case b of
+    ExpBr a ->
+      putByte bh 0 >> put_ bh a
+    PatBr a ->
+      putByte bh 1 >> put_ bh a
+    DecBrL a ->
+      putByte bh 2 >> put_ bh a
+    DecBrG a ->
+      putByte bh 3 >> put_ bh a
+    TypBr a ->
+      putByte bh 4 >> put_ bh a
+    VarBr a b ->
+      putByte bh 5 >> put_ bh a >> put_ bh b
+    TExpBr a ->
+      putByte bh 6 >> put_ bh a
+  get bh = do
+    tag <- getByte bh
+    case tag of
+      0 -> ExpBr <$> get bh
+      1 -> PatBr <$> get bh
+      2 -> DecBrL <$> get bh
+      3 -> DecBrG <$> get bh
+      4 -> TypBr <$> get bh
+      5 -> VarBr <$> get bh <*> get bh
+      6 -> TExpBr <$> get bh
+      _ -> getPanic "HsBracket"
+
+instance Binary SeName where
+  put_ bh (SeName n) = put_ bh n
+  get bh = mkSeName <$> get bh
+
+instance Binary RealSrcSpan where
+  put_ bh s =
+    put_ bh (srcSpanFile s) >>
+    put_ bh (srcSpanStartLine s) >>
+    put_ bh (srcSpanStartCol s) >>
+    put_ bh (srcSpanEndLine s) >>
+    put_ bh (srcSpanEndCol s)
+  get bh = do
+    file <- get bh
+    (startLine, startCol) <- (,) <$> get bh <*> get bh
+    (endLine, endCol) <- (,) <$> get bh <*> get bh
+    let startLoc = mkRealSrcLoc file startLine startCol
+        endLoc = mkRealSrcLoc file endLine endCol
+    return (mkRealSrcSpan startLoc endLoc)
+
+instance Binary UnboundVar where
+  put_ bh v = case v of
