[Git][ghc/ghc][wip/T24359] More improvements

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Wed Nov 20 17:45:29 UTC 2024



Simon Peyton Jones pushed to branch wip/T24359 at Glasgow Haskell Compiler / GHC


Commits:
9d743a53 by Simon Peyton Jones at 2024-11-20T17:45:04+00:00
More improvements

- - - - -


3 changed files:

- compiler/GHC/Core/InstEnv.hs
- compiler/GHC/HsToCore/Binds.hs
- compiler/GHC/Tc/TyCl/Instance.hs


Changes:

=====================================
compiler/GHC/Core/InstEnv.hs
=====================================
@@ -927,11 +927,8 @@ Here are the moving parts:
 * That info is recorded in the `cir_is_coherent` field of `OneInst`, and thence
   transferred to the `ep_is_coherent` field of the `EvBind` for the dictionary.
 
-* `GHC.HsToCore.Binds.dsHsWrapper` desugars the evidence application (f d) into
-  (nospec f d) if `d` is incoherent. It has to do a dependency analysis to
-  determine transitive dependencies, but we need to do that anyway.
-  See Note [Desugaring non-canonical evidence] in GHC.HsToCore.Binds.
-
+* In the desugarer we exploit this info:
+  see Note [Desugaring non-canonical evidence] in GHC.HsToCore.Expr.
   See also Note [nospecId magic] in GHC.Types.Id.Make.
 -}
 


=====================================
compiler/GHC/HsToCore/Binds.hs
=====================================
@@ -826,7 +826,7 @@ dsSpec mb_poly_rhs (SpecPrag poly_id spec_co spec_inl)
                    spec_bndrs (\_ poly_rhs -> core_app poly_rhs)
                    spec_inl
 
-dsSpec mb_poly_rhs (SpecPragE { spe_poly_id = poly_id
+dsSpec mb_poly_rhs (SpecPragE { spe_poly_id      = poly_id
                               , spe_tv_bndrs     = tv_bndrs
                               , spe_id_bndrs     = id_bndrs
                               , spe_lhs_ev_bndrs = lhs_evs
@@ -843,7 +843,9 @@ dsSpec mb_poly_rhs (SpecPragE { spe_poly_id = poly_id
   = dsTcEvBinds lhs_binds $ \ ds_lhs_binds ->
     dsTcEvBinds rhs_binds $ \ ds_rhs_binds ->
     do { dflags  <- getDynFlags
-       ; ds_call <- dsLExpr the_call
+       ; ds_call <- zapUnspecables $
+                      -- zapUnspecables: see Note [Desugaring RULE left hand sides]
+                    dsLExpr the_call
        ; let simpl_opts    = initSimpleOpts dflags
              core_call     = mkLets ds_lhs_binds      $
                              drop_cast                $


=====================================
compiler/GHC/Tc/TyCl/Instance.hs
=====================================
@@ -2002,7 +2002,17 @@ tcMethodBody skol_info clas tyvars dfun_ev_vars inst_tys
                 tcMethodBodyHelp sig_fn sel_id local_meth_id (L bind_loc lm_bind)
 
        ; global_meth_id <- addInlinePrags global_meth_id prags
-       ; spec_prags     <- tcSpecPrags global_meth_id prags
+       ; spec_prags     <- tcExtendIdEnv1 (idName sel_id) global_meth_id $
+                           -- tcExtendIdEnv1: tricky point: a SPECIALISE pragma in prags
+                           -- mentions sel_name but the pragma is really for global_meth_id.
+                           -- So we bind sel_name to global_meth_id, just in the pragmas.
+                           -- Example:
+                           --    instance C [a] where
+                           --       op :: forall b. Ord b => b -> a -> a
+                           --       {-# SPECIALISE b @Int #-}
+                           -- The speclalisation is for the `op` for this instance decl, not
+                           -- for the gloabal selector-id, of course.
+                           tcSpecPrags global_meth_id prags
 
         ; let specs  = mk_meth_spec_prags global_meth_id spec_inst_prags spec_prags
               export = ABE { abe_poly  = global_meth_id



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9d743a53bb51b4e0e5f94873048236b5b41894f6

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9d743a53bb51b4e0e5f94873048236b5b41894f6
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241120/ba64c8bc/attachment-0001.html>


More information about the ghc-commits mailing list