Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,251
Issues
4,251
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
394
Merge Requests
394
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
7707c269
Commit
7707c269
authored
Jul 23, 2009
by
simonpj@microsoft.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop generating redundant parens in 'deriving' code
This makes the code printed by -ddump-deriv look prettier
parent
ad2c24f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
18 deletions
+45
-18
compiler/hsSyn/HsPat.lhs
compiler/hsSyn/HsPat.lhs
+43
-15
compiler/hsSyn/HsUtils.lhs
compiler/hsSyn/HsUtils.lhs
+2
-3
No files found.
compiler/hsSyn/HsPat.lhs
View file @
7707c269
...
...
@@ -23,7 +23,7 @@ module HsPat (
mkPrefixConPat, mkCharLitPat, mkNilPat, mkCoPat, mkCoPatCoI,
isBangHsBind,
isBangHsBind,
hsPatNeedsParens,
patsAreAllCons, isConPat, isSigPat, isWildPat,
patsAreAllLits, isLitPat, isIrrefutableHsPat
) where
...
...
@@ -175,7 +175,7 @@ However HsRecFields is used only for patterns and expressions
\begin{code}
data HsRecFields id arg -- A bunch of record fields
-- { x = 3, y = True }
-- Used for both expression
a
and patterns
-- Used for both expression
s
and patterns
= HsRecFields { rec_flds :: [HsRecField id arg],
rec_dotdot :: Maybe Int }
-- Nothing => the normal case
...
...
@@ -248,8 +248,8 @@ pprPat (WildPat _) = char '_'
pprPat (LazyPat pat) = char '~' <> ppr pat
pprPat (BangPat pat) = char '!' <> ppr pat
pprPat (AsPat name pat) = parens (hcat [ppr name, char '@', ppr pat])
pprPat (ViewPat expr pat _)
= parens (hcat [pprLExpr expr, text " -> ", ppr pat])
pprPat (ParPat pat) = parens (ppr pat)
pprPat (ViewPat expr pat _) = parens (hcat [pprLExpr expr, text " -> ", ppr pat])
pprPat (ParPat pat)
= parens (ppr pat)
pprPat (ListPat pats _) = brackets (interpp'SP pats)
pprPat (PArrPat pats _) = pabrackets (interpp'SP pats)
pprPat (TuplePat pats bx _) = tupleParens bx (interpp'SP pats)
...
...
@@ -417,12 +417,12 @@ isIrrefutableHsPat :: OutputableBndr id => LPat id -> Bool
isIrrefutableHsPat pat
= go pat
where
go (L _ pat)
= go1 pat
go (L _ pat) = go1 pat
go1 (WildPat
_)
= True
go1 (VarPat
_)
= True
go1 (VarPatOut
_ _)
= True
go1 (LazyPat
_)
= True
go1 (WildPat
{})
= True
go1 (VarPat
{})
= True
go1 (VarPatOut
{})
= True
go1 (LazyPat
{})
= True
go1 (BangPat pat) = go pat
go1 (CoPat _ pat _) = go1 pat
go1 (ParPat pat) = go pat
...
...
@@ -431,22 +431,50 @@ isIrrefutableHsPat pat
go1 (SigPatIn pat _) = go pat
go1 (SigPatOut pat _) = go pat
go1 (TuplePat pats _ _) = all go pats
go1 (ListPat
_ _)
= False
go1 (PArrPat
_ _)
= False -- ?
go1 (ListPat
{})
= False
go1 (PArrPat
{})
= False -- ?
go1 (ConPatIn
_ _)
= False -- Conservative
go1 (ConPatIn
{})
= False -- Conservative
go1 (ConPatOut{ pat_con = L _ con, pat_args = details })
= isProductTyCon (dataConTyCon con)
&& all go (hsConPatArgs details)
go1 (LitPat
_)
= False
go1 (NPat
_ _ _)
= False
go1 (NPlusKPat
_ _ _ _
) = False
go1 (LitPat
{})
= False
go1 (NPat
{})
= False
go1 (NPlusKPat
{}
) = False
go1 (QuasiQuotePat {}) = urk pat -- Gotten rid of by renamer, before
-- isIrrefutablePat is called
go1 (TypePat {}) = urk pat
urk pat = pprPanic "isIrrefutableHsPat:" (ppr pat)
hsPatNeedsParens :: Pat a -> Bool
hsPatNeedsParens (WildPat {}) = False
hsPatNeedsParens (VarPat {}) = False
hsPatNeedsParens (VarPatOut {}) = True
hsPatNeedsParens (LazyPat {}) = False
hsPatNeedsParens (BangPat {}) = False
hsPatNeedsParens (CoPat {}) = True
hsPatNeedsParens (ParPat {}) = False
hsPatNeedsParens (AsPat {}) = False
hsPatNeedsParens (ViewPat {}) = True
hsPatNeedsParens (SigPatIn {}) = True
hsPatNeedsParens (SigPatOut {}) = True
hsPatNeedsParens (TuplePat {}) = False
hsPatNeedsParens (ListPat {}) = False
hsPatNeedsParens (PArrPat {}) = False
hsPatNeedsParens (ConPatIn _ ds) = conPatNeedsParens ds
hsPatNeedsParens (ConPatOut {}) = True
hsPatNeedsParens (LitPat {}) = False
hsPatNeedsParens (NPat {}) = False
hsPatNeedsParens (NPlusKPat {}) = True
hsPatNeedsParens (QuasiQuotePat {}) = True
hsPatNeedsParens (TypePat {}) = False
conPatNeedsParens :: HsConDetails a b -> Bool
conPatNeedsParens (PrefixCon args) = not (null args)
conPatNeedsParens (InfixCon {}) = False
conPatNeedsParens (RecCon {}) = False
\end{code}
compiler/hsSyn/HsUtils.lhs
View file @
7707c269
...
...
@@ -338,9 +338,8 @@ mkMatch pats expr binds
= noLoc (Match (map paren pats) Nothing
(GRHSs (unguardedRHS expr) binds))
where
paren p = case p of
L _ (VarPat _) -> p
L l _ -> L l (ParPat p)
paren lp@(L l p) | hsPatNeedsParens p = L l (ParPat lp)
| otherwise = lp
\end{code}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment