[Git][ghc/ghc][wip/hie-file-improvements] 2 commits: hie files: Dump the type table when dumping with -ddump-hie
Hannes Siebenhandl pushed to branch wip/hie-file-improvements at Glasgow Haskell Compiler / GHC Commits: 84281173 by Zubin Duggal at 2026-08-05T09:57:18+02:00 hie files: Dump the type table when dumping with -ddump-hie - - - - - 8d9e95e9 by Zubin Duggal at 2026-08-05T09:57:18+02:00 hie files: Take evidence for quantified constraints into account when saving evidence terms to the hie ast Fixes #25709 - - - - - 6 changed files: - compiler/GHC/Driver/Main/Passes.hs - compiler/GHC/Iface/Ext/Types.hs - testsuite/tests/hiefile/should_compile/T24493.stderr - + testsuite/tests/hiefile/should_run/T25709.hs - + testsuite/tests/hiefile/should_run/T25709.stdout - testsuite/tests/hiefile/should_run/all.T Changes: ===================================== compiler/GHC/Driver/Main/Passes.hs ===================================== @@ -92,7 +92,7 @@ import GHC.Iface.Make import GHC.Iface.Recomp import GHC.Iface.Tidy import GHC.Iface.Ext.Ast ( mkHieFile ) -import GHC.Iface.Ext.Types ( getAsts, hie_asts, hie_module ) +import GHC.Iface.Ext.Types ( getAsts, hie_asts, hie_module, hie_types ) import GHC.Iface.Ext.Binary ( readHieFile, writeHieFile , hie_file_result) import GHC.Iface.Ext.Debug ( diffFile, validateScopes ) @@ -167,7 +167,7 @@ import GHC.Data.StringBuffer import GHC.Data.Maybe import qualified GHC.Data.Strict as Strict - +import qualified Data.Array as A import Data.List ( nub, isPrefixOf, partition ) import qualified Data.List.NonEmpty as NE import Control.Monad @@ -332,7 +332,10 @@ extract_renamed_stuff mod_summary tc_result = do hieFile <- mkHieFile mod_summary tc_result (fromJust rn_info) let out_file = ml_hie_file $ ms_location mod_summary liftIO $ writeHieFile out_file hieFile - liftIO $ putDumpFileMaybe logger Opt_D_dump_hie "HIE AST" FormatHaskell (ppr $ hie_asts hieFile) + let hie_doc = + ppr (hie_asts hieFile) + $+$ ppr (A.assocs $ hie_types hieFile) + liftIO $ putDumpFileMaybe logger Opt_D_dump_hie "HIE AST" FormatHaskell hie_doc -- Validate HIE files when (gopt Opt_ValidateHie dflags) $ do ===================================== compiler/GHC/Iface/Ext/Types.hs ===================================== @@ -159,6 +159,18 @@ data HieType a | HCoercionTy deriving (Functor, Foldable, Traversable, Eq) +instance Outputable a => Outputable (HieType a) where + ppr (HTyVarTy name) = ppr name + ppr (HAppTy fun arg) = parens $ ppr fun <+> ppr arg + ppr (HTyConApp tc args) = parens $ ppr tc <+> ppr args + ppr (HForAllTy ((name, ty), flag) body) = + text "forall" <+> ppr flag <+> ppr name O.<> text ":" <+> ppr ty O.<> text "." <+> ppr body + ppr (HFunTy mult arg res) = parens $ ppr arg <+> arrow <+> ppr res <+> ppr mult + ppr (HQualTy ctxt ty) = parens $ ppr ctxt <+> text "=>" <+> ppr ty + ppr (HLitTy lit) = ppr lit + ppr (HCastTy ty) = text "cast" <+> ppr ty + ppr HCoercionTy = text "<coercion>" + type HieTypeFlat = HieType TypeIndex -- | Roughly isomorphic to the original core 'Type'. @@ -222,6 +234,10 @@ instance Binary (HieArgs TypeIndex) where put_ bh (HieArgs xs) = put_ bh xs get bh = HieArgs <$> get bh +instance Outputable a => Outputable (HieArgs a) where + ppr (HieArgs args) = braces $ hsep $ punctuate comma $ map pprArg args + where pprArg (vis, ty) = (if vis then id else parens) (ppr ty) + -- A HiePath is just a lexical FastString. We use a lexical FastString to avoid -- non-determinism when printing or storing HieASTs which are sorted by their ===================================== testsuite/tests/hiefile/should_compile/T24493.stderr ===================================== @@ -1,3 +1,4 @@ + ==================== HIE AST ==================== File: T24493.hs Node@T24493.hs:(1,8)-(3,8): Source: From source @@ -25,9 +26,10 @@ Node@T24493.hs:(1,8)-(3,8): Source: From source Node@T24493.hs:3:6-8: Source: From source {(annotations: {(HsLit, HsExpr)}), (types: [0]), (identifier info: {})} - + +[(0, (GHC.Internal.Base.String {}))] Got valid scopes -Got no roundtrip errors \ No newline at end of file +Got no roundtrip errors ===================================== testsuite/tests/hiefile/should_run/T25709.hs ===================================== @@ -0,0 +1,40 @@ +{-# LANGUAGE QuantifiedConstraints#-} +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE AllowAmbiguousTypes #-} +module Main where + +import TestUtils +import qualified Data.Map.Strict as M +import qualified Data.Set as S +import Data.Either +import Data.Maybe +import Data.Bifunctor (first) +import GHC.Plugins (moduleNameString, nameStableString, nameOccName, occNameString, isDerivedOccName) +import GHC.Iface.Ext.Types + + +import Data.Typeable + +data Some c where + Some :: c a => a -> Some c + +extractSome :: (Typeable a, forall x. c x => Typeable x) => Some c -> Maybe a +extractSome (Some a) = cast a + +f :: (forall x. Ord x => Eq [x]) => () +f = () +{-# NOINLINE f #-} + +g :: () +g = f + +useQC :: forall c a. (c a, forall x. c x => Show x) => a -> String +useQC x = show x + +points :: [(Int,Int)] +points = [(22,26),(29, 5), (32, 13)] + +main = do + (df, hf) <- readTestHie "T25709.hie" + let refmap = generateReferencesMap $ getAsts $ hie_asts hf + traverse (explainEv df hf refmap) points ===================================== testsuite/tests/hiefile/should_run/T25709.stdout ===================================== @@ -0,0 +1,110 @@ +========================== +At point (22,26), we found: +========================== +┌ +│ $dTypeable at T25709.hs:22:14-19, of type: Typeable a +│ is an evidence variable bound by a let, depending on: [$dTypeable] +│ with scope: LocalScope T25709.hs:22:14-29 +│ +│ Defined at <no location info> +└ +| +`- ┌ + │ $dTypeable at T25709.hs:22:1-29, of type: Typeable a + │ is an evidence variable bound by a HsWrapper + │ with scope: LocalScope T25709.hs:22:1-29 + │ bound at: T25709.hs:22:1-29 + │ Defined at <no location info> + └ + +┌ +│ $dTypeable at T25709.hs:22:14-19, of type: Typeable a +│ is an evidence variable bound by a let, depending on: [df, irred] +│ with scope: LocalScope T25709.hs:22:14-29 +│ +│ Defined at <no location info> +└ +| ++- ┌ +| │ df at T25709.hs:22:1-29, of type: forall x. c x => Typeable x +| │ is an evidence variable bound by a HsWrapper +| │ with scope: LocalScope T25709.hs:22:1-29 +| │ bound at: T25709.hs:22:1-29 +| │ Defined at <no location info> +| └ +| +`- ┌ + │ irred at T25709.hs:22:14-19, of type: c a + │ is an evidence variable bound by a let, depending on: [irred] + │ with scope: LocalScope T25709.hs:22:14-29 + │ + │ Defined at <no location info> + └ + | + `- ┌ + │ irred at T25709.hs:22:14-19, of type: c a + │ is an evidence variable bound by a pattern + │ with scope: LocalScope T25709.hs:22:14-29 + │ + │ Defined at <no location info> + └ + +========================== +At point (29,5), we found: +========================== +┌ +│ df at T25709.hs:1:1, of type: forall x. Ord x => Eq [x] +│ is an evidence variable bound by a let, depending on: [$p1Ord, +│ $fEqList] +│ with scope: ModuleScope +│ +│ Defined at <no location info> +└ +| ++- ┌ +| │ $p1Ord at T25709.hs:1:1, of type: forall a. Ord a => Eq a +| │ is a usage of an external evidence variable +| │ Defined in `GHC.Internal.Classes' +| └ +| +`- ┌ + │ $fEqList at T25709.hs:1:1, of type: forall a. Eq a => Eq [a] + │ is a usage of an external evidence variable + │ Defined in `GHC.Internal.Classes' + └ + +========================== +At point (32,13), we found: +========================== +┌ +│ $dShow at T25709.hs:32:1-16, of type: Show a +│ is an evidence variable bound by a let, depending on: [df, irred] +│ with scope: LocalScope T25709.hs:32:1-16 +│ bound at: T25709.hs:32:1-16 +│ Defined at <no location info> +└ +| ++- ┌ +| │ df at T25709.hs:32:1-16, of type: forall x. c x => Show x +| │ is an evidence variable bound by a HsWrapper +| │ with scope: LocalScope T25709.hs:32:1-16 +| │ bound at: T25709.hs:32:1-16 +| │ Defined at <no location info> +| └ +| +`- ┌ + │ irred at T25709.hs:32:1-16, of type: c a + │ is an evidence variable bound by a let, depending on: [irred] + │ with scope: LocalScope T25709.hs:32:1-16 + │ bound at: T25709.hs:32:1-16 + │ Defined at <no location info> + └ + | + `- ┌ + │ irred at T25709.hs:32:1-16, of type: c a + │ is an evidence variable bound by a HsWrapper + │ with scope: LocalScope T25709.hs:32:1-16 + │ bound at: T25709.hs:32:1-16 + │ Defined at <no location info> + └ + ===================================== testsuite/tests/hiefile/should_run/all.T ===================================== @@ -8,4 +8,5 @@ test('HieVdq', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUti test('T23540', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) test('T23120', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) test('T24544', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) -test('HieGadtConSigs', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) \ No newline at end of file +test('HieGadtConSigs', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) +test('T25709', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9d32d5479bcf272021b24068330201b... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9d32d5479bcf272021b24068330201b... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Hannes Siebenhandl (@fendor)