summaryrefslogtreecommitdiff
path: root/ghc/compiler/deSugar/MatchCon.lhs
diff options
context:
space:
mode:
authorsimonmar <unknown>2003-12-10 14:15:38 +0000
committersimonmar <unknown>2003-12-10 14:15:38 +0000
commit550421384b8364cdaf3135f7859c9f7d7ee1fff1 (patch)
treea786c7336f8404cf741da30c2760d5c65d00c9da /ghc/compiler/deSugar/MatchCon.lhs
parent60ea58ab5cbf8428997d5aa8ec9163a50fe5aed3 (diff)
downloadhaskell-550421384b8364cdaf3135f7859c9f7d7ee1fff1.tar.gz
[project @ 2003-12-10 14:15:16 by simonmar]
Add accurate source location annotations to HsSyn ------------------------------------------------- Every syntactic entity in HsSyn is now annotated with a SrcSpan, which details the exact beginning and end points of that entity in the original source file. All honest compilers should do this, and it was about time GHC did the right thing. The most obvious benefit is that we now have much more accurate error messages; when running GHC inside emacs for example, the cursor will jump to the exact location of an error, not just a line somewhere nearby. We haven't put a huge amount of effort into making sure all the error messages are accurate yet, so there could be some tweaking still needed, although the majority of messages I've seen have been spot-on. Error messages now contain a column number in addition to the line number, eg. read001.hs:25:10: Variable not in scope: `+#' To get the full text span info, use the new option -ferror-spans. eg. read001.hs:25:10-11: Variable not in scope: `+#' I'm not sure whether we should do this by default. Emacs won't understand the new error format, for one thing. In a more elaborate editor setting (eg. Visual Studio), we can arrange to actually highlight the subexpression containing an error. Eventually this information will be used so we can find elements in the abstract syntax corresponding to text locations, for performing high-level editor functions (eg. "tell me the type of this expression I just highlighted"). Performance of the compiler doesn't seem to be adversely affected. Parsing is still quicker than in 6.0.1, for example. Implementation: This was an excrutiatingly painful change to make: both Simon P.J. and myself have been working on it for the last three weeks or so. The basic changes are: - a new datatype SrcSpan, which represents a beginning and end position in a source file. - To reduce the pain as much as possible, we also defined: data Located e = L SrcSpan e - Every datatype in HsSyn has an equivalent Located version. eg. type LHsExpr id = Located (HsExpr id) and pretty much everywhere we used to use HsExpr we now use LHsExpr. Believe me, we thought about this long and hard, and all the other options were worse :-) Additional changes/cleanups we made at the same time: - The abstract syntax for bindings is now less arcane. MonoBinds and HsBinds with their built-in list constructors have gone away, replaced by HsBindGroup and HsBind (see HsSyn/HsBinds.lhs). - The various HsSyn type synonyms have now gone away (eg. RdrNameHsExpr, RenamedHsExpr, and TypecheckedHsExpr are now HsExpr RdrName, HsExpr Name, and HsExpr Id respectively). - Utilities over HsSyn are now collected in a new module HsUtils. More stuff still needs to be moved in here. - MachChar now has a real Char instead of an Int. All GHC versions that can compile GHC now support 32-bit Chars, so this was a simplification.
Diffstat (limited to 'ghc/compiler/deSugar/MatchCon.lhs')
-rw-r--r--ghc/compiler/deSugar/MatchCon.lhs5
1 files changed, 3 insertions, 2 deletions
diff --git a/ghc/compiler/deSugar/MatchCon.lhs b/ghc/compiler/deSugar/MatchCon.lhs
index a874218982..ed9f894834 100644
--- a/ghc/compiler/deSugar/MatchCon.lhs
+++ b/ghc/compiler/deSugar/MatchCon.lhs
@@ -20,6 +20,7 @@ import Subst ( mkSubst, mkInScopeSet, bindSubst, substExpr )
import CoreFVs ( exprFreeVars )
import VarEnv ( emptySubstEnv )
import ListSetOps ( equivClassesByUniq )
+import SrcLoc ( unLoc )
import Unique ( Uniquable(..) )
\end{code}
@@ -99,7 +100,7 @@ Wadler's chapter in SLPJ.
match_con vars (eqn1@(EqnInfo _ _ (ConPatOut data_con (PrefixCon arg_pats) _ ex_tvs ex_dicts : _) _)
: other_eqns)
= -- Make new vars for the con arguments; avoid new locals where possible
- mappM selectMatchVar arg_pats `thenDs` \ arg_vars ->
+ mappM selectMatchVarL arg_pats `thenDs` \ arg_vars ->
-- Now do the business to make the alt for _this_ ConPat ...
match (arg_vars ++ vars)
@@ -118,7 +119,7 @@ match_con vars (eqn1@(EqnInfo _ _ (ConPatOut data_con (PrefixCon arg_pats) _ ex_
where
shift_con_pat :: EquationInfo -> EquationInfo
shift_con_pat (EqnInfo n ctx (ConPatOut _ (PrefixCon arg_pats) _ _ _ : pats) match_result)
- = EqnInfo n ctx (arg_pats ++ pats) match_result
+ = EqnInfo n ctx (map unLoc arg_pats ++ pats) match_result
other_pats = [p | EqnInfo _ _ (p:_) _ <- other_eqns]