Zubin pushed to branch wip/25924 at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • compiler/GHC/Core/Opt/WorkWrap/Utils.hs
    ... ... @@ -30,7 +30,6 @@ import GHC.Core.Subst
    30 30
     import GHC.Core.Type
    
    31 31
     import GHC.Core.Multiplicity
    
    32 32
     import GHC.Core.Coercion
    
    33
    -import GHC.Core.Predicate( isDictTy )
    
    34 33
     import GHC.Core.Reduction
    
    35 34
     import GHC.Core.FamInstEnv
    
    36 35
     import GHC.Core.Predicate( isEqualityClass )
    
    ... ... @@ -1069,25 +1068,21 @@ unbox_one_arg opts arg_var
    1069 1068
     -- same type as @id@. Otherwise, no suitable filler could be found.
    
    1070 1069
     mkAbsentFiller :: WwOpts -> Id -> StrictnessMark -> Maybe CoreExpr
    
    1071 1070
     mkAbsentFiller opts arg str
    
    1072
    -  -- The lifted case: bind 'absentError'. See (AF1) in Note [Absent fillers]
    
    1073
    -  -- We want to use this case if possible, because we get a nice runtime panic message
    
    1074
    -  -- if we are wrong (like we were in #11126).  Otherwise we fall through to the
    
    1075
    -  -- less-desirable mkLitRubbish case.
    
    1071
    +  -- The lifted case: Bind 'absentError' for a nice panic message if we are
    
    1072
    +  -- wrong (like we were in #11126). See (1) in Note [Absent fillers]
    
    1076 1073
       | mightBeLiftedType arg_ty
    
    1077
    -  , not (isDictTy arg_ty)                 -- See (AF4) in Note [Absent fillers]
    
    1078
    -  , not (isStrictDmd (idDemandInfo arg))  -- See (AF2)
    
    1079
    -  , not (isMarkedStrict str)              --    in Note [Absent fillers]
    
    1074
    +  , not is_strict
    
    1075
    +  , not (isMarkedStrict str) -- See (2) in Note [Absent fillers]
    
    1080 1076
       = Just (mkAbsentErrorApp arg_ty msg)
    
    1081 1077
     
    
    1082 1078
       -- The default case for mono rep: Bind `RUBBISH[rr] arg_ty`
    
    1083
    -  -- See Note [Absent fillers]
    
    1084
    -  -- (AF3): mkLitRubbish returns Nothing if the representation is not
    
    1085
    -  --        monomorphic, in which case we can't make a filler
    
    1079
    +  -- See Note [Absent fillers], the main part
    
    1086 1080
       | otherwise
    
    1087 1081
       = mkLitRubbish arg_ty
    
    1088 1082
     
    
    1089 1083
       where
    
    1090
    -    arg_ty = idType arg
    
    1084
    +    arg_ty    = idType arg
    
    1085
    +    is_strict = isStrictDmd (idDemandInfo arg)
    
    1091 1086
     
    
    1092 1087
         msg = renderWithContext
    
    1093 1088
                 (defaultSDocContext { sdocSuppressUniques = True })
    
    ... ... @@ -1250,7 +1245,7 @@ conjure filler values at any type (and any representation or levity!).
    1250 1245
     
    
    1251 1246
     Needless to say, there are some wrinkles:
    
    1252 1247
     
    
    1253
    -(AF1) In case we have a absent, /lazy/, and /lifted/ arg, we use an error-thunk
    
    1248
    +  1. In case we have a absent, /lazy/, and /lifted/ arg, we use an error-thunk
    
    1254 1249
          instead. If absence analysis was wrong (e.g., #11126) and the binding
    
    1255 1250
          in fact is used, then we get a nice panic message instead of undefined
    
    1256 1251
          runtime behavior (See Modes of failure from Note [Rubbish literals]).
    
    ... ... @@ -1258,7 +1253,7 @@ Needless to say, there are some wrinkles:
    1258 1253
          Obviously, we can't use an error-thunk if the value is of unlifted rep
    
    1259 1254
          (like 'Int#' or 'MutVar#'), because we'd immediately evaluate the panic.
    
    1260 1255
     
    
    1261
    -(AF2) We also mustn't put an error-thunk (that fills in for an absent value of
    
    1256
    +  2. We also mustn't put an error-thunk (that fills in for an absent value of
    
    1262 1257
          lifted rep) in a strict field, because #16970 establishes the invariant
    
    1263 1258
          that strict fields are always evaluated, by possibly (re-)evaluating what is put in
    
    1264 1259
          a strict field. That's the reason why 'zs' binds a rubbish literal instead
    
    ... ... @@ -1284,8 +1279,8 @@ Needless to say, there are some wrinkles:
    1284 1279
          strictness check in place on top of threading through the marks from the
    
    1285 1280
          constructor. It's a *really* cheap and easy check to make anyway.
    
    1286 1281
     
    
    1287
    -(AF3) We can only emit a LitRubbish if the arg's type `arg_ty` is mono-rep, e.g.
    
    1288
    -     of the form `TYPE rep` where `rep` is not (and doesn't contain) a variable.
    
    1282
    +  3. We can only emit a LitRubbish if the arg's type @arg_ty@ is mono-rep, e.g.
    
    1283
    +     of the form @TYPE rep@ where @rep@ is not (and doesn't contain) a variable.
    
    1289 1284
          Why? Because if we don't know its representation (e.g. size in memory,
    
    1290 1285
          register class), we don't know what or how much rubbish to emit in codegen.
    
    1291 1286
          'mkLitRubbish' returns 'Nothing' in this case and we simply fall
    
    ... ... @@ -1295,30 +1290,8 @@ Needless to say, there are some wrinkles:
    1295 1290
          have to be representation monomorphic. But in the future, we might allow
    
    1296 1291
          levity polymorphism, e.g. a polymorphic levity variable in 'BoxedRep'.
    
    1297 1292
     
    
    1298
    -(AF4) Consider (#24934)
    
    1299
    -         f :: (a~b) => blah {-# INLINE f #-}
    
    1300
    -         f d x = case eq_sel d of co -> body
    
    1301
    -     In #24934 it turned out that `co` was unused; and we discarded the
    
    1302
    -     entire case-scrutinisation via the `exprOkToDiscard` test in
    
    1303
    -     `GHC.Core.Opt.Simplify.Iteration.rebuildCase`.  So now `d` is absent.
    
    1304
    -     But in the /unfolding/ for some reason we did not discard the `case`;
    
    1305
    -     so when we inline `f` we end up evaluating that `d` argument.  So we had
    
    1306
    -     better not replace it with an error thunk!
    
    1307
    -
    
    1308
    -     The root of it is this: `exprOkToDiscard` assumes that a dictionary is
    
    1309
    -     non-bottom (Note [exprOkForSpeculation and type classes]); but then we replace
    
    1310
    -     the (a~b) dictionary with an error thunk, breaking the invariant that every
    
    1311
    -     dictionary is non-bottom.  (If -XDictsStrict is on, the invariant is even
    
    1312
    -     more important.)
    
    1313
    -
    
    1314
    -     Simple solution: never use an error thunk for a dictionary; instead fall
    
    1315
    -     through to mkRubbishLit.  (The only downside is that we lose the compiler
    
    1316
    -     debugging advantages of (AF1).)
    
    1317
    -
    
    1318
    -     This is quite delicate.
    
    1319
    -
    
    1320
    -While (AF1) and (AF2) are simply an optimisation in terms of compiler debugging
    
    1321
    -experience, (AF3) should be irrelevant in most programs, if not all.
    
    1293
    +While (1) and (2) are simply an optimisation in terms of compiler debugging
    
    1294
    +experience, (3) should be irrelevant in most programs, if not all.
    
    1322 1295
     
    
    1323 1296
     Historical note: I did try the experiment of using an error thunk for unlifted
    
    1324 1297
     things too, relying on the simplifier to drop it as dead code.  But this is