[Git][ghc/ghc][master] Core Lint: distinguish let and letrec in locations

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Jul 18 10:38:32 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
00648e5d by Krzysztof Gogolewski at 2023-07-18T06:38:10-04:00
Core Lint: distinguish let and letrec in locations

Lint messages were saying "in the body of letrec" even for non-recursive
let.

I've also renamed BodyOfLetRec to BodyOfLet in stg, since there's no
separate letrec.

- - - - -


3 changed files:

- compiler/GHC/Core/Lint.hs
- compiler/GHC/Stg/Lint.hs
- testsuite/tests/corelint/T21115b.stderr


Changes:

=====================================
compiler/GHC/Core/Lint.hs
=====================================
@@ -565,9 +565,9 @@ lintRecBindings top_lvl pairs thing_inside
            ; lintLetBind top_lvl Recursive bndr' rhs rhs_ty
            ; return ue }
 
-lintLetBody :: [LintedId] -> CoreExpr -> LintM (LintedType, UsageEnv)
-lintLetBody bndrs body
-  = do { (body_ty, body_ue) <- addLoc (BodyOfLetRec bndrs) (lintCoreExpr body)
+lintLetBody :: LintLocInfo -> [LintedId] -> CoreExpr -> LintM (LintedType, UsageEnv)
+lintLetBody loc bndrs body
+  = do { (body_ty, body_ue) <- addLoc loc (lintCoreExpr body)
        ; mapM_ (lintJoinBndrType body_ty) bndrs
        ; return (body_ty, body_ue) }
 
@@ -900,7 +900,7 @@ lintCoreExpr (Let (NonRec tv (Type ty)) body)
                 -- Now extend the substitution so we
                 -- take advantage of it in the body
         ; extendTvSubstL tv ty'        $
-          addLoc (BodyOfLetRec [tv]) $
+          addLoc (BodyOfLet tv) $
           lintCoreExpr body } }
 
 lintCoreExpr (Let (NonRec bndr rhs) body)
@@ -912,7 +912,7 @@ lintCoreExpr (Let (NonRec bndr rhs) body)
          -- Now lint the binder
        ; lintBinder LetBind bndr $ \bndr' ->
     do { lintLetBind NotTopLevel NonRecursive bndr' rhs rhs_ty
-       ; addAliasUE bndr let_ue (lintLetBody [bndr'] body) } }
+       ; addAliasUE bndr let_ue (lintLetBody (BodyOfLet bndr') [bndr'] body) } }
 
   | otherwise
   = failWithL (mkLetErr bndr rhs)       -- Not quite accurate
@@ -932,7 +932,7 @@ lintCoreExpr e@(Let (Rec pairs) body)
           -- See Note [Multiplicity of let binders] in Var
         ; ((body_type, body_ue), ues) <-
             lintRecBindings NotTopLevel pairs $ \ bndrs' ->
-            lintLetBody bndrs' body
+            lintLetBody (BodyOfLetRec bndrs') bndrs' body
         ; return (body_type, body_ue  `addUE` scaleUE ManyTy (foldr1 addUE ues)) }
   where
     bndrs = map fst pairs
@@ -3177,7 +3177,8 @@ data LintLocInfo
   | LambdaBodyOf Id     -- The lambda-binder
   | RuleOf Id           -- Rules attached to a binder
   | UnfoldingOf Id      -- Unfolding of a binder
-  | BodyOfLetRec [Id]   -- One of the binders
+  | BodyOfLet Id        -- The let-bound variable
+  | BodyOfLetRec [Id]   -- The binders of the let
   | CaseAlt CoreAlt     -- Case alternative
   | CasePat CoreAlt     -- The *pattern* of the case alternative
   | CaseTy CoreExpr     -- The type field of a case expression
@@ -3467,11 +3468,14 @@ dumpLoc (RuleOf b)
 dumpLoc (UnfoldingOf b)
   = (getSrcLoc b, text "In the unfolding of" <+> pp_binder b)
 
+dumpLoc (BodyOfLet b)
+  = (noSrcLoc, text "In the body of a let with binder" <+> pp_binder b)
+
 dumpLoc (BodyOfLetRec [])
   = (noSrcLoc, text "In body of a letrec with no binders")
 
 dumpLoc (BodyOfLetRec bs@(b:_))
-  = ( getSrcLoc b, text "In the body of letrec with binders" <+> pp_binders bs)
+  = ( getSrcLoc b, text "In the body of a letrec with binders" <+> pp_binders bs)
 
 dumpLoc (AnExpr e)
   = (noSrcLoc, text "In the expression:" <+> ppr e)


=====================================
compiler/GHC/Stg/Lint.hs
=====================================
@@ -283,13 +283,13 @@ lintStgExpr (StgOpApp _ args _) =
 
 lintStgExpr (StgLet _ binds body) = do
     binders <- lintStgBinds NotTopLevel binds
-    addLoc (BodyOfLetRec binders) $
+    addLoc (BodyOfLet binders) $
       addInScopeVars binders $
         lintStgExpr body
 
 lintStgExpr (StgLetNoEscape _ binds body) = do
     binders <- lintStgBinds NotTopLevel binds
-    addLoc (BodyOfLetRec binders) $
+    addLoc (BodyOfLet binders) $
       addInScopeVars binders $
         lintStgExpr body
 
@@ -446,7 +446,7 @@ data LintFlags = LintFlags { lf_unarised :: !Bool
 data LintLocInfo
   = RhsOf Id            -- The variable bound
   | LambdaBodyOf [Id]   -- The lambda-binder
-  | BodyOfLetRec [Id]   -- One of the binders
+  | BodyOfLet [Id]      -- The binders of the let
 
 dumpLoc :: LintLocInfo -> (SrcSpan, SDoc)
 dumpLoc (RhsOf v) =
@@ -454,8 +454,8 @@ dumpLoc (RhsOf v) =
 dumpLoc (LambdaBodyOf bs) =
   (srcLocSpan (getSrcLoc (head bs)), text " [in body of lambda with binders " <> pp_binders bs <> char ']' )
 
-dumpLoc (BodyOfLetRec bs) =
-  (srcLocSpan (getSrcLoc (head bs)), text " [in body of letrec with binders " <> pp_binders bs <> char ']' )
+dumpLoc (BodyOfLet bs) =
+  (srcLocSpan (getSrcLoc (head bs)), text " [in body of let with binders " <> pp_binders bs <> char ']' )
 
 
 pp_binders :: [Id] -> SDoc


=====================================
testsuite/tests/corelint/T21115b.stderr
=====================================
@@ -4,8 +4,8 @@ T21115b.hs:9:1: warning:
     scrut ds
     In the RHS of foo :: Double# -> Int#
     In the body of lambda with binder ds :: Double#
-    In the body of letrec with binders fail :: (# #) -> Int#
-    In the body of letrec with binders fail :: (# #) -> Int#
+    In the body of a let with binder fail :: (# #) -> Int#
+    In the body of a let with binder fail :: (# #) -> Int#
     Substitution: <InScope = {}
                    IdSubst   = []
                    TvSubst   = []



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/00648e5dadc3294126c8f0494929a5a4bfd49302
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/20230718/75f7cfbb/attachment-0001.html>


More information about the ghc-commits mailing list