-tcCoreArg (UfVarArg v) = tcVar v `thenTc` \ v' -> returnTc (VarArg v')
-tcCoreArg (UfTyArg ty) = tcHsType ty `thenTc` \ ty' -> returnTc (TyArg ty')
-tcCoreArg (UfLitArg lit) = returnTc (LitArg lit)
-tcCoreArg (UfUsageArg u) = error "tcCoreArg: usage"
-
-tcCoreAlts (UfAlgAlts alts deflt)
- = mapTc tc_alt alts `thenTc` \ alts' ->
- tcCoreDefault deflt `thenTc` \ deflt' ->
- returnTc (AlgAlts alts' deflt')
- where
- tc_alt (con, bndrs, rhs) = tcVar con `thenTc` \ con' ->
- tcCoreValBndrs bndrs $ \ bndrs' ->
- tcCoreExpr rhs `thenTc` \ rhs' ->
- returnTc (con', bndrs', rhs')
-
-tcCoreAlts (UfPrimAlts alts deflt)
- = mapTc tc_alt alts `thenTc` \ alts' ->
- tcCoreDefault deflt `thenTc` \ deflt' ->
- returnTc (PrimAlts alts' deflt')
- where
- tc_alt (lit, rhs) = tcCoreExpr rhs `thenTc` \ rhs' ->
- returnTc (lit, rhs')
-
-tcCoreDefault UfNoDefault = returnTc NoDefault
-tcCoreDefault (UfBindDefault bndr rhs) = tcCoreValBndr bndr $ \ bndr' ->
- tcCoreExpr rhs `thenTc` \ rhs' ->
- returnTc (BindDefault bndr' rhs')
-
-tcCoercion (UfIn n) = tcVar n `thenTc` \ n' -> returnTc (CoerceIn n')
-tcCoercion (UfOut n) = tcVar n `thenTc` \ n' -> returnTc (CoerceOut n')
-
-tcCorePrim (UfOtherOp op)
- = tcVar op `thenTc` \ op_id ->
- case isPrimitiveId_maybe op_id of
- Just prim_op -> returnTc prim_op
- Nothing -> pprPanic "tcCorePrim" (ppr PprDebug op_id)
-
-tcCorePrim (UfCCallOp str casm gc arg_tys res_ty)
- = mapTc tcHsType arg_tys `thenTc` \ arg_tys' ->
- tcHsType res_ty `thenTc` \ res_ty' ->
- returnTc (CCallOp str casm gc arg_tys' res_ty')
+tcCoreAlt scrut_ty (UfDefault, names, rhs)
+ = ASSERT( null names )
+ tcCoreExpr rhs `thenTc` \ rhs' ->
+ returnTc (DEFAULT, [], rhs')
+
+tcCoreAlt scrut_ty (UfLitAlt lit, names, rhs)
+ = ASSERT( null names )
+ tcCoreExpr rhs `thenTc` \ rhs' ->
+ returnTc (LitAlt lit, [], rhs')
+
+tcCoreAlt scrut_ty (UfLitLitAlt str ty, names, rhs)
+ = ASSERT( null names )
+ tcCoreExpr rhs `thenTc` \ rhs' ->
+ tcIfaceType ty `thenTc` \ ty' ->
+ returnTc (LitAlt (MachLitLit str ty'), [], rhs')
+
+-- A case alternative is made quite a bit more complicated
+-- by the fact that we omit type annotations because we can
+-- work them out. True enough, but its not that easy!
+tcCoreAlt scrut_ty alt@(con, names, rhs)
+ = tcConAlt con `thenTc` \ con ->
+ let
+ (main_tyvars, _, ex_tyvars, _, _, _) = dataConSig con
+
+ (_, inst_tys, cons) = case splitAlgTyConApp_maybe scrut_ty of
+ Just stuff -> stuff
+ Nothing -> pprPanic "tcCoreAlt" (ppr alt)
+ ex_tyvars' = [mkTyVar name (tyVarKind tv) | (name,tv) <- names `zip` ex_tyvars]
+ ex_tys' = mkTyVarTys ex_tyvars'
+ arg_tys = dataConArgTys con (inst_tys ++ ex_tys')
+ id_names = drop (length ex_tyvars) names
+ arg_ids
+#ifdef DEBUG
+ | length id_names /= length arg_tys
+ = pprPanic "tcCoreAlts" (ppr (con, names, rhs) $$
+ (ppr main_tyvars <+> ppr ex_tyvars) $$
+ ppr arg_tys)
+ | otherwise
+#endif
+ = zipWithEqual "tcCoreAlts" mkLocalId id_names arg_tys
+ in
+ ASSERT( con `elem` cons && length inst_tys == length main_tyvars )
+ tcExtendTyVarEnv ex_tyvars' $
+ tcExtendGlobalValEnv arg_ids $
+ tcCoreExpr rhs `thenTc` \ rhs' ->
+ returnTc (DataAlt con, ex_tyvars' ++ arg_ids, rhs')
+
+
+tcConAlt :: UfConAlt Name -> TcM DataCon
+tcConAlt (UfTupleAlt (HsTupCon _ boxity arity))
+ = returnTc (tupleCon boxity arity)
+
+tcConAlt (UfDataAlt con_name)
+ = tcVar con_name `thenTc` \ con_id ->
+ returnTc (case isDataConWrapId_maybe con_id of
+ Just con -> con
+ Nothing -> pprPanic "tcCoreAlt" (ppr con_id))
+\end{code}
+
+\begin{code}
+ifaceSigCtxt sig_name
+ = hsep [ptext SLIT("In an interface-file signature for"), ppr sig_name]