[GHC] #9440: Buggy binder swap in occurrence analysis

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Occurrence analysis on case alternatives performs a "binder swap", whereby occurrences of the scrutinee in alternative RHSs are replaced by the case binder when the scrutinee is a variable or a casted variable. {{{ case x of w C vs -> rhs === case x of w C vs -> let x = w in rhs }}} This should check two conditions, mentioned in Note [Binder swap]. (a) x is free in `C vs -> rhs`, otherwise one of two bad things happen: 1) it is pointless 2) new binding of x would capture one of the alternative binders (vs) (b) w is not in vs Neither of these conditions is actually being checked. Additionally, the binder swap happens in the presence of casts: {{{ case x |> co of w C vs -> rhs === case x |> co of w C vs -> let x = w |> sym co in rhs }}} But the analysis is not returning usage info for free coercion variables in co. Condition (a) bit us in HERMIT when running `occurAnalyseExpr` on the following expression resulting from unfolding nested calls to `fst`: {{{ case x_X11b of wild_a3YB (,) x_a3YD ds1_a3YE -> case x_a3YD of wild_a3YB (,) x_a3YD ds1_a3YE -> x_a3YD }}} The analysis would erroneously result in: {{{ case x_X11b of wild_a3YB (,) x_a3YD ds1_a3YE -> case x_a3YD of wild_a3YB (,) x_a3YD ds1_a3YE -> let x_a3YD = wild_a3YB in x_a3YD }}} which is clearly Not Good. Patch forthcoming via Phabricator. Unfortunately, I don't have a good test case that doesn't involve HERMIT, but can confirm this patch fixes the problem above. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: D156 | -------------------------------------+------------------------------------- Changes (by afarmer): * status: new => patch * differential: => D156 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D156 | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * differential: D156 => Phab:D156 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D156 | -------------------------------------+------------------------------------- Comment (by simonpj): That's terrible! Than you for spotting this. Re (a), I'm not sure how convenient it is to check that `x` is free in `C vs -> rhs`. Perhaps it is easy. But if not, you could instead just check that `x` is not in `vs`. That could conveniently be done with checking (b). Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D156 | -------------------------------------+------------------------------------- Comment (by afarmer): (a) turned out to be easy enough, I just tagged the binders before checking for usage in the alt. (b) and the coercion variables required a slight bit of refactoring. See the Phab:D156 patch for details. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D156 | -------------------------------------+------------------------------------- Comment (by simonpj): I've added a comment or two to the Phab link. Austin: please commit. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D156 | -------------------------------------+------------------------------------- Comment (by afarmer): I've updated the Phab patch with a more explicit comment, as requested. It should be ready to go. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9440: Buggy binder swap in occurrence analysis
-------------------------------------+-------------------------------------
Reporter: afarmer | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.3
Resolution: | Keywords:
Operating System: | Architecture: Unknown/Multiple
Unknown/Multiple | Difficulty: Unknown
Type of failure: | Blocked By:
None/Unknown | Related Tickets:
Test Case: |
Blocking: |
Differential Revisions: Phab:D156 |
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#9440: Buggy binder swap in occurrence analysis -------------------------------------+------------------------------------- Reporter: afarmer | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Resolution: fixed | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D156 | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: patch => closed * resolution: => fixed * milestone: => 7.10.1 Comment: Merged. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9440#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC