[GHC] #13242: Panic "StgCmmEnv: variable not found" with ApplicativeDo and ExistentialQuantification
GHC
ghc-devs at haskell.org
Wed Feb 22 09:27:16 UTC 2017
#13242: Panic "StgCmmEnv: variable not found" with ApplicativeDo and
ExistentialQuantification
-------------------------------------+-------------------------------------
Reporter: ljli | Owner: simonmar
Type: bug | Status: new
Priority: highest | Milestone: 8.0.3
Component: Compiler | Version: 8.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
OK here's what I can do easily. Let's say that in a `Stmt`
{{{
pat <- rhs
}}}
* the `Stmt` ''requires'' constraints needed to typecheck `rhs`, and to
pattern-match `pat` (e.g. in a view pattern)
* the `Stmt` ''binds'' the existential type variables and constraints
brought into scope by the pattern `pat`
So for example, given
{{{
data T a where
MkT :: (Eq a, Show b) => a -> b -> T a
}}}
Suppose that `v :: t` is in scope. Then the stmt
{{{
MkT 1 x <- (...show v...) :: T t
}}}
* requires `Show t` (from the use of `show`) and `Num t` (from the literal
`1`).
* binds the existential `b` and constraint `Show b`.
Now consider
{{{
...stmts...
ApplicativeStmts [arg1, arg2, ... argN]
...more stmts...
}}}
where `argi :: ApplicativeArg`. Each `argi` itself contains one or more
`Stmts`.
It is easy to ensure that
* Constraints required by the `argi` can be solved from constraint bound
by `...stmts...`
* Constraints and existentials bound by the `argi` are not available to
solve constraints required either by `argj` (where i is different from j),
or by `...more stmts...`.
* Within the stmts of each `argi` individually, constraints bound by
earlier stmts can be used to solve later ones.
That is easy to implement and solves the immediate problem. I'm
validating now.
------------------------
But the rule is terribly unsatisfactory.
* To typecheck the program you must mentally desugar it into its
applicative groups.
* If you write
{{{
MkT x1 _ <- rhs1
MkT x2 _ <- rhs2
}}}
you really might intend that the `Eq t` bound by the first stmt is
available to solve requirements of `rhs2`. And with normal monadic
deguaring it would be, but not with `ApplicativeDo`. Worse, ''there is no
way to fix it'' becuase `ApplicativeDo` works module-wide.
My solution is: add syntax to allow the programmer to express the program
in the form of Figure 2 of our paper, that is, post-rearrangement.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13242#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list