Vladislav Zavialov pushed to branch wip/int-index/t18725 at Glasgow Haskell Compiler / GHC
Commits:
-
85b10c00
by Alan Zimmerman at 2026-07-31T22:09:47+01:00
-
c9a34a00
by Viktor Dukhovni at 2026-08-02T04:34:17-04:00
-
4f2a21f7
by Andreas Klebinger at 2026-08-02T22:46:46-04:00
-
21e4b89d
by Andreas Klebinger at 2026-08-02T22:46:46-04:00
-
d415f38a
by Alan Zimmerman at 2026-08-02T22:47:27-04:00
-
f938dae0
by Vladislav Zavialov at 2026-08-04T15:22:30+00:00
19 changed files:
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Decls/Overlap.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Stg/Lint.hs
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/ForeignCall.hs
- libraries/ghc-internal/src/GHC/Internal/Ix.hs
- + testsuite/tests/saks/should_compile/T18725a.hs
- testsuite/tests/saks/should_compile/all.T
- + testsuite/tests/saks/should_fail/T18725b.hs
- + testsuite/tests/saks/should_fail/T18725b.stderr
- testsuite/tests/saks/should_fail/all.T
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
Changes:
| ... | ... | @@ -1158,20 +1158,25 @@ ppDerivStrategy mb = |
| 1158 | 1158 | Nothing -> empty
|
| 1159 | 1159 | Just (L _ ds) -> ppr ds
|
| 1160 | 1160 | |
| 1161 | -ppOverlapPragma :: Maybe (LocatedP (OverlapMode (GhcPass p))) -> SDoc
|
|
| 1161 | +ppOverlapPragma :: forall p. IsPass p => Maybe (LocatedA (OverlapMode (GhcPass p))) -> SDoc
|
|
| 1162 | 1162 | ppOverlapPragma mb =
|
| 1163 | 1163 | case mb of
|
| 1164 | 1164 | Nothing -> empty
|
| 1165 | - Just (L _ (NoOverlap s)) -> maybe_stext s "{-# NO_OVERLAP #-}"
|
|
| 1166 | - Just (L _ (Overlappable s)) -> maybe_stext s "{-# OVERLAPPABLE #-}"
|
|
| 1167 | - Just (L _ (Overlapping s)) -> maybe_stext s "{-# OVERLAPPING #-}"
|
|
| 1168 | - Just (L _ (Overlaps s)) -> maybe_stext s "{-# OVERLAPS #-}"
|
|
| 1169 | - Just (L _ (Incoherent s)) -> maybe_stext s "{-# INCOHERENT #-}"
|
|
| 1170 | - Just (L _ (NonCanonical s)) -> maybe_stext s "{-# INCOHERENT #-}" -- No surface syntax for NONCANONICAL yet
|
|
| 1165 | + Just (L _ (NoOverlap s)) -> maybe_stext (stext s) "{-# NO_OVERLAP #-}"
|
|
| 1166 | + Just (L _ (Overlappable s)) -> maybe_stext (stext s) "{-# OVERLAPPABLE #-}"
|
|
| 1167 | + Just (L _ (Overlapping s)) -> maybe_stext (stext s) "{-# OVERLAPPING #-}"
|
|
| 1168 | + Just (L _ (Overlaps s)) -> maybe_stext (stext s) "{-# OVERLAPS #-}"
|
|
| 1169 | + Just (L _ (Incoherent s)) -> maybe_stext (stext s) "{-# INCOHERENT #-}"
|
|
| 1170 | + Just (L _ (NonCanonical s)) -> maybe_stext (stext s) "{-# INCOHERENT #-}" -- No surface syntax for NONCANONICAL yet
|
|
| 1171 | 1171 | where
|
| 1172 | 1172 | maybe_stext NoSourceText alt = text alt
|
| 1173 | 1173 | maybe_stext (SourceText src) _ = ftext src <+> text "#-}"
|
| 1174 | 1174 | |
| 1175 | + stext :: XOverlapMode (GhcPass p) -> SourceText
|
|
| 1176 | + stext s = case (ghcPass @p, s) of
|
|
| 1177 | + (GhcPs, (s,_)) -> s
|
|
| 1178 | + (GhcRn, (s,_)) -> s
|
|
| 1179 | + (GhcTc, s) -> s
|
|
| 1175 | 1180 | |
| 1176 | 1181 | instance (OutputableBndrId p) => Outputable (InstDecl (GhcPass p)) where
|
| 1177 | 1182 | ppr (ClsInstD { cid_inst = decl }) = ppr decl
|
| ... | ... | @@ -1578,7 +1583,7 @@ type instance Anno (FunDep (GhcPass p)) = SrcSpanAnnA |
| 1578 | 1583 | type instance Anno (FamilyResultSig (GhcPass p)) = EpAnnCO
|
| 1579 | 1584 | type instance Anno (FamilyDecl (GhcPass p)) = SrcSpanAnnA
|
| 1580 | 1585 | type instance Anno (InjectivityAnn (GhcPass p)) = EpAnnCO
|
| 1581 | -type instance Anno (CType (GhcPass p)) = SrcSpanAnnP
|
|
| 1586 | +type instance Anno (CType (GhcPass p)) = SrcSpanAnnA
|
|
| 1582 | 1587 | type instance Anno (HsDerivingClause (GhcPass p)) = EpAnnCO
|
| 1583 | 1588 | type instance Anno (DerivClauseTys (GhcPass _)) = SrcSpanAnnA
|
| 1584 | 1589 | type instance Anno (StandaloneKindSig (GhcPass p)) = SrcSpanAnnA
|
| ... | ... | @@ -1593,7 +1598,7 @@ type instance Anno (ClsInstDecl (GhcPass p)) = SrcSpanAnnA |
| 1593 | 1598 | type instance Anno (InstDecl (GhcPass p)) = SrcSpanAnnA
|
| 1594 | 1599 | type instance Anno (DocDecl (GhcPass p)) = SrcSpanAnnA
|
| 1595 | 1600 | type instance Anno (DerivDecl (GhcPass p)) = SrcSpanAnnA
|
| 1596 | -type instance Anno (OverlapMode (GhcPass p)) = SrcSpanAnnP
|
|
| 1601 | +type instance Anno (OverlapMode (GhcPass p)) = SrcSpanAnnA
|
|
| 1597 | 1602 | type instance Anno (DerivStrategy (GhcPass p)) = EpAnnCO
|
| 1598 | 1603 | type instance Anno (DefaultDecl (GhcPass p)) = SrcSpanAnnA
|
| 1599 | 1604 | type instance Anno (ForeignDecl (GhcPass p)) = SrcSpanAnnA
|
| ... | ... | @@ -26,6 +26,8 @@ import GHC.Prelude |
| 26 | 26 | |
| 27 | 27 | import GHC.Hs.Extension
|
| 28 | 28 | |
| 29 | +import GHC.Parser.Annotation ( AnnPragma )
|
|
| 30 | + |
|
| 29 | 31 | import Language.Haskell.Syntax.Decls.Overlap
|
| 30 | 32 | import Language.Haskell.Syntax.Extension
|
| 31 | 33 | |
| ... | ... | @@ -65,7 +67,9 @@ instance NFData OverlapFlag where |
| 65 | 67 | instance Outputable OverlapFlag where
|
| 66 | 68 | ppr flag = ppr (overlapMode flag) <+> pprSafeOverlap (isSafeOverlap flag)
|
| 67 | 69 | |
| 68 | -type instance XOverlapMode (GhcPass _) = SourceText
|
|
| 70 | +type instance XOverlapMode GhcPs = (SourceText, AnnPragma)
|
|
| 71 | +type instance XOverlapMode GhcRn = (SourceText, AnnPragma)
|
|
| 72 | +type instance XOverlapMode GhcTc = SourceText
|
|
| 69 | 73 | |
| 70 | 74 | type instance XXOverlapMode (GhcPass _) = DataConCantHappen
|
| 71 | 75 |
| ... | ... | @@ -1752,7 +1752,7 @@ instance ToHie (RScoped (LocatedAn NoEpAnns (DerivStrategy GhcRn))) where |
| 1752 | 1752 | NewtypeStrategy _ -> []
|
| 1753 | 1753 | ViaStrategy s -> [ toHie (TS (ResolvedScopes [sc]) s) ]
|
| 1754 | 1754 | |
| 1755 | -instance ToHie (LocatedP (OverlapMode GhcRn)) where
|
|
| 1755 | +instance ToHie (LocatedA (OverlapMode GhcRn)) where
|
|
| 1756 | 1756 | toHie (L span _) = locOnly (locA span)
|
| 1757 | 1757 | |
| 1758 | 1758 | instance ToHie (LocatedA (ConDecl GhcRn)) where
|
| ... | ... | @@ -1471,15 +1471,15 @@ inst_decl :: { LInstDecl GhcPs } |
| 1471 | 1471 | (fmap reverse $7)
|
| 1472 | 1472 | (AnnDataDefn [] [] NoEpTok tnewtype tdata (epTok $2) dcolon twhere oc cc NoEpTok)}}
|
| 1473 | 1473 | |
| 1474 | -overlap_pragma :: { Maybe (LocatedP (OverlapMode GhcPs)) }
|
|
| 1475 | - : '{-# OVERLAPPABLE' '#-}' {% fmap Just $ amsr (sLL $1 $> (Overlappable (getOVERLAPPABLE_PRAGs $1)))
|
|
| 1476 | - (AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn) }
|
|
| 1477 | - | '{-# OVERLAPPING' '#-}' {% fmap Just $ amsr (sLL $1 $> (Overlapping (getOVERLAPPING_PRAGs $1)))
|
|
| 1478 | - (AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn) }
|
|
| 1479 | - | '{-# OVERLAPS' '#-}' {% fmap Just $ amsr (sLL $1 $> (Overlaps (getOVERLAPS_PRAGs $1)))
|
|
| 1480 | - (AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn) }
|
|
| 1481 | - | '{-# INCOHERENT' '#-}' {% fmap Just $ amsr (sLL $1 $> (Incoherent (getINCOHERENT_PRAGs $1)))
|
|
| 1482 | - (AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn) }
|
|
| 1474 | +overlap_pragma :: { Maybe (LocatedA (OverlapMode GhcPs)) }
|
|
| 1475 | + : '{-# OVERLAPPABLE' '#-}' {% fmap Just $ amsA' (sLL $1 $> (Overlappable (getOVERLAPPABLE_PRAGs $1,
|
|
| 1476 | + AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn))) }
|
|
| 1477 | + | '{-# OVERLAPPING' '#-}' {% fmap Just $ amsA' (sLL $1 $> (Overlapping (getOVERLAPPING_PRAGs $1,
|
|
| 1478 | + AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn))) }
|
|
| 1479 | + | '{-# OVERLAPS' '#-}' {% fmap Just $ amsA' (sLL $1 $> (Overlaps (getOVERLAPS_PRAGs $1,
|
|
| 1480 | + AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn))) }
|
|
| 1481 | + | '{-# INCOHERENT' '#-}' {% fmap Just $ amsA' (sLL $1 $> (Incoherent (getINCOHERENT_PRAGs $1,
|
|
| 1482 | + AnnPragma (glR $1) (epTok $2) noAnn noAnn noAnn noAnn noAnn))) }
|
|
| 1483 | 1483 | | {- empty -} { Nothing }
|
| 1484 | 1484 | |
| 1485 | 1485 | deriv_strategy_no_via :: { LDerivStrategy GhcPs }
|
| ... | ... | @@ -1707,15 +1707,17 @@ datafam_inst_hdr :: { Located (Maybe (LHsContext GhcPs), HsOuterFamEqnTyVarBndrs |
| 1707 | 1707 | | type { sL1 $1 (Nothing, mkHsOuterImplicit, $1) }
|
| 1708 | 1708 | |
| 1709 | 1709 | |
| 1710 | -capi_ctype :: { Maybe (LocatedP (CType GhcPs)) }
|
|
| 1710 | +capi_ctype :: { Maybe (LocatedA (CType GhcPs)) }
|
|
| 1711 | 1711 | capi_ctype : '{-# CTYPE' STRING STRING '#-}'
|
| 1712 | - {% fmap Just $ amsr (sLL $1 $> (mkCType (getCTYPEs $1) (getSTRINGs $3) (Just (Header (getSTRINGs $2) (getSTRING $2)))
|
|
| 1713 | - (getSTRING $3)))
|
|
| 1714 | - (AnnPragma (glR $1) (epTok $4) noAnn (glR $2) (glR $3) noAnn noAnn) }
|
|
| 1712 | + {% fmap Just $ amsA' (sLL $1 $> (mkCType (getCTYPEs $1) (getSTRINGs $3)
|
|
| 1713 | + (AnnPragma (glR $1) (epTok $4) noAnn (glR $2) (glR $3) noAnn noAnn)
|
|
| 1714 | + (Just (Header (getSTRINGs $2) (getSTRING $2)))
|
|
| 1715 | + (getSTRING $3)))}
|
|
| 1715 | 1716 | |
| 1716 | 1717 | | '{-# CTYPE' STRING '#-}'
|
| 1717 | - {% fmap Just $ amsr (sLL $1 $> (mkCType (getCTYPEs $1) (getSTRINGs $2) Nothing (getSTRING $2)))
|
|
| 1718 | - (AnnPragma (glR $1) (epTok $3) noAnn noAnn (glR $2) noAnn noAnn) }
|
|
| 1718 | + {% fmap Just $ amsA' (sLL $1 $> (mkCType (getCTYPEs $1) (getSTRINGs $2)
|
|
| 1719 | + (AnnPragma (glR $1) (epTok $3) noAnn noAnn (glR $2) noAnn noAnn)
|
|
| 1720 | + Nothing (getSTRING $2)))}
|
|
| 1719 | 1721 | |
| 1720 | 1722 | | { Nothing }
|
| 1721 | 1723 |
| ... | ... | @@ -229,7 +229,7 @@ mkClassDecl loc' (L _ (mcxt, tycl_hdr)) fds where_cls layout annsIn |
| 229 | 229 | mkTyData :: SrcSpan
|
| 230 | 230 | -> Bool
|
| 231 | 231 | -> NewOrData
|
| 232 | - -> Maybe (LocatedP (CType GhcPs))
|
|
| 232 | + -> Maybe (LocatedA (CType GhcPs))
|
|
| 233 | 233 | -> Located (Maybe (LHsContext GhcPs), LHsType GhcPs)
|
| 234 | 234 | -> Maybe (LHsKind GhcPs)
|
| 235 | 235 | -> [LConDecl GhcPs]
|
| ... | ... | @@ -251,7 +251,7 @@ mkTyData loc' is_type_data new_or_data cType (L _ (mcxt, tycl_hdr)) |
| 251 | 251 | tcdDataDefn = defn,
|
| 252 | 252 | tcdModifiers = [] })) }
|
| 253 | 253 | |
| 254 | -mkDataDefn :: Maybe (LocatedP (CType GhcPs))
|
|
| 254 | +mkDataDefn :: Maybe (LocatedA (CType GhcPs))
|
|
| 255 | 255 | -> Maybe (LHsContext GhcPs)
|
| 256 | 256 | -> Maybe (LHsKind GhcPs)
|
| 257 | 257 | -> DataDefnCons (LConDecl GhcPs)
|
| ... | ... | @@ -326,7 +326,7 @@ mkTyFamInstEqn loc bndrs lhs rhs annEq |
| 326 | 326 | |
| 327 | 327 | mkDataFamInst :: SrcSpan
|
| 328 | 328 | -> NewOrData
|
| 329 | - -> Maybe (LocatedP (CType GhcPs))
|
|
| 329 | + -> Maybe (LocatedA (CType GhcPs))
|
|
| 330 | 330 | -> (Maybe ( LHsContext GhcPs), HsOuterFamEqnTyVarBndrs GhcPs
|
| 331 | 331 | , LHsType GhcPs)
|
| 332 | 332 | -> Maybe (LHsKind GhcPs)
|
| ... | ... | @@ -92,6 +92,7 @@ be ill-typed in Core. But it must still be well-kinded! |
| 92 | 92 | -}
|
| 93 | 93 | |
| 94 | 94 | {-# LANGUAGE TypeFamilies #-}
|
| 95 | +{-# LANGUAGE PatternSynonyms #-}
|
|
| 95 | 96 | |
| 96 | 97 | module GHC.Stg.Lint ( lintStgTopBindings ) where
|
| 97 | 98 | |
| ... | ... | @@ -123,6 +124,7 @@ import GHC.Unit.Module ( Module ) |
| 123 | 124 | import GHC.Data.Bag ( Bag, emptyBag, isEmptyBag, snocBag, bagToList )
|
| 124 | 125 | |
| 125 | 126 | import Control.Monad
|
| 127 | +import GHC.Exts ( oneShot )
|
|
| 126 | 128 | import GHC.Core.Multiplicity (scaledThing)
|
| 127 | 129 | import GHC.Settings (Platform)
|
| 128 | 130 | import GHC.Core.TyCon (primRepCompatible, primRepsCompatible)
|
| ... | ... | @@ -432,17 +434,40 @@ The Lint monad |
| 432 | 434 | ************************************************************************
|
| 433 | 435 | -}
|
| 434 | 436 | |
| 435 | -newtype LintM a = LintM
|
|
| 436 | - { unLintM :: Module
|
|
| 437 | - -> LintFlags
|
|
| 438 | - -> DiagOpts -- Diagnostic options
|
|
| 439 | - -> StgPprOpts -- Pretty-printing options
|
|
| 437 | +data LintReaderEnv = LintReaderEnv
|
|
| 438 | + { le_mod :: !Module
|
|
| 439 | + , le_flags :: !LintFlags
|
|
| 440 | + , le_diag_opts :: !DiagOpts -- Diagnostic options
|
|
| 441 | + , le_ppr_opts :: !StgPprOpts -- Pretty-printing options
|
|
| 442 | + }
|
|
| 443 | + |
|
| 444 | +newtype LintM a = LintM'
|
|
| 445 | + { unLintM :: LintReaderEnv
|
|
| 440 | 446 | -> [LintLocInfo] -- Locations
|
| 441 | 447 | -> IdSet -- Local vars in scope
|
| 442 | 448 | -> Bag SDoc -- Error messages so far
|
| 443 | 449 | -> (a, Bag SDoc) -- Result and error messages (if any)
|
| 444 | 450 | }
|
| 445 | - deriving (Functor)
|
|
| 451 | +instance Functor LintM where
|
|
| 452 | + fmap f (LintM m) =
|
|
| 453 | + LintM $ \env loc scope errs ->
|
|
| 454 | + case m env loc scope errs of
|
|
| 455 | + (a, errs') -> (f a, errs')
|
|
| 456 | + |
|
| 457 | +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad
|
|
| 458 | +{-# COMPLETE LintM #-}
|
|
| 459 | +pattern LintM :: (LintReaderEnv
|
|
| 460 | + -> [LintLocInfo]
|
|
| 461 | + -> IdSet
|
|
| 462 | + -> Bag SDoc
|
|
| 463 | + -> (a, Bag SDoc))
|
|
| 464 | + -> LintM a
|
|
| 465 | +pattern LintM m <- LintM' m
|
|
| 466 | + where
|
|
| 467 | + LintM m = LintM' $ oneShot (\env -> oneShot
|
|
| 468 | + (\loc -> oneShot
|
|
| 469 | + (\scope -> oneShot
|
|
| 470 | + (\errs -> m env loc scope errs))))
|
|
| 446 | 471 | |
| 447 | 472 | data LintFlags = LintFlags { lf_unarised :: !Bool
|
| 448 | 473 | , lf_platform :: !Platform
|
| ... | ... | @@ -473,14 +498,16 @@ pp_binders bs |
| 473 | 498 | |
| 474 | 499 | initL :: Platform -> DiagOpts -> Module -> Bool -> StgPprOpts -> IdSet -> LintM a -> Maybe SDoc
|
| 475 | 500 | initL platform diag_opts this_mod unarised opts locals (LintM m) = do
|
| 476 | - let (_, errs) = m this_mod (LintFlags unarised platform) diag_opts opts [] locals emptyBag
|
|
| 501 | + let !flags = LintFlags unarised platform
|
|
| 502 | + !env = LintReaderEnv this_mod flags diag_opts opts
|
|
| 503 | + (_, errs) = m env [] locals emptyBag
|
|
| 477 | 504 | if isEmptyBag errs then
|
| 478 | 505 | Nothing
|
| 479 | 506 | else
|
| 480 | 507 | Just (vcat (punctuate blankLine (bagToList errs)))
|
| 481 | 508 | |
| 482 | 509 | instance Applicative LintM where
|
| 483 | - pure a = LintM $ \_mod _lf _df _opts _loc _scope errs -> (a, errs)
|
|
| 510 | + pure a = LintM $ \_env _loc _scope errs -> (a, errs)
|
|
| 484 | 511 | (<*>) = ap
|
| 485 | 512 | (*>) = thenL_
|
| 486 | 513 | |
| ... | ... | @@ -489,14 +516,14 @@ instance Monad LintM where |
| 489 | 516 | (>>) = (*>)
|
| 490 | 517 | |
| 491 | 518 | thenL :: LintM a -> (a -> LintM b) -> LintM b
|
| 492 | -thenL m k = LintM $ \mod lf diag_opts opts loc scope errs
|
|
| 493 | - -> case unLintM m mod lf diag_opts opts loc scope errs of
|
|
| 494 | - (r, errs') -> unLintM (k r) mod lf diag_opts opts loc scope errs'
|
|
| 519 | +thenL m k = LintM $ \env loc scope errs
|
|
| 520 | + -> case unLintM m env loc scope errs of
|
|
| 521 | + (r, errs') -> unLintM (k r) env loc scope errs'
|
|
| 495 | 522 | |
| 496 | 523 | thenL_ :: LintM a -> LintM b -> LintM b
|
| 497 | -thenL_ m k = LintM $ \mod lf diag_opts opts loc scope errs
|
|
| 498 | - -> case unLintM m mod lf diag_opts opts loc scope errs of
|
|
| 499 | - (_, errs') -> unLintM k mod lf diag_opts opts loc scope errs'
|
|
| 524 | +thenL_ m k = LintM $ \env loc scope errs
|
|
| 525 | + -> case unLintM m env loc scope errs of
|
|
| 526 | + (_, errs') -> unLintM k env loc scope errs'
|
|
| 500 | 527 | |
| 501 | 528 | checkL :: Bool -> SDoc -> LintM ()
|
| 502 | 529 | checkL True _ = return ()
|
| ... | ... | @@ -525,7 +552,8 @@ checkPostUnariseId id |
| 525 | 552 | id_ty = idType id
|
| 526 | 553 | |
| 527 | 554 | addErrL :: SDoc -> LintM ()
|
| 528 | -addErrL msg = LintM $ \_mod _lf df _opts loc _scope errs -> ((), addErr df errs msg loc)
|
|
| 555 | +addErrL msg = LintM $ \LintReaderEnv{le_diag_opts = df} loc _scope errs
|
|
| 556 | + -> ((), addErr df errs msg loc)
|
|
| 529 | 557 | |
| 530 | 558 | addErr :: DiagOpts -> Bag SDoc -> SDoc -> [LintLocInfo] -> Bag SDoc
|
| 531 | 559 | addErr diag_opts errs_so_far msg locs
|
| ... | ... | @@ -537,23 +565,23 @@ addErr diag_opts errs_so_far msg locs |
| 537 | 565 | mk_msg [] = msg
|
| 538 | 566 | |
| 539 | 567 | addLoc :: LintLocInfo -> LintM a -> LintM a
|
| 540 | -addLoc extra_loc m = LintM $ \mod lf diag_opts opts loc scope errs
|
|
| 541 | - -> unLintM m mod lf diag_opts opts (extra_loc:loc) scope errs
|
|
| 568 | +addLoc extra_loc m = LintM $ \env loc scope errs
|
|
| 569 | + -> unLintM m env (extra_loc:loc) scope errs
|
|
| 542 | 570 | |
| 543 | 571 | addInScopeVars :: [Id] -> LintM a -> LintM a
|
| 544 | -addInScopeVars ids m = LintM $ \mod lf diag_opts opts loc scope errs
|
|
| 572 | +addInScopeVars ids m = LintM $ \env loc scope errs
|
|
| 545 | 573 | -> let
|
| 546 | 574 | new_set = mkVarSet ids
|
| 547 | - in unLintM m mod lf diag_opts opts loc (scope `unionVarSet` new_set) errs
|
|
| 575 | + in unLintM m env loc (scope `unionVarSet` new_set) errs
|
|
| 548 | 576 | |
| 549 | 577 | getLintFlags :: LintM LintFlags
|
| 550 | -getLintFlags = LintM $ \_mod lf _df _opts _loc _scope errs -> (lf, errs)
|
|
| 578 | +getLintFlags = LintM $ \LintReaderEnv{le_flags = lf} _loc _scope errs -> (lf, errs)
|
|
| 551 | 579 | |
| 552 | 580 | getStgPprOpts :: LintM StgPprOpts
|
| 553 | -getStgPprOpts = LintM $ \_mod _lf _df opts _loc _scope errs -> (opts, errs)
|
|
| 581 | +getStgPprOpts = LintM $ \LintReaderEnv{le_ppr_opts = opts} _loc _scope errs -> (opts, errs)
|
|
| 554 | 582 | |
| 555 | 583 | checkInScope :: Id -> LintM ()
|
| 556 | -checkInScope id = LintM $ \mod _lf diag_opts _opts loc scope errs
|
|
| 584 | +checkInScope id = LintM $ \LintReaderEnv{le_mod = mod, le_diag_opts = diag_opts} loc scope errs
|
|
| 557 | 585 | -> if nameIsLocalOrFrom mod (idName id) && not (id `elemVarSet` scope) then
|
| 558 | 586 | ((), addErr diag_opts errs (hsep [ppr id, dcolon, ppr (idType id),
|
| 559 | 587 | text "is out of scope"]) loc)
|
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
|
| 12 | 12 | |
| 13 | 13 | -- | Handles @deriving@ clauses on @data@ declarations.
|
| 14 | -module GHC.Tc.Deriv ( tcDeriving, DerivInfo(..) ) where
|
|
| 14 | +module GHC.Tc.Deriv ( tcDeriving, DerivInfo(..), tcOverlapMode ) where
|
|
| 15 | 15 | |
| 16 | 16 | import GHC.Prelude
|
| 17 | 17 | |
| ... | ... | @@ -776,12 +776,12 @@ deriveStandalone (L loc (DerivDecl (warn, _) deriv_ty mb_lderiv_strat overlap_mo |
| 776 | 776 | |
| 777 | 777 | tcOverlapMode :: OverlapMode GhcRn -> OverlapMode GhcTc
|
| 778 | 778 | tcOverlapMode = \case
|
| 779 | - NoOverlap s -> NoOverlap s
|
|
| 780 | - Overlappable s -> Overlappable s
|
|
| 781 | - Overlapping s -> Overlapping s
|
|
| 782 | - Overlaps s -> Overlaps s
|
|
| 783 | - Incoherent s -> Incoherent s
|
|
| 784 | - NonCanonical s -> NonCanonical s
|
|
| 779 | + NoOverlap s -> NoOverlap (fst s)
|
|
| 780 | + Overlappable s -> Overlappable (fst s)
|
|
| 781 | + Overlapping s -> Overlapping (fst s)
|
|
| 782 | + Overlaps s -> Overlaps (fst s)
|
|
| 783 | + Incoherent s -> Incoherent (fst s)
|
|
| 784 | + NonCanonical s -> NonCanonical (fst s)
|
|
| 785 | 785 | |
| 786 | 786 | -- Typecheck the type in a standalone deriving declaration.
|
| 787 | 787 | --
|
| ... | ... | @@ -558,7 +558,7 @@ tcClsInstDecl (L loc (ClsInstDecl { cid_poly_ty = hs_ty |
| 558 | 558 | -- Dfun location is that of instance *header*
|
| 559 | 559 | |
| 560 | 560 | ; let warn = fmap unLoc lwarn
|
| 561 | - ; ispec <- newClsInst (fmap unLoc overlap_mode) dfun_name
|
|
| 561 | + ; ispec <- newClsInst (fmap (tcOverlapMode . unLoc) overlap_mode) dfun_name
|
|
| 562 | 562 | tyvars theta clas inst_tys warn
|
| 563 | 563 | |
| 564 | 564 | ; let inst_binds = InstBindings
|
| ... | ... | @@ -72,7 +72,6 @@ import GHC.Rename.Utils( mkRnSyntaxExpr ) |
| 72 | 72 | import GHC.Types.Id.Make( mkDictFunId )
|
| 73 | 73 | import GHC.Types.Arity ( Arity, VisArity )
|
| 74 | 74 | import GHC.Types.Basic ( TypeOrKind(..) )
|
| 75 | -import GHC.Types.SourceText
|
|
| 76 | 75 | import GHC.Types.SrcLoc as SrcLoc
|
| 77 | 76 | import GHC.Types.Var.Env
|
| 78 | 77 | import GHC.Types.Id
|
| ... | ... | @@ -912,7 +911,7 @@ hasFixedRuntimeRepRes std_nm user_expr ty = mapM_ do_check mb_arity |
| 912 | 911 | ************************************************************************
|
| 913 | 912 | -}
|
| 914 | 913 | |
| 915 | -getOverlapFlag :: Maybe (OverlapMode (GhcPass p)) -- User pragma if any
|
|
| 914 | +getOverlapFlag :: Maybe (OverlapMode GhcTc) -- User pragma if any
|
|
| 916 | 915 | -> TcM OverlapFlag
|
| 917 | 916 | -- Construct the OverlapFlag from the global module flags,
|
| 918 | 917 | -- but if the overlap_mode argument is (Just m),
|
| ... | ... | @@ -936,9 +935,9 @@ getOverlapFlag overlap_mode_prag |
| 936 | 935 | |
| 937 | 936 | overlap_mode
|
| 938 | 937 | | Just m <- overlap_mode_prag = m
|
| 939 | - | incoherent_ok = Incoherent NoSourceText
|
|
| 940 | - | overlap_ok = Overlaps NoSourceText
|
|
| 941 | - | otherwise = NoOverlap NoSourceText
|
|
| 938 | + | incoherent_ok = Incoherent noAnn
|
|
| 939 | + | overlap_ok = Overlaps noAnn
|
|
| 940 | + | otherwise = NoOverlap noAnn
|
|
| 942 | 941 | |
| 943 | 942 | -- final_overlap_mode: the `-fspecialise-incoherents` flag controls the
|
| 944 | 943 | -- meaning of the `Incoherent` overlap mode: as either an Incoherent overlap
|
| ... | ... | @@ -964,7 +963,7 @@ tcGetInsts :: TcM [ClsInst] |
| 964 | 963 | -- Gets the local class instances.
|
| 965 | 964 | tcGetInsts = fmap tcg_insts getGblEnv
|
| 966 | 965 | |
| 967 | -newClsInst :: Maybe (OverlapMode (GhcPass p)) -- User pragma
|
|
| 966 | +newClsInst :: Maybe (OverlapMode GhcTc) -- User pragma
|
|
| 968 | 967 | -> Name -> [TyVar] -> ThetaType
|
| 969 | 968 | -> Class -> [Type] -> Maybe (WarningTxt GhcRn) -> TcM ClsInst
|
| 970 | 969 | newClsInst overlap_mode dfun_name tvs theta clas tys warn
|
| ... | ... | @@ -356,10 +356,10 @@ cvtDec (InstanceD o ctxt ty decs) |
| 356 | 356 | where
|
| 357 | 357 | overlap pragma =
|
| 358 | 358 | case pragma of
|
| 359 | - TH.Overlaps -> Hs.Overlaps (SourceText $ fsLit "{-# OVERLAPS")
|
|
| 360 | - TH.Overlappable -> Hs.Overlappable (SourceText $ fsLit "{-# OVERLAPPABLE")
|
|
| 361 | - TH.Overlapping -> Hs.Overlapping (SourceText $ fsLit "{-# OVERLAPPING")
|
|
| 362 | - TH.Incoherent -> Hs.Incoherent (SourceText $ fsLit "{-# INCOHERENT")
|
|
| 359 | + TH.Overlaps -> Hs.Overlaps (SourceText $ fsLit "{-# OVERLAPS", noAnn)
|
|
| 360 | + TH.Overlappable -> Hs.Overlappable (SourceText $ fsLit "{-# OVERLAPPABLE", noAnn)
|
|
| 361 | + TH.Overlapping -> Hs.Overlapping (SourceText $ fsLit "{-# OVERLAPPING", noAnn)
|
|
| 362 | + TH.Incoherent -> Hs.Incoherent (SourceText $ fsLit "{-# INCOHERENT", noAnn)
|
|
| 363 | 363 | |
| 364 | 364 | |
| 365 | 365 |
| ... | ... | @@ -109,6 +109,7 @@ import Data.Data (Data) |
| 109 | 109 | import Data.Functor ((<&>))
|
| 110 | 110 | |
| 111 | 111 | import Control.DeepSeq (NFData(..))
|
| 112 | +import GHC.Parser.Annotation (AnnPragma, noAnn)
|
|
| 112 | 113 | |
| 113 | 114 | {-
|
| 114 | 115 | ************************************************************************
|
| ... | ... | @@ -213,11 +214,11 @@ instance Outputable CCallSpec where |
| 213 | 214 | |
| 214 | 215 | defaultCType :: String -> CType (GhcPass p)
|
| 215 | 216 | defaultCType =
|
| 216 | - CType (CTypeGhc NoSourceText NoSourceText) Nothing . packHText
|
|
| 217 | + CType (CTypeGhc NoSourceText NoSourceText noAnn) Nothing . packHText
|
|
| 217 | 218 | |
| 218 | -mkCType :: SourceText -> SourceText -> Maybe (Header (GhcPass p)) -> HText -> CType (GhcPass p)
|
|
| 219 | -mkCType x y m =
|
|
| 220 | - CType (CTypeGhc x y) m
|
|
| 219 | +mkCType :: SourceText -> SourceText -> AnnPragma -> Maybe (Header (GhcPass p)) -> HText -> CType (GhcPass p)
|
|
| 220 | +mkCType x y ann m =
|
|
| 221 | + CType (CTypeGhc x y ann) m
|
|
| 221 | 222 | |
| 222 | 223 | typeCheckCType :: CType GhcRn -> CType GhcTc
|
| 223 | 224 | typeCheckCType (CType x y z) = CType x (typeCheckHeader <$> y) z
|
| ... | ... | @@ -302,6 +303,7 @@ data StaticTargetGhc = StaticTargetGhc |
| 302 | 303 | data CTypeGhc = CTypeGhc
|
| 303 | 304 | { cTypeSourceText :: SourceText
|
| 304 | 305 | , cTypeOtherText :: SourceText
|
| 306 | + , cTypeAnn :: AnnPragma
|
|
| 305 | 307 | }
|
| 306 | 308 | deriving (Data, Eq)
|
| 307 | 309 | |
| ... | ... | @@ -349,6 +351,7 @@ instance Binary CTypeGhc where |
| 349 | 351 | return $ CTypeGhc
|
| 350 | 352 | { cTypeSourceText = str1
|
| 351 | 353 | , cTypeOtherText = str2
|
| 354 | + , cTypeAnn = noAnn
|
|
| 352 | 355 | }
|
| 353 | 356 | |
| 354 | 357 | instance NFData StaticTargetGhc where
|
| ... | ... | @@ -142,7 +142,7 @@ For 1-d, 2-d, and 3-d arrays of Int we have specialised instances to avoid this. |
| 142 | 142 | |
| 143 | 143 | Note [Out-of-bounds error messages]
|
| 144 | 144 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 145 | -The default method for 'index' generates hoplelessIndexError, because
|
|
| 145 | +The default method for 'index' generates 'hopelessIndexError', because
|
|
| 146 | 146 | Ix doesn't have Show as a superclass. For particular base types we
|
| 147 | 147 | can do better, so we override the default method for index.
|
| 148 | 148 |
| 1 | +{-# LANGUAGE ExplicitForAll, KindSignatures, StandaloneKindSignatures,
|
|
| 2 | + DataKinds, GADTs #-}
|
|
| 3 | + |
|
| 4 | +module T18725a where
|
|
| 5 | + |
|
| 6 | +import Data.Kind (Type)
|
|
| 7 | + |
|
| 8 | +type U :: Type
|
|
| 9 | +data U where P :: forall u. E u -> U
|
|
| 10 | +data E (u :: U) |
| ... | ... | @@ -35,6 +35,7 @@ test('T16726', normal, compile, ['']) |
| 35 | 35 | test('T16731', normal, compile, [''])
|
| 36 | 36 | test('T16721', normal, ghci_script, ['T16721.script'])
|
| 37 | 37 | test('T16756a', normal, compile, [''])
|
| 38 | +test('T18725a', normal, compile, [''])
|
|
| 38 | 39 | |
| 39 | 40 | test('saks027', req_th, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
|
| 40 | 41 | test('saks028', req_th, compile, [''])
|
| 1 | +{-# LANGUAGE ExplicitForAll, KindSignatures, StandaloneKindSignatures,
|
|
| 2 | + DataKinds, GADTs #-}
|
|
| 3 | + |
|
| 4 | +module T18725b where
|
|
| 5 | + |
|
| 6 | +-- type U :: Type -- Rejected without the sig
|
|
| 7 | +data U where P :: forall u. E u -> U
|
|
| 8 | +data E (u :: U) |
| 1 | +T18725b.hs:8:14: error: [GHC-85413]
|
|
| 2 | + • Type constructor ‘U’ cannot be used here
|
|
| 3 | + (it is defined and used in the same recursive group)
|
|
| 4 | + • In the kind ‘U’
|
|
| 5 | + In the data type declaration for ‘E’
|
|
| 6 | + |
| ... | ... | @@ -38,3 +38,5 @@ test('T18863d', normal, compile_fail, ['']) |
| 38 | 38 | test('T20916', normal, compile_fail, [''])
|
| 39 | 39 | test('saks018-fail', normal, compile_fail, [''])
|
| 40 | 40 | test('saks021-fail', normal, compile_fail, [''])
|
| 41 | +test('T18725b', normal, compile_fail, [''])
|
|
| 42 | + |
| ... | ... | @@ -2246,40 +2246,40 @@ instance ExactPrint (TyFamInstDecl GhcPs) where |
| 2246 | 2246 | |
| 2247 | 2247 | -- ---------------------------------------------------------------------
|
| 2248 | 2248 | |
| 2249 | -instance Typeable p => ExactPrint (LocatedP (OverlapMode (GhcPass p))) where
|
|
| 2250 | - getAnnotationEntry = entryFromLocatedA
|
|
| 2251 | - setAnnotationAnchor = setAnchorAn
|
|
| 2249 | +instance ExactPrint (OverlapMode GhcPs) where
|
|
| 2250 | + getAnnotationEntry _ = NoEntryVal
|
|
| 2251 | + setAnnotationAnchor a _ _ _ = a
|
|
| 2252 | 2252 | |
| 2253 | 2253 | -- NOTE: NoOverlap is only used in the typechecker
|
| 2254 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (NoOverlap src)) = do
|
|
| 2254 | + exact (NoOverlap (src, AnnPragma o c s l1 l2 t m)) = do
|
|
| 2255 | 2255 | o' <- markAnnOpen'' o src "{-# NO_OVERLAP"
|
| 2256 | 2256 | c' <- markEpToken c
|
| 2257 | - return (L (EpAnn l (AnnPragma o' c' s l1 l2 t m) cs) (NoOverlap src))
|
|
| 2257 | + return (NoOverlap (src, AnnPragma o' c' s l1 l2 t m))
|
|
| 2258 | 2258 | |
| 2259 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (Overlappable src)) = do
|
|
| 2259 | + exact (Overlappable (src, AnnPragma o c s l1 l2 t m)) = do
|
|
| 2260 | 2260 | o' <- markAnnOpen'' o src "{-# OVERLAPPABLE"
|
| 2261 | 2261 | c' <- markEpToken c
|
| 2262 | - return (L (EpAnn l (AnnPragma o' c' s l1 l2 t m) cs) (Overlappable src))
|
|
| 2262 | + return (Overlappable (src, AnnPragma o' c' s l1 l2 t m))
|
|
| 2263 | 2263 | |
| 2264 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (Overlapping src)) = do
|
|
| 2264 | + exact (Overlapping (src, AnnPragma o c s l1 l2 t m)) = do
|
|
| 2265 | 2265 | o' <- markAnnOpen'' o src "{-# OVERLAPPING"
|
| 2266 | 2266 | c' <- markEpToken c
|
| 2267 | - return (L (EpAnn l (AnnPragma o' c' s l1 l2 t m) cs) (Overlapping src))
|
|
| 2267 | + return (Overlapping (src, AnnPragma o' c' s l1 l2 t m))
|
|
| 2268 | 2268 | |
| 2269 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (Overlaps src)) = do
|
|
| 2269 | + exact (Overlaps (src, AnnPragma o c s l1 l2 t m)) = do
|
|
| 2270 | 2270 | o' <- markAnnOpen'' o src "{-# OVERLAPS"
|
| 2271 | 2271 | c' <- markEpToken c
|
| 2272 | - return (L (EpAnn l (AnnPragma o' c' s l1 l2 t m) cs) (Overlaps src))
|
|
| 2272 | + return (Overlaps (src, AnnPragma o' c' s l1 l2 t m))
|
|
| 2273 | 2273 | |
| 2274 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (Incoherent src)) = do
|
|
| 2274 | + exact (Incoherent (src, AnnPragma o c s l1 l2 t m)) = do
|
|
| 2275 | 2275 | o' <- markAnnOpen'' o src "{-# INCOHERENT"
|
| 2276 | 2276 | c' <- markEpToken c
|
| 2277 | - return (L (EpAnn l (AnnPragma o' c' s l1 l2 t m) cs) (Incoherent src))
|
|
| 2277 | + return (Incoherent (src, AnnPragma o' c' s l1 l2 t m))
|
|
| 2278 | 2278 | |
| 2279 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (NonCanonical src)) = do
|
|
| 2279 | + exact (NonCanonical (src, AnnPragma o c s l1 l2 t m)) = do
|
|
| 2280 | 2280 | o' <- markAnnOpen'' o src "{-# INCOHERENT"
|
| 2281 | 2281 | c' <- markEpToken c
|
| 2282 | - return (L (EpAnn l (AnnPragma o' c' s l1 l2 t m) cs) (Incoherent src))
|
|
| 2282 | + return (Incoherent (src, AnnPragma o' c' s l1 l2 t m))
|
|
| 2283 | 2283 | |
| 2284 | 2284 | -- ---------------------------------------------------------------------
|
| 2285 | 2285 | |
| ... | ... | @@ -4401,13 +4401,14 @@ instance ExactPrint t => ExactPrint (HsModifierOf t GhcPs) where |
| 4401 | 4401 | |
| 4402 | 4402 | -- ---------------------------------------------------------------------
|
| 4403 | 4403 | |
| 4404 | -instance Typeable p => ExactPrint (LocatedP (CType (GhcPass p))) where
|
|
| 4405 | - getAnnotationEntry = entryFromLocatedA
|
|
| 4406 | - setAnnotationAnchor = setAnchorAn
|
|
| 4404 | +instance Typeable p => ExactPrint (CType (GhcPass p)) where
|
|
| 4405 | + getAnnotationEntry _ = NoEntryVal
|
|
| 4406 | + setAnnotationAnchor a _ _ _ = a
|
|
| 4407 | 4407 | |
| 4408 | - exact (L (EpAnn l (AnnPragma o c s l1 l2 t m) cs) (CType ext mh ct)) = do
|
|
| 4408 | + exact (CType ext mh ct) = do
|
|
| 4409 | 4409 | let stp = cTypeSourceText ext
|
| 4410 | 4410 | stct = cTypeOtherText ext
|
| 4411 | + AnnPragma o c s l1 l2 t m = cTypeAnn ext
|
|
| 4411 | 4412 | o' <- markAnnOpen'' o stp "{-# CTYPE"
|
| 4412 | 4413 | l1' <- case mh of
|
| 4413 | 4414 | Nothing -> return l1
|
| ... | ... | @@ -4415,7 +4416,7 @@ instance Typeable p => ExactPrint (LocatedP (CType (GhcPass p))) where |
| 4415 | 4416 | printStringAtAA l1 (toSourceTextWithSuffix srcH "" "")
|
| 4416 | 4417 | l2' <- printStringAtAA l2 (toSourceTextWithSuffix stct (unpackHText ct) "")
|
| 4417 | 4418 | c' <- markEpToken c
|
| 4418 | - return (L (EpAnn l (AnnPragma o' c' s l1' l2' t m) cs) (CType ext mh ct))
|
|
| 4419 | + return (CType (ext { cTypeAnn = AnnPragma o' c' s l1' l2' t m }) mh ct)
|
|
| 4419 | 4420 | |
| 4420 | 4421 | -- ---------------------------------------------------------------------
|
| 4421 | 4422 |
| ... | ... | @@ -836,8 +836,8 @@ type instance Anno (FamilyResultSig DocNameI) = EpAnn NoEpAnns |
| 836 | 836 | type instance Anno (HsOuterTyVarBndrs Specificity DocNameI) = SrcSpanAnnA
|
| 837 | 837 | type instance Anno (HsSigType DocNameI) = SrcSpanAnnA
|
| 838 | 838 | type instance Anno (BooleanFormula DocNameI) = SrcSpanAnnBF
|
| 839 | -type instance Anno (OverlapMode DocNameI) = EpAnn AnnPragma
|
|
| 840 | -type instance Anno (CType DocNameI) = EpAnn AnnPragma
|
|
| 839 | +type instance Anno (OverlapMode DocNameI) = SrcSpanAnnA
|
|
| 840 | +type instance Anno (CType DocNameI) = SrcSpanAnnA
|
|
| 841 | 841 | type instance Anno (Header DocNameI) = EpAnn AnnPragma
|
| 842 | 842 | type instance Anno (HsModifierOf (LocatedA (HsType DocNameI)) DocNameI) = SrcSpanAnnA
|
| 843 | 843 | type instance Anno (HsContextDetails DocNameI a) = SrcSpanAnnA
|