[Git][ghc/ghc][wip/T16742] Allow runtimeError applications under let/app invariant

Ben Gamari gitlab at gitlab.haskell.org
Tue Jun 4 02:09:26 UTC 2019



Ben Gamari pushed to branch wip/T16742 at Glasgow Haskell Compiler / GHC


Commits:
fafdc6ac by Ben Gamari at 2019-06-04T02:09:12Z
Allow runtimeError applications under let/app invariant

PrelRules.shiftRule can now rewrite Int# expressions to bottom due to
the invalid-shift check introduced by
1503da32d26fb59fb6ebb620bfd0f8c08638f627. To accomodate this we allow
known-bottoming expressions under the let/app invariant.

- - - - -


2 changed files:

- compiler/coreSyn/CoreLint.hs
- compiler/coreSyn/CoreSyn.hs


Changes:

=====================================
compiler/coreSyn/CoreLint.hs
=====================================
@@ -536,7 +536,8 @@ lintSingleBinding top_lvl_flag rec_flag (binder,rhs)
        ; checkL ( isJoinId binder
                || not (isUnliftedType binder_ty)
                || (isNonRec rec_flag && exprOkForSpeculation rhs)
-               || exprIsTickedString rhs)
+               || exprIsTickedString rhs
+                )
            (badBndrTyMsg binder (text "unlifted"))
 
         -- Check that if the binder is top-level or recursive, it's not
@@ -1018,7 +1019,7 @@ lintCoreArg fun_ty arg
              (ppr arg <+> dcolon <+> parens (ppr arg_ty <+> dcolon <+> ppr (typeKind arg_ty))))
           -- check for levity polymorphism first, because otherwise isUnliftedType panics
 
-       ; checkL (not (isUnliftedType arg_ty) || exprOkForSpeculation arg)
+       ; checkL (not (isUnliftedType arg_ty) || exprOkForSpeculation arg || exprIsBottom arg)
                 (mkLetAppMsg arg)
        ; lintValApp arg fun_ty arg_ty }
 


=====================================
compiler/coreSyn/CoreSyn.hs
=====================================
@@ -420,9 +420,9 @@ parts of the compilation pipeline.
 
 Note [CoreSyn let/app invariant]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The let/app invariant
-     the right hand side of a non-recursive 'Let', and
-     the argument of an 'App',
+The let/app invariant:
+    the right hand side of a non-recursive 'Let', and
+    the argument of an 'App',
     /may/ be of unlifted type, but only if
     the expression is ok-for-speculation
     or the 'Let' is for a join point.
@@ -445,6 +445,14 @@ which will generate a @case@ if necessary
 The let/app invariant is initially enforced by mkCoreLet and mkCoreApp in
 coreSyn/MkCore.
 
+One notable exception to this rule is bottoming expressions. For instance, we
+allow
+
+  y::Int = I# (runtimeError ...)
+
+since we sometimes need to make unlifted bindings bottom (e.g. see
+PrelRules.shiftRule).
+
 Note [CoreSyn type and coercion invariant]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 We allow a /non-recursive/, /non-top-level/ let to bind type and



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/fafdc6accc987e09fc14172ea1c6e8d70faae73c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/fafdc6accc987e09fc14172ea1c6e8d70faae73c
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190603/4a166761/attachment-0001.html>


More information about the ghc-commits mailing list