[GHC] #9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler (Type | Version: 7.8.3 checker) | Operating System: Keywords: pattern synonyms | Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: Incorrect Difficulty: Moderate (less | result at runtime than a day) | Test Case: Blocked By: | Blocking: Related Tickets: 9732 | Differential Revisions: -------------------------------------+------------------------------------- As discovered while investigating #9732, if you have something like {{{ {-# LANGUAGE PatternSynonyms, MagicHash #-} import GHC.Base pattern P = True f :: Bool -> Int# f P = 42# }}} `f` is compiled into {{{ Main.f :: GHC.Types.Bool -> GHC.Prim.Int# [LclIdX, Str=DmdType] Main.f = letrec { f_apU :: GHC.Types.Bool -> GHC.Prim.Int# [LclId, Str=DmdType] f_apU = \ (ds_dq1 :: GHC.Types.Bool) -> break<2>() let { fail_dq2 :: GHC.Prim.Void# -> GHC.Prim.Int# [LclId, Str=DmdType] fail_dq2 = \ (ds_dq3 [OS=OneShot] :: GHC.Prim.Void#) -> Control.Exception.Base.patError @ GHC.Prim.Int# "unboxed.hs:7:1-9|function f"# } in case fail_dq2 GHC.Prim.void# of wild_00 { __DEFAULT -> (case break<1>() 42 of wild_00 { __DEFAULT -> Main.$mP @ GHC.Prim.Int# ds_dq1 wild_00 }) wild_00 }; } in f_apU }}} Note how `fail_dq2` is applied on `void#` _before_ the pattern match, meaning the following expression: {{{ I# (f True) }}} will fail with {{{ *** Exception: unboxed.hs:7:1-9: Non-exhaustive patterns in function f }}} This is because the the type of `P`'s matcher, instantiated for its use in `f`, is {{{ $mP :: Bool -> Int# -> Int# -> Int# }}} so of course it is strict both on the success and the failure continuation. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: pattern synonyms Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by Dr. ERDI Gergo <gergo@…>): In [changeset:"474e535b6b121809a8d75df5a4c37dc574d3d302/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="474e535b6b121809a8d75df5a4c37dc574d3d302" In pattern synonym matchers, support unboxed continuation results (fixes #9783). This requires ensuring the continuations have arguments by adding a dummy Void# argument when needed. This is so that matching on a pattern synonym is lazy even when the result is unboxed, e.g. pattern P = () f P = 0# In this case, without dummy arguments, the generated matcher's type would be $mP :: forall (r :: ?). () -> r -> r -> r which is called in `f` at type `() -> Int# -> Int# -> Int#`, so it would be strict, in particular, in the failure continuation of `patError`. We work around this by making sure both continuations have arguments: $mP :: forall (r :: ?). () -> (Void# -> r) -> (Void# -> r) -> r Of course, if `P` (and thus, the success continuation) has any arguments, we are only adding the extra dummy argument to the failure continuation. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: merge Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: pattern synonyms Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * status: new => merge -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: merge Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: pattern synonyms Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by thomie): cactus: if you meant for thoughtpolice to merge this into 7.8.4, you should set the milestone to 7.8.4. If it can wait till 7.10.1, the status of the ticket can be changed to close (it's already merged). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: merge Priority: normal | Milestone: 7.8.4 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: pattern synonyms Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * milestone: 7.10.1 => 7.8.4 Comment: @thomie: Thanks, yes I think this one should be merged into 7.8.4. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: merge Priority: normal | Milestone: 7.8.4 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: PatternSynonyms Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * keywords: pattern synonyms => PatternSynonyms -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: closed Priority: normal | Milestone: 7.8.4 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: PatternSynonyms Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: This couldn't be merged cleanly; so I'm afraid I'm going to drop it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: PatternSynonyms Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * milestone: 7.8.4 => 7.10.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: merge Priority: normal | Milestone: 7.8.4 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: PatternSynonyms Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * status: closed => merge * milestone: 7.10.1 => 7.8.4 Comment: I have pushed a new version of the commit that applies cleanly to `ghc-7.8` as `a91a2af`, please merge that. Also, in the future, please try applying the patches in question at an earlier time, instead of discovering if they have problems so close to the freeze date. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9783: Pattern synonym matcher is unnecessarily strict on unboxed continuations -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: PatternSynonyms Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Moderate (less Unknown/Multiple | than a day) Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: 9732 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * milestone: 7.8.4 => 7.10.1 Comment: 7.8.4 is already done; closing. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9783#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC