Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
-
185df3e6
by Zubin Duggal at 2026-08-06T04:58:20-04:00
-
268b2fe3
by Zubin Duggal at 2026-08-06T04:58:20-04:00
-
8db1de70
by Simon Jakobi at 2026-08-06T04:58:21-04:00
-
528b0d8a
by Simon Peyton Jones at 2026-08-06T04:58:22-04:00
11 changed files:
- compiler/GHC/Core/Class.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Iface/Ext/Types.hs
- compiler/GHC/Rename/HsType.hs
- compiler/GHC/Types/Id/Make.hs
- testsuite/.gitignore
- testsuite/Makefile
- 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:
| ... | ... | @@ -84,9 +84,9 @@ data Class |
| 84 | 84 | -- Here fun-deps are [([a,b],[c]), ([a,c],[b])]
|
| 85 | 85 | type FunDep a = ([a],[a])
|
| 86 | 86 | |
| 87 | -type ClassOpItem = (Id, DefMethInfo)
|
|
| 88 | - -- Selector function; contains unfolding
|
|
| 89 | - -- Default-method info
|
|
| 87 | +type ClassOpItem = ( Id -- Dictionary selector function
|
|
| 88 | + -- See Note [Dictionary selectors]
|
|
| 89 | + , DefMethInfo) -- Default-method info
|
|
| 90 | 90 | |
| 91 | 91 | type DefMethInfo = Maybe (Name, DefMethSpec Type)
|
| 92 | 92 | -- Nothing No default method
|
| ... | ... | @@ -164,7 +164,19 @@ classMinimalDef :: Class -> ClassMinimalDef |
| 164 | 164 | classMinimalDef Class{ classBody = ConcreteClass{ cls_min_def = d } } = d
|
| 165 | 165 | classMinimalDef _ = mkTrue -- TODO: make sure this is the right direction
|
| 166 | 166 | |
| 167 | -{-
|
|
| 167 | +{- Note [Dictionary selectors]
|
|
| 168 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 169 | +Each `ClassOpItem` stores a dictionary selector `Id`:
|
|
| 170 | + |
|
| 171 | +* The type of the selector is always closed, and has form
|
|
| 172 | + forall a1..an. C a1 .. an => blah
|
|
| 173 | + where `a1..an` are the class variables, and
|
|
| 174 | + `blah` is the method type.
|
|
| 175 | + See GHC.Types.Id.Make.mkDictSelId, which constructs them.
|
|
| 176 | + |
|
| 177 | +* The selector has no unfolding, but one RULE.
|
|
| 178 | + See Note [ClassOp/DFun selection] in GHC.Tc.TyCl.Instance
|
|
| 179 | + |
|
| 168 | 180 | Note [Associated type defaults]
|
| 169 | 181 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 170 | 182 | The following is an example of associated type defaults:
|
| ... | ... | @@ -92,7 +92,7 @@ import GHC.Iface.Make |
| 92 | 92 | import GHC.Iface.Recomp
|
| 93 | 93 | import GHC.Iface.Tidy
|
| 94 | 94 | import GHC.Iface.Ext.Ast ( mkHieFile )
|
| 95 | -import GHC.Iface.Ext.Types ( getAsts, hie_asts, hie_module )
|
|
| 95 | +import GHC.Iface.Ext.Types ( getAsts, hie_asts, hie_module, hie_types )
|
|
| 96 | 96 | import GHC.Iface.Ext.Binary ( readHieFile, writeHieFile , hie_file_result)
|
| 97 | 97 | import GHC.Iface.Ext.Debug ( diffFile, validateScopes )
|
| 98 | 98 | |
| ... | ... | @@ -167,7 +167,7 @@ import GHC.Data.StringBuffer |
| 167 | 167 | import GHC.Data.Maybe
|
| 168 | 168 | import qualified GHC.Data.Strict as Strict
|
| 169 | 169 | |
| 170 | - |
|
| 170 | +import qualified Data.Array as A
|
|
| 171 | 171 | import Data.List ( nub, isPrefixOf, partition )
|
| 172 | 172 | import qualified Data.List.NonEmpty as NE
|
| 173 | 173 | import Control.Monad
|
| ... | ... | @@ -332,7 +332,10 @@ extract_renamed_stuff mod_summary tc_result = do |
| 332 | 332 | hieFile <- mkHieFile mod_summary tc_result (fromJust rn_info)
|
| 333 | 333 | let out_file = ml_hie_file $ ms_location mod_summary
|
| 334 | 334 | liftIO $ writeHieFile out_file hieFile
|
| 335 | - liftIO $ putDumpFileMaybe logger Opt_D_dump_hie "HIE AST" FormatHaskell (ppr $ hie_asts hieFile)
|
|
| 335 | + let hie_doc =
|
|
| 336 | + ppr (hie_asts hieFile)
|
|
| 337 | + $+$ ppr (A.assocs $ hie_types hieFile)
|
|
| 338 | + liftIO $ putDumpFileMaybe logger Opt_D_dump_hie "HIE AST" FormatHaskell hie_doc
|
|
| 336 | 339 | |
| 337 | 340 | -- Validate HIE files
|
| 338 | 341 | when (gopt Opt_ValidateHie dflags) $ do
|
| ... | ... | @@ -159,6 +159,18 @@ data HieType a |
| 159 | 159 | | HCoercionTy
|
| 160 | 160 | deriving (Functor, Foldable, Traversable, Eq)
|
| 161 | 161 | |
| 162 | +instance Outputable a => Outputable (HieType a) where
|
|
| 163 | + ppr (HTyVarTy name) = ppr name
|
|
| 164 | + ppr (HAppTy fun arg) = parens $ ppr fun <+> ppr arg
|
|
| 165 | + ppr (HTyConApp tc args) = parens $ ppr tc <+> ppr args
|
|
| 166 | + ppr (HForAllTy ((name, ty), flag) body) =
|
|
| 167 | + text "forall" <+> ppr flag <+> ppr name O.<> text ":" <+> ppr ty O.<> text "." <+> ppr body
|
|
| 168 | + ppr (HFunTy mult arg res) = parens $ ppr arg <+> arrow <+> ppr res <+> ppr mult
|
|
| 169 | + ppr (HQualTy ctxt ty) = parens $ ppr ctxt <+> text "=>" <+> ppr ty
|
|
| 170 | + ppr (HLitTy lit) = ppr lit
|
|
| 171 | + ppr (HCastTy ty) = text "cast" <+> ppr ty
|
|
| 172 | + ppr HCoercionTy = text "<coercion>"
|
|
| 173 | + |
|
| 162 | 174 | type HieTypeFlat = HieType TypeIndex
|
| 163 | 175 | |
| 164 | 176 | -- | Roughly isomorphic to the original core 'Type'.
|
| ... | ... | @@ -222,6 +234,10 @@ instance Binary (HieArgs TypeIndex) where |
| 222 | 234 | put_ bh (HieArgs xs) = put_ bh xs
|
| 223 | 235 | get bh = HieArgs <$> get bh
|
| 224 | 236 | |
| 237 | +instance Outputable a => Outputable (HieArgs a) where
|
|
| 238 | + ppr (HieArgs args) = braces $ hsep $ punctuate comma $ map pprArg args
|
|
| 239 | + where pprArg (vis, ty) = (if vis then id else parens) (ppr ty)
|
|
| 240 | + |
|
| 225 | 241 | |
| 226 | 242 | -- A HiePath is just a lexical FastString. We use a lexical FastString to avoid
|
| 227 | 243 | -- non-determinism when printing or storing HieASTs which are sorted by their
|
| ... | ... | @@ -1188,10 +1188,20 @@ bindHsOuterTyVarBndrs :: OutputableBndrFlag flag 'Renamed |
| 1188 | 1188 | -> RnM (a, FreeNames)
|
| 1189 | 1189 | bindHsOuterTyVarBndrs doc mb_cls implicit_vars outer_bndrs thing_inside =
|
| 1190 | 1190 | case outer_bndrs of
|
| 1191 | + |
|
| 1191 | 1192 | HsOuterImplicit{} ->
|
| 1193 | + -- Add an implicit `forall a1..an` at the top, where `a1..an`
|
|
| 1194 | + -- are not-otherwise-in-scope type variables.
|
|
| 1195 | + -- Used when there is no forall, or a /visible/ (forall a -> blah)
|
|
| 1196 | + -- See Note [forall-or-nothing rule] in Language.Haskell.Syntax.Type
|
|
| 1192 | 1197 | rnImplicitTvOccs mb_cls implicit_vars $ \implicit_vars' ->
|
| 1193 | 1198 | thing_inside $ HsOuterImplicit { hso_ximplicit = implicit_vars' }
|
| 1199 | + |
|
| 1194 | 1200 | HsOuterExplicit{hso_bndrs = exp_bndrs} ->
|
| 1201 | + -- The type already has an explicit, user-written, invisible forall,
|
|
| 1202 | + -- so do not add an implicit forall
|
|
| 1203 | + -- See Note [forall-or-nothing rule] in Language.Haskell.Syntax.Type
|
|
| 1204 | + --
|
|
| 1195 | 1205 | -- Note: If we pass mb_cls instead of Nothing below, bindLHsTyVarBndrs
|
| 1196 | 1206 | -- will use class variables for any names the user meant to bring in
|
| 1197 | 1207 | -- scope here. This is an explicit forall, so we want fresh names, not
|
| ... | ... | @@ -480,7 +480,7 @@ Therefore there is no loss of generality if we make all selectors unrestricted. |
| 480 | 480 | mkDictSelId :: Name -- Name of one of the *value* selectors
|
| 481 | 481 | -- (dictionary superclass or method)
|
| 482 | 482 | -> Class -> Id
|
| 483 | --- Important: see Note [ClassOp/DFun selection] in GHC.Tc.TyCl.Instance
|
|
| 483 | +-- See Note [Dictionary selectors]
|
|
| 484 | 484 | mkDictSelId name clas
|
| 485 | 485 | = mkGlobalId (ClassOpId clas terminating) name sel_ty info
|
| 486 | 486 | where
|
| ... | ... | @@ -72,7 +72,7 @@ mk/ghcconfig*_test___spaces_ghc*.exe.mk |
| 72 | 72 | # NOTE: to edit this section in Vim, add your ignore annotations some where
|
| 73 | 73 | # in the list, select the entire section and say ':sort u' to sort it.
|
| 74 | 74 | |
| 75 | -/mk/ghc-config
|
|
| 75 | +/ghc-config/ghc-config
|
|
| 76 | 76 | |
| 77 | 77 | /tests/ado/ado001
|
| 78 | 78 | /tests/annotations/should_compile/th/build_make
|
| ... | ... | @@ -46,5 +46,6 @@ clean distclean maintainer-clean: |
| 46 | 46 | $(RM) -f mk/*.o
|
| 47 | 47 | $(RM) -f mk/*.hi
|
| 48 | 48 | $(RM) -f mk/ghcconfig*.mk
|
| 49 | - $(RM) -f mk/ghc-config mk/ghc-config.exe
|
|
| 49 | + $(RM) -f ghc-config/ghc-config ghc-config/ghc-config.exe
|
|
| 50 | + $(RM) -f ghc-config/ghc-config.o ghc-config/ghc-config.hi
|
|
| 50 | 51 | $(RM) -f driver/*.pyc |
| 1 | + |
|
| 1 | 2 | ==================== HIE AST ====================
|
| 2 | 3 | File: T24493.hs
|
| 3 | 4 | Node@T24493.hs:(1,8)-(3,8): Source: From source
|
| ... | ... | @@ -25,9 +26,10 @@ Node@T24493.hs:(1,8)-(3,8): Source: From source |
| 25 | 26 | Node@T24493.hs:3:6-8: Source: From source
|
| 26 | 27 | {(annotations: {(HsLit, HsExpr)}), (types: [0]),
|
| 27 | 28 | (identifier info: {})}
|
| 28 | -
|
|
| 29 | +
|
|
| 29 | 30 | |
| 31 | +[(0, (GHC.Internal.Base.String {}))]
|
|
| 30 | 32 | |
| 31 | 33 | |
| 32 | 34 | Got valid scopes
|
| 33 | -Got no roundtrip errors |
|
| \ No newline at end of file | ||
| 35 | +Got no roundtrip errors |
| 1 | +{-# LANGUAGE QuantifiedConstraints#-}
|
|
| 2 | +{-# LANGUAGE UndecidableInstances #-}
|
|
| 3 | +{-# LANGUAGE AllowAmbiguousTypes #-}
|
|
| 4 | +module Main where
|
|
| 5 | + |
|
| 6 | +import TestUtils
|
|
| 7 | +import qualified Data.Map.Strict as M
|
|
| 8 | +import qualified Data.Set as S
|
|
| 9 | +import Data.Either
|
|
| 10 | +import Data.Maybe
|
|
| 11 | +import Data.Bifunctor (first)
|
|
| 12 | +import GHC.Plugins (moduleNameString, nameStableString, nameOccName, occNameString, isDerivedOccName)
|
|
| 13 | +import GHC.Iface.Ext.Types
|
|
| 14 | + |
|
| 15 | + |
|
| 16 | +import Data.Typeable
|
|
| 17 | + |
|
| 18 | +data Some c where
|
|
| 19 | + Some :: c a => a -> Some c
|
|
| 20 | + |
|
| 21 | +extractSome :: (Typeable a, forall x. c x => Typeable x) => Some c -> Maybe a
|
|
| 22 | +extractSome (Some a) = cast a
|
|
| 23 | + |
|
| 24 | +f :: (forall x. Ord x => Eq [x]) => ()
|
|
| 25 | +f = ()
|
|
| 26 | +{-# NOINLINE f #-}
|
|
| 27 | + |
|
| 28 | +g :: ()
|
|
| 29 | +g = f
|
|
| 30 | + |
|
| 31 | +useQC :: forall c a. (c a, forall x. c x => Show x) => a -> String
|
|
| 32 | +useQC x = show x
|
|
| 33 | + |
|
| 34 | +points :: [(Int,Int)]
|
|
| 35 | +points = [(22,26),(29, 5), (32, 13)]
|
|
| 36 | + |
|
| 37 | +main = do
|
|
| 38 | + (df, hf) <- readTestHie "T25709.hie"
|
|
| 39 | + let refmap = generateReferencesMap $ getAsts $ hie_asts hf
|
|
| 40 | + traverse (explainEv df hf refmap) points |
| 1 | +==========================
|
|
| 2 | +At point (22,26), we found:
|
|
| 3 | +==========================
|
|
| 4 | +┌
|
|
| 5 | +│ $dTypeable at T25709.hs:22:14-19, of type: Typeable a
|
|
| 6 | +│ is an evidence variable bound by a let, depending on: [$dTypeable]
|
|
| 7 | +│ with scope: LocalScope T25709.hs:22:14-29
|
|
| 8 | +│
|
|
| 9 | +│ Defined at <no location info>
|
|
| 10 | +└
|
|
| 11 | +|
|
|
| 12 | +`- ┌
|
|
| 13 | + │ $dTypeable at T25709.hs:22:1-29, of type: Typeable a
|
|
| 14 | + │ is an evidence variable bound by a HsWrapper
|
|
| 15 | + │ with scope: LocalScope T25709.hs:22:1-29
|
|
| 16 | + │ bound at: T25709.hs:22:1-29
|
|
| 17 | + │ Defined at <no location info>
|
|
| 18 | + └
|
|
| 19 | + |
|
| 20 | +┌
|
|
| 21 | +│ $dTypeable at T25709.hs:22:14-19, of type: Typeable a
|
|
| 22 | +│ is an evidence variable bound by a let, depending on: [df, irred]
|
|
| 23 | +│ with scope: LocalScope T25709.hs:22:14-29
|
|
| 24 | +│
|
|
| 25 | +│ Defined at <no location info>
|
|
| 26 | +└
|
|
| 27 | +|
|
|
| 28 | ++- ┌
|
|
| 29 | +| │ df at T25709.hs:22:1-29, of type: forall x. c x => Typeable x
|
|
| 30 | +| │ is an evidence variable bound by a HsWrapper
|
|
| 31 | +| │ with scope: LocalScope T25709.hs:22:1-29
|
|
| 32 | +| │ bound at: T25709.hs:22:1-29
|
|
| 33 | +| │ Defined at <no location info>
|
|
| 34 | +| └
|
|
| 35 | +|
|
|
| 36 | +`- ┌
|
|
| 37 | + │ irred at T25709.hs:22:14-19, of type: c a
|
|
| 38 | + │ is an evidence variable bound by a let, depending on: [irred]
|
|
| 39 | + │ with scope: LocalScope T25709.hs:22:14-29
|
|
| 40 | + │
|
|
| 41 | + │ Defined at <no location info>
|
|
| 42 | + └
|
|
| 43 | + |
|
|
| 44 | + `- ┌
|
|
| 45 | + │ irred at T25709.hs:22:14-19, of type: c a
|
|
| 46 | + │ is an evidence variable bound by a pattern
|
|
| 47 | + │ with scope: LocalScope T25709.hs:22:14-29
|
|
| 48 | + │
|
|
| 49 | + │ Defined at <no location info>
|
|
| 50 | + └
|
|
| 51 | + |
|
| 52 | +==========================
|
|
| 53 | +At point (29,5), we found:
|
|
| 54 | +==========================
|
|
| 55 | +┌
|
|
| 56 | +│ df at T25709.hs:1:1, of type: forall x. Ord x => Eq [x]
|
|
| 57 | +│ is an evidence variable bound by a let, depending on: [$p1Ord,
|
|
| 58 | +│ $fEqList]
|
|
| 59 | +│ with scope: ModuleScope
|
|
| 60 | +│
|
|
| 61 | +│ Defined at <no location info>
|
|
| 62 | +└
|
|
| 63 | +|
|
|
| 64 | ++- ┌
|
|
| 65 | +| │ $p1Ord at T25709.hs:1:1, of type: forall a. Ord a => Eq a
|
|
| 66 | +| │ is a usage of an external evidence variable
|
|
| 67 | +| │ Defined in `GHC.Internal.Classes'
|
|
| 68 | +| └
|
|
| 69 | +|
|
|
| 70 | +`- ┌
|
|
| 71 | + │ $fEqList at T25709.hs:1:1, of type: forall a. Eq a => Eq [a]
|
|
| 72 | + │ is a usage of an external evidence variable
|
|
| 73 | + │ Defined in `GHC.Internal.Classes'
|
|
| 74 | + └
|
|
| 75 | + |
|
| 76 | +==========================
|
|
| 77 | +At point (32,13), we found:
|
|
| 78 | +==========================
|
|
| 79 | +┌
|
|
| 80 | +│ $dShow at T25709.hs:32:1-16, of type: Show a
|
|
| 81 | +│ is an evidence variable bound by a let, depending on: [df, irred]
|
|
| 82 | +│ with scope: LocalScope T25709.hs:32:1-16
|
|
| 83 | +│ bound at: T25709.hs:32:1-16
|
|
| 84 | +│ Defined at <no location info>
|
|
| 85 | +└
|
|
| 86 | +|
|
|
| 87 | ++- ┌
|
|
| 88 | +| │ df at T25709.hs:32:1-16, of type: forall x. c x => Show x
|
|
| 89 | +| │ is an evidence variable bound by a HsWrapper
|
|
| 90 | +| │ with scope: LocalScope T25709.hs:32:1-16
|
|
| 91 | +| │ bound at: T25709.hs:32:1-16
|
|
| 92 | +| │ Defined at <no location info>
|
|
| 93 | +| └
|
|
| 94 | +|
|
|
| 95 | +`- ┌
|
|
| 96 | + │ irred at T25709.hs:32:1-16, of type: c a
|
|
| 97 | + │ is an evidence variable bound by a let, depending on: [irred]
|
|
| 98 | + │ with scope: LocalScope T25709.hs:32:1-16
|
|
| 99 | + │ bound at: T25709.hs:32:1-16
|
|
| 100 | + │ Defined at <no location info>
|
|
| 101 | + └
|
|
| 102 | + |
|
|
| 103 | + `- ┌
|
|
| 104 | + │ irred at T25709.hs:32:1-16, of type: c a
|
|
| 105 | + │ is an evidence variable bound by a HsWrapper
|
|
| 106 | + │ with scope: LocalScope T25709.hs:32:1-16
|
|
| 107 | + │ bound at: T25709.hs:32:1-16
|
|
| 108 | + │ Defined at <no location info>
|
|
| 109 | + └
|
|
| 110 | + |
| ... | ... | @@ -8,4 +8,5 @@ test('HieVdq', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUti |
| 8 | 8 | test('T23540', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
| 9 | 9 | test('T23120', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
| 10 | 10 | test('T24544', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
| 11 | -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 | ||
| 11 | +test('HieGadtConSigs', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
|
| 12 | +test('T25709', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) |