From 38fd8e0de2bee1c27bd9bed3c26500e2e119dd21 Mon Sep 17 00:00:00 2001
From: Patrick Palka <patrick@parcs.ath.cx>
Date: Sun, 8 Jul 2012 12:49:22 -0400
Subject: [PATCH] Allow 'default' declarations in GHCi
---
compiler/main/HscMain.hs | 5 ++++-
compiler/main/HscTypes.lhs | 4 ++++
compiler/typecheck/TcRnDriver.lhs | 1 +
ghc/InteractiveUI.hs | 2 +-
4 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs
index 0b03e83..215a654 100644
|
a
|
b
|
|
| 1510 | 1510 | let finsts = tcg_fam_insts tc_gblenv |
| 1511 | 1511 | insts = tcg_insts tc_gblenv |
| 1512 | 1512 | |
| | 1513 | let defaults = tcg_default tc_gblenv |
| | 1514 | |
| 1513 | 1515 | {- Desugar it -} |
| 1514 | 1516 | -- We use a basically null location for iNTERACTIVE |
| 1515 | 1517 | let iNTERACTIVELoc = ModLocation{ ml_hs_file = Nothing, |
| … |
… |
|
| 1561 | 1563 | |
| 1562 | 1564 | let ictxt1 = extendInteractiveContext icontext tythings |
| 1563 | 1565 | ictxt = ictxt1 { ic_sys_vars = sys_vars ++ ic_sys_vars ictxt1, |
| 1564 | | ic_instances = (insts, finsts) } |
| | 1566 | ic_instances = (insts, finsts), |
| | 1567 | ic_default = defaults } |
| 1565 | 1568 | |
| 1566 | 1569 | return (tythings, ictxt) |
| 1567 | 1570 | |
diff --git a/compiler/main/HscTypes.lhs b/compiler/main/HscTypes.lhs
index adaa9a3..343df00 100644
|
a
|
b
|
|
| 943 | 943 | -- ^ The function that is used for printing results |
| 944 | 944 | -- of expressions in ghci and -e mode. |
| 945 | 945 | |
| | 946 | ic_default :: Maybe [Type], |
| | 947 | -- ^ The current default types, set by a 'default' declaration |
| | 948 | |
| 946 | 949 | #ifdef GHCI |
| 947 | 950 | ic_resume :: [Resume], |
| 948 | 951 | -- ^ The stack of breakpoint contexts |
| … |
… |
|
| 987 | 990 | ic_fix_env = emptyNameEnv, |
| 988 | 991 | -- System.IO.print by default |
| 989 | 992 | ic_int_print = printName, |
| | 993 | ic_default = Nothing, |
| 990 | 994 | #ifdef GHCI |
| 991 | 995 | ic_resume = [], |
| 992 | 996 | #endif |
diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs
index fa87eb1..5bfb091 100644
|
a
|
b
|
|
| 1197 | 1197 | -- setting tcg_field_env is necessary to make RecordWildCards work |
| 1198 | 1198 | -- (test: ghci049) |
| 1199 | 1199 | , tcg_fix_env = ic_fix_env icxt |
| | 1200 | , tcg_default = ic_default icxt |
| 1200 | 1201 | }) $ |
| 1201 | 1202 | |
| 1202 | 1203 | tcExtendGhciEnv visible_tmp_ids $ -- Note [GHCi temporary Ids] |
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 1dc203d..d73156e 100644
|
a
|
b
|
|
| 768 | 768 | -- rather than a stmt. |
| 769 | 769 | declPrefixes :: [String] |
| 770 | 770 | declPrefixes = ["class ","data ","newtype ","type ","instance ", "deriving ", |
| 771 | | "foreign "] |
| | 771 | "foreign ", "default ", "default("] |
| 772 | 772 | |
| 773 | 773 | -- | Entry point to execute some haskell code from user |
| 774 | 774 | runStmt :: String -> SingleStep -> GHCi Bool |