+ tc_boot_sig (TypeSig (L _ name) ty)
+ = do { sigma_ty <- tcHsSigType (FunSigCtxt name) ty
+ ; return (mkVanillaGlobal name sigma_ty vanillaIdInfo) }
+ -- Notice that we make GlobalIds, not LocalIds
+tcHsBootSigs groups = pprPanic "tcHsBootSigs" (ppr groups)
+
+badBootDeclErr :: Message
+badBootDeclErr = ptext SLIT("Illegal declarations in an hs-boot file")
+
+------------------------
+tcLocalBinds :: HsLocalBinds Name -> TcM thing
+ -> TcM (HsLocalBinds TcId, thing)
+
+tcLocalBinds EmptyLocalBinds thing_inside
+ = do { thing <- thing_inside
+ ; return (EmptyLocalBinds, thing) }
+
+tcLocalBinds (HsValBinds binds) thing_inside
+ = do { (binds', thing) <- tcValBinds NotTopLevel binds thing_inside
+ ; return (HsValBinds binds', thing) }
+
+tcLocalBinds (HsIPBinds (IPBinds ip_binds _)) thing_inside
+ = do { (thing, lie) <- getLIE thing_inside
+ ; (avail_ips, ip_binds') <- mapAndUnzipM (wrapLocSndM tc_ip_bind) ip_binds
+
+ -- If the binding binds ?x = E, we must now
+ -- discharge any ?x constraints in expr_lie
+ ; dict_binds <- tcSimplifyIPs avail_ips lie
+ ; return (HsIPBinds (IPBinds ip_binds' dict_binds), thing) }
+ where
+ -- I wonder if we should do these one at at time
+ -- Consider ?x = 4
+ -- ?y = ?x + 1
+ tc_ip_bind (IPBind ip expr)
+ = newTyFlexiVarTy argTypeKind `thenM` \ ty ->
+ newIPDict (IPBindOrigin ip) ip ty `thenM` \ (ip', ip_inst) ->
+ tcCheckRho expr ty `thenM` \ expr' ->
+ returnM (ip_inst, (IPBind ip' expr'))
+
+------------------------
+tcValBinds :: TopLevelFlag
+ -> HsValBinds Name -> TcM thing
+ -> TcM (HsValBinds TcId, thing)
+
+tcValBinds top_lvl (ValBindsIn binds sigs) thing_inside
+ = pprPanic "tcValBinds" (ppr binds)
+
+tcValBinds top_lvl (ValBindsOut binds sigs) thing_inside
+ = tcAddLetBoundTyVars binds $
+ -- BRING ANY SCOPED TYPE VARIABLES INTO SCOPE
+ -- Notice that they scope over
+ -- a) the type signatures in the binding group
+ -- b) the bindings in the group
+ -- c) the scope of the binding group (the "in" part)
+
+ do { -- Typecheck the signature
+ tc_ty_sigs <- recoverM (returnM []) (tcTySigs sigs)
+ ; let { prag_fn = mkPragFun sigs
+ ; sig_fn = lookupSig tc_ty_sigs
+ ; sig_ids = map sig_id tc_ty_sigs }
+
+ -- Extend the envt right away with all
+ -- the Ids declared with type signatures
+ ; (binds', thing) <- tcExtendIdEnv sig_ids $
+ tc_val_binds top_lvl sig_fn prag_fn
+ binds thing_inside
+
+ ; return (ValBindsOut binds' sigs, thing) }
+
+------------------------
+tc_val_binds :: TopLevelFlag -> TcSigFun -> TcPragFun
+ -> [(RecFlag, LHsBinds Name)] -> TcM thing
+ -> TcM ([(RecFlag, LHsBinds TcId)], thing)
+-- Typecheck a whole lot of value bindings,
+-- one strongly-connected component at a time
+
+tc_val_binds top_lvl sig_fn prag_fn [] thing_inside
+ = do { thing <- thing_inside
+ ; return ([], thing) }
+
+tc_val_binds top_lvl sig_fn prag_fn (group : groups) thing_inside
+ = do { (group', (groups', thing))
+ <- tc_group top_lvl sig_fn prag_fn group $
+ tc_val_binds top_lvl sig_fn prag_fn groups thing_inside
+ ; return (group' ++ groups', thing) }
+
+------------------------
+tc_group :: TopLevelFlag -> TcSigFun -> TcPragFun
+ -> (RecFlag, LHsBinds Name) -> TcM thing
+ -> TcM ([(RecFlag, LHsBinds TcId)], thing)
+
+-- Typecheck one strongly-connected component of the original program.
+-- We get a list of groups back, because there may
+-- be specialisations etc as well
+
+tc_group top_lvl sig_fn prag_fn (NonRecursive, binds) thing_inside
+ = -- A single non-recursive binding
+ -- We want to keep non-recursive things non-recursive
+ -- so that we desugar unlifted bindings correctly
+ do { (binds, thing) <- tcPolyBinds top_lvl NonRecursive NonRecursive
+ sig_fn prag_fn binds thing_inside
+ ; return ([(NonRecursive, b) | b <- binds], thing) }
+
+tc_group top_lvl sig_fn prag_fn (Recursive, binds) thing_inside
+ = -- A recursive strongly-connected component
+ -- To maximise polymorphism (with -fglasgow-exts), we do a new
+ -- strongly-connected component analysis, this time omitting
+ -- any references to variables with type signatures.
+ --
+ -- Then we bring into scope all the variables with type signatures
+ do { traceTc (text "tc_group rec" <+> pprLHsBinds binds)
+ ; gla_exts <- doptM Opt_GlasgowExts
+ ; (binds,thing) <- if gla_exts
+ then go new_sccs
+ else tc_binds Recursive binds thing_inside
+ ; return ([(Recursive, unionManyBags binds)], thing) }
+ -- Rec them all together
+ where
+ new_sccs :: [SCC (LHsBind Name)]
+ new_sccs = stronglyConnComp (mkEdges sig_fn binds)