[GHC] #12035: hs-boot knot tying insufficient for ghc --make

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 (Type checker) | Keywords: hs-boot | Operating System: Unknown/Multiple backpack | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHC in one-shot mode goes through great pains to make sure that if we are typechecking A.hs with an A.hs-boot, any references to A in the interfaces we load in should point to the `TyThing`s from our LOCAL `tcg_type_env` (`_var`), not the declarations from the `hs-boot`. Indeed, it is never right to load the hi-boot file into the EPS (#10182, #10336). Because in one-shot compilation we are loading things into the EPS anew, there is not much risk of having stale `TyThing`s lying around which still refer to the old `hs-boot` ModDetails. `ghc --make` does not do a sufficient job as knot tying. Specifically, any `Id`s/`TyThing`s from the HPT which were built against the `hs-boot` ModDetails will have out-of-date information. We do manage to tie the knot if we use `tcLookupGlobal` directly, which does look in the local type environment (e.g., #12034 affects both `-c` and `--make`), but if we get our hands on a `TyThing` indirectly, we're in trouble. The case where this is most obvious is unfoldings; see #10083 for an example of GHC behaving differently between `-c` and `--make` (although, ironically, `--make`s bad behavior masks the bug). It's not entirely clear how to fix this problem. In analogy to what happens in `-c`, we should clear the stale `TyThing`s from our HPT and retypecheck them after we have setup the type environment for our `hs` file. But presently in `--make` we don't lazily load types from our home package. Maybe we should! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: | backpack 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 don't understand. In `--make` mode, doesn't `GhcMake.typecheckLoop` re- typecheck all the modules that depended on the `hs-boot` file? Isn't that precisely what `typecheckLoop` is for? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: | backpack 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 ezyang): This PDF gives the full story, http://web.mit.edu/~ezyang/Public/backpack- symbol-tables.pdf but the short answer is that there are two ways we loop tie hs-boot. The first, which is correctly implemented for `--make`, is retypechecking all the modules that depended on the `hs-boot` file. The second is tying the loop ''at the same time'' we are typechecking the `hs` module which implements the `hs-boot` file; i.e., it's what `tcg_type_env_var` is for. If we have: {{{ -- A.hs-boot module A where x :: Bool -- B.hs module B where import {-# SOURCE #-} A y = not x -- A.hs module A where import B x = True z = not y }}} When we typecheck `A.hs`, does the unfolding for `y` have an up-to-date unfolding for `x`? In one-shot mode the answer is yes (and thus we see the behavior of #10083), but in make mode the answer is no. The retypecheck loop has nothing to do with it, since it happens AFTER we finish building the hs file. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: | backpack Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2213 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => patch * differential: => Phab:D2213 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler (Type | Version: 8.1
checker) | Keywords: hs-boot
Resolution: | backpack
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2213
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang

#12035: hs-boot knot tying insufficient for ghc --make
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler (Type | Version: 8.1
checker) | Keywords: hs-boot
Resolution: | backpack
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2213
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: fixed | backpack Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2213 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: fixed | backpack Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2213 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Edward, both these changes are small but subtle. But they both lack any commentary. Would it be worth adding some? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: fixed | backpack Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2213 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): Already done, in https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/TyingTheKnot :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: fixed | backpack Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2213 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Very good -- but that wiki page is not referred to by the crucial code changes in the above patches. And it might be worth connecting the code changes to the tickets... an example (in the ticket) is often so illuminating. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12035: hs-boot knot tying insufficient for ghc --make
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler (Type | Version: 8.1
checker) | Keywords: hs-boot
Resolution: fixed | backpack
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2213
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang

#12035: hs-boot knot tying insufficient for ghc --make -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Keywords: hs-boot Resolution: fixed | backpack Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2213 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): Done! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12035#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC