- tc_datacon btys
- = let
- arg_stricts = map get_strictness btys
- tys = map get_pty btys
- in
- mapTc tcHsTopType tys `thenTc` \ arg_tys ->
- mk_data_con arg_stricts arg_tys []
-
- tc_newcon ty mb_f
- = tcHsTopBoxedType ty `thenTc` \ arg_ty ->
- -- can't allow an unboxed type here, because we're effectively
- -- going to remove the constructor while coercing it to a boxed type.
- let
- field_label =
- case mb_f of
- Nothing -> []
- Just f -> [mkFieldLabel (getName f) tycon arg_ty (head allFieldLabelTags)]
- in
- mk_data_con [notMarkedStrict] [arg_ty] field_label
-
- tc_rec_con fields
- = checkTc (null ex_tyvars) (exRecConErr name) `thenTc_`
- mapTc tc_field fields `thenTc` \ field_label_infos_s ->
- let
- field_label_infos = concat field_label_infos_s
- arg_stricts = [strict | (_, _, strict) <- field_label_infos]
- arg_tys = [ty | (_, ty, _) <- field_label_infos]
-
- field_labels = [ mkFieldLabel (getName name) tycon ty tag
- | ((name, ty, _), tag) <- field_label_infos `zip` allFieldLabelTags ]
- in
- mk_data_con arg_stricts arg_tys field_labels
-
- tc_field (field_label_names, bty)
- = tcHsTopType (get_pty bty) `thenTc` \ field_ty ->
- returnTc [(name, field_ty, get_strictness bty) | name <- field_label_names]
-
- mk_data_con arg_stricts arg_tys fields
- = -- Now we've checked all the field types we must
- -- zonk the existential tyvars to finish the kind
- -- inference on their kinds, and commit them to being
- -- immutable type variables. (The top-level tyvars are
- -- already fixed, by the preceding kind-inference pass.)
- mapNF_Tc zonkTcTyVarToTyVar ex_tyvars `thenNF_Tc` \ ex_tyvars' ->
- zonkTcClassConstraints ex_theta `thenNF_Tc` \ ex_theta' ->
- let
- data_con = mkDataCon name arg_stricts fields
- tyvars (thinContext arg_tys ctxt)
- ex_tyvars' ex_theta'
- arg_tys
- tycon data_con_id data_con_wrap_id
- data_con_id = mkDataConId wkr_name data_con
- data_con_wrap_id = mkDataConWrapId data_con
- in
- returnNF_Tc data_con
+ kc_sig_type = case new_or_data of
+ DataType -> kcHsSigType
+ NewType -> kcHsLiftedSigType
+ -- Can't allow an unlifted type here, because we're effectively
+ -- going to remove the constructor while coercing it to a lifted type.
+
+
+tcConDecls :: NewOrData -> TyCon -> [TyVar] -> ThetaType
+ -> DataConDetails RenamedConDecl -> TcM (DataConDetails DataCon)
+
+tcConDecls new_or_data tycon tyvars ctxt con_decls
+ = case con_decls of
+ Unknown -> returnM Unknown
+ HasCons n -> returnM (HasCons n)
+ DataCons cs -> mappM tc_con_decl cs `thenM` \ data_cons ->
+ returnM (DataCons data_cons)
+ where
+ tc_con_decl (ConDecl name ex_tvs ex_ctxt details src_loc)
+ = addSrcLoc src_loc $
+ tcHsTyVars ex_tvs (kcConDetails new_or_data ex_ctxt details) $ \ ex_tyvars ->
+ tcHsTheta ex_ctxt `thenM` \ ex_theta ->
+ case details of
+ PrefixCon btys -> tc_datacon ex_tyvars ex_theta btys
+ InfixCon bty1 bty2 -> tc_datacon ex_tyvars ex_theta [bty1,bty2]
+ RecCon fields -> tc_rec_con ex_tyvars ex_theta fields
+ where
+
+ tc_datacon ex_tyvars ex_theta btys
+ = mappM tcHsType (map getBangType btys) `thenM` \ arg_tys ->
+ tcMkDataCon name
+ (map getBangStrictness btys)
+ [{- No field labels -}]
+ tyvars ctxt ex_tyvars ex_theta
+ arg_tys tycon
+
+ tc_rec_con ex_tyvars ex_theta fields
+ = checkTc (null ex_tyvars) (exRecConErr name) `thenM_`
+ mappM tc_field (fields `zip` allFieldLabelTags) `thenM` \ field_labels ->
+ let
+ arg_stricts = [getBangStrictness bty | (n, bty) <- fields]
+ arg_tys = map fieldLabelType field_labels
+ in
+ tcMkDataCon name arg_stricts field_labels
+ tyvars ctxt ex_tyvars ex_theta
+ arg_tys tycon
+
+ tc_field ((field_label_name, bty), tag)
+ = tcHsType (getBangType bty) `thenM` \ field_ty ->
+ returnM (mkFieldLabel field_label_name tycon field_ty tag)
+
+tcMkDataCon :: Name
+ -> [StrictnessMark] -> [FieldLabel]
+ -> [TyVar] -> ThetaType
+ -> [TyVar] -> ThetaType
+ -> [Type] -> TyCon
+ -> TcM DataCon
+-- A wrapper for DataCon.mkDataCon that
+-- a) makes the worker Id
+-- b) makes the wrapper Id if necessary, including
+-- allocating its unique (hence monadic)
+tcMkDataCon src_name arg_stricts fields
+ tyvars ctxt ex_tyvars ex_theta
+ arg_tys tycon
+ = lookupSysName src_name mkDataConWrapperOcc `thenM` \ wrap_name ->
+ lookupSysName src_name mkDataConWorkerOcc `thenM` \ work_name ->
+ -- This last one takes the name of the data constructor in the source
+ -- code, which (for Haskell source anyway) will be in the SrcDataName name
+ -- space, and makes it into a "real data constructor name"
+ let
+ data_con = mkDataCon src_name arg_stricts fields
+ tyvars (thinContext arg_tys ctxt)
+ ex_tyvars ex_theta
+ arg_tys tycon
+ data_con_work_id data_con_wrap_id
+ data_con_work_id = mkDataConWorkId work_name data_con
+ data_con_wrap_id = mkDataConWrapId wrap_name data_con
+ in
+ returnM data_con