
Matthew Pickering pushed to branch wip/improve-implicit-lifting-error at Glasgow Haskell Compiler / GHC Commits: 51fc7dd4 by Matthew Pickering at 2025-06-12T16:46:33+01:00 Refactor the treatment of nested Template Haskell splices * The difference between a normal splice, a quasiquoter and implicit splice caused by lifting is stored in the AST after renaming. * Information that the renamer learns about splices is stored in the relevant splice extension points (XUntypedSpliceExpr, XQuasiQuote). * Normal splices and quasi quotes record the flavour of splice (exp/pat/dec etc) * Implicit lifting stores information about why the lift was attempted, so if it fails, that can be reported to the user. * After renaming, the decision taken to attempt to implicitly lift a variable is stored in the `XXUntypedSplice` extension field in the `HsImplicitLiftSplice` constructor. * Since all the information is stored in the AST, in `HsUntypedSplice`, the type of `PendingRnSplice` now just stores a `HsUntypedSplice`. * Error messages since the original program can be easily printed, this is noticeable in the case of implicit lifting. * The user-written syntax is directly type-checked. Before, some desugaring took place in the * Fixes .hie files to work better with nested splices (nested splices are not indexed) * The location of the quoter in a quasiquote is now located, so error messages will precisely point to it (and again, it is indexed by hie files) In the future, the typechecked AST should also retain information about the splices and the specific desugaring being left to the desugarer. Also, `runRnSplice` should call `tcUntypedSplice`, otherwise the typechecking logic is duplicated (see the `QQError` and `QQTopError` tests for a difference caused by this). - - - - - e180a7a9 by Matthew Pickering at 2025-06-13T10:07:11+01:00 Improve error messages when implicit lifting fails This patch concerns programs which automatically try to fix level errors by inserting `Lift`. For example: ``` foo x = [| x |] ~> foo x = [| $(lift x) |] ``` Before, there were two problems with the message. 1. (#26031), the location of the error was reported as the whole quotation. 2. (#26035), the message just mentions there is no Lift instance, but gives no indicate why the user program needed a Lift instance in the first place. This problem is especially bad when you disable `ImplicitStagePersistence`, so you just end up with a confusing "No instance for" message rather than an error message about levels This patch fixes both these issues. Firstly, `PendingRnSplice` differentiates between a user-written splice and an implicit lift. Then, the Lift instance is precisely requested with a specific origin in the typechecker. If the instance fails to be solved, the message is reported using the `TcRnBadlyLevelled` constructor (like a normal level error). Fixes #26031, #26035 - - - - - 79 changed files: - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Expr.hs-boot - compiler/GHC/Hs/Instances.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Lexer.x - compiler/GHC/Rename/Expr.hs - compiler/GHC/Rename/Splice.hs - compiler/GHC/Tc/Errors.hs - compiler/GHC/Tc/Errors/Ppr.hs - compiler/GHC/Tc/Errors/Types.hs - compiler/GHC/Tc/Gen/App.hs - compiler/GHC/Tc/Gen/Expr.hs - compiler/GHC/Tc/Gen/Head.hs - compiler/GHC/Tc/Gen/Splice.hs - compiler/GHC/Tc/Gen/Splice.hs-boot - compiler/GHC/Tc/Solver/Monad.hs - compiler/GHC/Tc/Types/ErrCtxt.hs - compiler/GHC/Tc/Types/Origin.hs - compiler/GHC/Tc/Types/TH.hs - compiler/GHC/Tc/Utils/Concrete.hs - compiler/GHC/Tc/Utils/TcMType.hs - compiler/GHC/ThToHs.hs - compiler/GHC/Types/Name/Reader.hs - compiler/GHC/Types/ThLevelIndex.hs - compiler/Language/Haskell/Syntax/Expr.hs - compiler/Language/Haskell/Syntax/Extension.hs - testsuite/tests/annotations/should_fail/annfail03.stderr - testsuite/tests/annotations/should_fail/annfail09.stderr - testsuite/tests/diagnostic-codes/codes.stdout - testsuite/tests/linear/should_fail/LinearTHFail.stderr - testsuite/tests/linters/notes.stdout - testsuite/tests/perf/compiler/hard_hole_fits.stderr - testsuite/tests/quasiquotation/T3953.stderr - testsuite/tests/quasiquotation/qq001/qq001.stderr - testsuite/tests/quasiquotation/qq002/qq002.stderr - testsuite/tests/quasiquotation/qq003/qq003.stderr - testsuite/tests/quasiquotation/qq004/qq004.stderr - + testsuite/tests/quotes/LiftErrMsg.hs - + testsuite/tests/quotes/LiftErrMsg.stderr - + testsuite/tests/quotes/LiftErrMsgDefer.hs - + testsuite/tests/quotes/LiftErrMsgDefer.stderr - + testsuite/tests/quotes/LiftErrMsgTyped.hs - + testsuite/tests/quotes/LiftErrMsgTyped.stderr - + testsuite/tests/quotes/QQError.hs - + testsuite/tests/quotes/QQError.stderr - testsuite/tests/quotes/T10384.stderr - testsuite/tests/quotes/TH_localname.stderr - testsuite/tests/quotes/all.T - testsuite/tests/splice-imports/SI03.stderr - testsuite/tests/splice-imports/SI05.stderr - testsuite/tests/splice-imports/SI16.stderr - testsuite/tests/splice-imports/SI18.stderr - testsuite/tests/splice-imports/SI20.stderr - testsuite/tests/splice-imports/SI25.stderr - testsuite/tests/splice-imports/SI28.stderr - testsuite/tests/splice-imports/SI31.stderr - + testsuite/tests/th/QQInQuote.hs - + testsuite/tests/th/QQTopError.hs - + testsuite/tests/th/QQTopError.stderr - testsuite/tests/th/T10598_TH.stderr - testsuite/tests/th/T14681.stderr - testsuite/tests/th/T16976z.stderr - testsuite/tests/th/T17804.stderr - testsuite/tests/th/T17820a.stderr - testsuite/tests/th/T17820b.stderr - testsuite/tests/th/T17820c.stderr - testsuite/tests/th/T17820d.stderr - testsuite/tests/th/T17820e.stderr - testsuite/tests/th/T23829_hasty.stderr - testsuite/tests/th/T23829_hasty_b.stderr - testsuite/tests/th/T5508.stderr - testsuite/tests/th/T5795.stderr - testsuite/tests/th/TH_Lift.stderr - testsuite/tests/th/all.T - testsuite/tests/th/overloaded/TH_overloaded_constraints_fail.stderr - utils/check-exact/ExactPrint.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c9263db3da9fe4af97028773aa2482b... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c9263db3da9fe4af97028773aa2482b... You're receiving this email because of your account on gitlab.haskell.org.