- -- "private_binders" is the list of binders in val_binds
- -- which don't appear in the local_global_prs list
- -- These only really show up in stuff produced from compiling
- -- class and instance declarations.
- -- We need to add suitable polymorphic versions of them to the
- -- local_global_prs.
- private_binders = binders `minusList` [local | (local,_) <- local_global_prs]
- binders = collectTypedBinders val_binds
- mk_poly_private_binder id = newSysLocalDs (snd (quantifyTy tyvars (idType id)))
-
- tyvar_tys = mkTyVarTys tyvars
-\end{code}
-
-
-%==============================================
-\subsubsection{AbsBind case: overloading}
-%==============================================
-
-If there is overloading we go for the general case.
-
-We want the global identifiers to be abstracted wrt all types and
-dictionaries; and the local identifiers wrt the non-overloaded types.
-That is, we try to avoid global scoping of type abstraction. Example
-
- f :: Eq a => a -> [(a,b)] -> b
- f = ...f...
-
-Here, f is fully polymorphic in b. So we generate
-
- f ab d = let ...dict defns...
- in
- letrec f' b = ...(f' b)...
- in f' b
-
-*Notice* that we don't clone type variables, and *do* make use of
-shadowing. It is possible to do cloning, but it makes the code quite
-a bit more complicated, and the simplifier will clone it all anyway.
-
-Why bother with this gloss? Because it makes it more likely that
-the defn of f' can get floated out, notably if f gets specialised
-to a particular type for a.
-
-\begin{code}
-dsBinds (AbsBinds all_tyvars dicts local_global_prs dict_binds val_binds)
- = -- If there is any non-overloaded polymorphism, make new locals with
- -- appropriate polymorphism
- (if null non_overloaded_tyvars
- then
- -- No non-overloaded polymorphism, so stay with current envt
- returnDs (id, [], [])
- else
- -- Some local, non-overloaded polymorphism
- cloneTyVarsDs non_overloaded_tyvars `thenDs` \ local_tyvars ->
-
- mapDs mk_binder binders `thenDs` \ new_binders ->
- let
- old_new_pairs = binders `zip` new_binders
- in
-
- listDs [ mkSatTyApp new non_ov_tyvar_tys `thenDs` \ app ->
- returnDs (old, app)
- | (old,new) <- old_new_pairs
- ] `thenDs` \ extra_env ->
- let
- local_binds = [NonRec old app | (old,app) <- extra_env, old `is_elem` locals]
- is_elem = isIn "dsBinds"
- in
- returnDs (lookupId old_new_pairs, extra_env, local_binds)
- )
- `thenDs` \ (binder_subst_fn, local_env, local_binds) ->
-
--- pprTrace "AbsBinds:all:" (ppAbove (ppr PprDebug local_binds) (ppr PprDebug local_env)) $
-
- extendEnvDs local_env (
-
- dsInstBinds non_overloaded_tyvars dict_binds `thenDs` \ (inst_bind_pairs, inst_env) ->
-
- extendEnvDs inst_env (
-
- dsBind non_overloaded_tyvars [] binder_subst_fn inst_bind_pairs val_binds
- )) `thenDs` \ core_binds ->
-
- let
- tuple_rhs = mkCoLetsAny core_binds (
- mkCoLetsAny local_binds (
- mkTupleExpr locals ))
+ error_string = "function " ++ showSDoc (ppr fun)
+
+dsMonoBinds auto_scc (PatMonoBind pat grhss locn) rest
+ = putSrcLocDs locn $
+ dsGuarded grhss `thenDs` \ body_expr ->
+ mkSelectorBinds pat body_expr `thenDs` \ sel_binds ->
+ mapDs (addAutoScc auto_scc) sel_binds `thenDs` \ sel_binds ->
+ returnDs (sel_binds ++ rest)
+
+ -- Common case: one exported variable
+ -- All non-recursive bindings come through this way
+dsMonoBinds auto_scc
+ (AbsBinds all_tyvars dicts exps@[(tyvars, global, local)] inlines binds) rest
+ = ASSERT( all (`elem` tyvars) all_tyvars )
+ dsMonoBinds (addSccs auto_scc exps) binds [] `thenDs` \ core_prs ->
+ let
+ -- Always treat the binds as recursive, because the typechecker
+ -- makes rather mixed-up dictionary bindings
+ core_binds = [Rec core_prs]
+ global' = (global, mkInline (idName global `elemNameSet` inlines) $
+ mkLams tyvars $ mkLams dicts $
+ mkDsLets core_binds (Var local))