[Git][ghc/ghc][wip/usage-env] linear types: Don't add external names to the usage env

Krzysztof Gogolewski (@monoidal) gitlab at gitlab.haskell.org
Thu Apr 27 10:36:43 UTC 2023



Krzysztof Gogolewski pushed to branch wip/usage-env at Glasgow Haskell Compiler / GHC


Commits:
04ed536d by Krzysztof Gogolewski at 2023-04-27T12:36:11+02:00
linear types: Don't add external names to the usage env

This has no observable effect, but avoids storing useless data.

- - - - -


3 changed files:

- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/UsageEnv.hs
- compiler/GHC/Tc/Gen/Head.hs


Changes:

=====================================
compiler/GHC/Core/Lint.hs
=====================================
@@ -3210,7 +3210,7 @@ varCallSiteUsage :: Id -> LintM UsageEnv
 varCallSiteUsage id =
   do m <- getUEAliases
      return $ case lookupNameEnv m (getName id) of
-         Nothing    -> unitUE id OneTy
+         Nothing    -> singleUsageUE id
          Just id_ue -> id_ue
 
 ensureEqTys :: LintedType -> LintedType -> SDoc -> LintM ()


=====================================
compiler/GHC/Core/UsageEnv.hs
=====================================
@@ -10,13 +10,14 @@ module GHC.Core.UsageEnv
   , scaleUsage
   , supUE
   , supUEs
-  , unitUE
+  , singleUsageUE
   , zeroUE
   ) where
 
 import Data.Foldable
 import GHC.Prelude
 import GHC.Core.Multiplicity
+import GHC.Types.Var
 import GHC.Types.Name
 import GHC.Types.Name.Env
 import GHC.Utils.Outputable
@@ -54,8 +55,13 @@ scaleUsage x     (MUsage y) = MUsage $ mkMultMul x y
 -- For now, we use extra multiplicity Bottom for empty case.
 data UsageEnv = UsageEnv !(NameEnv Mult) Bool
 
-unitUE :: NamedThing n => n -> Mult -> UsageEnv
-unitUE x w = UsageEnv (unitNameEnv (getName x) w) False
+-- | Record a single usage of an Id, i.e. {n: 1}
+-- Exception: We do not record external names (both GlobalIds and top-level LocalIds)
+-- because they're not relevant to linearity checking.
+singleUsageUE :: Id -> UsageEnv
+singleUsageUE x | isExternalName n = zeroUE
+                | otherwise = UsageEnv (unitNameEnv n OneTy) False
+  where n = getName x
 
 zeroUE, bottomUE :: UsageEnv
 zeroUE = UsageEnv emptyNameEnv False


=====================================
compiler/GHC/Tc/Gen/Head.hs
=====================================
@@ -48,7 +48,7 @@ import GHC.Tc.Utils.Concrete ( hasFixedRuntimeRep_syntactic )
 import GHC.Tc.Utils.Instantiate
 import GHC.Tc.Instance.Family ( tcLookupDataFamInst )
 import GHC.Core.FamInstEnv    ( FamInstEnvs )
-import GHC.Core.UsageEnv      ( unitUE )
+import GHC.Core.UsageEnv      ( singleUsageUE )
 import GHC.Tc.Errors.Types
 import GHC.Tc.Solver          ( InferMode(..), simplifyInfer )
 import GHC.Tc.Utils.Env
@@ -1091,7 +1091,7 @@ tc_infer_id id_name
 check_local_id :: Id -> TcM ()
 check_local_id id
   = do { checkThLocalId id
-       ; tcEmitBindingUsage $ unitUE (idName id) OneTy }
+       ; tcEmitBindingUsage $ singleUsageUE id }
 
 check_naughty :: OccName -> TcId -> TcM ()
 check_naughty lbl id



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/04ed536d9dd91a77725ca2ae4485f6146f7d9a8c
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/20230427/f781ba88/attachment-0001.html>


More information about the ghc-commits mailing list