| ... |
... |
@@ -12,7 +12,8 @@ import GHC.Prelude |
|
12
|
12
|
|
|
13
|
13
|
import GHC.HsToCore.Pmc.Types
|
|
14
|
14
|
import GHC.HsToCore.Pmc.Utils
|
|
15
|
|
-import GHC.Core (Expr(Var,App))
|
|
|
15
|
+import GHC.Core (CoreExpr, Expr(Var,App))
|
|
|
16
|
+import GHC.Core.Utils (stripTicksTopE)
|
|
16
|
17
|
import GHC.Data.FastString (unpackFS, lengthFS, mkFastStringShortText)
|
|
17
|
18
|
import GHC.Driver.DynFlags
|
|
18
|
19
|
import GHC.Hs
|
| ... |
... |
@@ -474,24 +475,28 @@ desugarLocalBinds _binds = return GdEnd |
|
474
|
475
|
-- | Desugar a pattern guard
|
|
475
|
476
|
-- @pat <- e ==> let x = e; <guards for pat <- x>@
|
|
476
|
477
|
desugarBind :: LPat GhcTc -> LHsExpr GhcTc -> DsM GrdDag
|
|
477
|
|
-desugarBind p e = dsLExpr e >>= \case
|
|
478
|
|
- Var y
|
|
479
|
|
- | Nothing <- isDataConId_maybe y
|
|
480
|
|
- -- RHS is a variable, so that will allow us to omit the let
|
|
481
|
|
- -> desugarLPat y p
|
|
482
|
|
- rhs -> do
|
|
483
|
|
- (x, grds) <- desugarLPatV p
|
|
484
|
|
- pure (PmLet x rhs `consGrdDag` grds)
|
|
|
478
|
+desugarBind p e =
|
|
|
479
|
+ dsLExpr_stripTicks e >>= \case
|
|
|
480
|
+ Var y
|
|
|
481
|
+ | Nothing <- isDataConId_maybe y
|
|
|
482
|
+ -- RHS is a variable, so that will allow us to omit the let
|
|
|
483
|
+ -> desugarLPat y p
|
|
|
484
|
+ rhs -> do
|
|
|
485
|
+ (x, grds) <- desugarLPatV p
|
|
|
486
|
+ pure (PmLet x rhs `consGrdDag` grds)
|
|
485
|
487
|
|
|
486
|
488
|
-- | Desugar a boolean guard
|
|
487
|
489
|
-- @e ==> let x = e; True <- x@
|
|
488
|
490
|
desugarBoolGuard :: LHsExpr GhcTc -> DsM GrdDag
|
|
489
|
491
|
desugarBoolGuard e
|
|
490
|
|
- | isJust (isTrueLHsExpr e) = return GdEnd
|
|
|
492
|
+ | isJust (isTrueLHsExpr e) -- NB: looks through ticks
|
|
491
|
493
|
-- The formal thing to do would be to generate (True <- True)
|
|
492
|
494
|
-- but it is trivial to solve so instead we give back an empty
|
|
493
|
495
|
-- GrdDag for efficiency
|
|
494
|
|
- | otherwise = dsLExpr e >>= \case
|
|
|
496
|
+ = return GdEnd
|
|
|
497
|
+
|
|
|
498
|
+ | otherwise
|
|
|
499
|
+ = dsLExpr_stripTicks e >>= \case
|
|
495
|
500
|
Var y
|
|
496
|
501
|
| Nothing <- isDataConId_maybe y
|
|
497
|
502
|
-- Omit the let by matching on y
|
| ... |
... |
@@ -500,6 +505,19 @@ desugarBoolGuard e |
|
500
|
505
|
x <- mkPmId boolTy
|
|
501
|
506
|
pure $ sequencePmGrds [PmLet x rhs, vanillaConGrd x trueDataCon []]
|
|
502
|
507
|
|
|
|
508
|
+-- | Desugar an expression, stripping off top-level ticks from the resulting
|
|
|
509
|
+-- Core expression.
|
|
|
510
|
+--
|
|
|
511
|
+-- This function is used instead of 'dsLExpr' when we are immediately going to
|
|
|
512
|
+-- inspect the Core (as we do in e.g. 'desugarBoolGuard' or 'desugarBind') to
|
|
|
513
|
+-- make sure we properly look through intervening ticks (fixing #27360).
|
|
|
514
|
+--
|
|
|
515
|
+-- It's not needed when all we do is stash the resulting 'CoreExpr' into a
|
|
|
516
|
+-- 'GrdDag', as the rest of the machinery (such as 'GHC.HsToCore.Pmc.Solver.addCoreCt')
|
|
|
517
|
+-- looks through ticks.
|
|
|
518
|
+dsLExpr_stripTicks :: LHsExpr GhcTc -> DsM CoreExpr
|
|
|
519
|
+dsLExpr_stripTicks e = stripTicksTopE (const True) <$> dsLExpr e
|
|
|
520
|
+
|
|
503
|
521
|
{- Note [Field match order for RecCon]
|
|
504
|
522
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
505
|
523
|
The order for RecCon field patterns actually determines evaluation order of
|