Alan Zimmerman pushed to branch wip/az/epa-tidy-locatedxxx-22 at Glasgow Haskell Compiler / GHC

Commits:

29 changed files:

Changes:

  • changelog.d/27556
    1
    +section: compiler
    
    2
    +synopsis: Remove a too strict assert in coreprep; fixes a bug where debug builds
    
    3
    +    of GHC would fail to compile correctly optimized programs.
    
    4
    +mrs: !16558
    
    5
    +issues: #27556

  • changelog.d/implicit-field-strictness-warning
    1
    +section: compiler
    
    2
    +synopsis: Add `-Wimplicit-field-strictness`
    
    3
    +issues: #16836
    
    4
    +mrs: !16555
    
    5
    +
    
    6
    +description: {
    
    7
    +    The new opt-in warning :ghc-flag:`-Wimplicit-field-strictness` reports
    
    8
    +    data constructor fields that lack an explicit strictness annotation
    
    9
    +    (``!`` or ``~``).
    
    10
    +}

  • changelog.d/lazy-field-annotations
    ... ... @@ -11,4 +11,7 @@ description: {
    11 11
         continues to control the default strictness of unannotated fields.
    
    12 12
     
    
    13 13
         See `GHC Proposal #752 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0752-lazy-field-annotations.rst>`_.
    
    14
    +
    
    15
    +    Also note the new opt-in :ghc-flag:`-Wimplicit-field-strictness` warning, which
    
    16
    +    reports fields lacking an explicit annotation.
    
    14 17
     }

  • compiler/GHC/CoreToStg/Prep.hs
    ... ... @@ -1260,10 +1260,9 @@ cpeApp top_env expr
    1260 1260
     
    
    1261 1261
           -- See Note [Ticks and mandatory eta expansion]
    
    1262 1262
           AITick tickish
    
    1263
    -        | tickishPlace tickish == PlaceRuntime
    
    1263
    +        | PlaceRuntime <- tickishPlace tickish
    
    1264 1264
             , req_depth > 0
    
    1265
    -        -> assert (isProfTick tickish) $
    
    1266
    -           rebuild_app' env as fun' floats ss (tickish:rt_ticks) req_depth
    
    1265
    +        -> rebuild_app' env as fun' floats ss (tickish:rt_ticks) req_depth
    
    1267 1266
             | otherwise
    
    1268 1267
             -- See [Floating Ticks in CorePrep]
    
    1269 1268
             -> rebuild_app' env as fun' (snocFloat floats (FloatTick tickish)) ss rt_ticks req_depth
    

  • compiler/GHC/Driver/Flags.hs
    ... ... @@ -1142,6 +1142,7 @@ data WarningFlag =
    1142 1142
        | Opt_WarnUnrecognisedModifiers                   -- ^ @since 10.0
    
    1143 1143
        | Opt_WarnSemaphoreOpenFailure                   -- Since 10.0.1
    
    1144 1144
        | Opt_WarnDefaultedCallStack                      -- ^ @since 10.2
    
    1145
    +   | Opt_WarnImplicitFieldStrictness                 -- ^ @since 10.2
    
    1145 1146
        deriving (Eq, Ord, Show, Enum, Bounded)
    
    1146 1147
     
    
    1147 1148
     -- | Return the names of a WarningFlag
    
    ... ... @@ -1251,6 +1252,7 @@ warnFlagNames wflag = case wflag of
    1251 1252
       Opt_WarnTypeEqualityRequiresOperators           -> "type-equality-requires-operators" :| []
    
    1252 1253
       Opt_WarnMissingRoleAnnotations                  -> "missing-role-annotations" :| []
    
    1253 1254
       Opt_WarnImplicitRhsQuantification               -> "implicit-rhs-quantification" :| []
    
    1255
    +  Opt_WarnImplicitFieldStrictness                 -> "implicit-field-strictness" :| []
    
    1254 1256
       Opt_WarnIncompleteExportWarnings                -> "incomplete-export-warnings" :| []
    
    1255 1257
       Opt_WarnIncompleteRecordSelectors               -> "incomplete-record-selectors" :| []
    
    1256 1258
       Opt_WarnBadlyLevelledTypes                      -> "badly-levelled-types" :| []
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -2449,6 +2449,7 @@ wWarningFlagsDeps = [minBound..maxBound] >>= \x -> case x of
    2449 2449
       Opt_WarnUnrecognisedModifiers -> warnSpec x
    
    2450 2450
       Opt_WarnSemaphoreOpenFailure -> warnSpec x
    
    2451 2451
       Opt_WarnDefaultedCallStack -> warnSpec x
    
    2452
    +  Opt_WarnImplicitFieldStrictness -> warnSpec x
    
    2452 2453
     
    
    2453 2454
     warningGroupsDeps :: [(Deprecation, FlagSpec WarningGroup)]
    
    2454 2455
     warningGroupsDeps = map mk warningGroups
    

  • compiler/GHC/Hs/Doc.hs
    ... ... @@ -58,6 +58,7 @@ import Language.Haskell.Syntax.Doc
    58 58
     import Language.Haskell.Syntax.Extension
    
    59 59
     import Language.Haskell.Syntax.Module.Name
    
    60 60
     
    
    61
    +-- Exact print annotations ignore LHsDoc, so bare SrcSpan is fine
    
    61 62
     type instance Anno (WithHsDocIdentifiers (HsDocString (GhcPass pass)) (GhcPass pass)) = SrcSpan
    
    62 63
     
    
    63 64
     deriving instance (Data pass, Data (LIdP pass), Data a) => Data (WithHsDocIdentifiers a pass)
    

  • compiler/GHC/Hs/Extension/Pass.hs
    ... ... @@ -46,6 +46,7 @@ type instance XRec (GhcPass p) a = XRecGhc a
    46 46
     -- but pass-independent, source location
    
    47 47
     type XRecGhc a = GenLocated (Anno a) a
    
    48 48
     
    
    49
    +-- Exact print annotations ignore LHsDoc, so bare SrcSpan is fine
    
    49 50
     type instance Anno (HsDocString (GhcPass _))  = SrcSpan
    
    50 51
     type instance Anno HsDocStringChunk           = SrcSpan
    
    51 52
     
    

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -1384,6 +1384,21 @@ instance Diagnostic TcRnMessage where
    1384 1384
           hang (text "Missing role annotation" <> colon)
    
    1385 1385
              2 (text "type role" <+> ppr name <+> hsep (map ppr roles))
    
    1386 1386
     
    
    1387
    +    TcRnImplicitFieldStrictness _lazy_anns cons -> mkSimpleDecorated $
    
    1388
    +      hang (text "These constructor fields lack an explicit strictness annotation" <> colon)
    
    1389
    +         2 (vcat (map ppr_con (NE.toList cons)))
    
    1390
    +      where
    
    1391
    +        ppr_con (con, fields) =
    
    1392
    +          bullet <+> text "In" <+> quotes (ppr con) <> colon <+> ppr_fields (NE.toList fields)
    
    1393
    +        ppr_fields fields
    
    1394
    +          | let names = [n | ImplicitStrictnessRecField n <- fields]
    
    1395
    +          , not (null names)
    
    1396
    +          = text "field" <> plural names <+> quotedListWithAnd (map ppr names)
    
    1397
    +          | otherwise
    
    1398
    +          = let poss = [i | ImplicitStrictnessPosField i <- fields]
    
    1399
    +            in text "field" <> plural poss
    
    1400
    +               <+> unquotedListWith (text "and") (map int poss)
    
    1401
    +
    
    1387 1402
         TcRnIllformedTypePattern p
    
    1388 1403
           -> mkSimpleDecorated $
    
    1389 1404
               hang (text "Ill-formed type pattern:") 2 (ppr p)
    
    ... ... @@ -2693,6 +2708,8 @@ instance Diagnostic TcRnMessage where
    2693 2708
           -> ErrorWithoutFlag
    
    2694 2709
         TcRnMissingRoleAnnotation{}
    
    2695 2710
           -> WarningWithFlag Opt_WarnMissingRoleAnnotations
    
    2711
    +    TcRnImplicitFieldStrictness{}
    
    2712
    +      -> WarningWithFlag Opt_WarnImplicitFieldStrictness
    
    2696 2713
         TcRnIllegalInvisTyVarBndr{}
    
    2697 2714
           -> ErrorWithoutFlag
    
    2698 2715
         TcRnIllegalWildcardTyVarBndr{}
    
    ... ... @@ -3428,6 +3445,12 @@ instance Diagnostic TcRnMessage where
    3428 3445
           -> noHints
    
    3429 3446
         TcRnMissingRoleAnnotation{}
    
    3430 3447
           -> noHints
    
    3448
    +    TcRnImplicitFieldStrictness lazy_anns _
    
    3449
    +      -> SuggestExplicitFieldStrictness
    
    3450
    +         : [ useExtensionInOrderTo
    
    3451
    +               (text "to allow" <+> quotes (char '~') <+> text "annotations")
    
    3452
    +               LangExt.LazyFieldAnnotations
    
    3453
    +           | not lazy_anns ]
    
    3431 3454
         TcRnIllegalInvisTyVarBndr{}
    
    3432 3455
           -> [suggestExtension LangExt.TypeAbstractions]
    
    3433 3456
         TcRnIllegalWildcardTyVarBndr{}
    

  • compiler/GHC/Tc/Errors/Types.hs
    ... ... @@ -123,6 +123,7 @@ module GHC.Tc.Errors.Types (
    123 123
       , TypeSyntax(..)
    
    124 124
       , typeSyntaxExtension
    
    125 125
       , SuggestLinear(..)
    
    126
    +  , ImplicitStrictnessField(..)
    
    126 127
     
    
    127 128
         -- * Errors for hs-boot and signature files
    
    128 129
       , BadBootDecls(..)
    
    ... ... @@ -4235,6 +4236,23 @@ data TcRnMessage where
    4235 4236
     
    
    4236 4237
       -}
    
    4237 4238
       TcRnMissingRoleAnnotation :: Name -> [Role] -> TcRnMessage
    
    4239
    +
    
    4240
    +  {-| TcRnImplicitFieldStrictness is a warning that occurs when a data
    
    4241
    +     constructor field lacks an explicit strictness annotation (@!@ or @~@)
    
    4242
    +
    
    4243
    +     Controlled by flags:
    
    4244
    +       - Wimplicit-field-strictness
    
    4245
    +
    
    4246
    +     Test cases:
    
    4247
    +       T16836a, T16836b, T16836c, T16836d
    
    4248
    +
    
    4249
    +  -}
    
    4250
    +  TcRnImplicitFieldStrictness
    
    4251
    +    :: Bool -- ^ whether @LazyFieldAnnotations@ is enabled
    
    4252
    +    -> NonEmpty (Name, NonEmpty ImplicitStrictnessField)
    
    4253
    +       -- ^ per data constructor, the fields lacking annotations
    
    4254
    +    -> TcRnMessage
    
    4255
    +
    
    4238 4256
       {-| TcRnPatersonCondFailure is an error that occurs when an instance
    
    4239 4257
           declaration fails to conform to the Paterson conditions. Which particular condition
    
    4240 4258
           fails depends on the constructor of PatersonCondFailure
    
    ... ... @@ -6399,6 +6417,14 @@ data PatSynInvalidRhsReason
    6399 6417
       | PatSynUnboundVar !Name
    
    6400 6418
       deriving (Generic)
    
    6401 6419
     
    
    6420
    +-- | A constructor field lacking an explicit strictness annotation, as
    
    6421
    +-- reported by 'TcRnImplicitFieldStrictness'.
    
    6422
    +data ImplicitStrictnessField
    
    6423
    +    -- | A record field
    
    6424
    +  = ImplicitStrictnessRecField FieldLabelString
    
    6425
    +    -- | A positional argument (1-based index)
    
    6426
    +  | ImplicitStrictnessPosField Int
    
    6427
    +
    
    6402 6428
     data BadFieldAnnotationReason where
    
    6403 6429
       {-| A lazy data type field annotation (~) was used without enabling the
    
    6404 6430
         extension LazyFieldAnnotations.
    

  • compiler/GHC/Tc/TyCl.hs
    ... ... @@ -5022,6 +5022,16 @@ checkValidTyCon tc
    5022 5022
                    ; mapM_ (checkValidDataCon dflags ex_ok tc) data_cons
    
    5023 5023
                    ; mapM_ (checkPartialRecordField data_cons) (tyConFieldLabels tc)
    
    5024 5024
     
    
    5025
    +               ; warn_implicit_strictness <- woptM Opt_WarnImplicitFieldStrictness
    
    5026
    +               ; when (warn_implicit_strictness
    
    5027
    +                       && not (isNewTyCon tc)
    
    5028
    +                       && not (isTypeDataTyCon tc)) $
    
    5029
    +                 whenIsJust (NE.nonEmpty (mapMaybe conImplicitStrictnessFields data_cons)) $
    
    5030
    +                   \offenders ->
    
    5031
    +                     do { lazy_anns <- xoptM LangExt.LazyFieldAnnotations
    
    5032
    +                        ; addDiagnosticTc $
    
    5033
    +                          TcRnImplicitFieldStrictness lazy_anns offenders }
    
    5034
    +
    
    5025 5035
                     -- Check that fields with the same name share a type
    
    5026 5036
                    ; mapM_ check_fields groups }}
    
    5027 5037
       where
    
    ... ... @@ -5072,6 +5082,29 @@ checkValidTyCon tc
    5072 5082
                     res2 = dataConOrigResTy con2
    
    5073 5083
                     fty2 = dataConFieldType con2 lbl
    
    5074 5084
     
    
    5085
    +-- | For a given data constructor, collect the fields to report for
    
    5086
    +-- @-Wimplicit-field-strictness@.
    
    5087
    +--
    
    5088
    +-- Only fields whose type is known to be lifted are collected: unlifted
    
    5089
    +-- fields are unconditionally strict, and annotating one with @!@ or
    
    5090
    +-- @~@ would trigger @-Wredundant-strictness-flags@.
    
    5091
    +conImplicitStrictnessFields :: DataCon -> Maybe (Name, NonEmpty ImplicitStrictnessField)
    
    5092
    +conImplicitStrictnessFields con
    
    5093
    +  | Just ne_fields <- NE.nonEmpty fields
    
    5094
    +  = Just (dataConName con, ne_fields)
    
    5095
    +  | otherwise
    
    5096
    +  = Nothing
    
    5097
    +  where
    
    5098
    +    fld_refs = case dataConFieldLabels con of
    
    5099
    +      []   -> map ImplicitStrictnessPosField [1..]
    
    5100
    +      lbls -> map (ImplicitStrictnessRecField . flLabel) lbls
    
    5101
    +    fields = [ ref
    
    5102
    +             | (ref, arg_ty, HsSrcBang _ _ NoSrcStrict)
    
    5103
    +                 <- zip3 fld_refs
    
    5104
    +                         (map scaledThing (dataConOrigArgTys con))
    
    5105
    +                         (dataConSrcBangs con)
    
    5106
    +             , typeLevity_maybe arg_ty == Just Lifted ]
    
    5107
    +
    
    5075 5108
     checkPartialRecordField :: [DataCon] -> FieldLabel -> TcM ()
    
    5076 5109
     -- Checks the partial record field selector, and warns.
    
    5077 5110
     -- See Note [Checking partial record field]
    

  • compiler/GHC/Types/Error/Codes.hs
    ... ... @@ -542,6 +542,7 @@ type family GhcDiagnosticCode c = n | n -> c where
    542 542
       GhcDiagnosticCode "TcRnNegativeNumTypeLiteral"                    = 93632
    
    543 543
       GhcDiagnosticCode "TcRnUnusedQuantifiedTypeVar"                   = 54180
    
    544 544
       GhcDiagnosticCode "TcRnMissingRoleAnnotation"                     = 65490
    
    545
    +  GhcDiagnosticCode "TcRnImplicitFieldStrictness"                   = 47032
    
    545 546
     
    
    546 547
       GhcDiagnosticCode "TcRnUntickedPromotedThing"                     = 49957
    
    547 548
       GhcDiagnosticCode "TcRnIllegalBuiltinSyntax"                      = 39716
    

  • compiler/GHC/Types/Hint.hs
    ... ... @@ -343,6 +343,14 @@ data GhcHint
    343 343
         -}
    
    344 344
       | SuggestAddStandaloneKindSignature Name
    
    345 345
     
    
    346
    +    {-| Suggests to annotate each constructor field with explicit strictness
    
    347
    +        (@!@ or @~@).
    
    348
    +
    
    349
    +        Triggered by: 'GHC.Tc.Errors.Types.TcRnImplicitFieldStrictness'
    
    350
    +        Test case(s): warnings/should_compile/T16836a
    
    351
    +    -}
    
    352
    +  | SuggestExplicitFieldStrictness
    
    353
    +
    
    346 354
         {-| Suggests the user to fill in the wildcard constraint to
    
    347 355
             disambiguate which constraint that is.
    
    348 356
     
    

  • compiler/GHC/Types/Hint/Ppr.hs
    ... ... @@ -185,6 +185,9 @@ instance Outputable GhcHint where
    185 185
           -> text "Use a standalone deriving declaration instead"
    
    186 186
         SuggestAddStandaloneKindSignature name
    
    187 187
           -> text "Add a standalone kind signature for" <+> quotes (ppr name)
    
    188
    +    SuggestExplicitFieldStrictness
    
    189
    +      -> text "Annotate each field with" <+> quotes (char '!')
    
    190
    +         <+> text "(strict) or" <+> quotes (char '~') <+> text "(lazy)"
    
    188 191
         SuggestFillInWildcardConstraint
    
    189 192
           -> text "Fill in the wildcard constraint yourself"
    
    190 193
         SuggestAppropriateTHTick ns
    

  • compiler/GHC/Types/Tickish.hs
    ... ... @@ -13,7 +13,6 @@ module GHC.Types.Tickish (
    13 13
       mkNoCount,
    
    14 14
       mkNoScope,
    
    15 15
       tickishIsCode,
    
    16
    -  isProfTick,
    
    17 16
       TickishPlacement(..),
    
    18 17
       tickishPlace,
    
    19 18
       tickishContains,
    
    ... ... @@ -545,10 +544,6 @@ tickishIsCode ProfNote{} = True
    545 544
     tickishIsCode Breakpoint{} = True
    
    546 545
     tickishIsCode HpcTick{}    = True
    
    547 546
     
    
    548
    -isProfTick :: GenTickish pass -> Bool
    
    549
    -isProfTick ProfNote{} = True
    
    550
    -isProfTick _          = False
    
    551
    -
    
    552 547
     -- | Governs the kind of expression that the tick gets placed on when
    
    553 548
     -- annotating for example using @mkTick@. If we find that we want to
    
    554 549
     -- put a tickish on an expression ruled out here, we try to float it
    

  • docs/users_guide/exts/strict.rst
    ... ... @@ -194,6 +194,9 @@ The ``~`` annotation must be written in prefix form::
    194 194
     See `GHC Proposal #229 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0229-whitespace-bang-patterns.rst>`__
    
    195 195
     for the precise rules.
    
    196 196
     
    
    197
    +See also :ghc-flag:`-Wimplicit-field-strictness`, which warns about
    
    198
    +fields lacking an explicit annotation.
    
    199
    +
    
    197 200
     .. _strict-data:
    
    198 201
     
    
    199 202
     Strict-by-default data types
    

  • docs/users_guide/using-warnings.rst
    ... ... @@ -2505,6 +2505,21 @@ of ``-W(no-)*``.
    2505 2505
         In other words the type-class role cannot be accidentally left
    
    2506 2506
         representational or phantom, which could affected the code correctness.
    
    2507 2507
     
    
    2508
    +.. ghc-flag:: -Wimplicit-field-strictness
    
    2509
    +    :shortdesc: warn when constructor fields lack explicit strictness annotations
    
    2510
    +    :type: dynamic
    
    2511
    +    :reverse: -Wno-implicit-field-strictness
    
    2512
    +    :category:
    
    2513
    +
    
    2514
    +    :since: 10.2.1
    
    2515
    +    :default: off
    
    2516
    +
    
    2517
    +    .. index::
    
    2518
    +         single: strictness annotations, missing
    
    2519
    +
    
    2520
    +    This warning reports data constructor fields that lack an explicit
    
    2521
    +    strictness annotation (``!`` or ``~``).
    
    2522
    +
    
    2508 2523
     .. ghc-flag:: -Wimplicit-rhs-quantification
    
    2509 2524
         :shortdesc: warn when type variables on the RHS of a type synonym are implicitly quantified
    
    2510 2525
         :type: dynamic
    

  • testsuite/tests/simplCore/should_compile/T27556.hs
    1
    +import Control.Exception
    
    2
    +
    
    3
    +main = mask $ \restore -> restore (pure ())
    
    4
    +

  • testsuite/tests/simplCore/should_compile/T27556.script
    1
    +:l T27556

  • testsuite/tests/simplCore/should_compile/all.T
    ... ... @@ -611,3 +611,4 @@ test('T27296', [], makefile_test, ['T27296'])
    611 611
     test('T27296b', [], makefile_test, ['T27296b'])
    
    612 612
     test('T27589', [grep_errmsg(r'wombat')], compile, ['-O -ddump-simpl -dno-typeable-binds -dsuppress-uniques'])
    
    613 613
     test('T27590', [grep_errmsg(r'wombat')], compile, ['-O -ddump-simpl -dno-typeable-binds -dsuppress-uniques'])
    
    614
    +test('T27556', [only_ways('ghci'), extra_hc_opts('-O -fno-unoptimized-core-for-interpreter')], ghci_script, ['T27556.script'])

  • testsuite/tests/warnings/should_compile/T16836a.hs
    1
    +{-# OPTIONS_GHC -Wimplicit-field-strictness #-}
    
    2
    +{-# LANGUAGE GADTs #-}
    
    3
    +{-# LANGUAGE TypeFamilies #-}
    
    4
    +{-# LANGUAGE TypeOperators #-}
    
    5
    +module T16836a where
    
    6
    +
    
    7
    +-- plain multi-constructor data
    
    8
    +-- warns for both constructors
    
    9
    +data T a = MkT a Bool
    
    10
    +         | MkT2 !Int a
    
    11
    +
    
    12
    +-- record with a shared field group
    
    13
    +-- warns for x, y and z; not for b
    
    14
    +data R = MkR { x, y :: Int, z :: Char, b :: !Bool }
    
    15
    +
    
    16
    +-- infix constructor
    
    17
    +-- warns for the first argument
    
    18
    +data I = Int :+: !Bool
    
    19
    +
    
    20
    +-- GADT syntax
    
    21
    +-- warns for the first argument
    
    22
    +data G a where
    
    23
    +  MkG :: Int -> !Bool -> G a
    
    24
    +
    
    25
    +-- GADT record syntax
    
    26
    +-- warns for gx
    
    27
    +data GR a where
    
    28
    +  MkGR :: { gx :: Int, gy :: !Bool } -> GR a
    
    29
    +
    
    30
    +-- data family instance
    
    31
    +-- warns
    
    32
    +data family F a
    
    33
    +data instance F Int = MkF Char
    
    34
    +
    
    35
    +-- fully annotated
    
    36
    +-- doesn't warn
    
    37
    +data S = MkS !Int !Bool

  • testsuite/tests/warnings/should_compile/T16836a.stderr
    1
    +T16836a.hs:9:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    2
    +    • These constructor fields lack an explicit strictness annotation:
    
    3
    +        • In ‘MkT’: fields 1 and 2
    
    4
    +        • In ‘MkT2’: field 2
    
    5
    +    • In the data type declaration for ‘T’
    
    6
    +    Suggested fixes:
    
    7
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    8
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    9
    +        to allow ‘~’ annotations
    
    10
    +
    
    11
    +T16836a.hs:14:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    12
    +    • These constructor fields lack an explicit strictness annotation:
    
    13
    +        • In ‘MkR’: fields ‘x’, ‘y’ and ‘z’
    
    14
    +    • In the data type declaration for ‘R’
    
    15
    +    Suggested fixes:
    
    16
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    17
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    18
    +        to allow ‘~’ annotations
    
    19
    +
    
    20
    +T16836a.hs:18:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    21
    +    • These constructor fields lack an explicit strictness annotation:
    
    22
    +        • In ‘:+:’: field 1
    
    23
    +    • In the data type declaration for ‘I’
    
    24
    +    Suggested fixes:
    
    25
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    26
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    27
    +        to allow ‘~’ annotations
    
    28
    +
    
    29
    +T16836a.hs:22:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    30
    +    • These constructor fields lack an explicit strictness annotation:
    
    31
    +        • In ‘MkG’: field 1
    
    32
    +    • In the data type declaration for ‘G’
    
    33
    +    Suggested fixes:
    
    34
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    35
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    36
    +        to allow ‘~’ annotations
    
    37
    +
    
    38
    +T16836a.hs:27:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    39
    +    • These constructor fields lack an explicit strictness annotation:
    
    40
    +        • In ‘MkGR’: field ‘gx’
    
    41
    +    • In the data type declaration for ‘GR’
    
    42
    +    Suggested fixes:
    
    43
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    44
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    45
    +        to allow ‘~’ annotations
    
    46
    +
    
    47
    +T16836a.hs:33:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    48
    +    • These constructor fields lack an explicit strictness annotation:
    
    49
    +        • In ‘MkF’: field 1
    
    50
    +    • In the data family instance declaration for ‘F’
    
    51
    +    Suggested fixes:
    
    52
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    53
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    54
    +        to allow ‘~’ annotations
    
    55
    +

  • testsuite/tests/warnings/should_compile/T16836b.hs
    1
    +{-# OPTIONS_GHC -Wimplicit-field-strictness #-}
    
    2
    +{-# LANGUAGE GADTs #-}
    
    3
    +{-# LANGUAGE TypeFamilies #-}
    
    4
    +{-# LANGUAGE TypeData #-}
    
    5
    +{-# LANGUAGE EmptyDataDecls #-}
    
    6
    +{-# LANGUAGE LazyFieldAnnotations #-}
    
    7
    +module T16836b where
    
    8
    +
    
    9
    +-- fully annotated declarations don't warn
    
    10
    +data T a = MkT ~a !Bool
    
    11
    +data R = MkR { x, y :: !Int, z :: ~Char }
    
    12
    +data G a where
    
    13
    +  MkG :: !Int -> ~Bool -> G a
    
    14
    +data family F a
    
    15
    +data instance F Int = MkF !Char
    
    16
    +
    
    17
    +-- newtypes can't have annotations; exempt
    
    18
    +newtype N = MkN Int
    
    19
    +
    
    20
    +-- 'type data' can't have annotations; exempt
    
    21
    +type data TD = MkTD Bool
    
    22
    +
    
    23
    +-- no fields, nothing to annotate
    
    24
    +data E
    
    25
    +data Nullary = A | B

  • testsuite/tests/warnings/should_compile/T16836c.hs
    1
    +{-# OPTIONS_GHC -Wimplicit-field-strictness #-}
    
    2
    +{-# LANGUAGE StrictData #-}
    
    3
    +module T16836c where
    
    4
    +
    
    5
    +-- unannotated fields warn under StrictData too
    
    6
    +data T a = MkT a !Bool ~Char

  • testsuite/tests/warnings/should_compile/T16836c.stderr
    1
    +T16836c.hs:6:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    2
    +    • These constructor fields lack an explicit strictness annotation:
    
    3
    +        • In ‘MkT’: field 1
    
    4
    +    • In the data type declaration for ‘T’
    
    5
    +    Suggested fix: Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    6
    +

  • testsuite/tests/warnings/should_compile/T16836d.hs
    1
    +{-# OPTIONS_GHC -Wimplicit-field-strictness #-}
    
    2
    +{-# LANGUAGE MagicHash #-}
    
    3
    +{-# LANGUAGE UnboxedTuples #-}
    
    4
    +{-# LANGUAGE UnliftedDatatypes #-}
    
    5
    +module T16836d where
    
    6
    +
    
    7
    +import GHC.Exts
    
    8
    +
    
    9
    +-- unlifted fields can't be usefully annotated; exempt
    
    10
    +data P = MkP Int# (# Int, Int #)
    
    11
    +
    
    12
    +type UD :: UnliftedType
    
    13
    +data UD = MkUD
    
    14
    +
    
    15
    +-- a field of an unlifted data type is exempt too
    
    16
    +data Q = MkQ UD
    
    17
    +
    
    18
    +-- mixed constructor
    
    19
    +-- warns only for the lifted field 2
    
    20
    +data M = MkM Int# Int

  • testsuite/tests/warnings/should_compile/T16836d.stderr
    1
    +T16836d.hs:20:1: warning: [GHC-47032] [-Wimplicit-field-strictness]
    
    2
    +    • These constructor fields lack an explicit strictness annotation:
    
    3
    +        • In ‘MkM’: field 2
    
    4
    +    • In the data type declaration for ‘M’
    
    5
    +    Suggested fixes:
    
    6
    +      • Annotate each field with ‘!’ (strict) or ‘~’ (lazy)
    
    7
    +      • Use the ‘LazyFieldAnnotations’ extension (implied by ‘StrictData’)
    
    8
    +        to allow ‘~’ annotations
    
    9
    +

  • testsuite/tests/warnings/should_compile/all.T
    ... ... @@ -91,3 +91,7 @@ test('T25901_imp_unused_3', [extra_files(['T25901_helper_3.hs'])], multimod_comp
    91 91
     test('T25901_imp_unused_4', normal, compile, ['-Wunused-imports'])
    
    92 92
     test('T25901_imp_dodgy_1', [extra_files(['T25901_helper_1.hs'])], multimod_compile, ['T25901_imp_dodgy_1', '-v0 -Wdodgy-imports'])
    
    93 93
     test('T25901_imp_dodgy_2', [extra_files(['T25901_helper_2.hs'])], multimod_compile, ['T25901_imp_dodgy_2', '-v0 -Wdodgy-imports'])
    
    94
    +test('T16836a', normal, compile, [''])
    
    95
    +test('T16836b', normal, compile, [''])
    
    96
    +test('T16836c', normal, compile, [''])
    
    97
    +test('T16836d', normal, compile, [''])

  • utils/check-exact/ExactPrint.hs
    ... ... @@ -3397,13 +3397,13 @@ instance ExactPrint (HsCmd GhcPs) where
    3397 3397
           e' <- markAnnotated e
    
    3398 3398
           return (HsCmdLet (tkLet', tkIn') binds' e')
    
    3399 3399
     
    
    3400
    -  exact (HsCmdDo (an0,loc) (L l es)) = do
    
    3400
    +  exact (HsCmdDo (an0,loc) es) = do
    
    3401 3401
         debugM $ "HsCmdDo"
    
    3402 3402
         loc' <- printStringAtAA loc "do"
    
    3403 3403
         (an1,es') <- markAnnList' an0 $ do
    
    3404
    -      ee <- mapM markAnnotated es
    
    3404
    +      ee <- markAnnotated es
    
    3405 3405
           return ee
    
    3406
    -    return (HsCmdDo (an1,loc') (L l es'))
    
    3406
    +    return (HsCmdDo (an1,loc') es')
    
    3407 3407
     
    
    3408 3408
     -- ---------------------------------------------------------------------
    
    3409 3409
     
    
    ... ... @@ -4462,10 +4462,10 @@ instance ExactPrint [LocatedA (StmtLR GhcPs GhcPs (LocatedA (HsCmd GhcPs)))] whe
    4462 4462
           Just (initStmts, ls@(L _ (LastStmt _ _body _ _))) -> do
    
    4463 4463
             debugM $ "LocatedL [ExprLStmt: snocView"
    
    4464 4464
             ls' <- markAnnotated ls
    
    4465
    -        initStmts' <- markAnnotated initStmts
    
    4465
    +        initStmts' <- mapM markAnnotated initStmts
    
    4466 4466
             return (initStmts' ++ [ls'])
    
    4467 4467
           _ -> do
    
    4468
    -        stmts' <- markAnnotated stmts
    
    4468
    +        stmts' <- mapM markAnnotated stmts
    
    4469 4469
             return stmts'
    
    4470 4470
     
    
    4471 4471
     instance ExactPrint [Located HsDocStringChunk] where