[GHC] #8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error
----------------------------------+-------------------------------------
Reporter: CoreyOConnor | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: x86_64 (amd64) | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
----------------------------------+-------------------------------------
The attached program produces an core lint error when compiling with
optimization.
{{{
$ ghc -O -debug -dcore-lint Main
[1 of 1] Compiling Main ( Main.hs, Main.o )
*** Core Lint errors : in result of Float out(FOS {Lam = Just 0,
Consts = True,
PAPs = True}) ***
<no location info>: Warning:
In the type ‛cache_s16y’
@ cache_s16y is out of scope
*** Offending Program ***
Main.focusAst
:: forall syntax_aB4.
GHC.Types.Int
-> Main.BufferImpl syntax_aB4 -> Main.BufferImpl syntax_aB4
[LclIdX,
Arity=2,
Str=DmdType m,
Unf=Unf{Src=InlineStable, TopLvl=True, Arity=2, Value=True,
ConLike=True, WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=False)
Tmpl= \ (@ syntax_aMw)
(r_aB5 [Occ=Once] :: GHC.Types.Int)
(b_aB6 [Occ=Once!] :: Main.BufferImpl syntax_aMw) ->
case b_aB6
of _ [Occ=Dead, Dmd=] ->
case ds_dOP
of _ [Occ=Dead, Dmd=] ->
case dt_s16z r_aB5 cache_s16A of dt_XBQ { __DEFAULT ->
Main.FBufferData
@ syntax_aMw
(Main.HLState @ syntax_aMw @ cache_s16y dt_s16z dt_XBQ)
}
}
}}]
Main.focusAst =
\ (@ syntax_aMw)
(r_aB5 :: GHC.Types.Int)
(b_aB6 :: Main.BufferImpl syntax_aMw) ->
case b_aB6
of _ [Occ=Dead, Dmd=] ->
case ds_dOP
of _ [Occ=Dead] { Main.HLState @ cache_s220 dt_s221 cache_s222 ->
case dt_s221 r_aB5 cache_s222 of dt_XBQ { __DEFAULT ->
Main.FBufferData
@ syntax_aMw
(Main.HLState @ syntax_aMw @ cache_s220 dt_s221 dt_XBQ)
}
}
}
<snip>
}}}
The full log is attached.
The same error occurs with a GHC HEAD build from 2012/12/12. I will check
with a latest HEAD.
--
Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by Fuuzetsu): I tried with HEAD I built earlier today and I don't seem to be able to reproduce on 32-bit Linux. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by CoreyOConnor): I just re-built ghc-7.8 branch on linux 64bit and Mac 64bit. SHA: 1bf47fddd62f1d9f0ab3303658c0ae68f225a6d4 This still exhibits the issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by CoreyOConnor): The lint error no longer shows up if the strictness annotation is removed form hlCache of FBufferData. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by monoidal): Here's a simpler version, compiling `-O -dcore-lint` gives an error {{{ {-# LANGUAGE ExistentialQuantification #-} module Main where data HLState = forall a. HLState (a -> a) !a data BufferImpl = FBufferData !HLState focusAst :: BufferImpl -> HLState focusAst (FBufferData (HLState f x)) = HLState f (f x) main = return () }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by goldfire): I've tracked this one down, I know exactly what's going wrong, and I know how to fix this particular case, but I'm worried that this may be representative of a class of errors, and I'm not sure how to fix the lot of them. The problem is that !SetLevels, while doing various core transformations (which I don't yet understand), builds up a substitution. This subst is applied as the `CoreExpr` tree is traversed. But, some bits are crucially left out. The bug in this report is because the binder of a `case` statement is left out -- its type is a type variable, but the type variable is substed during the transformation. The result: a binder whose type contains an out-of-scope type variable. The solution, of course, is to make sure to apply the subst to the binder's type. For example, the following works: {{{ = do { let substed_bndr = setVarType case_bndr (substTy (le_subst env) (varType case_bndr)) case_bndr' = TB substed_bndr bndr_spec }}} These lines should be in place of the current line 385, which sets `case_bndr'` without a subst. But, a casual look around tells me that lambda-bound binders are also seemingly left out of the substitution, and I see that there is a `cloneVar` function which seems to be applying the subst. Perhaps the fix should use `cloneVar`. In any case, there's more going on here than I feel comfortable fiddling with, but a cognoscente should be able to use my detective work to squash the bug in rather little time. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by simonpj): Well nailed! We need the cloning because when we float bindings out we might widen the scope of its binders, and we don't want to accidentally capture an un- related occurrence. Originally we only floated let-bindings, which bind only Ids, and so the substitution substituted only for Ids. But now we flaot case-expressions too, and they can bind type variables. Once the substitution binds type variables it must be applied to many more things (e.g. the types of other binders) which is not done at all at the moment. So your diagnosis is right but the fix isn't a one-liner. I'll work on it. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Changes (by thoughtpolice): * version: 7.6.3 => 7.8.1-rc1 * milestone: => 7.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by CoreyOConnor): Thanks for the investigation! Is there a situation where this would cause a runtime crash? I ran across this investigating a crash in the yi editor application. According to valgrind the GC performs an invalid write: writes into a block not allocated AFAICT. If that is too much to conjecture then no worries. I'm still breaking the crash down into a smaller test case. This just fell out of that process. :-) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Changes (by thoughtpolice): * version: 7.8.1-rc1 => 7.8.1-rc2 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------+---------------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Changes (by thoughtpolice): * priority: normal => highest Comment: Simon says this is a legitimate bug in the floater; so it should definitely be fixed and merged to 7.8. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error
-------------------------------------+----------------------------------
Reporter: CoreyOConnor | Owner:
Type: bug | Status: new
Priority: highest | Milestone: 7.8.1
Component: Compiler | Version: 7.8.1-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: x86_64 (amd64)
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+----------------------------------
Comment (by Simon Peyton Jones

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------------------+------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: merge Priority: highest | Milestone: 7.8.1 Component: Compiler | Version: Resolution: | 7.8.1-rc2 Operating System: Unknown/Multiple | Keywords: Type of failure: None/Unknown | Architecture: Test Case: | x86_64 (amd64) simplCore/should_compile/T8714 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by simonpj): * status: new => merge * testcase: => simplCore/should_compile/T8714 Comment: Finally fixed this. Sorry it's been a long time coming ... I kept getting distracted. Thank you for a lovely small test case. Let's merge this to 7.8 Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------------------+------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: merge Priority: highest | Milestone: 7.8.1 Component: Compiler | Version: Resolution: | 7.8.1-rc2 Operating System: Unknown/Multiple | Keywords: Type of failure: None/Unknown | Architecture: Test Case: | x86_64 (amd64) simplCore/should_compile/T8714 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by nomeata): Your commit does not validate: {{{ compiler/simplCore/SetLevels.lhs:467:31: Not in scope: `expr' Perhaps you meant `exp' (imported from Prelude) }}} https://s3.amazonaws.com/archive.travis-ci.org/jobs/20523523/log.txt -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------------------+------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: merge Priority: highest | Milestone: 7.8.1 Component: Compiler | Version: Resolution: | 7.8.1-rc2 Operating System: Unknown/Multiple | Keywords: Type of failure: None/Unknown | Architecture: Test Case: | x86_64 (amd64) simplCore/should_compile/T8714 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by simonpj): Ha that'll teach me to make a last minute cosmetic change after validating. Patch coming. S -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8714: ExistentialQuantification plus DeriveDataTypeable leads to core lint error -------------------------------------------------+------------------------- Reporter: CoreyOConnor | Owner: Type: bug | Status: Priority: highest | closed Component: Compiler | Milestone: 7.8.1 Resolution: fixed | Version: Operating System: Unknown/Multiple | 7.8.1-rc2 Type of failure: None/Unknown | Keywords: Test Case: | Architecture: simplCore/should_compile/T8714 | x86_64 (amd64) Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8714#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC