[GHC] #11656: Alllow static pointers to local closed definitions

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- A limitation of the original patch implementing `-XStaticPointers` is that while the following all work, {{{#!hs t1 = static not t2 = static (\x -> case x of True -> False; False -> True) }}} the below does not: {{{#!hs t3 = static foo where foo True = False }}} Yet `foo` is perfectly "static": it's a closed expression that can readily be floated to top-level. So in short: `-XStaticPointers` should not consider only expressions with top-level identifiers, but in general any closed expression (which may involve local closed identifiers too). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 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 mboes): Note that the main reason that this was not implemented the first time around is that we couldn't get floating of closed local identifiers to top-level to work properly. This is likely an easy and straightforward task though - Facundo and I just don't have the requisite knowledge it seems. So any help from core developers more familiar with GHC would be greatly appreciated. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 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): I'm happy to help, but too snowed under to take the lead. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 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 facundo.dominguez): This is the mechanism we were considering so far: 1. Have the renamer compute whether bindings in scope are closed. 2. When the renamer finds a static form, allow the free vars to be top- level or closed local bindings. 3. Desugar the static form. This produces a list of floated Core bindings. 4. For each such Core binding find the free variables of local definitions. 5. For each found local definition traverse the enclosing top-level binding to remove it. 6. Add each removed local definition at the top level. If it simplifies anything, a variant is to skip (5) and have (6) copy the local definitions as local definitions of the Core bindings produced in (3). This might duplicate local definitions once per static form in which they are used. Does copying definitions like this require also renaming bindings? Local definitions may transitively use other local definitions, in which case all of them should be floated. We were wondering if we are the first hackers in need of a function in GHC to determine if bindings are closed or not. Maybe someone could point if this is computed elsewhere already. We only found a flag {{{tct_closed}}} which only applies to types, not expressions. Is floating local definitions to the top-level disruptive for other compilation stages? We are open to proposals of alternative mechanisms. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 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): I'm afraid I need more examples to understand these steps. Rather than do this on a ticket, would you like to start a wiki page to explain the problem, and the proposed solution, with examples complicated enough to demonstrate the need for each step. One tantalising point is that we already have a `FloatOut` pass for Core that will do much of this. Once I understand the problem better we can think about whether it could be useful. Thanks! PS: v busy until the ICFP deadline (2 wks) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 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 facundo.dominguez): I just introduced a new section in StaticPointers#Localbindingsinthestaticform. Let me know if it is still not clear. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 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: | -------------------------------------+------------------------------------- Changes (by alpmestan): * cc: alpmestan (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mboes): * blockedby: => 11698 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * owner: => facundo.dominguez -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): There is a working implementation in https://github.com/ghc/ghc/compare/master...tweag:fd/float-static I hope to submit a phabricator revision next week. Currently have to update the documentation, improve error messages and update linter. I would be thankful for any suggestion about which part of the linter to modify in order to produce errors when applications of the {{{StaticPtr}}} constructor appear nested within other expressions. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
I would be thankful for any suggestion about which part of the linter to modify in order to produce errors when applications of the {{{StaticPtr}}} constructor appear nested within other expressions.
It's a bit awkward with the current structure of `CoreLint`. I best might be * Make `lintCoreExpr` complain if if it finds a `StaticPtr` constructor * Make the non-recursive case of `lint_bind` (in `lintCorBindings`) call a new function `lintTopNonRec` or something. * `lintTopNonRec` can have a case for `(StaticPtr e1 e2)` on its RHS, and allow it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104 Wiki Page: | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: new => patch * differential: => Phab:D2104 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions
-------------------------------------+-------------------------------------
Reporter: mboes | Owner:
| facundo.dominguez
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: 11698 | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2104
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Facundo Domínguez

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104 Wiki Page: | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Facundo, I noticed that there is an entry for this feature in the 8.0.2 release notes on `master` but the patch is not present on the `ghc-8.0` branch. Did you expect this to go into 8.0.2? While the patch applies fairly easily its size, even if it mostly touches static pointers code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104 Wiki Page: | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): I think I added them in 8.0.2 because it was the next release in sight. mboes? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104 Wiki Page: | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): This should affect the StaticPointers mostly. I don't think it is of high risk, but it is not risk-free either and we don't have an urgency to include it now. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: | facundo.dominguez Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: => 8.2.1 Comment: Let's punt on it in that case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104, Wiki Page: | Phab:D2655 -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: closed => new * owner: facundo.dominguez => * differential: Phab:D2104 => Phab:D2104, Phab:D2655 * resolution: fixed => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104, Wiki Page: | Phab:D2655 -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11656: Alllow static pointers to local closed definitions
-------------------------------------+-------------------------------------
Reporter: mboes | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 7.10.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: 11698 | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2104,
Wiki Page: | Phab:D2655
-------------------------------------+-------------------------------------
Comment (by Facundo Domínguez

#11656: Alllow static pointers to local closed definitions -------------------------------------+------------------------------------- Reporter: mboes | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 11698 | Blocking: Related Tickets: | Differential Rev(s): Phab:D2104, Wiki Page: | Phab:D2655 -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11656#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC