diff options
author | Matthías Páll Gissurarson <mpg@mpg.is> | 2017-03-29 17:30:28 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-03-29 18:06:21 -0400 |
commit | 26c95f46e679fb73e1ec2bec2be0801c72fd1449 (patch) | |
tree | eeedf7a400c80f07a8295c333875576d1b7b5800 /compiler/main/DynFlags.hs | |
parent | 924a65fc27bb2a3e24489f7baea7ad5fb8a556ac (diff) | |
download | haskell-26c95f46e679fb73e1ec2bec2be0801c72fd1449.tar.gz |
Show valid substitutions for typed holes
The idea is to implement a mechanism similar to PureScript, where they
suggest which identifiers in scope would fit the given hole. In
PureScript, they use subsumption (which is what we would like here as
well). For subsumption, we would have to check each type in scope
whether the hole is a subtype of the given type, but that would require
`tcSubType` and constraint satisfiability checking. Currently,
`TcSimplify` uses a lot of functions from `TcErrors`, so that would
require more of a rewrite, I will hold on with that for now, and submit
the more simpler type equality version.
As an example, consider
```
ps :: String -> IO ()
ps = putStrLn
ps2 :: a -> IO ()
ps2 _ = putStrLn "hello, world"
main :: IO ()
main = _ "hello, world"
```
The results would be something like
```
• Found hole: _ :: [Char] -> IO ()
• In the expression: _
In a stmt of a 'do' block: _ "hello, world"
In the expression:
do _ "hello, world"
• Relevant bindings include
main :: IO () (bound at test.hs:13:1)
ps :: String -> IO () (bound at test.hs:7:1)
ps2 :: forall a. a -> IO () (bound at test.hs:10:1)
Valid substitutions include
putStrLn :: String
-> IO () (imported from ‘Prelude’ at
test.hs:1:1-14
(and originally defined in
‘System.IO’))
putStr :: String
-> IO () (imported from ‘Prelude’ at
test.hs:1:1-14
(and originally defined in ‘System.IO’))
```
We'd like here for ps2 to be suggested as well, but for that we require
subsumption.
Reviewers: austin, bgamari, dfeuer, mpickering
Reviewed By: dfeuer, mpickering
Subscribers: mpickering, Wizek, dfeuer, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3361
Diffstat (limited to 'compiler/main/DynFlags.hs')
-rw-r--r-- | compiler/main/DynFlags.hs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 927d3c46a0..2750ca6aa8 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -708,6 +708,8 @@ data DynFlags = DynFlags { maxRelevantBinds :: Maybe Int, -- ^ Maximum number of bindings from the type envt -- to show in type error messages + maxValidSubstitutions :: Maybe Int, -- ^ Maximum number of substitutions + -- to show in type error messages maxUncoveredPatterns :: Int, -- ^ Maximum number of unmatched patterns to show -- in non-exhaustiveness warnings simplTickFactor :: Int, -- ^ Multiplier for simplifier ticks @@ -1539,6 +1541,7 @@ defaultDynFlags mySettings = maxPmCheckIterations = 2000000, ruleCheck = Nothing, maxRelevantBinds = Just 6, + maxValidSubstitutions = Just 6, maxUncoveredPatterns = 4, simplTickFactor = 100, specConstrThreshold = Just 2000, @@ -3134,6 +3137,10 @@ dynamic_flags_deps = [ (intSuffix (\n d -> d { maxRelevantBinds = Just n })) , make_ord_flag defFlag "fno-max-relevant-binds" (noArg (\d -> d { maxRelevantBinds = Nothing })) + , make_ord_flag defFlag "fmax-valid-substitutions" + (intSuffix (\n d -> d { maxValidSubstitutions = Just n })) + , make_ord_flag defFlag "fno-max-valid-substitutions" + (noArg (\d -> d { maxValidSubstitutions = Nothing })) , make_ord_flag defFlag "fmax-uncovered-patterns" (intSuffix (\n d -> d { maxUncoveredPatterns = n })) , make_ord_flag defFlag "fsimplifier-phases" |