[GHC] #15541: package environment files and the GHC API

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Keywords: package | Operating System: Unknown/Multiple environment | Architecture: | Type of failure: Documentation Unknown/Multiple | bug Test Case: | Blocked By: Blocking: | Related Tickets: #15513 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The GHC API respects package environment files, which is not documented and was not announced. I consider this to be at least a severe documentation bug. Afaik this goes back to ghc-8.0. #15513 is a ticket that essentially asks for the corresponding entry in the migration guide. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by alanz): * cc: alanz (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): Also relevant : https://github.com/lspitzner/brittany/issues/173 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Updates both the interactive and program DynFlags in a Session. This also reads the package database (unless it has already been read), and
#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by lspitzner): The haddock on `setSessionDynFlags` currently reads: prepares the compilers knowledge about packages. It can be called again to load new packages: just add new package flags to (packageFlags dflags).
Returns a list of new packages that may need to be linked in using the
dynamic linker (see linkPackages) as a result of new package flags. If you are not doing linking or doing static linking, you can ignore the list of packages returned. I assume this is where package environment files are read. So in addition to nothing being documented, this semantic change was made to a function with the innocuous name of `setSessionDynFlags`. Please don't do that. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): The motivation for this design is that package environments should be transparent to the user, giving tooling a means of configuring GHC for a project without further user intervention. This is much the same way GHC will automatically look at the environment's global and user package databases. That being said, package environments are often much more transient and it's not hard to see how this might go wrong. I see a few ways forward here: * Rip the `interpretPackageEnv` call out of `setSessionDynFlags` (or rather, `initPackages`) and require API users to do this manually. * Add a flag to `setSessionDynFlags` specifying whether package environments should be respected * Keep the status quo but document it lspitzner, perhaps you have an opinion on what this interface should look like? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: dcoutts (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

The motivation for this design is that package environments should be
#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by lspitzner): transparent to the user, giving tooling a means of configuring GHC for a project without further user intervention. I consider the whole feature to be a mistake, see [https://hexagoxel.de/postsforpublish/posts/2018-08-25-ghc-pkg-env- misfeature.html this summary post]. As a consequence, if I had to choose between the options you presented, I'd vote for the first (rip out this side-effect from `setSessionDynFlags`). Some further opinionated thoughts: - If you expose `getFoo` and `setFoo`, `getFoo >>= setFoo` **must behave as identity**, free of (side- / other) effects. No amount of API docs excuses a violation. - It is likely to surprise and generally inadvisable to have any actions exposed in an API depend on `CWD`, especially by default. - The actions in the API should all have a single, clearly defined purpose. In brittany we encountered exactly the same question when it came to user config handling in its API. Perhaps have a look at how the brittany API is designed when it comes to `Config` values: https://hackage.haskell.org/package/brittany-0.11.0.0/docs/Language- Haskell-Brittany.html. Note how `parsePrintModule` is explicit about its inputs, promises to be semantically pure, and that there are separate actions that explicitly handle the filesystem reading of config files. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * priority: high => highest Comment: These issues with package environment files are quite serious so I am bumping the priority -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * cc: osa1 (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15541: package environment files and the GHC API -------------------------------------+------------------------------------- Reporter: lspitzner | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.6.1 Component: GHC API | Version: 8.4.3 Resolution: | Keywords: package | environment Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #15513 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by lspitzner): It is unfortunate and unintended that the scope of these ticket(s) got progressively larger. This was a consequence of my thought-process (1. this is cabal misfeature 2. I can at least fix one usecase if only the API was documented 3. no wait, this transcends my usecase and should be fixed for both ghc UI and API). Sorry about that. So while I'd like to have a ticket "turn package-environment feature off by default" for both UI and API, I don't want to create yet another ticket. I trust you can handle this appropriately. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15541#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC