| ... |
... |
@@ -1821,8 +1821,15 @@ simplArg :: SimplEnvIS -- ^ Used only for its InScopeSet |
|
1821
|
1821
|
-- continuation passed to 'simplExprC'
|
|
1822
|
1822
|
-> OutType -- ^ Type of the function applied to this arg
|
|
1823
|
1823
|
-> StaticEnv -> CoreExpr -- ^ Expression with its static envt
|
|
1824
|
|
- -> MOutCoercion -- Wrap this around the result
|
|
|
1824
|
+ -> MOutCoercion -- ^ Wrap this around the result
|
|
1825
|
1825
|
-> SimplM OutExpr
|
|
|
1826
|
+-- Simplify a function argument
|
|
|
1827
|
+--
|
|
|
1828
|
+-- DO NOT float anything outside, hence simplExprC. Doing sio is no benefit (unlike
|
|
|
1829
|
+-- in a let-binding), and we'd have to be very careful about
|
|
|
1830
|
+-- f (let x*=e in b)
|
|
|
1831
|
+-- If we floated that let out, and f was lazy, the demand info on `x` would be
|
|
|
1832
|
+-- unsound, so (a) we'd have to zap it and (b) it'd be unsound
|
|
1826
|
1833
|
simplArg _ _ _ (Simplified {}) arg mco
|
|
1827
|
1834
|
= -- See Note [Avoid repeated simplification]
|
|
1828
|
1835
|
return (mkCastMCo arg mco) -- Handles the very common case of mco=MRefl
|
| ... |
... |
@@ -2379,6 +2386,7 @@ simplOutId env noinline_fun cont |
|
2379
|
2386
|
, ApplyToVal { sc_cont = outer_cont, sc_arg = the_call, sc_cast = call_mco
|
|
2380
|
2387
|
, sc_env = UnSimplified arg_se } <- cont2
|
|
2381
|
2388
|
= do { let -- encl_app_cont collects any /arguments/ from `outer_cont`
|
|
|
2389
|
+ -- This implements (NOI0-b) in Note [noinlineId magic]
|
|
2382
|
2390
|
(encl_app_cont, new_outer_cont) = splitContArgs outer_cont
|
|
2383
|
2391
|
new_call_ty = contHoleType new_outer_cont
|
|
2384
|
2392
|
|
| ... |
... |
@@ -2400,15 +2408,14 @@ simplOutId env noinline_fun cont |
|
2400
|
2408
|
do { let call_stop = addCastMCo call_mco (mkBoringStop call_ty)
|
|
2401
|
2409
|
; return (the_call, call_stop, call_ty, outer_cont) }
|
|
2402
|
2410
|
|
|
2403
|
|
- -- Now simplify the function itself, in call_cont, crucially setting
|
|
2404
|
|
- -- sm_inline = False. The /arguments/ in `call_cont` will be simplified
|
|
2405
|
|
- -- with their own flags, captured in `arg_se`
|
|
|
2411
|
+ -- Now simplify the function itself, in call_cont,
|
|
|
2412
|
+ -- crucially setting sm_inline=False and sm_case_case=False.
|
|
|
2413
|
+ -- The /arguments/ in `call_cont` will be simplified
|
|
|
2414
|
+ -- with their own flags, captured in `arg_se`
|
|
2406
|
2415
|
; let call_env = updMode updModeForNoInline $
|
|
2407
|
2416
|
arg_se `setInScopeFromE` env
|
|
2408
|
|
- ; (floats1, call1) <- wrapJoinFloatsX $
|
|
2409
|
|
- simplExprF call_env inner_fun call_cont
|
|
2410
|
|
- -- wrapJoinFloatsX: any floating join bindings must stay
|
|
2411
|
|
- -- around the call, not be floated out
|
|
|
2417
|
+ ; call1 <- simplExprC call_env inner_fun call_cont
|
|
|
2418
|
+ -- simplExprC: don't float anthing out of a `noinline` call
|
|
2412
|
2419
|
|
|
2413
|
2420
|
-- Now `rebuild` does the rest, wrapping in final_outer_cont
|
|
2414
|
2421
|
; let (new_noinline_fun, rep) = getNoinlineId final_call_ty
|
| ... |
... |
@@ -2416,9 +2423,8 @@ simplOutId env noinline_fun cont |
|
2416
|
2423
|
`App` Type rep
|
|
2417
|
2424
|
`App` Type final_call_ty
|
|
2418
|
2425
|
`App` call1
|
|
2419
|
|
- ; (floats2, res) <- rebuild (env `setInScopeFromF` floats1)
|
|
2420
|
|
- noinline_expr final_outer_cont
|
|
2421
|
|
- ; return (floats1 `addFloats` floats2 , res) }
|
|
|
2426
|
+ ; rebuild (env `setInScopeFromF` floats1)
|
|
|
2427
|
+ noinline_expr final_outer_cont }
|
|
2422
|
2428
|
|
|
2423
|
2429
|
where
|
|
2424
|
2430
|
var_at_head :: CoreExpr -> Bool
|
| ... |
... |
@@ -2537,10 +2543,6 @@ rebuildCall env fun_info |
|
2537
|
2543
|
-- Note [Shadowing in the Simplifier]
|
|
2538
|
2544
|
|
|
2539
|
2545
|
| otherwise -- Lazy, or already simplified arguments
|
|
2540
|
|
- -- DO NOT float anything outside, hence simplExprC
|
|
2541
|
|
- -- There is no benefit (unlike in a let-binding), and we'd
|
|
2542
|
|
- -- have to be very careful about bogus strictness through
|
|
2543
|
|
- -- floating a demanded let.
|
|
2544
|
2546
|
= do { arg' <- simplArg env (Just fun_info) fun_ty arg_se arg arg_mco
|
|
2545
|
2547
|
; rebuildCall env (addValArgTo fun_info arg' fun_ty) cont }
|
|
2546
|
2548
|
|