Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

16 changed files:

Changes:

  • changelog.d/27936
    1
    +section: compiler
    
    2
    +synopsis:
    
    3
    +  Ensure in-scope set computations always look into kinds, avoiding
    
    4
    +  "needInScope" assertion failures in various places in the compiler.
    
    5
    +mrs: !16799
    
    6
    +issues: #27936

  • compiler/GHC/Core/FVs.hs
    ... ... @@ -11,18 +11,17 @@ Taken quite directly from the Peyton Jones/Lester paper.
    11 11
     module GHC.Core.FVs (
    
    12 12
             -- * Free variables of expressions and binding groups
    
    13 13
             exprFreeVars,     exprsFreeVars,
    
    14
    -        exprFreeVarsDSet,
    
    14
    +        exprFreeVarsDSet, exprsFreeVarsDSet,
    
    15 15
             exprFreeVarsList, exprsFreeVarsList,
    
    16 16
             exprFreeIds,      exprsFreeIds,
    
    17 17
             exprFreeIdsDSet,  exprsFreeIdsDSet,
    
    18 18
             exprFreeIdsList,  exprsFreeIdsList,
    
    19 19
             bindFreeVars,
    
    20 20
     
    
    21
    -        -- * Selective shallow free variables of expressions
    
    21
    +        -- * Selective free variables of expressions
    
    22 22
             InterestingVarFun,
    
    23 23
             exprSomeFreeVars, exprsSomeFreeVars,
    
    24 24
             exprSomeFreeVarsList, exprsSomeFreeVarsList, exprsSomeFreeVarsDSet,
    
    25
    -        deepExprsFreeVarsDSet,
    
    26 25
     
    
    27 26
             -- * Free variables of Rules, Vars and Ids
    
    28 27
             bndrTypeTyCoFVs, bndrFVs, dBndrFreeVars,
    
    ... ... @@ -73,95 +72,118 @@ import GHC.Builtin.WiredIn.Types( unrestrictedFunTyConName )
    73 72
     import GHC.Builtin.WiredIn.Prim( fUNTyCon )
    
    74 73
     import GHC.Data.Maybe( orElse )
    
    75 74
     
    
    76
    -import GHC.Utils.EndoOS
    
    77 75
     import GHC.Utils.Misc
    
    78 76
     import GHC.Utils.Panic.Plain
    
    79 77
     
    
    80 78
     {-
    
    81 79
     ************************************************************************
    
    82 80
     *                                                                      *
    
    83
    -       Find the shallow free variables of term
    
    81
    +                  Free variables of terms
    
    84 82
     *                                                                      *
    
    85 83
     ************************************************************************
    
    86 84
     
    
    87 85
     Note [Free variables of an expression]
    
    88 86
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    89
    -This function simply finds the shallow free variables of an expression.
    
    90
    -So far as type variables are concerned, it only finds tyvars that are
    
    91
    -        * free in type arguments,
    
    92
    -        * free in the type of a binder,
    
    93
    -but not those that are free in the type of variable occurrences.
    
    94
    -
    
    95
    -(FVE1) For /types/ we have a shallow free-var finder and a deep free-var finder,
    
    96
    -  both implemented via TyCoFolder.  For /terms/ we have just one free-var
    
    97
    -  finder (shallow).
    
    98
    -
    
    99
    -  If we want the deep free vars (as in `deepExprsFreeVarsDSet`) we use
    
    100
    -  `closeOverKinds`. There is no deep reason for this.  Maybe we should
    
    101
    -  make a folder for terms as well.
    
    102
    --}
    
    87
    +'exprFreeVars' computes the /deep/ free variables of an expression, in the
    
    88
    +sense of Note [Shallow and deep free variables] in GHC.Core.TyCo.FVs:
    
    89
    +
    
    90
    +(FVE1) An occurrence of a variable `v` contributes `v` together with the deep
    
    91
    +  free variables of v's type (and, for an Id, of its multiplicity).
    
    103 92
     
    
    93
    +The selective variants, e.g. 'exprSomeFreeVars', are also deep.
    
    94
    +They only collect interesting free variables, and entirely skip looking into
    
    95
    +the kind of non-interesting free variables.
    
    96
    +
    
    97
    +The type of a variable is traversed only when the variable is first collected,
    
    98
    +so each free variable's type is visited at most once per call; see
    
    99
    +Note [Computing deep free variables] in GHC.Core.TyCo.FVs.
    
    100
    +-}
    
    104 101
     
    
    105 102
     -- | Find all locally-defined free Ids or type variables in an expression
    
    106 103
     -- returning a non-deterministic set.
    
    104
    +--
    
    105
    +-- The result is deep; see Note [Free variables of an expression].
    
    107 106
     exprFreeVars :: CoreExpr -> VarSet
    
    108 107
     exprFreeVars = dVarSetToVarSet . exprFreeVarsDSet
    
    109 108
     
    
    110 109
     -- | Find all locally-defined free Ids or type variables in an expression
    
    111 110
     -- returning a deterministic set.
    
    111
    +--
    
    112
    +-- The result is deep; see Note [Free variables of an expression].
    
    112 113
     exprFreeVarsDSet :: CoreExpr -> DVarSet
    
    113 114
     exprFreeVarsDSet = runFVSelective isLocalVar . exprFVs
    
    114 115
     
    
    115
    --- | Find all locally-defined free Ids or type variables in several expressions
    
    116
    +-- | Find all locally-defined free Ids or type variables in several expressions,
    
    116 117
     -- returning a non-deterministic set.
    
    118
    +--
    
    119
    +-- The result is deep; see Note [Free variables of an expression].
    
    117 120
     exprsFreeVars :: [CoreExpr] -> VarSet
    
    118 121
     exprsFreeVars = dVarSetToVarSet . exprsFreeVarsDSet
    
    119 122
     
    
    120
    --- | Find all locally-defined free Ids or type variables in several expressions
    
    123
    +-- | Find all locally-defined free Ids or type variables in several expressions,
    
    121 124
     -- returning a deterministically ordered list.
    
    125
    +--
    
    126
    +-- The result is deep; see Note [Free variables of an expression].
    
    122 127
     exprsFreeVarsList :: [CoreExpr] -> [Var]
    
    123 128
     exprsFreeVarsList = runFVSelectiveList isLocalVar . exprsFVs
    
    124 129
     
    
    130
    +-- | Find all locally-defined free Ids or type variables in several expressions,
    
    131
    +-- returning a deterministic set.
    
    132
    +--
    
    133
    +-- The result is deep; see Note [Free variables of an expression].
    
    125 134
     exprsFreeVarsDSet :: [CoreExpr] -> DVarSet
    
    126 135
     exprsFreeVarsDSet = runFVSelective isLocalVar . exprsFVs
    
    127 136
     
    
    128
    -deepExprsFreeVarsDSet :: [CoreExpr] -> DVarSet
    
    129
    --- See (FVE1) in Note [Free variables of an expression]
    
    130
    -deepExprsFreeVarsDSet = closeOverKindsDSet . exprsFreeVarsDSet
    
    131
    -
    
    132 137
     -- | Find all locally-defined free Ids or type variables in an expression
    
    133 138
     -- returning a deterministically ordered list.
    
    139
    +--
    
    140
    +-- The result is deep; see Note [Free variables of an expression].
    
    134 141
     exprFreeVarsList :: CoreExpr -> [Var]
    
    135 142
     exprFreeVarsList = dVarSetElems . exprFreeVarsDSet
    
    136 143
     
    
    137
    --- | Find all locally-defined free Ids in an expression
    
    138
    -exprFreeIds :: CoreExpr -> IdSet        -- Find all locally-defined free Ids
    
    144
    +-- | Find all locally-defined free Ids in an expression.
    
    145
    +--
    
    146
    +-- The result is deep; see Note [Free variables of an expression].
    
    147
    +exprFreeIds :: CoreExpr -> IdSet
    
    139 148
     exprFreeIds = dVarSetToVarSet . exprFreeIdsDSet
    
    140 149
     
    
    141
    -exprsFreeIds :: [CoreExpr] -> IdSet        -- Find all locally-defined free Ids
    
    150
    +-- | Find all locally-defined free Ids in several expressions.
    
    151
    +--
    
    152
    +-- The result is deep; see Note [Free variables of an expression].
    
    153
    +exprsFreeIds :: [CoreExpr] -> IdSet
    
    142 154
     exprsFreeIds = dVarSetToVarSet . exprsFreeIdsDSet
    
    143 155
     
    
    144 156
     -- | Find all locally-defined free Ids in an expression
    
    145 157
     -- returning a deterministic set.
    
    146
    -exprFreeIdsDSet :: CoreExpr -> DIdSet -- Find all locally-defined free Ids
    
    158
    +--
    
    159
    +-- The result is deep; see Note [Free variables of an expression].
    
    160
    +exprFreeIdsDSet :: CoreExpr -> DIdSet
    
    147 161
     exprFreeIdsDSet = runFVSelective isLocalId . exprFVs
    
    148 162
     
    
    149 163
     -- | Find all locally-defined free Ids in several expressions
    
    150 164
     -- returning a deterministic set.
    
    151
    -exprsFreeIdsDSet :: [CoreExpr] -> DIdSet -- Find all locally-defined free Ids
    
    165
    +--
    
    166
    +-- The result is deep; see Note [Free variables of an expression].
    
    167
    +exprsFreeIdsDSet :: [CoreExpr] -> DIdSet
    
    152 168
     exprsFreeIdsDSet = runFVSelective isLocalId . exprsFVs
    
    153 169
     
    
    154 170
     -- | Find all locally-defined free Ids in an expression
    
    155 171
     -- returning a deterministically ordered list.
    
    156
    -exprFreeIdsList :: CoreExpr -> [Id] -- Find all locally-defined free Ids
    
    172
    +--
    
    173
    +-- The result is deep; see Note [Free variables of an expression].
    
    174
    +exprFreeIdsList :: CoreExpr -> [Id]
    
    157 175
     exprFreeIdsList = dVarSetElems . exprFreeIdsDSet
    
    158 176
     
    
    159 177
     -- | Find all locally-defined free Ids in several expressions
    
    160 178
     -- returning a deterministically ordered list.
    
    161
    -exprsFreeIdsList :: [CoreExpr] -> [Id]   -- Find all locally-defined free Ids
    
    179
    +--
    
    180
    +-- The result is deep; see Note [Free variables of an expression].
    
    181
    +exprsFreeIdsList :: [CoreExpr] -> [Id]
    
    162 182
     exprsFreeIdsList = dVarSetElems . exprsFreeIdsDSet
    
    163 183
     
    
    164
    --- | Find all locally defined free Ids in a binding group
    
    184
    +-- | Find all locally-defined free Ids or type variables in a binding group.
    
    185
    +--
    
    186
    +-- The result is deep; see Note [Free variables of an expression].
    
    165 187
     bindFreeVars :: CoreBind -> VarSet
    
    166 188
     bindFreeVars = runFVSelectiveSet isLocalVar . bind_fvs
    
    167 189
     
    
    ... ... @@ -171,6 +193,8 @@ bind_fvs (Rec prs) = addBndrsSelectiveFV (map fst prs) $
    171 193
                             mapUnionFV rhs_fvs prs
    
    172 194
     
    
    173 195
     -- | Finds free variables in an expression selected by a predicate
    
    196
    +--
    
    197
    +-- See Note [Free variables of an expression].
    
    174 198
     exprSomeFreeVars :: InterestingVarFun   -- ^ Says which 'Var's are interesting
    
    175 199
                      -> CoreExpr
    
    176 200
                      -> VarSet
    
    ... ... @@ -221,30 +245,25 @@ addCoreBndrsFV :: [CoreBndr] -> SelectiveDFV -> SelectiveDFV
    221 245
     addCoreBndrsFV bndrs fv = foldr addCoreBndrFV fv bndrs
    
    222 246
     
    
    223 247
     unitFV :: Var -> SelectiveDFV
    
    224
    --- Deals with an occurrence
    
    225
    --- Shallow: does not look at the kind
    
    226
    -unitFV v = MkFV (\env -> EndoOS (do_it env))
    
    227
    -  where
    
    228
    -    do_it (bvs, is_interesting) acc
    
    229
    -      | v `elemVarSet` bvs     = acc  -- First exclude the bound vars
    
    230
    -      | not (is_interesting v) = acc  -- The "selective" bit
    
    231
    -      | v `elemDVarSet` acc    = acc
    
    232
    -      | otherwise              = acc `extendDVarSet` v
    
    248
    +-- Deals with an occurrence: the variable and, if it is newly collected,
    
    249
    +-- the free variables of its type and multiplicity.
    
    250
    +-- See (FVE1) in Note [Free variables of an expression]
    
    251
    +unitFV = deepSelUnitFV bndrTypeTyCoFVs
    
    233 252
     
    
    234 253
     exprsFVs :: [CoreExpr] -> SelectiveDFV
    
    235 254
     exprsFVs = mapUnionFV exprFVs
    
    236 255
     
    
    237 256
     exprFVs :: CoreExpr -> SelectiveDFV
    
    238
    -exprFVs (Type ty)       = shallowSelTypeFV ty
    
    239
    -exprFVs (Coercion co)   = shallowSelCoFV co
    
    257
    +exprFVs (Type ty)       = deepSelTypeFV ty
    
    258
    +exprFVs (Coercion co)   = deepSelCoFV co
    
    240 259
     exprFVs (Var var)       = unitFV var
    
    241 260
     exprFVs (Lit _)         = mempty
    
    242 261
     exprFVs (Tick t expr)   = tickish_fvs t `mappend` exprFVs expr
    
    243 262
     exprFVs (App fun arg)   = exprFVs fun `mappend` exprFVs arg
    
    244 263
     exprFVs (Lam bndr body) = addCoreBndrFV bndr (exprFVs body)
    
    245
    -exprFVs (Cast expr co)  = exprFVs expr `mappend` shallowSelCoFV co
    
    264
    +exprFVs (Cast expr co)  = exprFVs expr `mappend` deepSelCoFV co
    
    246 265
     exprFVs (Case scrut bndr ty alts)
    
    247
    -  = exprFVs scrut `mappend` shallowSelTypeFV ty `mappend`
    
    266
    +  = exprFVs scrut `mappend` deepSelTypeFV ty `mappend`
    
    248 267
         addCoreBndrFV bndr (mapUnionFV alt_fvs alts)
    
    249 268
       where
    
    250 269
         alt_fvs (Alt _ bndrs rhs) = addCoreBndrsFV bndrs (exprFVs rhs)
    
    ... ... @@ -267,13 +286,13 @@ tickish_fvs _ = mempty
    267 286
     
    
    268 287
     ---------
    
    269 288
     bndrTypeTyCoFVs :: Var -> SelectiveDFV
    
    270
    --- Find the free variables of a binder.
    
    289
    +-- Find the (deep) free variables of the type of a variable.
    
    271 290
     -- In the case of ids, don't forget the multiplicity field!
    
    272 291
     bndrTypeTyCoFVs var
    
    273
    -  = shallowSelTypeFV (varType var) `mappend` mult_fvs
    
    292
    +  = deepSelTypeFV (varType var) `mappend` mult_fvs
    
    274 293
       where
    
    275 294
         mult_fvs = case varMultMaybe var of
    
    276
    -                 Just mult -> shallowSelTypeFV mult
    
    295
    +                 Just mult -> deepSelTypeFV mult
    
    277 296
                      Nothing   -> mempty
    
    278 297
     
    
    279 298
     dBndrTypeTyCoVars :: Var -> DTyCoVarSet
    
    ... ... @@ -286,11 +305,10 @@ bndrFreeVars id = assert (isId id) $
    286 305
                       dBndrFreeVars id
    
    287 306
     
    
    288 307
     dBndrFreeVars :: Id -> DVarSet
    
    289
    --- Shallow free vars
    
    290 308
     dBndrFreeVars id = runFVSelective isLocalVar $ bndrFVs id
    
    291 309
     
    
    292 310
     bndrFVs :: Id -> SelectiveDFV
    
    293
    --- Shallow free vars of types, rules, and inlining
    
    311
    +-- Free vars of types, rules, and inlining
    
    294 312
     bndrFVs id = assert (isId id) $
    
    295 313
                  bndrTypeTyCoFVs id `mappend`
    
    296 314
                  bndrRuleAndUnfoldingFVs id
    
    ... ... @@ -593,7 +611,8 @@ Note [The FVAnn invariant]
    593 611
     Invariant: a FVAnn, say S, is closed:
    
    594 612
       That is: if v is in S,
    
    595 613
                then freevars( v's type/kind ) is also in S
    
    596
    -So FVAnn computes /deep/ free variables
    
    614
    +So FVAnn computes /deep/ free variables, just like `exprFreeVars` does;
    
    615
    +see Note [Free variables of an expression].
    
    597 616
     -}
    
    598 617
     
    
    599 618
     type FVAnn = DVarSet  -- See Note [The FVAnn invariant]
    
    ... ... @@ -690,22 +709,15 @@ freeVars = go
    690 709
       where
    
    691 710
         go :: CoreExpr -> CoreExprWithFVs
    
    692 711
         go (Var v)
    
    693
    -      | isLocalVar v = (aFreeVar v `unionDVarSet` ty_fvs `unionDVarSet` mult_vars, AnnVar v)
    
    694
    -      | otherwise    = (emptyDVarSet,                 AnnVar v)
    
    695
    -      where
    
    696
    -        mult_vars = tyCoVarsOfTypeDSet (idMult v)
    
    697
    -        ty_fvs = dBndrTypeTyCoVars v
    
    698
    -                 -- See Note [The FVAnn invariant]
    
    712
    +      | isLocalVar v = (aFreeVar v `unionDVarSet` dBndrTypeTyCoVars v, AnnVar v)
    
    713
    +                       -- See Note [The FVAnn invariant]
    
    714
    +      | otherwise    = (emptyDVarSet, AnnVar v)
    
    699 715
     
    
    700 716
         go (Lit lit) = (emptyDVarSet, AnnLit lit)
    
    701 717
         go (Lam b body)
    
    702
    -      = ( b_fvs `unionDVarSet` (b `delBinderFV` body_fvs)
    
    703
    -        , AnnLam b body' )
    
    718
    +      = ( b `delBinderFV` body_fvs, AnnLam b body' )
    
    704 719
           where
    
    705 720
             body'@(body_fvs, _) = go body
    
    706
    -        b_ty  = idType b
    
    707
    -        b_fvs = tyCoVarsOfTypeDSet b_ty
    
    708
    -                -- See Note [The FVAnn invariant]
    
    709 721
     
    
    710 722
         go (App fun arg)
    
    711 723
           = ( freeVarsOf fun' `unionDVarSet` freeVarsOf arg'
    
    ... ... @@ -750,8 +762,7 @@ freeVars = go
    750 762
             , AnnTick tickish expr2 )
    
    751 763
           where
    
    752 764
             expr2 = go expr
    
    753
    -        tickishFVs (Breakpoint _ _ ids) = mkDVarSet ids
    
    754
    -        tickishFVs _                    = emptyDVarSet
    
    765
    +        tickishFVs = runFVSelective isLocalVar . tickish_fvs
    
    755 766
     
    
    756 767
         go (Type ty)     = (tyCoVarsOfTypeDSet ty, AnnType ty)
    
    757 768
         go (Coercion co) = (tyCoVarsOfCoDSet co, AnnCoercion co)

  • compiler/GHC/Core/Lint.hs
    ... ... @@ -2216,7 +2216,8 @@ lintCoreRule fun fun_ty rule@(Rule { ru_name = name, ru_bndrs = bndrs
    2216 2216
       where
    
    2217 2217
         rule_doc = text "Rule" <+> doubleQuotes (ftext name) <> colon
    
    2218 2218
     
    
    2219
    -    lhs_fvs = deepExprsFreeVarsDSet args  -- Matching binds deeply
    
    2219
    +    lhs_fvs = exprsFreeVarsDSet args  -- Rule matching binds deeply, so compare
    
    2220
    +                                      -- against the deep free vars
    
    2220 2221
         rhs_fvs = exprFreeVarsDSet rhs
    
    2221 2222
     
    
    2222 2223
         is_bad_bndr :: Var -> Bool
    

  • compiler/GHC/Core/Opt/Arity.hs
    ... ... @@ -3230,15 +3230,12 @@ etaBodyForJoinPoint need_args body
    3230 3230
                                              ppr body $$ ppr (exprType body)
    
    3231 3231
     
    
    3232 3232
         body_ty = exprType body
    
    3233
    -    in_scope = mkInScopeSet (exprFreeVars body `unionVarSet` tyCoVarsOfType body_ty)
    
    3234
    -    -- in_scope is a bit tricky.
    
    3235
    -    -- - We are wrapping `body` in some value lambdas, so must not shadow
    
    3236
    -    --   any free vars of `body`
    
    3237
    -    -- - We are wrapping `body` in some type lambdas, so must not shadow any
    
    3238
    -    --   tyvars in body_ty.  Example: body is just a variable
    
    3239
    -    --            (g :: forall (a::k). T k a -> Int)
    
    3240
    -    --   We must not shadown that `k` when adding the /\a. So treat the free vars
    
    3241
    -    --   of body_ty as in-scope.  Showed up in #23026.
    
    3233
    +    in_scope = mkInScopeSet (exprFreeVars body)
    
    3234
    +    -- We are wrapping `body` in lambdas, so the in-scope set must contain the
    
    3235
    +    -- /deep/ free vars of `body` (exprFreeVars returns deep free vars).
    
    3236
    +    -- Why? See Note [No type-shadowing in Core]: if body is just a variable
    
    3237
    +    --        (g :: forall (a::k). T k a -> Int)
    
    3238
    +    -- we must not shadow that `k` when adding the /\a (#23026).
    
    3242 3239
     
    
    3243 3240
     --------------
    
    3244 3241
     freshEtaId :: Int -> Subst -> Scaled Type -> (Subst, Id)
    

  • compiler/GHC/Core/Opt/Simplify/Utils.hs
    ... ... @@ -2360,13 +2360,14 @@ new binding is abstracted. Several points worth noting
    2360 2360
                poly_t = /\ a b -> (e1, e2)
    
    2361 2361
                poly_x = /\ a   -> fst (poly_t a *b*)
    
    2362 2362
     
    
    2363
    -(AB2) We must do closeOverKinds.  Example (#10934):
    
    2363
    +(AB2) We must abstract over kind variables too.  Example (#10934):
    
    2364 2364
            f = /\k (f:k->*) (a:k). let t = AccFailure @ (f a) in ...
    
    2365 2365
           Here we want to float 't', but we must remember to abstract over
    
    2366 2366
           'k' as well, even though it is not explicitly mentioned in the RHS,
    
    2367 2367
           otherwise we get
    
    2368 2368
              t = /\ (f:k->*) (a:k). AccFailure @ (f a)
    
    2369
    -      which is obviously bogus.
    
    2369
    +      which is obviously bogus.  `exprSomeFreeVars isTyVar` is deep,
    
    2370
    +      so the kind variables are picked up with the rest.
    
    2370 2371
     
    
    2371 2372
     (AB3) We get the variables to abstract over by filtering down the
    
    2372 2373
           the main_tvs for the original function, picking only ones
    
    ... ... @@ -2449,7 +2450,7 @@ abstractFloats uf_opts top_lvl main_tvs floats body
    2449 2450
             rhs' = GHC.Core.Subst.substExpr subst rhs
    
    2450 2451
     
    
    2451 2452
             -- tvs_here: see Note [Which type variables to abstract over]
    
    2452
    -        tvs_here = choose_tvs (exprSomeFreeVars isTyVar rhs')
    
    2453
    +        tvs_here = choose_tvs (exprSomeFreeVars isTyVar rhs')  -- (AB2)
    
    2453 2454
     
    
    2454 2455
         abstract subst (CyclicSCC trpls)
    
    2455 2456
           = do { (poly_ids, poly_apps) <- mapAndUnzipM (mk_poly1 tvs_here) ids
    
    ... ... @@ -2478,14 +2479,12 @@ abstractFloats uf_opts top_lvl main_tvs floats body
    2478 2479
                               --    because it has a non-CoVar precondition
    
    2479 2480
                | Just poly_app <- GHC.Core.Subst.lookupIdSubst_maybe subst var
    
    2480 2481
                = -- 'var' is like 'x' in (AB4)
    
    2481
    -             exprSomeFreeVars isTyVar poly_app `unionVarSet` free_tvs
    
    2482
    +             exprSomeFreeVars isTyVar poly_app `unionVarSet` free_tvs  -- (AB2)
    
    2482 2483
                | otherwise
    
    2483 2484
                = free_tvs
    
    2484 2485
     
    
    2485 2486
         choose_tvs free_tvs
    
    2486
    -       = filter (`elemVarSet` all_free_tvs) main_tvs  -- (AB3)
    
    2487
    -       where
    
    2488
    -         all_free_tvs = closeOverKinds free_tvs       -- (AB2)
    
    2487
    +       = filter (`elemVarSet` free_tvs) main_tvs  -- (AB3)
    
    2489 2488
     
    
    2490 2489
         mk_poly1 :: [TyVar] -> Id -> SimplM (Id, CoreExpr)
    
    2491 2490
         mk_poly1 tvs_here var
    

  • compiler/GHC/Core/Opt/SpecConstr.hs
    ... ... @@ -60,6 +60,7 @@ import GHC.Types.Unique( hasKey )
    60 60
     
    
    61 61
     import GHC.Data.Maybe     ( fromMaybe, orElse, catMaybes, isJust, isNothing )
    
    62 62
     import GHC.Data.FastString
    
    63
    +import GHC.Data.Pair
    
    63 64
     
    
    64 65
     import GHC.Utils.Misc
    
    65 66
     import GHC.Utils.Outputable
    
    ... ... @@ -2317,17 +2318,18 @@ they are constructor applications.
    2317 2318
     Note [Free type variables of the qvar types]
    
    2318 2319
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2319 2320
     In a call (f @a x True), that we want to specialise, what variables should
    
    2320
    -we quantify over.  Clearly over 'a' and 'x', but what about any type variables
    
    2321
    -free in x's type?  In fact we don't need to worry about them because (f @a)
    
    2322
    -can only be a well-typed application if its type is compatible with x, so any
    
    2323
    -variables free in x's type must be free in (f @a), and hence either be gathered
    
    2324
    -via 'a' itself, or be in scope at f's defn.  Hence we just take
    
    2325
    -  (exprsFreeVars pats).
    
    2326
    -
    
    2327
    -BUT phantom type synonyms can mess this reasoning up,
    
    2328
    -  eg   x::T b   with  type T b = Int
    
    2329
    -So we apply expandTypeSynonyms to the bound Ids.
    
    2330
    -See # 5458.  Yuk.
    
    2321
    +we quantify over?  Clearly over 'a' and 'x', but what about any type variables
    
    2322
    +free in x's type?  In fact we don't need to worry about them, because
    
    2323
    +argsToPats gives 'x' the type of the corresponding argument of f, instantiated
    
    2324
    +at the type arguments of the call pattern (and similarly for the fields of a
    
    2325
    +data constructor in the pattern).  So any variables free in x's type are free
    
    2326
    +in (f @a), and hence either gathered via 'a' itself, or in scope at f's defn.
    
    2327
    +Hence we just take (exprsFreeVars pats).
    
    2328
    +
    
    2329
    +We do not use the type of the actual argument: it is not necessarily
    
    2330
    +syntactically equal to the type of f's argument, and so may mention other
    
    2331
    +variables, e.g. with a phantom type synonym (#5458)
    
    2332
    +  x::T b   with  type T b = Int
    
    2331 2333
     
    
    2332 2334
     Note [SpecConstr call patterns]
    
    2333 2335
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -2337,7 +2339,7 @@ Wrinkles:
    2337 2339
     
    
    2338 2340
     * The list of argument patterns, cp_args, is no longer than the
    
    2339 2341
       visible lambdas of the binding, ri_arg_occs.  This is done via
    
    2340
    -  the zipWithM in callToPat.
    
    2342
    +  argsToPats in callToPat.
    
    2341 2343
     
    
    2342 2344
     * The list of argument patterns can certainly be shorter than the
    
    2343 2345
       lambdas in the function definition (under-saturated).  For example
    
    ... ... @@ -2602,8 +2604,9 @@ callToPat :: ScEnv -> [ArgOcc] -> Call -> UniqSM (Maybe CallPat)
    2602 2604
     callToPat env bndr_occs call@(Call fn args con_env)
    
    2603 2605
       = do  { let in_scope = substInScopeSet (sc_subst env)
    
    2604 2606
     
    
    2605
    -        ; arg_triples <- zipWith3M (argToPat env in_scope con_env) args bndr_occs (map (const NotMarkedStrict) args)
    
    2606
    -                   -- This zip trims the args to be no longer than
    
    2607
    +        ; arg_triples <- argsToPats env in_scope con_env (idType fn) args bndr_occs
    
    2608
    +                                    (repeat NotMarkedStrict)
    
    2609
    +                   -- This trims the args to be no longer than
    
    2607 2610
                        -- the lambdas in the function definition (bndr_occs)
    
    2608 2611
     
    
    2609 2612
               -- Drop boring patterns from the end
    
    ... ... @@ -2631,14 +2634,11 @@ callToPat env bndr_occs call@(Call fn args con_env)
    2631 2634
                     -- See Note [Shadowing in SpecConstr] at the top
    
    2632 2635
     
    
    2633 2636
                   (qktvs, qids) = partition isTyVar qvars
    
    2634
    -              qvars'        = scopedSort qktvs ++ map sanitise qids
    
    2637
    +              qvars'        = scopedSort qktvs ++ qids
    
    2635 2638
                     -- Order into kind variables, type variables, term variables
    
    2636 2639
                     -- The kind of a type variable may mention a kind variable
    
    2637 2640
                     -- and the type of a term variable may mention a type variable
    
    2638 2641
     
    
    2639
    -              sanitise id = updateIdTypeAndMult expandTypeSynonyms id
    
    2640
    -                -- See Note [Free type variables of the qvar types]
    
    2641
    -
    
    2642 2642
             -- Check for bad coercion variables: see Note [SpecConstr and casts]
    
    2643 2643
             ; let bad_covars = filter isCoVar qids
    
    2644 2644
             ; warnPprTrace (not (null bad_covars))
    
    ... ... @@ -2657,18 +2657,49 @@ callToPat env bndr_occs call@(Call fn args con_env)
    2657 2657
                       ; return (Just cp_res) }
    
    2658 2658
               else return Nothing }
    
    2659 2659
     
    
    2660
    -    -- argToPat takes an actual argument, and returns an abstracted
    
    2661
    -    -- version, consisting of just the "constructor skeleton" of the
    
    2662
    -    -- argument, with non-constructor sub-expression replaced by new
    
    2663
    -    -- placeholder variables.  For example:
    
    2664
    -    --    C a (D (f x) (g y))  ==>  C p1 (D p2 p3)
    
    2660
    +-- | Turn the arguments of an application into patterns using 'argToPat'.
    
    2661
    +--
    
    2662
    +-- See Note [Free type variables of the qvar types].
    
    2663
    +argsToPats :: ScEnv
    
    2664
    +           -> InScopeSet          -- ^ what's in scope at the function definition site
    
    2665
    +           -> ValueEnv            -- ^ 'ValueEnv' at the call site
    
    2666
    +           -> Type                -- ^ type of the head (function or data constructor)
    
    2667
    +           -> [CoreArg]           -- ^ arguments of the head
    
    2668
    +           -> [ArgOcc]            -- ^ occurrence info, one per argument; the result is trimmed to this length
    
    2669
    +           -> [StrictnessMark]    -- ^ strictness info, one per value argument
    
    2670
    +           -> UniqSM [(Bool, CoreArg, [Id])]
    
    2671
    +argsToPats env in_scope val_env = go
    
    2672
    +  where
    
    2673
    +    go _ [] _ _ = return []
    
    2674
    +    go _ _ [] _ = return []
    
    2675
    +    go fun_ty (arg : args) (occ : occs) strs
    
    2676
    +      = do { (pat, strs') <- case arg of
    
    2677
    +               Type {} -> do { pat <- argToPat env in_scope val_env arg_ty arg occ NotMarkedStrict
    
    2678
    +                             ; return (pat, strs) }
    
    2679
    +               _ | str : strs' <- strs
    
    2680
    +                       -> do { pat <- argToPat env in_scope val_env arg_ty arg occ str
    
    2681
    +                             ; return (pat, strs') }
    
    2682
    +                 | otherwise
    
    2683
    +                       -> pprPanic "argsToPats: more value arguments than strictness marks"
    
    2684
    +                                   (ppr fun_ty $$ ppr (arg : args))
    
    2685
    +           ; pats <- go (applyTypeToArgs fun_ty [sndOf3 pat]) args occs strs'
    
    2686
    +           ; return (pat : pats) }
    
    2687
    +      where
    
    2688
    +        arg_ty = piTyBinderType (fst (splitPiTy fun_ty))
    
    2665 2689
     
    
    2690
    +-- | 'argToPat' takes an actual argument, and returns an abstracted
    
    2691
    +-- version, consisting of just the "constructor skeleton" of the
    
    2692
    +-- argument, with non-constructor sub-expression replaced by new
    
    2693
    +-- placeholder variables.  For example:
    
    2694
    +--
    
    2695
    +-- > C a (D (f x) (g y))  ==>  C p1 (D p2 p3)
    
    2666 2696
     argToPat :: ScEnv
    
    2667
    -         -> InScopeSet                  -- What's in scope at the fn defn site
    
    2668
    -         -> ValueEnv                    -- ValueEnv at the call site
    
    2669
    -         -> CoreArg                     -- A call arg (or component thereof)
    
    2670
    -         -> ArgOcc
    
    2671
    -         -> StrictnessMark              -- Tells us if this argument is a strict field of a data constructor
    
    2697
    +         -> InScopeSet                  -- ^ what's in scope at the function definition site
    
    2698
    +         -> ValueEnv                    -- ^ 'ValueEnv' at the call site
    
    2699
    +         -> Type                        -- ^ type for this argument
    
    2700
    +         -> CoreArg                     -- ^ A call arg (or component thereof)
    
    2701
    +         -> ArgOcc                      -- ^ occurrence info for the argument
    
    2702
    +         -> StrictnessMark              -- ^ Tells us if this argument is a strict field of a data constructor
    
    2672 2703
                                             -- See Note [SpecConstr and strict fields]
    
    2673 2704
              -> UniqSM (Bool, CoreArg, [Id])
    
    2674 2705
     
    
    ... ... @@ -2682,25 +2713,26 @@ argToPat :: ScEnv
    2682 2713
     --              lvl7         --> (True, lvl7)      if lvl7 is bound
    
    2683 2714
     --                                                 somewhere further out
    
    2684 2715
     
    
    2685
    -argToPat env in_scope val_env arg arg_occ arg_str
    
    2716
    +argToPat env in_scope val_env pat_ty arg arg_occ arg_str
    
    2686 2717
       = do
    
    2687 2718
         -- pprTraceM "argToPatIn" (ppr arg)
    
    2688
    -    !res <- argToPat1 env in_scope val_env arg arg_occ arg_str
    
    2719
    +    !res <- argToPat1 env in_scope val_env pat_ty arg arg_occ arg_str
    
    2689 2720
         -- pprTraceM "argToPatOut" (ppr res)
    
    2690 2721
         return res
    
    2691 2722
     
    
    2692 2723
     argToPat1 :: ScEnv
    
    2693 2724
       -> InScopeSet
    
    2694 2725
       -> ValueEnv
    
    2726
    +  -> Type
    
    2695 2727
       -> Expr CoreBndr
    
    2696 2728
       -> ArgOcc
    
    2697 2729
       -> StrictnessMark
    
    2698 2730
       -> UniqSM (Bool, Expr CoreBndr, [Id])
    
    2699
    -argToPat1 _env _in_scope _val_env arg@(Type {}) _arg_occ _arg_str
    
    2731
    +argToPat1 _env _in_scope _val_env _pat_ty arg@(Type {}) _arg_occ _arg_str
    
    2700 2732
       = return (False, arg, [])
    
    2701 2733
     
    
    2702
    -argToPat1 env in_scope val_env (Tick _ arg) arg_occ arg_str
    
    2703
    -  = argToPat env in_scope val_env arg arg_occ arg_str
    
    2734
    +argToPat1 env in_scope val_env pat_ty (Tick _ arg) arg_occ arg_str
    
    2735
    +  = argToPat env in_scope val_env pat_ty arg arg_occ arg_str
    
    2704 2736
             -- Note [Tick annotations in call patterns]
    
    2705 2737
             -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2706 2738
             -- Ignore Notes.  In particular, we want to ignore any InlineMe notes
    
    ... ... @@ -2708,8 +2740,8 @@ argToPat1 env in_scope val_env (Tick _ arg) arg_occ arg_str
    2708 2740
             -- ride roughshod over them all for now.
    
    2709 2741
             --- See Note [Tick annotations in RULE matching] in GHC.Core.Rules
    
    2710 2742
     
    
    2711
    -argToPat1 env in_scope val_env (Let _ arg) arg_occ arg_str
    
    2712
    -  = argToPat env in_scope val_env arg arg_occ arg_str
    
    2743
    +argToPat1 env in_scope val_env pat_ty (Let _ arg) arg_occ arg_str
    
    2744
    +  = argToPat env in_scope val_env pat_ty arg arg_occ arg_str
    
    2713 2745
             -- See Note [Matching lets] in "GHC.Core.Rules"
    
    2714 2746
             -- Look through let expressions
    
    2715 2747
             -- e.g.         f (let v = rhs in (v,w))
    
    ... ... @@ -2717,35 +2749,34 @@ argToPat1 env in_scope val_env (Let _ arg) arg_occ arg_str
    2717 2749
             -- because the rule-matcher will look through the let.
    
    2718 2750
     
    
    2719 2751
        -- Casts: see Note [SpecConstr and casts]
    
    2720
    -argToPat1 env in_scope val_env (Cast arg co) arg_occ arg_str
    
    2752
    +argToPat1 env in_scope val_env pat_ty (Cast arg co) arg_occ arg_str
    
    2721 2753
       | not (ignoreType env ty2)
    
    2722
    -  = do  { (interesting, arg', strict_args) <- argToPat env in_scope val_env arg arg_occ arg_str
    
    2754
    +  = do  { (interesting, arg', strict_args) <- argToPat env in_scope val_env ty1 arg arg_occ arg_str
    
    2723 2755
             ; if not interesting then
    
    2724
    -                wildCardPat ty2 arg_str
    
    2756
    +                wildCardPat pat_ty arg_str
    
    2725 2757
               else
    
    2726 2758
                     return (interesting, Cast arg' co, strict_args) }
    
    2727 2759
       where
    
    2728
    -    ty2 = coercionRKind co
    
    2760
    +    Pair ty1 ty2 = coercionKind co
    
    2729 2761
     
    
    2730 2762
       -- Check for a constructor application
    
    2731 2763
       -- NB: this *precedes* the Var case, so that we catch nullary constrs
    
    2732
    -argToPat1 env in_scope val_env arg arg_occ _arg_str
    
    2764
    +argToPat1 env in_scope val_env _pat_ty arg arg_occ _arg_str
    
    2733 2765
       | Just (ConVal _wf (DataAlt dc) args) <- isValue val_env arg
    
    2734 2766
         -- Ignore `_wf` here; see Note [ConVal work-free-ness] (2)
    
    2735 2767
       , not (ignoreDataCon env dc)        -- See Note [NoSpecConstr]
    
    2736 2768
       , Just arg_occs <- mb_scrut dc
    
    2737 2769
       = do { let (ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) args
    
    2738
    -             con_str, matched_str :: [StrictnessMark]
    
    2770
    +             con_str :: [StrictnessMark]
    
    2739 2771
                  -- con_str corresponds 1-1 with the /value/ arguments
    
    2740
    -             -- matched_str corresponds 1-1 with /all/ arguments
    
    2741 2772
                  con_str = dataConRepStrictness dc
    
    2742
    -             matched_str = match_vals con_str rest_args
    
    2773
    +             con_ty  = applyTypeToArgs (dataConRepType dc) ty_args
    
    2743 2774
           --  ; pprTraceM "bangs" (ppr (length rest_args == length con_str) $$
    
    2744 2775
           --       ppr dc $$
    
    2745 2776
           --       ppr con_str $$
    
    2746 2777
           --       ppr rest_args $$
    
    2747 2778
           --       ppr (map isTypeArg rest_args))
    
    2748
    -       ; prs <- zipWith3M (argToPat env in_scope val_env) rest_args arg_occs matched_str
    
    2779
    +       ; prs <- argsToPats env in_scope val_env con_ty rest_args arg_occs con_str
    
    2749 2780
            ; let args' = map sndOf3 prs :: [CoreArg]
    
    2750 2781
            ; assertPpr (length con_str == length (filter isRuntimeArg rest_args))
    
    2751 2782
                 ( ppr con_str $$ ppr rest_args $$
    
    ... ... @@ -2760,17 +2791,6 @@ argToPat1 env in_scope val_env arg arg_occ _arg_str
    2760 2791
                                 -> Just (repeat UnkOcc)
    
    2761 2792
                                 | otherwise
    
    2762 2793
                                 -> Nothing
    
    2763
    -    match_vals bangs (arg:args)
    
    2764
    -      | isTypeArg arg
    
    2765
    -      = NotMarkedStrict : match_vals bangs args
    
    2766
    -      | (b:bs) <- bangs
    
    2767
    -      = b : match_vals bs args
    
    2768
    -    match_vals [] [] = []
    
    2769
    -    match_vals as bs =
    
    2770
    -        pprPanic "spec-constr:argToPat - Bangs don't match value arguments"
    
    2771
    -            (text "arg:" <> ppr arg $$
    
    2772
    -             text "remaining args:" <> ppr as $$
    
    2773
    -             text "remaining bangs:" <> ppr bs)
    
    2774 2794
     
    
    2775 2795
       -- Check if the argument is a variable that
    
    2776 2796
       --    (a) is used in an interesting way in the function body
    
    ... ... @@ -2779,7 +2799,7 @@ argToPat1 env in_scope val_env arg arg_occ _arg_str
    2779 2799
       --         business of absence analysis, not SpecConstr.)
    
    2780 2800
       --    (b) we know what its value is
    
    2781 2801
       -- In that case it counts as "interesting"
    
    2782
    -argToPat1 env in_scope val_env (Var v) arg_occ arg_str
    
    2802
    +argToPat1 env in_scope val_env _pat_ty (Var v) arg_occ arg_str
    
    2783 2803
       | sc_force env || specialisableArgOcc arg_occ  -- (a)
    
    2784 2804
         -- See Note [Forcing specialisation], point (FS3)
    
    2785 2805
       , is_value                                     -- (b)
    
    ... ... @@ -2836,8 +2856,8 @@ argToPat in_scope val_env arg arg_occ
    2836 2856
     
    
    2837 2857
       -- The default case: make a wild-card
    
    2838 2858
       -- We use this for coercions too
    
    2839
    -argToPat1 _env _in_scope _val_env arg _arg_occ arg_str
    
    2840
    -  = wildCardPat (exprType arg) arg_str
    
    2859
    +argToPat1 _env _in_scope _val_env pat_ty _arg _arg_occ arg_str
    
    2860
    +  = wildCardPat pat_ty arg_str
    
    2841 2861
     
    
    2842 2862
     -- | wildCardPats are always boring
    
    2843 2863
     wildCardPat :: Type -> StrictnessMark -> UniqSM (Bool, CoreArg, [Id])
    

  • compiler/GHC/Core/Opt/Specialise.hs
    ... ... @@ -2111,7 +2111,7 @@ to push the cast back inside. It would be terrible if the cast
    2111 2111
     defeated specialisation!  Hence the use of collectBindersPushingCo.
    
    2112 2112
     
    
    2113 2113
     Note [Evidence foralls]
    
    2114
    -~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2114
    +~~~~~~~~~~~~~~~~~~~~~~~
    
    2115 2115
     Suppose (#12212) that we are specialising
    
    2116 2116
        f :: forall a b. (Num a, F a ~# F b) => blah
    
    2117 2117
     with a=b=Int. Then the RULE will be something like
    
    ... ... @@ -2120,18 +2120,13 @@ with a=b=Int. Then the RULE will be something like
    2120 2120
     where that `g` is really (Coercion (CoVar g)), since `g` is a
    
    2121 2121
     coercion variable and can't appear as (Var g).
    
    2122 2122
     
    
    2123
    -But both varToCoreExpr (when constructing the LHS args), and the
    
    2124
    -simplifier (when simplifying the LHS args), will transform to
    
    2123
    +When simplifying the LHS args, the simplifier may replace g with Refl:
    
    2125 2124
        RULE forall (d:Num Int) (g :: F Int ~ F Int).
    
    2126 2125
             f Int Int d <F Int> = f_spec
    
    2127
    -by replacing g with Refl.  So now 'g' is unbound, which results in a later
    
    2128
    -crash. So we use Refl right off the bat, and do not forall-quantify 'g':
    
    2129
    - * varToCoreExpr generates a (Coercion Refl)
    
    2130
    - * exprsFreeIdsList returns the Ids bound by the args,
    
    2131
    -   which won't include g
    
    2132
    -
    
    2133
    -You might wonder if this will match as often, but the simplifier replaces
    
    2134
    -complicated Refl coercions with Refl pretty aggressively.
    
    2126
    +So now 'g' is unbound on the LHS. That is OK: since g's type is
    
    2127
    +reflexive, the rule matcher instantiates it to Refl when the rule fires;
    
    2128
    +see Note [Unbound RULE binders] in GHC.Core.Rules. So specHeader simply
    
    2129
    +forall-quantifies 'g' like any other unspecialised binder.
    
    2135 2130
     
    
    2136 2131
     Note [Orphans and auto-generated rules]
    
    2137 2132
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -2483,13 +2478,13 @@ instance Outputable SpecArg where
    2483 2478
       ppr UnspecArg     = text "UnspecArg"
    
    2484 2479
     
    
    2485 2480
     specArgsFVs :: InterestingVarFun -> [SpecArg] -> VarSet
    
    2486
    --- Find the shallow deep free vars of the SpecArgs that are not already in scope
    
    2481
    +-- Find the (deep) free vars of the SpecArgs
    
    2487 2482
     specArgsFVs interesting args
    
    2488 2483
       = runFVSelectiveSet interesting $
    
    2489 2484
         mapUnionFV get args
    
    2490 2485
       where
    
    2491 2486
         get :: SpecArg -> SelectiveDFV
    
    2492
    -    get (SpecType ty)   = shallowSelTypeFV ty
    
    2487
    +    get (SpecType ty)   = deepSelTypeFV ty
    
    2493 2488
         get (SpecDict dx)   = exprFVs dx
    
    2494 2489
         get UnspecType      = mempty
    
    2495 2490
         get UnspecArg       = mempty
    
    ... ... @@ -2652,15 +2647,12 @@ specHeader subst (bndr:bndrs) (UnspecArg : args)
    2652 2647
                  <- specHeader subst1 bndrs args
    
    2653 2648
     
    
    2654 2649
            ; let dummy_arg = varToCoreExpr bndr'
    
    2655
    -               -- dummy_arg is usually just (Var bndr),
    
    2656
    -               -- but if bndr :: t1 ~# t2, it'll be (Coercion (CoVar bndr))
    
    2657
    -               --     or even Coercion Refl (if t1=t2)
    
    2658
    -               -- See Note [Evidence foralls]
    
    2659
    -             bndrs = exprFreeIdsList dummy_arg
    
    2650
    +               -- dummy_arg is (Var bndr'), or (Coercion (CoVarCo bndr'))
    
    2651
    +               -- if bndr' is a coercion variable; see Note [Evidence foralls]
    
    2660 2652
     
    
    2661 2653
            ; pure ( useful, subst2
    
    2662
    -              , bndrs ++ rule_bs,     dummy_arg : rule_es
    
    2663
    -              , bndrs ++ spec_bs, dx, dummy_arg : spec_args ) }
    
    2654
    +              , bndr' : rule_bs,     dummy_arg : rule_es
    
    2655
    +              , bndr' : spec_bs, dx, dummy_arg : spec_args ) }
    
    2664 2656
     
    
    2665 2657
     
    
    2666 2658
     -- | Binds a dictionary argument to a fresh name, to preserve sharing
    

  • compiler/GHC/Core/Subst.hs
    ... ... @@ -590,15 +590,15 @@ substRule subst subst_ru_fn rule@(Rule { ru_bndrs = bndrs, ru_args = args
    590 590
     ------------------
    
    591 591
     substDVarSet :: HasDebugCallStack => Subst -> DVarSet -> DVarSet
    
    592 592
     -- Apply the substitution to the vars in the set,
    
    593
    +-- and take the (deep) free vars of the result
    
    593 594
     substDVarSet subst@(Subst _ _ tv_env cv_env) fvs
    
    594 595
       = runFVSelective isLocalVar $
    
    595 596
         strictFoldDVarSet (mappend . do_one) mempty fvs
    
    596 597
       where
    
    597 598
       do_one :: Var -> SelectiveDFV
    
    598 599
       do_one fv
    
    599
    -  do_one fv
    
    600
    -     | isTyVar fv = shallowSelTypeFV (lookupVarEnv tv_env fv `orElse` mkTyVarTy fv)
    
    600
    +     | isTyVar fv = deepSelTypeFV (lookupVarEnv tv_env fv `orElse` mkTyVarTy fv)
    
    601
    +     | isCoVar fv = deepSelCoFV   (lookupVarEnv cv_env fv `orElse` mkCoVarCo fv)
    
    601 602
          | otherwise  = exprFVs (lookupIdSubst subst fv)
    
    602 603
     
    
    603 604
     ------------------
    

  • compiler/GHC/Core/TyCo/FVs.hs
    ... ... @@ -26,8 +26,9 @@ module GHC.Core.TyCo.FVs
    26 26
             coVarsOfCo, coVarsOfCos,
    
    27 27
             coVarsOfCoDSet, coVarsOfCosDSet,
    
    28 28
     
    
    29
    -        -- Shallow, deterministic, composable
    
    30
    -        shallowSelTypeFV, shallowSelCoFV,
    
    29
    +        -- Selective, deterministic, composable
    
    30
    +        shallowSelTypeFV,
    
    31
    +        deepSelTypeFV, deepSelCoFV, deepSelUnitFV,
    
    31 32
     
    
    32 33
             -- Almost devoid
    
    33 34
             almostDevoidCoVarOfCo,
    
    ... ... @@ -50,7 +51,6 @@ module GHC.Core.TyCo.FVs
    50 51
             occCheckExpand,
    
    51 52
     
    
    52 53
             -- * Closing over kinds
    
    53
    -        closeOverKindsDSet,
    
    54 54
             closeOverKinds,
    
    55 55
       ) where
    
    56 56
     
    
    ... ... @@ -111,6 +111,9 @@ Examples:
    111 111
       forall (a:(k:Type)). a   {k}        {k}
    
    112 112
       (a:k->Type) (b:k)        {a,b}      {a,b,k}
    
    113 113
     
    
    114
    +Free variables of /terms/ (GHC.Core.FVs) are always deep; see
    
    115
    +Note [Free variables of an expression] in GHC.Core.FVs.
    
    116
    +
    
    114 117
     
    
    115 118
     Note [Computing deep free variables]
    
    116 119
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -150,9 +153,10 @@ GHC.Types.Var.FV. At an occurrence of a variable (a::k)
    150 153
       AND add on the free vars of its kind `k`.
    
    151 154
       BUT in this latter step, start with an empty BoundVars set.
    
    152 155
     
    
    153
    -The "start with an empty BoundVars set" is implemented in `deepUnitFV`.  It's
    
    154
    -not /necessary/ to zap the BoundVars set, because of Invariant (NoTypeShadowing).
    
    155
    -But it's a tiny bit more efficient because the BoundVars set is smaller.
    
    156
    +The "start with an empty BoundVars set" is implemented in the `*UnitFV`
    
    157
    +functions.  It's not /necessary/ to zap the BoundVars set, because of
    
    158
    +Invariant (NoTypeShadowing).  But it's a tiny bit more efficient because the
    
    159
    +BoundVars set is smaller.
    
    156 160
     
    
    157 161
     Side note: the free-variable binder would still work even without (NoTypeShadowing).
    
    158 162
     Consider:
    
    ... ... @@ -256,39 +260,47 @@ deepCosFV :: [Coercion] -> TyCoFV
    256 260
     (deepTypeFV, deepTypesFV, deepCoFV, deepCosFV) = foldTyCo deepTcvFolder
    
    257 261
     
    
    258 262
     deepTcvFolder :: TyCoFolder TyCoFV
    
    263
    +deepTcvFolder = deepFolder (deepUnitFV fvs) fvs addBndrFV
    
    264
    +  where fvs = deepTypeFV . varType
    
    265
    +
    
    266
    +deepFolder :: Monoid fv
    
    267
    +           => (TyCoVar -> fv)        -- ^ an occurrence of a variable
    
    268
    +           -> (TyCoVar -> fv)        -- ^ the free variables of a variable's type
    
    269
    +           -> (TyCoVar -> fv -> fv)  -- ^ go under a binder
    
    270
    +           -> TyCoFolder fv
    
    271
    +-- A folder computing deep free variables; the occurrence function is one of
    
    272
    +-- the `*UnitFV` functions. See Note [Computing deep free variables].
    
    273
    +--
    
    259 274
     -- It's important that we use a one-shot EndoOS, to ensure that all
    
    260 275
     -- the free-variable finders are eta-expanded.  Lacking the one-shot-ness
    
    261 276
     -- led to some big slow downs.  See Note [The one-shot state monad trick]
    
    262 277
     -- in GHC.Utils.Monad
    
    263
    -deepTcvFolder = TyCoFolder { tcf_view = noView  -- See Note [Free vars and synonyms]
    
    264
    -                           , tcf_tyvar = do_tcv, tcf_covar = do_tcv
    
    265
    -                           , tcf_hole  = do_hole, tcf_lit = const mempty
    
    266
    -                           , tcf_tycobinder = addBndrFV }
    
    267
    -  where
    
    268
    -    do_tcv :: TyVar -> TyCoFV
    
    269
    -    do_tcv = deepUnitFV deepTypeFV
    
    270
    -
    
    271
    -    do_hole :: CoercionHole -> TyCoFV
    
    272
    -    do_hole hole = deepTypeFV (varType (coHoleCoVar hole))
    
    278
    +{-# INLINE deepFolder #-}
    
    279
    +deepFolder occ fvs_of_type add_bndr
    
    280
    +  = TyCoFolder { tcf_view = noView  -- See Note [Free vars and synonyms]
    
    281
    +               , tcf_tyvar = occ, tcf_covar = occ
    
    282
    +               , tcf_hole  = fvs_of_type . coHoleCoVar
    
    273 283
                          -- We don't collect the CoercionHole itself, but we /do/
    
    274 284
                          -- need to collect the free variables of its /kind/
    
    275 285
                          -- See Note [CoercionHoles and coercion free variables]
    
    286
    +               , tcf_lit   = const mempty
    
    287
    +               , tcf_tycobinder = add_bndr }
    
    276 288
     
    
    277
    -deepUnitFV :: (Type -> TyCoFV) -> TyCoVar -> TyCoFV
    
    278
    --- Deal with a single TyCoVar
    
    279
    --- Takes a function to find free vars of the kind
    
    289
    +deepUnitFV :: (TyCoVar -> TyCoFV) -- ^ the free variables of a variable's type
    
    290
    +           -> TyCoVar -> TyCoFV
    
    291
    +-- Deal with an occurrence of a single 'TyCoVar'
    
    280 292
     -- See Note [Computing deep free variables]
    
    281
    -{-# INLINE deepUnitFV #-}   -- INLINE to specialise on fvs_of_kind
    
    282
    -deepUnitFV fvs_of_kind
    
    293
    +{-# INLINE deepUnitFV #-}   -- INLINE to specialise on fvs_of_type
    
    294
    +deepUnitFV fvs_of_type
    
    283 295
       = \v -> MkFV (\bvs -> EndoOS (do_it bvs v))
    
    284 296
       where
    
    285 297
         do_it :: BoundVars -> TyCoVar -> TyCoVarSet -> TyCoVarSet
    
    286 298
         do_it bvs v acc | v `elemVarSet` bvs = acc
    
    287 299
                         | v `elemVarSet` acc = acc
    
    288
    -                    | otherwise          = runFVAcc (fvs_of_kind (varType v)) acc
    
    300
    +                    | otherwise          = runFVAcc (fvs_of_type v) acc
    
    289 301
                                                `extendVarSet` v
    
    290
    -                  -- Left-to-right: add the kind variables to the
    
    291
    -                  --                accumulator before v itself
    
    302
    +                    -- Left-to-right: add the kind variables to the
    
    303
    +                    --                accumulator before v itself
    
    292 304
     
    
    293 305
     {- *********************************************************************
    
    294 306
     *                                                                      *
    
    ... ... @@ -389,31 +401,22 @@ deepDetCoFV :: Coercion -> DTyCoFV
    389 401
     (deepDetTypeFV, deepDetTypesFV, deepDetCoFV, _) = foldTyCo deepDetTcvFolder
    
    390 402
     
    
    391 403
     deepDetTcvFolder :: TyCoFolder DTyCoFV
    
    392
    --- This one returns a /deterministic/ list
    
    393
    --- See `deepTcvFolder` for the general pattern
    
    394
    -deepDetTcvFolder
    
    395
    -  = TyCoFolder { tcf_view = noView
    
    396
    -               , tcf_tyvar = do_tcv, tcf_covar = do_tcv
    
    397
    -               , tcf_hole  = do_hole, tcf_lit = const mempty
    
    398
    -               , tcf_tycobinder = addBndrFV }
    
    399
    -  where
    
    400
    -    do_tcv = deepDetUnitFV deepDetTypeFV
    
    401
    -    do_hole hole = deepDetTypeFV (varType (coHoleCoVar hole))
    
    402
    -
    
    403
    -deepDetUnitFV :: (Type -> DTyCoFV) -> TyCoVar -> DTyCoFV
    
    404
    --- Deal with a single TyCoVar
    
    405
    --- Takes a function to find free vars of the kind
    
    406
    --- See Note [Computing deep free variables]
    
    407
    -deepDetUnitFV fvs_of_kind v
    
    408
    -  = MkFV (\bvs -> EndoOS (do_it bvs))
    
    404
    +-- This one returns a /deterministic/ set
    
    405
    +deepDetTcvFolder = deepFolder (deepDetUnitFV fvs) fvs addBndrFV
    
    406
    +  where fvs = deepDetTypeFV . varType
    
    407
    +
    
    408
    +deepDetUnitFV :: (TyCoVar -> DTyCoFV) -- ^ the free variables of a variable's type
    
    409
    +              -> TyCoVar -> DTyCoFV
    
    410
    +-- Deterministic version of 'deepUnitFV'
    
    411
    +{-# INLINE deepDetUnitFV #-}   -- INLINE to specialise on fvs_of_type
    
    412
    +deepDetUnitFV fvs_of_type
    
    413
    +  = \v -> MkFV (\bvs -> EndoOS (do_it bvs v))
    
    409 414
       where
    
    410
    -    do_it :: BoundVars -> DTyCoVarSet -> DTyCoVarSet
    
    411
    -    do_it bvs acc | v `elemVarSet` bvs  = acc
    
    412
    -                  | v `elemDVarSet` acc = acc
    
    413
    -                  | otherwise           = runFVAcc (fvs_of_kind (varType v)) acc
    
    414
    -                                          `extendDVarSet` v
    
    415
    -                  -- Left-to-right: add the kind variables to the
    
    416
    -                  --                accumulator before v itself
    
    415
    +    do_it :: BoundVars -> TyCoVar -> DTyCoVarSet -> DTyCoVarSet
    
    416
    +    do_it bvs v acc | v `elemVarSet` bvs  = acc
    
    417
    +                    | v `elemDVarSet` acc = acc
    
    418
    +                    | otherwise           = runFVAcc (fvs_of_type v) acc
    
    419
    +                                            `extendDVarSet` v
    
    417 420
     
    
    418 421
     {- *********************************************************************
    
    419 422
     *                                                                      *
    
    ... ... @@ -430,30 +433,61 @@ someTyCoVarsOfTypes interesting
    430 433
       = runFVSelectiveList interesting . mapUnionFV shallowSelTypeFV
    
    431 434
     
    
    432 435
     shallowSelTypeFV :: Type -> SelectiveDFV
    
    433
    -shallowSelCoFV   :: Coercion -> SelectiveDFV
    
    434 436
     -- Returns shallow free vars
    
    435 437
     -- See Note [Shallow and deep free variables]
    
    436
    -(shallowSelTypeFV, _, shallowSelCoFV, _) = foldTyCo selectiveTcvFolder
    
    438
    +(shallowSelTypeFV, _, _, _) = foldTyCo selectiveTcvFolder
    
    437 439
     
    
    438 440
     selectiveTcvFolder :: TyCoFolder SelectiveDFV
    
    439 441
     -- This one takes an `InterestingVarFun`, and returns shallow free vars
    
    440 442
     -- See `shallowTcvFolder` for the general pattern
    
    441 443
     selectiveTcvFolder
    
    442 444
       = TyCoFolder { tcf_view  = noView  -- See Note [Free vars and synonyms]
    
    443
    -               , tcf_tyvar = do_tcv, tcf_covar = do_tcv
    
    445
    +               , tcf_tyvar = shallowSelUnitFV, tcf_covar = shallowSelUnitFV
    
    444 446
                    , tcf_hole  = do_hole, tcf_lit = const mempty
    
    445 447
                    , tcf_tycobinder = addBndrSelectiveFV }
    
    446 448
       where
    
    447
    -    do_tcv v = MkFV (\env -> EndoOS (do_it env))
    
    448
    -      where
    
    449
    -        do_it (bvs,is_interesting) acc
    
    450
    -          | v `elemVarSet` bvs     = acc  -- First exclude bound variables
    
    451
    -          | not (is_interesting v) = acc  -- The "selective" bit
    
    452
    -          | v `elemDVarSet` acc    = acc
    
    453
    -          | otherwise              = acc `extendDVarSet` v
    
    454
    -
    
    455 449
         do_hole hole = shallowSelTypeFV (varType (coHoleCoVar hole))
    
    456 450
     
    
    451
    +shallowSelUnitFV :: TyCoVar -> SelectiveDFV
    
    452
    +shallowSelUnitFV v = MkFV (\env -> EndoOS (do_it env))
    
    453
    +  where
    
    454
    +    do_it (bvs,is_interesting) acc
    
    455
    +      | v `elemVarSet` bvs     = acc  -- First exclude bound variables
    
    456
    +      | not (is_interesting v) = acc  -- The "selective" bit
    
    457
    +      | v `elemDVarSet` acc    = acc
    
    458
    +      | otherwise              = acc `extendDVarSet` v
    
    459
    +
    
    460
    +
    
    461
    +{- *********************************************************************
    
    462
    +*                                                                      *
    
    463
    +          Selective, deep, deterministic free vars
    
    464
    +*                                                                      *
    
    465
    +********************************************************************* -}
    
    466
    +
    
    467
    +deepSelTypeFV :: Type -> SelectiveDFV
    
    468
    +deepSelCoFV   :: Coercion -> SelectiveDFV
    
    469
    +-- Returns deep free vars, selectively
    
    470
    +-- See Note [Shallow and deep free variables]
    
    471
    +(deepSelTypeFV, _, deepSelCoFV, _) = foldTyCo deepSelectiveTcvFolder
    
    472
    +
    
    473
    +deepSelectiveTcvFolder :: TyCoFolder SelectiveDFV
    
    474
    +deepSelectiveTcvFolder = deepFolder (deepSelUnitFV fvs) fvs addBndrSelectiveFV
    
    475
    +  where fvs = deepSelTypeFV . varType
    
    476
    +
    
    477
    +deepSelUnitFV :: (TyCoVar -> SelectiveDFV) -- ^ the free variables of a variable's type
    
    478
    +              -> TyCoVar -> SelectiveDFV
    
    479
    +-- ^ Selective version of 'deepUnitFV'.
    
    480
    +{-# INLINE deepSelUnitFV #-}   -- INLINE to specialise on fvs_of_type
    
    481
    +deepSelUnitFV fvs_of_type
    
    482
    +  = \v -> MkFV (\env -> EndoOS (do_it env v))
    
    483
    +  where
    
    484
    +    do_it (bvs,is_interesting) v acc
    
    485
    +      | v `elemVarSet` bvs     = acc
    
    486
    +      | not (is_interesting v) = acc
    
    487
    +      | v `elemDVarSet` acc    = acc
    
    488
    +      | otherwise              = runFVSelectiveAcc is_interesting (fvs_of_type v) acc
    
    489
    +                                 `extendDVarSet` v
    
    490
    +
    
    457 491
     
    
    458 492
     {- *********************************************************************
    
    459 493
     *                                                                      *
    
    ... ... @@ -508,7 +542,7 @@ deepCoVarFolder = TyCoFolder { tcf_view = noView
    508 542
           -- the tyvar won't end up in the accumulator, so
    
    509 543
           -- we'd look repeatedly.  Blargh.
    
    510 544
     
    
    511
    -    do_covar = deepUnitFV deepCoVarTypeFV
    
    545
    +    do_covar = deepUnitFV (deepCoVarTypeFV . varType)
    
    512 546
     
    
    513 547
         do_hole hole  = do_covar (coHoleCoVar hole)
    
    514 548
           -- We /do/ treat a CoercionHole as a free variable
    
    ... ... @@ -540,7 +574,7 @@ deepDetCoVarFolder = TyCoFolder { tcf_view = noView
    540 574
         do_tyvar _  = mempty
    
    541 575
     
    
    542 576
         do_covar :: CoVar -> DCoVarFV
    
    543
    -    do_covar = deepDetUnitFV det_ty
    
    577
    +    do_covar = deepDetUnitFV (det_ty . varType)
    
    544 578
     
    
    545 579
         do_hole hole  = do_covar (coHoleCoVar hole)
    
    546 580
     
    
    ... ... @@ -558,13 +592,6 @@ closeOverKinds vs = nonDetStrictFoldVarSet do_one vs vs
    558 592
       where
    
    559 593
         do_one v = runFVAcc (deepTypeFV (varType v))
    
    560 594
     
    
    561
    --- | Add the kind variables free in the kinds of the tyvars in the given set.
    
    562
    --- Returns a deterministic set.
    
    563
    -closeOverKindsDSet :: DTyVarSet -> DTyVarSet
    
    564
    -closeOverKindsDSet vs = nonDetStrictFoldDVarSet do_one vs vs
    
    565
    -  where
    
    566
    -    do_one v = runFVAcc (deepDetTypeFV (varType v))
    
    567
    -
    
    568 595
     
    
    569 596
     {-
    
    570 597
     %************************************************************************
    
    ... ... @@ -779,7 +806,7 @@ inj_vars_of_type :: Bool -> Type -> TyCoFV
    779 806
     inj_vars_of_type look_under_tfs = go
    
    780 807
       where
    
    781 808
         go ty | Just ty' <- rewriterView ty = go ty'
    
    782
    -    go (TyVarTy v)                      = deepUnitFV go v
    
    809
    +    go (TyVarTy v)                      = deepUnitFV (go . varType) v
    
    783 810
         go (AppTy f a)                      = go f `mappend` go a
    
    784 811
         go (FunTy _ w ty1 ty2)              = go w `mappend` go ty1 `mappend` go ty2
    
    785 812
         go (TyConApp tc tys)                = go_tc tc tys
    

  • compiler/GHC/Core/Type.hs
    ... ... @@ -168,7 +168,6 @@ module GHC.Core.Type (
    168 168
             typeSize, occCheckExpand,
    
    169 169
     
    
    170 170
             -- ** Closing over kinds
    
    171
    -        closeOverKindsDSet,
    
    172 171
             closeOverKinds,
    
    173 172
     
    
    174 173
             -- * Forcing evaluation of types
    

  • compiler/GHC/HsToCore.hs
    ... ... @@ -92,6 +92,7 @@ import GHC.Types.Id.Info
    92 92
     import GHC.Types.InlinePragma ( alwaysInlinePragma, competesWith )
    
    93 93
     import GHC.Types.ForeignStubs
    
    94 94
     import GHC.Types.Avail
    
    95
    +import GHC.Types.Var ( isNonCoVarId )
    
    95 96
     import GHC.Types.Var.Set
    
    96 97
     import GHC.Types.SrcLoc
    
    97 98
     import GHC.Types.SourceFile
    
    ... ... @@ -479,7 +480,7 @@ dsWarnRuleShadowing fn_id
    479 480
       where
    
    480 481
         bndrs_set = mkVarSet bndrs
    
    481 482
         arg_ids = filterOut (`elemVarSet` bndrs_set) $
    
    482
    -              exprsSomeFreeVarsList isId args
    
    483
    +              exprsSomeFreeVarsList isNonCoVarId args
    
    483 484
     
    
    484 485
         check check_rules_too lhs_id
    
    485 486
           | isLocalId lhs_id || canUnfold (idUnfolding lhs_id)
    

  • compiler/GHC/HsToCore/Binds.hs
    ... ... @@ -1014,8 +1014,7 @@ dsSpec_help poly_nm poly_id poly_rhs spec_inl orig_bndrs ds_call
    1014 1014
                  is_local v = v `elemVarSet` locals
    
    1015 1015
     
    
    1016 1016
                  -- Find `rule_bndrs`: (S2) of Note [Desugaring new-form SPECIALISE pragmas]
    
    1017
    -             -- We have to do closeOverKinds beccause exprsSomeFreeVars is shallow
    
    1018
    -             rule_bndrs = scopedSort $ dVarSetElems $ closeOverKindsDSet $
    
    1017
    +             rule_bndrs = scopedSort $ dVarSetElems $
    
    1019 1018
                               exprsSomeFreeVarsDSet is_local rule_lhs_args
    
    1020 1019
     
    
    1021 1020
                  -- getRenamings: (S3) of  Note [Desugaring new-form SPECIALISE pragmas]
    

  • compiler/GHC/Tc/Utils/TcType.hs
    ... ... @@ -183,7 +183,7 @@ module GHC.Tc.Utils.TcType (
    183 183
       coreView,
    
    184 184
     
    
    185 185
       tyCoVarsOfType, tyCoVarsOfTypes, closeOverKinds,
    
    186
    -  tyCoVarsOfTypeDSet, tyCoVarsOfTypesDSet, closeOverKindsDSet,
    
    186
    +  tyCoVarsOfTypeDSet, tyCoVarsOfTypesDSet,
    
    187 187
       tyCoVarsOfTypeList, tyCoVarsOfTypesList,
    
    188 188
       noFreeVarsOfType,
    
    189 189
     
    

  • compiler/GHC/Types/Var/FV.hs
    ... ... @@ -6,7 +6,7 @@ module GHC.Types.Var.FV (
    6 6
             BoundVars, VarSetFV, DVarSetFV, SelectiveDFV,
    
    7 7
             TyCoFV, DTyCoFV,
    
    8 8
             runFVTop, runFVAcc, runTyCoVars, runTyCoVarsDSet,
    
    9
    -        runFVSelective, runFVSelectiveList, runFVSelectiveSet,
    
    9
    +        runFVSelective, runFVSelectiveAcc, runFVSelectiveList, runFVSelectiveSet,
    
    10 10
             InterestingVarFun,
    
    11 11
     
    
    12 12
             updEnvFV, addBndrFV, addBndrsFV, addBndrSelectiveFV, addBndrsSelectiveFV,
    
    ... ... @@ -225,8 +225,11 @@ runTyCoVarsDSet :: DTyCoFV -> DTyCoVarSet
    225 225
     runTyCoVarsDSet f = runFVAcc f emptyDVarSet
    
    226 226
     
    
    227 227
     runFVSelective :: InterestingVarFun -> SelectiveDFV -> DVarSet
    
    228
    -runFVSelective interesting f
    
    229
    -  = runEndoOS (runFV f (emptyVarSet, interesting)) emptyDVarSet
    
    228
    +runFVSelective interesting f = runFVSelectiveAcc interesting f emptyDVarSet
    
    229
    +
    
    230
    +runFVSelectiveAcc :: InterestingVarFun -> SelectiveDFV -> DVarSet -> DVarSet
    
    231
    +-- Add the interesting free variables to the accumulator
    
    232
    +runFVSelectiveAcc interesting f = runEndoOS (runFV f (emptyVarSet, interesting))
    
    230 233
     
    
    231 234
     runFVSelectiveList :: InterestingVarFun -> SelectiveDFV -> [Var]
    
    232 235
     runFVSelectiveList interesting f = dVarSetElems (runFVSelective interesting f)
    

  • testsuite/tests/simplCore/should_compile/T27936.hs
    1
    +{-# LANGUAGE GADTs, ViewPatterns, RankNTypes #-}
    
    2
    +{-# OPTIONS_GHC -fno-opt-coercion #-}
    
    3
    +module T27936 where
    
    4
    +
    
    5
    +data G a where
    
    6
    +  MkG :: G Int
    
    7
    +
    
    8
    +f :: G a -> a -> Int -> Int
    
    9
    +f MkG v (((\x -> (v + 1, x)) :: forall b. b -> (Int, b)) -> (y, _)) = y

  • testsuite/tests/simplCore/should_compile/all.T
    ... ... @@ -627,3 +627,5 @@ test('T27749',
    627 627
          compile, ['-O -g3 -ddump-simpl -dsuppress-uniques'])
    
    628 628
     
    
    629 629
     test('T27629', only_ways(['optasm']), makefile_test, ['T27629'])
    
    630
    +
    
    631
    +test('T27936', normal, compile, [''])