diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-09-21 20:07:04 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-10-29 04:18:52 -0400 |
commit | 2ef2fac4c412a25fa64f79b759d69d22a4ebc784 (patch) | |
tree | afe8262c627704f420916df1d010f53c1346081c /compiler/GHC/Rename | |
parent | 22f5d9a951dbc9cfdf55984c5e2a6fad28a6f650 (diff) | |
download | haskell-wip/T18723.tar.gz |
Check for large tuples more thoroughlywip/T18723
This fixes #18723 by:
* Moving the existing `GHC.Tc.Gen.HsType.bigConstraintTuple` validity
check to `GHC.Rename.Utils.checkCTupSize` for consistency with
`GHC.Rename.Utils.checkTupSize`, and
* Using `check(C)TupSize` when checking tuple _types_, in addition
to checking names, expressions, and patterns.
Note that I put as many of these checks as possible in the typechecker so
that GHC can properly distinguish between boxed and constraint tuples. The
exception to this rule is checking names, which I perform in the renamer
(in `GHC.Rename.Env`) so that we can rule out `(,, ... ,,)` and
`''(,, ... ,,)` alike in one fell swoop.
While I was in town, I also removed the `HsConstraintTuple` and
`HsBoxedTuple` constructors of `HsTupleSort`, which are functionally
unused. This requires a `haddock` submodule bump.
Diffstat (limited to 'compiler/GHC/Rename')
-rw-r--r-- | compiler/GHC/Rename/Expr.hs | 1 | ||||
-rw-r--r-- | compiler/GHC/Rename/Pat.hs | 9 | ||||
-rw-r--r-- | compiler/GHC/Rename/Utils.hs | 18 |
3 files changed, 19 insertions, 9 deletions
diff --git a/compiler/GHC/Rename/Expr.hs b/compiler/GHC/Rename/Expr.hs index e0855f8c24..14218b01f6 100644 --- a/compiler/GHC/Rename/Expr.hs +++ b/compiler/GHC/Rename/Expr.hs @@ -282,7 +282,6 @@ rnExpr (ExplicitList x _ exps) rnExpr (ExplicitTuple x tup_args boxity) = do { checkTupleSection tup_args - ; checkTupSize (length tup_args) ; (tup_args', fvs) <- mapAndUnzipM rnTupArg tup_args ; return (ExplicitTuple x tup_args' boxity, plusFVs fvs) } where diff --git a/compiler/GHC/Rename/Pat.hs b/compiler/GHC/Rename/Pat.hs index 4a85c898ff..b0f15d3d19 100644 --- a/compiler/GHC/Rename/Pat.hs +++ b/compiler/GHC/Rename/Pat.hs @@ -37,8 +37,8 @@ module GHC.Rename.Pat (-- main entry points -- Literals rnLit, rnOverLit, - -- Pattern Error messages that are also used elsewhere - checkTupSize, patSigErr + -- Pattern Error message that is also used elsewhere + patSigErr ) where -- ENH: thin imports to only what is necessary for patterns @@ -59,7 +59,7 @@ import GHC.Rename.Utils ( HsDocContext(..), newLocalBndrRn, bindLocalNames , warnUnusedMatches, newLocalBndrRn , checkUnusedRecordWildcard , checkDupNames, checkDupAndShadowedNames - , checkTupSize , unknownSubordinateErr ) + , unknownSubordinateErr ) import GHC.Rename.HsType import GHC.Builtin.Names import GHC.Types.Name @@ -498,8 +498,7 @@ rnPatAndThen mk (ListPat _ pats) False -> return (ListPat Nothing pats') } rnPatAndThen mk (TuplePat x pats boxed) - = do { liftCps $ checkTupSize (length pats) - ; pats' <- rnLPatsAndThen mk pats + = do { pats' <- rnLPatsAndThen mk pats ; return (TuplePat x pats' boxed) } rnPatAndThen mk (SumPat x pat alt arity) diff --git a/compiler/GHC/Rename/Utils.hs b/compiler/GHC/Rename/Utils.hs index 85dd2566ea..a29a8b6602 100644 --- a/compiler/GHC/Rename/Utils.hs +++ b/compiler/GHC/Rename/Utils.hs @@ -11,7 +11,7 @@ This module contains miscellaneous functions related to renaming. module GHC.Rename.Utils ( checkDupRdrNames, checkShadowedRdrNames, checkDupNames, checkDupAndShadowedNames, dupNamesErr, - checkTupSize, + checkTupSize, checkCTupSize, addFvRn, mapFvRn, mapMaybeFvRn, warnUnusedMatches, warnUnusedTypePatterns, warnUnusedTopBinds, warnUnusedLocalBinds, @@ -57,7 +57,7 @@ import GHC.Driver.Session import GHC.Data.FastString import Control.Monad import Data.List -import GHC.Settings.Constants ( mAX_TUPLE_SIZE ) +import GHC.Settings.Constants ( mAX_TUPLE_SIZE, mAX_CTUPLE_SIZE ) import qualified Data.List.NonEmpty as NE import qualified GHC.LanguageExtensions as LangExt @@ -572,7 +572,9 @@ typeAppErr what (L _ k) <+> quotes (char '@' <> ppr k)) 2 (text "Perhaps you intended to use TypeApplications") -checkTupSize :: Int -> RnM () +-- | Ensure that a boxed or unboxed tuple has arity no larger than +-- 'mAX_TUPLE_SIZE'. +checkTupSize :: Int -> TcM () checkTupSize tup_size | tup_size <= mAX_TUPLE_SIZE = return () @@ -581,6 +583,16 @@ checkTupSize tup_size nest 2 (parens (text "max size is" <+> int mAX_TUPLE_SIZE)), nest 2 (text "Workaround: use nested tuples or define a data type")]) +-- | Ensure that a constraint tuple has arity no larger than 'mAX_CTUPLE_SIZE'. +checkCTupSize :: Int -> TcM () +checkCTupSize tup_size + | tup_size <= mAX_CTUPLE_SIZE + = return () + | otherwise + = addErr (hang (text "Constraint tuple arity too large:" <+> int tup_size + <+> parens (text "max arity =" <+> int mAX_CTUPLE_SIZE)) + 2 (text "Instead, use a nested tuple")) + {- ************************************************************************ |