X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FbasicTypes%2FMkId.lhs;h=46099590c67cdcf73aab965b456c0f98b96e9be8;hb=247fd64109002ed88c27bc5d6cfea6a71ee48cfa;hp=c621e5b8f5c3dd21bdc236dfa0b2a51dca0cbea7;hpb=cd829ab3b15e6a7c30cedde2ca59fb5617aec32c;p=ghc-hetmet.git diff --git a/compiler/basicTypes/MkId.lhs b/compiler/basicTypes/MkId.lhs index c621e5b..4609959 100644 --- a/compiler/basicTypes/MkId.lhs +++ b/compiler/basicTypes/MkId.lhs @@ -47,7 +47,10 @@ import TysPrim ( openAlphaTyVars, alphaTyVar, alphaTy, import TysWiredIn ( charTy, mkListTy ) import PrelRules ( primOpRules ) import Type ( TyThing(..), mkForAllTy, tyVarsOfTypes, newTyConInstRhs, coreEqType, + PredType(..), mkTopTvSubst, substTyVar ) +import TcGadt ( gadtRefine, refineType, emptyRefinement ) +import HsBinds ( ExprCoFn(..), isIdCoercion ) import Coercion ( mkSymCoercion, mkUnsafeCoercion, splitNewTypeRepCo_maybe, isEqPred ) import TcType ( Type, ThetaType, mkDictTy, mkPredTys, mkPredTy, @@ -56,16 +59,17 @@ import TcType ( Type, ThetaType, mkDictTy, mkPredTys, mkPredTy, isUnLiftedType, mkForAllTys, mkTyVarTy, tyVarsOfType, tcSplitFunTys, tcSplitForAllTys, dataConsStupidTheta ) -import CoreUtils ( exprType ) +import CoreUtils ( exprType, dataConInstPat ) import CoreUnfold ( mkTopUnfolding, mkCompulsoryUnfolding ) import Literal ( nullAddrLit, mkStringLit ) import TyCon ( TyCon, isNewTyCon, tyConDataCons, FieldLabel, tyConStupidTheta, isProductTyCon, isDataTyCon, isRecursiveTyCon, newTyConCo, tyConArity ) import Class ( Class, classTyCon, classSelIds ) -import Var ( Id, TyVar, Var, setIdType, mkWildCoVar ) +import Var ( Id, TyVar, Var, setIdType, mkCoVar, mkWildCoVar ) import VarSet ( isEmptyVarSet, subVarSet, varSetElems ) -import Name ( mkFCallName, mkWiredInName, Name, BuiltInSyntax(..) ) +import Name ( mkFCallName, mkWiredInName, Name, BuiltInSyntax(..), + mkSysTvName ) import OccName ( mkOccNameFS, varName ) import PrimOp ( PrimOp, primOpSig, primOpOcc, primOpTag ) import ForeignCall ( ForeignCall ) @@ -468,13 +472,8 @@ mkRecordSelId tycon field_label stupid_dict_tys = mkPredTys (dataConsStupidTheta data_cons_w_field) n_stupid_dicts = length stupid_dict_tys - (pre_field_tyvars,pre_field_theta,field_tau) = tcSplitSigmaTy field_ty - -- tcSplitSigmaTy puts tyvars with EqPred kinds in with the theta, but - -- this is not what we want here, so we need to split out the EqPreds - -- as new wild tyvars - field_tyvars = pre_field_tyvars ++ eq_vars - eq_vars = map (mkWildCoVar . mkPredTy) - (filter isEqPred pre_field_theta) + (field_tyvars,pre_field_theta,field_tau) = tcSplitSigmaTy field_ty + field_theta = filter (not . isEqPred) pre_field_theta field_dict_tys = mkPredTys field_theta n_field_dict_tys = length field_dict_tys @@ -554,25 +553,43 @@ mkRecordSelId tycon field_label mk_alt data_con = -- In the non-vanilla case, the pattern must bind type variables and -- the context stuff; hence the arg_prefix binding below - pprTrace "mkReboxingAlt" (ppr data_con <+> ppr (arg_prefix ++ arg_ids)) $ mkReboxingAlt uniqs data_con (arg_prefix ++ arg_ids) (Var the_arg_id) + mkReboxingAlt uniqs data_con (arg_prefix ++ arg_ids) rhs where + -- TODO: this is *not* right; Orig vs Rep tys (arg_prefix, arg_ids) | isVanillaDataCon data_con -- Instantiate from commmon base = ([], mkTemplateLocalsNum arg_base (dataConInstOrigArgTys data_con res_tys)) | otherwise -- The case pattern binds type variables, which are used -- in the types of the arguments of the pattern - = (dc_tvs ++ mkTemplateLocalsNum arg_base (mkPredTys dc_theta), - mkTemplateLocalsNum arg_base' dc_arg_tys) + = (ex_tvs ++ co_tvs ++ dict_vs, field_vs) - (pre_dc_tvs, pre_dc_theta, dc_arg_tys) = dataConSig data_con - -- again we need to pull the EqPreds out of dc_theta, into dc_tvs - dc_eqvars = map (mkWildCoVar . mkPredTy) (filter isEqPred pre_dc_theta) - dc_tvs = drop (length (dataConUnivTyVars data_con)) pre_dc_tvs ++ dc_eqvars + (ex_tvs, co_tvs, arg_vs) = dataConInstPat uniqs' data_con res_tys + (dict_vs, field_vs) = splitAt (length dc_theta) arg_vs + + (_, pre_dc_theta, dc_arg_tys) = dataConSig data_con dc_theta = filter (not . isEqPred) pre_dc_theta + arg_base' = arg_base + length dc_theta unpack_base = arg_base' + length dc_arg_tys - uniqs = map mkBuiltinUnique [unpack_base..] + + uniq_list = map mkBuiltinUnique [unpack_base..] + + Succeeded refinement = gadtRefine emptyRefinement ex_tvs co_tvs + (co_fn, _) = refineType refinement (idType the_arg_id) + + rhs = perform_co co_fn (Var the_arg_id) + + perform_co (ExprCoFn co) expr = Cast expr co + perform_co id_co expr = ASSERT(isIdCoercion id_co) expr + + -- split the uniq_list into two + uniqs = takeHalf uniq_list + uniqs' = takeHalf (drop 1 uniq_list) + + takeHalf [] = [] + takeHalf (h:_:t) = h:(takeHalf t) + takeHalf (h:t) = [h] the_arg_id = assoc "mkRecordSelId:mk_alt" (field_lbls `zip` arg_ids) field_label field_lbls = dataConFieldLabels data_con