Hannes Siebenhandl pushed to branch wip/fendor/has-field-hie at Glasgow Haskell Compiler / GHC
Commits:
-
b372f2b2
by fendor at 2026-09-16T10:52:33+02:00
8 changed files:
- compiler/GHC/Iface/Ext/Ast.hs
- + testsuite/tests/hiefile/should_run/HasFieldQueries.hs
- + testsuite/tests/hiefile/should_run/HasFieldQueries.stdout
- + testsuite/tests/hiefile/should_run/HieTypeable.hs
- + testsuite/tests/hiefile/should_run/HieTypeable.stdout
- testsuite/tests/hiefile/should_run/RecordDotTypes.stdout
- testsuite/tests/hiefile/should_run/T23492.stdout
- testsuite/tests/hiefile/should_run/all.T
Changes:
| ... | ... | @@ -33,7 +33,7 @@ import GHC.Types.Basic |
| 33 | 33 | import GHC.Types.UnresolvedImport ( isGeneratedImport )
|
| 34 | 34 | import GHC.Types.FieldLabel
|
| 35 | 35 | import GHC.Types.Avail ( Avails )
|
| 36 | -import GHC.Types.Id ( isDataConId_maybe )
|
|
| 36 | +import GHC.Types.Id ( isDataConId_maybe, isId )
|
|
| 37 | 37 | import GHC.Types.Name ( Name, nameSrcSpan, nameUnique, wiredInNameTyThing_maybe, getName )
|
| 38 | 38 | import GHC.Types.Name.Env ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
|
| 39 | 39 | import GHC.Types.Name.Reader ( RecFieldInfo(..), WithUserRdr(..) )
|
| ... | ... | @@ -682,7 +682,7 @@ instance ToHie (Context (Located (WithUserRdr Name))) where |
| 682 | 682 | |
| 683 | 683 | hieEvIdsOfTerm :: EvTerm -> [EvId]
|
| 684 | 684 | -- Returns only EvIds satisfying relevantEvId
|
| 685 | -hieEvIdsOfTerm = runFVSelectiveList isEvId . evTermFVs
|
|
| 685 | +hieEvIdsOfTerm = runFVSelectiveList isId . evTermFVs
|
|
| 686 | 686 | |
| 687 | 687 | instance ToHie (EvBindContext (LocatedA TcEvBinds)) where
|
| 688 | 688 | toHie (EvBindContext sc sp (L span (EvBinds bs)))
|
| 1 | +{-# LANGUAGE OverloadedRecordDot #-}
|
|
| 2 | +module Main where
|
|
| 3 | + |
|
| 4 | +import TestUtils
|
|
| 5 | +import GHC.Records
|
|
| 6 | +import GHC.TypeLits
|
|
| 7 | +import Data.Tree
|
|
| 8 | + |
|
| 9 | +data Thing = Thing {field1 :: Char, field2 :: Bool}
|
|
| 10 | + deriving (Show, Eq)
|
|
| 11 | + |
|
| 12 | +foo :: Thing -> String
|
|
| 13 | +foo t = show t.field1
|
|
| 14 | +-- ^ this is the point
|
|
| 15 | + |
|
| 16 | +testing2 (x :: Thing) = x.field1
|
|
| 17 | +-- ^ this is the point
|
|
| 18 | +-- ^ this is the point
|
|
| 19 | + |
|
| 20 | +data NestedThing = NestedThing { nested1 :: Thing }
|
|
| 21 | + |
|
| 22 | +nestedSig :: NestedThing -> Char
|
|
| 23 | +nestedSig n = n.nested1.field1
|
|
| 24 | +-- ^ this is the point
|
|
| 25 | +-- ^ this is the point
|
|
| 26 | + |
|
| 27 | +nestedNoSig n = n.nested1.field2 :: Bool
|
|
| 28 | +-- ^ this is the point
|
|
| 29 | +-- ^ this is the point
|
|
| 30 | + |
|
| 31 | + |
|
| 32 | +withConstraint :: HasField "field1" x Char => x -> Char
|
|
| 33 | +withConstraint x = x.field1
|
|
| 34 | +-- ^ this is the point
|
|
| 35 | + |
|
| 36 | +points =
|
|
| 37 | + [ (13,17)
|
|
| 38 | + , (16,25)
|
|
| 39 | + , (16,27)
|
|
| 40 | + , (23,17)
|
|
| 41 | + , (23,25)
|
|
| 42 | + , (27,20)
|
|
| 43 | + , (27,28)
|
|
| 44 | + , (33,22)
|
|
| 45 | + ]
|
|
| 46 | + |
|
| 47 | +main = do
|
|
| 48 | + (df, hf) <- readTestHie "HasFieldQueries.hie"
|
|
| 49 | + let refmap = generateReferencesMap $ getAsts $ hie_asts hf
|
|
| 50 | + |
|
| 51 | + traverse (explainEv df hf refmap) points
|
|
| 52 | + return () |
| 1 | +==========================
|
|
| 2 | +At point (13,17), we found:
|
|
| 3 | +==========================
|
|
| 4 | +┌
|
|
| 5 | +│ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char
|
|
| 6 | +│ is an evidence variable bound by a let, depending on: [C:HasField,
|
|
| 7 | +│ field1]
|
|
| 8 | +│ with scope: ModuleScope
|
|
| 9 | +│
|
|
| 10 | +│ Defined at <no location info>
|
|
| 11 | +└
|
|
| 12 | +|
|
|
| 13 | ++- ┌
|
|
| 14 | +| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a
|
|
| 15 | +| │ is a usage of an external evidence variable
|
|
| 16 | +| │ Defined in `GHC.Internal.Records'
|
|
| 17 | +| └
|
|
| 18 | +|
|
|
| 19 | +`- ┌
|
|
| 20 | + │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char
|
|
| 21 | + │ is a usage of an external evidence variable
|
|
| 22 | + │ Defined at HasFieldQueries.hs:9:21
|
|
| 23 | + └
|
|
| 24 | + |
|
| 25 | +==========================
|
|
| 26 | +At point (16,25), we found:
|
|
| 27 | +==========================
|
|
| 28 | +==========================
|
|
| 29 | +At point (16,27), we found:
|
|
| 30 | +==========================
|
|
| 31 | +┌
|
|
| 32 | +│ $dHasField at HasFieldQueries.hs:16:1-32, of type: HasField "field1" Thing Char
|
|
| 33 | +│ is an evidence variable bound by a let, depending on: [C:HasField,
|
|
| 34 | +│ field1]
|
|
| 35 | +│ with scope: LocalScope HasFieldQueries.hs:16:1-32
|
|
| 36 | +│ bound at: HasFieldQueries.hs:16:1-32
|
|
| 37 | +│ Defined at <no location info>
|
|
| 38 | +└
|
|
| 39 | +|
|
|
| 40 | ++- ┌
|
|
| 41 | +| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a
|
|
| 42 | +| │ is a usage of an external evidence variable
|
|
| 43 | +| │ Defined in `GHC.Internal.Records'
|
|
| 44 | +| └
|
|
| 45 | +|
|
|
| 46 | +`- ┌
|
|
| 47 | + │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char
|
|
| 48 | + │ is a usage of an external evidence variable
|
|
| 49 | + │ Defined at HasFieldQueries.hs:9:21
|
|
| 50 | + └
|
|
| 51 | + |
|
| 52 | +==========================
|
|
| 53 | +At point (23,17), we found:
|
|
| 54 | +==========================
|
|
| 55 | +┌
|
|
| 56 | +│ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "nested1" NestedThing Thing
|
|
| 57 | +│ is an evidence variable bound by a let, depending on: [C:HasField,
|
|
| 58 | +│ nested1]
|
|
| 59 | +│ with scope: ModuleScope
|
|
| 60 | +│
|
|
| 61 | +│ Defined at <no location info>
|
|
| 62 | +└
|
|
| 63 | +|
|
|
| 64 | ++- ┌
|
|
| 65 | +| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a
|
|
| 66 | +| │ is a usage of an external evidence variable
|
|
| 67 | +| │ Defined in `GHC.Internal.Records'
|
|
| 68 | +| └
|
|
| 69 | +|
|
|
| 70 | +`- ┌
|
|
| 71 | + │ nested1 at HasFieldQueries.hs:1:1, of type: NestedThing -> Thing
|
|
| 72 | + │ is a usage of an external evidence variable
|
|
| 73 | + │ Defined at HasFieldQueries.hs:20:34
|
|
| 74 | + └
|
|
| 75 | + |
|
| 76 | +==========================
|
|
| 77 | +At point (23,25), we found:
|
|
| 78 | +==========================
|
|
| 79 | +┌
|
|
| 80 | +│ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char
|
|
| 81 | +│ is an evidence variable bound by a let, depending on: [C:HasField,
|
|
| 82 | +│ field1]
|
|
| 83 | +│ with scope: ModuleScope
|
|
| 84 | +│
|
|
| 85 | +│ Defined at <no location info>
|
|
| 86 | +└
|
|
| 87 | +|
|
|
| 88 | ++- ┌
|
|
| 89 | +| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a
|
|
| 90 | +| │ is a usage of an external evidence variable
|
|
| 91 | +| │ Defined in `GHC.Internal.Records'
|
|
| 92 | +| └
|
|
| 93 | +|
|
|
| 94 | +`- ┌
|
|
| 95 | + │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char
|
|
| 96 | + │ is a usage of an external evidence variable
|
|
| 97 | + │ Defined at HasFieldQueries.hs:9:21
|
|
| 98 | + └
|
|
| 99 | + |
|
| 100 | +==========================
|
|
| 101 | +At point (27,20), we found:
|
|
| 102 | +==========================
|
|
| 103 | +┌
|
|
| 104 | +│ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "nested1" r r
|
|
| 105 | +│ is an evidence variable bound by a let, depending on: [$dHasField]
|
|
| 106 | +│ with scope: LocalScope HasFieldQueries.hs:27:1-40
|
|
| 107 | +│ bound at: HasFieldQueries.hs:27:1-40
|
|
| 108 | +│ Defined at <no location info>
|
|
| 109 | +└
|
|
| 110 | +|
|
|
| 111 | +`- ┌
|
|
| 112 | + │ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "nested1" r r
|
|
| 113 | + │ is an evidence variable bound by a type signature
|
|
| 114 | + │ with scope: LocalScope HasFieldQueries.hs:27:1-40
|
|
| 115 | + │ bound at: HasFieldQueries.hs:27:1-40
|
|
| 116 | + │ Defined at <no location info>
|
|
| 117 | + └
|
|
| 118 | + |
|
| 119 | +==========================
|
|
| 120 | +At point (27,28), we found:
|
|
| 121 | +==========================
|
|
| 122 | +┌
|
|
| 123 | +│ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "field2" r Bool
|
|
| 124 | +│ is an evidence variable bound by a let, depending on: [$dHasField]
|
|
| 125 | +│ with scope: LocalScope HasFieldQueries.hs:27:1-40
|
|
| 126 | +│ bound at: HasFieldQueries.hs:27:1-40
|
|
| 127 | +│ Defined at <no location info>
|
|
| 128 | +└
|
|
| 129 | +|
|
|
| 130 | +`- ┌
|
|
| 131 | + │ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "field2" r Bool
|
|
| 132 | + │ is an evidence variable bound by a type signature
|
|
| 133 | + │ with scope: LocalScope HasFieldQueries.hs:27:1-40
|
|
| 134 | + │ bound at: HasFieldQueries.hs:27:1-40
|
|
| 135 | + │ Defined at <no location info>
|
|
| 136 | + └
|
|
| 137 | + |
|
| 138 | +==========================
|
|
| 139 | +At point (33,22), we found:
|
|
| 140 | +==========================
|
|
| 141 | +┌
|
|
| 142 | +│ $dHasField at HasFieldQueries.hs:33:1-27, of type: HasField "field1" x Char
|
|
| 143 | +│ is an evidence variable bound by a let, depending on: [$dHasField]
|
|
| 144 | +│ with scope: LocalScope HasFieldQueries.hs:33:1-27
|
|
| 145 | +│ bound at: HasFieldQueries.hs:33:1-27
|
|
| 146 | +│ Defined at <no location info>
|
|
| 147 | +└
|
|
| 148 | +|
|
|
| 149 | +`- ┌
|
|
| 150 | + │ $dHasField at HasFieldQueries.hs:33:1-27, of type: HasField "field1" x Char
|
|
| 151 | + │ is an evidence variable bound by a HsWrapper
|
|
| 152 | + │ with scope: LocalScope HasFieldQueries.hs:33:1-27
|
|
| 153 | + │ bound at: HasFieldQueries.hs:33:1-27
|
|
| 154 | + │ Defined at <no location info>
|
|
| 155 | + └
|
|
| 156 | + |
| 1 | +module Main where
|
|
| 2 | + |
|
| 3 | +import Data.Dynamic
|
|
| 4 | +import Data.Typeable
|
|
| 5 | +import TestUtils
|
|
| 6 | + |
|
| 7 | +data Thing = Thing {field1 :: Char, field2 :: Bool}
|
|
| 8 | + deriving (Show, Eq)
|
|
| 9 | + |
|
| 10 | +castFromDynamic :: Dynamic -> Maybe Thing
|
|
| 11 | +castFromDynamic d = fromDynamic d
|
|
| 12 | + -- ^ this is the point
|
|
| 13 | + |
|
| 14 | +rep :: Thing -> TypeRep
|
|
| 15 | +rep d = typeOf d
|
|
| 16 | + -- ^ this is the point
|
|
| 17 | + |
|
| 18 | +points =
|
|
| 19 | + [ (11,21)
|
|
| 20 | + , (15,10)
|
|
| 21 | + ]
|
|
| 22 | + |
|
| 23 | +main = do
|
|
| 24 | + (df, hf) <- readTestHie "HieTypeable.hie"
|
|
| 25 | + let refmap = generateReferencesMap $ getAsts $ hie_asts hf
|
|
| 26 | + |
|
| 27 | + traverse (explainEv df hf refmap) points
|
|
| 28 | + return () |
| 1 | +==========================
|
|
| 2 | +At point (11,21), we found:
|
|
| 3 | +==========================
|
|
| 4 | +┌
|
|
| 5 | +│ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing
|
|
| 6 | +│ is an evidence variable bound by a let, depending on: [$dTypeable]
|
|
| 7 | +│ with scope: ModuleScope
|
|
| 8 | +│
|
|
| 9 | +│ Defined at <no location info>
|
|
| 10 | +└
|
|
| 11 | +|
|
|
| 12 | +`- ┌
|
|
| 13 | + │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing
|
|
| 14 | + │ is an evidence variable bound by a let, depending on: []
|
|
| 15 | + │ with scope: ModuleScope
|
|
| 16 | + │
|
|
| 17 | + │ Defined at <no location info>
|
|
| 18 | + └
|
|
| 19 | + |
|
| 20 | +==========================
|
|
| 21 | +At point (15,10), we found:
|
|
| 22 | +==========================
|
|
| 23 | +┌
|
|
| 24 | +│ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing
|
|
| 25 | +│ is an evidence variable bound by a let, depending on: []
|
|
| 26 | +│ with scope: ModuleScope
|
|
| 27 | +│
|
|
| 28 | +│ Defined at <no location info>
|
|
| 29 | +└
|
|
| 30 | + |
| 1 | 1 | At (22,6), got type: MyRecord
|
| 2 | -At (22,20), got type: Integer
|
|
| 2 | +At (22,20), got type: MyRecord -> Integer
|
|
| 3 | 3 | At (22,25), got type: MyRecord
|
| 4 | -At (22,28), got type: String
|
|
| 5 | -At (22,29), got type: String |
|
| \ No newline at end of file | ||
| 4 | +At (22,28), got type: MyChild -> [Char]
|
|
| 5 | +At (22,29), got type: MyChild -> [Char] |
| ... | ... | @@ -4,4 +4,4 @@ PartialFieldSelector |
| 4 | 4 | At (18,7), got type: PartialFieldSelector -> Bool
|
| 5 | 5 | At (23,7), got type: PartialFieldSelector
|
| 6 | 6 | At (23,8), got type: PartialFieldSelector
|
| 7 | -At (23,9), got type: Bool |
|
| 7 | +At (23,9), got type: PartialFieldSelector -> Bool |
| ... | ... | @@ -10,3 +10,5 @@ test('T23120', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUti |
| 10 | 10 | test('T24544', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
| 11 | 11 | test('HieGadtConSigs', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
| 12 | 12 | test('T25709', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
| 13 | +test('HasFieldQueries', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info'])
|
|
| 14 | +test('HieTypeable', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) |