Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 9c3a0937 by Matthew Pickering at 2025-07-22T21:14:52-04:00 template haskell: use a precise condition when implicitly lifting Implicit lifting corrects a level error by replacing references to `x` with `$(lift x)`, therefore you can use a level `n` binding at level `n + 1`, if it can be lifted. Therefore, we now have a precise check that the use level is 1 more than the bind level. Before this bug was not observable as you only had 0 and 1 contexts but it is easily evident when using explicit level imports. Fixes #26088 - - - - - 5 changed files: - compiler/GHC/Rename/Splice.hs - + testsuite/tests/splice-imports/T26088.stderr - + testsuite/tests/splice-imports/T26088A.hs - + testsuite/tests/splice-imports/T26088B.hs - testsuite/tests/splice-imports/all.T Changes: ===================================== compiler/GHC/Rename/Splice.hs ===================================== @@ -35,6 +35,7 @@ import GHC.Rename.Pat ( rnPat ) import GHC.Types.Error import GHC.Types.Basic ( TopLevelFlag, isTopLevel, maxPrec ) import GHC.Types.SourceText ( SourceText(..) ) +import GHC.Types.ThLevelIndex import GHC.Utils.Outputable import GHC.Unit.Module import GHC.Types.SrcLoc @@ -1001,7 +1002,7 @@ checkCrossLevelLifting dflags reason top_lvl is_local allow_lifting bind_lvl use , xopt LangExt.ImplicitStagePersistence dflags = when (isExternalName name) (keepAlive name) >> return (HsVar noExtField name_var) -- 4. Name is in a bracket, and lifting is allowed | Brack _ pending <- use_lvl - , any (use_lvl_idx >=) (Set.toList bind_lvl) + , any (\bind_idx -> use_lvl_idx == incThLevelIndex bind_idx) (Set.toList bind_lvl) , allow_lifting = do let mgre = case reason of ===================================== testsuite/tests/splice-imports/T26088.stderr ===================================== @@ -0,0 +1,6 @@ +T26088A.hs:8:8: error: [GHC-28914] + • Level error: ‘a’ is bound at level -1 but used at level 1 + • Available from the imports: + • imported from ‘T26088B’ at -1 at T26088A.hs:4:1-21 + • In the Template Haskell quotation: [| a |] + ===================================== testsuite/tests/splice-imports/T26088A.hs ===================================== @@ -0,0 +1,8 @@ +{-# LANGUAGE ExplicitLevelImports, TemplateHaskell #-} +module T26088A where + +import splice T26088B +import Language.Haskell.TH.Syntax + +x :: Q Exp +x = [| a |] ===================================== testsuite/tests/splice-imports/T26088B.hs ===================================== @@ -0,0 +1,3 @@ +module T26088B where + +a = () ===================================== testsuite/tests/splice-imports/all.T ===================================== @@ -47,3 +47,4 @@ test('SI35', ['-package ghc']) test('SI36', [extra_files(["SI36_A.hs", "SI36_B1.hs", "SI36_B2.hs", "SI36_B3.hs", "SI36_C1.hs", "SI36_C2.hs", "SI36_C3.hs"])], multimod_compile_fail, ['SI36', '-v0']) test('T26087', [], multimod_compile_fail, ['T26087A', '']) +test('T26088', [], multimod_compile_fail, ['T26088A', '-v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9c3a09370fc8f047cb475d80c9edfde3... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9c3a09370fc8f047cb475d80c9edfde3... You're receiving this email because of your account on gitlab.haskell.org.