[Git][ghc/ghc][wip/T18389] tcConArgs: Only typecheck each record type once

Ryan Scott gitlab at gitlab.haskell.org
Mon Oct 26 11:18:24 UTC 2020



Ryan Scott pushed to branch wip/T18389 at Glasgow Haskell Compiler / GHC


Commits:
b55cf285 by Ryan Scott at 2020-10-26T07:18:00-04:00
tcConArgs: Only typecheck each record type once

- - - - -


1 changed file:

- compiler/GHC/Tc/TyCl.hs


Changes:

=====================================
compiler/GHC/Tc/TyCl.hs
=====================================
@@ -3413,18 +3413,22 @@ tcConArgs (InfixCon bty1 bty2)
   = do { bty1' <- tcConArg bty1
        ; bty2' <- tcConArg bty2
        ; return [bty1', bty2'] }
-tcConArgs (RecCon fields)
-  = mapM tcConArg btys
+tcConArgs (RecCon (L _ fields))
+  = concatMapM tc_field fields
   where
     -- We need to ensure that each distinct field name gets its own type.
     -- For example, if we have:
     --
     --   data T = MkT { a,b,c :: Int }
     --
-    -- Then we should return /three/ Int types, not just one!
-    btys = [ hsLinear (cd_fld_type f)
-           | L _ f <- unLoc fields
-           , _fld_name <- cd_fld_names f ]
+    -- Then we should return /three/ Int types, not just one! At the same
+    -- time, we don't want to kind-check Int three separate times, as that
+    -- would be redundant. Therefore, we kind-check Int once and 'replicate'
+    -- it so that we return three occurrences of it.
+    tc_field :: LConDeclField GhcRn -> TcM [(Scaled TcType, HsSrcBang)]
+    tc_field (L _ f) = do
+      bty' <- tcConArg $ hsLinear $ cd_fld_type f
+      pure $ replicate (length (cd_fld_names f)) bty'
 
 tcConArg :: HsScaled GhcRn (LHsType GhcRn) -> TcM (Scaled TcType, HsSrcBang)
 tcConArg (HsScaled w bty)



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b55cf28534eaef254c16da050f5e63dc3ff6d7af
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/20201026/4446b385/attachment-0001.html>


More information about the ghc-commits mailing list