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

Commits:

2 changed files:

Changes:

  • compiler/GHC/Rename/Splice.hs
    ... ... @@ -182,12 +182,12 @@ rnUntypedBracket e br_body
    182 182
            }
    
    183 183
     
    
    184 184
     rn_utbracket :: HsQuote GhcPs -> RnM (HsQuote GhcRn, FreeVars)
    
    185
    -rn_utbracket (VarBr _ flg rdr_name)
    
    186
    -  = do { name <- lookupOccRn (if flg then WL_Term else WL_Type) (unLoc rdr_name)
    
    185
    +rn_utbracket (VarBr _ is_value_name rdr_name)
    
    186
    +  = do { name <- lookupOccRn (if is_value_name then WL_Term else WL_Type) (unLoc rdr_name)
    
    187 187
            ; let res_name = L (l2l (locA rdr_name)) (WithUserRdr (unLoc rdr_name) name)
    
    188
    -       ; if flg then checkThLocalNameNoLift res_name else checkThLocalTyName name
    
    189
    -       ; check_namespace flg name
    
    190
    -       ; return (VarBr noExtField flg (noLocA name), unitFV name) }
    
    188
    +       ; if is_value_name then checkThLocalNameNoLift res_name else checkThLocalTyName name
    
    189
    +       ; check_namespace is_value_name name
    
    190
    +       ; return (VarBr noExtField is_value_name (noLocA name), unitFV name) }
    
    191 191
     
    
    192 192
     rn_utbracket (ExpBr _ e) = do { (e', fvs) <- rnLExpr e
    
    193 193
                                     ; return (ExpBr noExtField e', fvs) }
    
    ... ... @@ -919,8 +919,7 @@ checkThLocalTyName name
    919 919
             ; case mb_local_use of {
    
    920 920
                  Nothing -> return () ;  -- Not a locally-bound thing
    
    921 921
                  Just (top_lvl, bind_lvl, use_lvl) ->
    
    922
    -    do  { let use_lvl_idx = thLevelIndex use_lvl
    
    923
    -        -- We don't check the well levelledness of name here.
    
    922
    +    do  -- We don't check the well levelledness of name here.
    
    924 923
             -- this would break test for #20969
    
    925 924
             --
    
    926 925
             -- Consequently there is no check&restiction for top level splices.
    
    ... ... @@ -929,11 +928,11 @@ checkThLocalTyName name
    929 928
             -- Therefore checkCrossLevelLiftingTy shouldn't assume anything
    
    930 929
             -- about bind_lvl and use_lvl relation.
    
    931 930
             --
    
    932
    -        ; traceRn "checkThLocalTyName" (ppr name <+> ppr bind_lvl
    
    931
    +        { traceRn "checkThLocalTyName" (ppr name <+> ppr bind_lvl
    
    933 932
                                                      <+> ppr use_lvl
    
    934 933
                                                      <+> ppr use_lvl)
    
    935 934
             ; dflags <- getDynFlags
    
    936
    -        ; checkCrossLevelLiftingTy dflags top_lvl bind_lvl use_lvl use_lvl_idx name } } }
    
    935
    +        ; checkCrossLevelLiftingTy dflags top_lvl bind_lvl use_lvl name } } }
    
    937 936
     
    
    938 937
     -- | Check whether we are allowed to use a Name in this context (for TH purposes)
    
    939 938
     -- In the case of a level incorrect program, attempt to fix it by using
    
    ... ... @@ -947,15 +946,18 @@ checkThLocalNameWithLift = checkThLocalName True
    947 946
     checkThLocalNameNoLift :: LIdOccP GhcRn -> RnM ()
    
    948 947
     checkThLocalNameNoLift name = checkThLocalName False name >> return ()
    
    949 948
     
    
    950
    --- | Implemenation of the level checks
    
    949
    +-- | Implementation of the level checks
    
    951 950
     -- See Note [Template Haskell levels]
    
    952 951
     checkThLocalName :: Bool -> LIdOccP GhcRn -> RnM (HsExpr GhcRn)
    
    953 952
     checkThLocalName allow_lifting name_var
    
    954 953
       -- Exact and Orig names are not imported, so presumed available at all levels.
    
    954
    +  -- whenever the user uses exact names, e.g. say @'mkNameG_v' "" "Foo" "bar"@,
    
    955
    +  -- even though the 'mkNameG_v' here is essentially a quotation, we do not do
    
    956
    +  -- level checks as we assume that the user was trying to bypass the level checks
    
    955 957
       | isExact (userRdrName (unLoc name_var)) || isOrig (userRdrName (unLoc name_var))
    
    956 958
       = return (HsVar noExtField name_var)
    
    957
    -  | isUnboundName name   -- Do not report two errors for
    
    958
    -  = return (HsVar noExtField name_var)            --   $(not_in_scope args)
    
    959
    +  | isUnboundName name                  -- Do not report two errors for
    
    960
    +  = return (HsVar noExtField name_var)  --   $(not_in_scope args)
    
    959 961
       | isWiredInName name
    
    960 962
       = return (HsVar noExtField name_var)
    
    961 963
       | otherwise
    
    ... ... @@ -964,16 +966,15 @@ checkThLocalName allow_lifting name_var
    964 966
             ; case mb_local_use of {
    
    965 967
                  Nothing -> return (HsVar noExtField name_var) ;  -- Not a locally-bound thing
    
    966 968
                  Just (top_lvl, bind_lvl, use_lvl) ->
    
    967
    -    do  { let use_lvl_idx = thLevelIndex use_lvl
    
    968
    -        ; cur_mod <- extractModule <$> getGblEnv
    
    969
    +    do  { cur_mod <- extractModule <$> getGblEnv
    
    969 970
             ; let is_local
    
    970 971
                       | Just mod <- nameModule_maybe name = mod == cur_mod
    
    971 972
                       | otherwise = True
    
    972
    -        ; traceRn "checkThLocalName" (ppr name <+> ppr bind_lvl <+> ppr use_lvl <+> ppr use_lvl)
    
    973
    +        ; traceRn "checkThLocalName" (ppr name <+> ppr bind_lvl <+> ppr use_lvl)
    
    973 974
             ; dflags <- getDynFlags
    
    974 975
             ; env <- getGlobalRdrEnv
    
    975 976
             ; let mgre = lookupGRE_Name env name
    
    976
    -        ; checkCrossLevelLifting dflags (LevelCheckSplice name mgre) top_lvl is_local allow_lifting bind_lvl use_lvl use_lvl_idx name_var } } }
    
    977
    +        ; checkCrossLevelLifting dflags (LevelCheckSplice name mgre) top_lvl is_local allow_lifting bind_lvl use_lvl name_var } } }
    
    977 978
       where
    
    978 979
         name = getName name_var
    
    979 980
     
    
    ... ... @@ -981,14 +982,21 @@ checkThLocalName allow_lifting name_var
    981 982
     checkCrossLevelLifting :: DynFlags
    
    982 983
                            -> LevelCheckReason
    
    983 984
                            -> TopLevelFlag
    
    985
    +                       -- ^ whether or not the identifier is a top level identifier
    
    984 986
                            -> Bool
    
    987
    +                       -- ^ the name of the current module is the name of the module
    
    988
    +                       --   of the name that we're examining (if it exists)
    
    985 989
                            -> Bool
    
    990
    +                       -- ^ whether or not the compiler is allowed to insert
    
    991
    +                       -- 'lift' to fix a potential staging error
    
    986 992
                            -> Set.Set ThLevelIndex
    
    993
    +                       -- ^ the levels at which the identifier is bound
    
    987 994
                            -> ThLevel
    
    988
    -                       -> ThLevelIndex
    
    995
    +                       -- ^ the level that the identifier is being used at
    
    989 996
                            -> LIdOccP GhcRn
    
    997
    +                       -- ^ the identifier that is being checked
    
    990 998
                            -> TcM (HsExpr GhcRn)
    
    991
    -checkCrossLevelLifting dflags reason top_lvl is_local allow_lifting bind_lvl use_lvl use_lvl_idx name_var
    
    999
    +checkCrossLevelLifting dflags reason top_lvl_flg is_local allow_lifting bind_lvl use_lvl name_var
    
    992 1000
       -- 1. If name is in-scope, at the correct level.
    
    993 1001
       | use_lvl_idx `Set.member` bind_lvl = return (HsVar noExtField name_var)
    
    994 1002
       -- 2. Name is imported with -XImplicitStagePersistence
    
    ... ... @@ -996,11 +1004,12 @@ checkCrossLevelLifting dflags reason top_lvl is_local allow_lifting bind_lvl use
    996 1004
       , xopt LangExt.ImplicitStagePersistence dflags = return (HsVar noExtField name_var)
    
    997 1005
       -- 3. Name is top-level, with -XImplicitStagePersistence, and needs
    
    998 1006
       -- to be persisted into the future.
    
    999
    -  | isTopLevel top_lvl
    
    1007
    +  | isTopLevel top_lvl_flg
    
    1000 1008
       , is_local
    
    1001 1009
       , any (use_lvl_idx >=) (Set.toList bind_lvl)
    
    1002 1010
       , xopt LangExt.ImplicitStagePersistence dflags = when (isExternalName name) (keepAlive name) >> return (HsVar noExtField name_var)
    
    1003 1011
       -- 4. Name is in a bracket, and lifting is allowed
    
    1012
    +  --    We need to increment at most once because nested brackets are not allowed
    
    1004 1013
       | Brack _ pending <- use_lvl
    
    1005 1014
       , any (\bind_idx -> use_lvl_idx == incThLevelIndex bind_idx) (Set.toList bind_lvl)
    
    1006 1015
       , allow_lifting
    
    ... ... @@ -1020,10 +1029,11 @@ checkCrossLevelLifting dflags reason top_lvl is_local allow_lifting bind_lvl use
    1020 1029
       | otherwise = addErrTc (TcRnBadlyLevelled reason bind_lvl use_lvl_idx Nothing ErrorWithoutFlag ) >> return (HsVar noExtField name_var)
    
    1021 1030
       where
    
    1022 1031
         name = getName name_var
    
    1032
    +    use_lvl_idx = thLevelIndex use_lvl
    
    1023 1033
     
    
    1024
    -checkCrossLevelLiftingTy :: DynFlags -> TopLevelFlag -> Set.Set ThLevelIndex -> ThLevel -> ThLevelIndex -> Name -> TcM ()
    
    1025
    -checkCrossLevelLiftingTy dflags top_lvl bind_lvl _use_lvl use_lvl_idx name
    
    1026
    -  | isTopLevel top_lvl
    
    1034
    +checkCrossLevelLiftingTy :: DynFlags -> TopLevelFlag -> Set.Set ThLevelIndex -> ThLevel -> Name -> TcM ()
    
    1035
    +checkCrossLevelLiftingTy dflags top_lvl_flg bind_lvl use_lvl name
    
    1036
    +  | isTopLevel top_lvl_flg
    
    1027 1037
       , xopt LangExt.ImplicitStagePersistence dflags
    
    1028 1038
       = return ()
    
    1029 1039
     
    
    ... ... @@ -1038,6 +1048,8 @@ checkCrossLevelLiftingTy dflags top_lvl bind_lvl _use_lvl use_lvl_idx name
    1038 1048
     
    
    1039 1049
       | otherwise
    
    1040 1050
       = return ()
    
    1051
    +  where
    
    1052
    +  use_lvl_idx = thLevelIndex use_lvl
    
    1041 1053
     
    
    1042 1054
     {-
    
    1043 1055
     Note [Keeping things alive for Template Haskell]
    

  • compiler/GHC/Tc/Solver/Monad.hs
    ... ... @@ -1683,17 +1683,15 @@ which is defined at the top-level and therefore fails with an error that we have
    1683 1683
     the stage restriction.
    
    1684 1684
     
    
    1685 1685
     ```
    
    1686
    -Main.hs:12:14: error:
    
    1687
    -    • GHC stage restriction:
    
    1688
    -        instance for ‘Show
    
    1689
    -                        (T ())’ is used in a top-level splice, quasi-quote, or annotation,
    
    1690
    -        and must be imported, not defined locally
    
    1686
    +Main.hs:10:14: error: [GHC-28914]
    
    1687
    +    • Level error: instance for ‘Show (T ())’ is bound at level 0
    
    1688
    +      but used at level -1
    
    1691 1689
         • In the expression: foo [|| T () ||]
    
    1692
    -      In the Template Haskell splice $$(foo [|| T () ||])
    
    1690
    +      In the typed Template Haskell splice: $$(foo [|| T () ||])
    
    1693 1691
           In the expression: $$(foo [|| T () ||])
    
    1694 1692
        |
    
    1695
    -12 |   let x = $$(foo [|| T () ||])
    
    1696
    -   |
    
    1693
    +10 |   let x = $$(foo [|| T () ||])
    
    1694
    +   |              ^^^
    
    1697 1695
     ```
    
    1698 1696
     
    
    1699 1697
     Solving a `Typeable (T t1 ...tn)` constraint generates code that relies on