diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2019-01-09 18:44:48 +0300 |
---|---|---|
committer | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2019-01-13 00:17:20 -0500 |
commit | a34ee61545930d569d0dbafb3a4a5db3a7a711e5 (patch) | |
tree | 940ad55163a9c12a97b15a529d7a2c57a8efef7a /compiler/deSugar | |
parent | 448f0e7dd78a8d9404f1aa5e8522cc284360c06d (diff) | |
download | haskell-a34ee61545930d569d0dbafb3a4a5db3a7a711e5.tar.gz |
Refactor GHCi UI to fix #11606, #12091, #15721, #16096
Instead of parsing and executing a statement or declaration directly we
now parse them first and then execute in a separate step. This gives us
the flexibility to inspect the parsed declaration before execution.
Using this we now inspect parsed declarations, and if it's a single
declaration of form `x = y` we execute it as `let x = y` instead, fixing
a ton of problems caused by poor declaration support in GHCi.
To avoid any users of the modules I left `execStmt` and `runDecls`
unchanged and added `execStmt'` and `runDecls'` which work on parsed
statements/declarations.
Diffstat (limited to 'compiler/deSugar')
-rw-r--r-- | compiler/deSugar/Desugar.hs | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/compiler/deSugar/Desugar.hs b/compiler/deSugar/Desugar.hs index aa24ee0a5d..aa9748ee35 100644 --- a/compiler/deSugar/Desugar.hs +++ b/compiler/deSugar/Desugar.hs @@ -149,8 +149,7 @@ deSugar hsc_env keep_alive <- readIORef keep_var ; let (rules_for_locals, rules_for_imps) = partition isLocalRule all_rules final_prs = addExportFlagsAndRules target export_set keep_alive - mod rules_for_locals - (fromOL all_prs) + rules_for_locals (fromOL all_prs) final_pgm = combineEvBinds ds_ev_binds final_prs -- Notice that we put the whole lot in a big Rec, even the foreign binds @@ -284,9 +283,9 @@ deSugarExpr hsc_env tc_expr = do { -} addExportFlagsAndRules - :: HscTarget -> NameSet -> NameSet -> Module -> [CoreRule] + :: HscTarget -> NameSet -> NameSet -> [CoreRule] -> [(Id, t)] -> [(Id, t)] -addExportFlagsAndRules target exports keep_alive mod rules prs +addExportFlagsAndRules target exports keep_alive rules prs = mapFst add_one prs where add_one bndr = add_rules name (add_export name bndr) @@ -319,20 +318,10 @@ addExportFlagsAndRules target exports keep_alive mod rules prs -- simplification), and retain them all in the TypeEnv so they are -- available from the command line. -- - -- Most of the time, this can be accomplished by use of - -- targetRetainsAllBindings, which returns True if the target is - -- HscInteractive. However, there are cases when one can use GHCi with - -- a target other than HscInteractive (e.g., with the -fobject-code - -- flag enabled, as in #12091). In such scenarios, - -- targetRetainsAllBindings can return False, so we must fall back on - -- isInteractiveModule to be doubly sure we export entities defined in - -- a GHCi session. - -- -- isExternalName separates the user-defined top-level names from those -- introduced by the type checker. is_exported :: Name -> Bool - is_exported | targetRetainsAllBindings target - || isInteractiveModule mod = isExternalName + is_exported | targetRetainsAllBindings target = isExternalName | otherwise = (`elemNameSet` exports) {- |