summaryrefslogtreecommitdiff
path: root/compiler/GHC/Core/UsageEnv.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC/Core/UsageEnv.hs')
-rw-r--r--compiler/GHC/Core/UsageEnv.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/GHC/Core/UsageEnv.hs b/compiler/GHC/Core/UsageEnv.hs
index 3f28178fe2..4b40ac67c6 100644
--- a/compiler/GHC/Core/UsageEnv.hs
+++ b/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