Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"stan: nodeInfo" with ghc-9.4.7 #541

Closed
facundominguez opened this issue Nov 19, 2023 · 7 comments
Closed

"stan: nodeInfo" with ghc-9.4.7 #541

facundominguez opened this issue Nov 19, 2023 · 7 comments

Comments

@facundominguez
Copy link

facundominguez commented Nov 19, 2023

Hello! When running stan with ghc-9.4.7 in the liquid-fixpoint repo I get the following crash and error message

$ cabal build liquid-fixpoint
$ cabal install stan --installdir=.bin --install-method=copy --overwrite-policy=always
$ .bin/stan
  ⓘ Checking environment variables and CLI arguments for default configurations file usage...
    Fiasco:
      * [Error  ] No STAN_USE_DEFAULT_CONFIG Env Variable is set
      * [Error  ] No CLI option specified for no-default

  ⓘ Reading Configurations from /home/facundo/tweag/liquidhaskell/liquid-fixpoint/.stan.toml ...
  ⓘ The following Configurations are used:

    Result:
      ∩ Exclude
          ID: STAN-0001
          All files
      ∩ Exclude
          ID: STAN-0002
          All files
      ∩ Exclude
          ID: STAN-0003
          All files
      ∩ Exclude
          ID: STAN-0004
          All files
      ∩ Exclude
          ID: STAN-0005
          All files
      ∩ Exclude
          ID: STAN-0008
          All files
      ∩ Exclude
          ID: STAN-0009
          All files
      ∩ Exclude
          ID: STAN-0012
          All files
      ∩ Exclude
          ID: STAN-0013
          All files
      ∩ Exclude
          ID: STAN-0014
          All files
      ∩ Exclude
          ID: STAN-0019
          All files
      ∩ Exclude
          ID: STAN-0101
          All files
      ∩ Exclude
          ID: STAN-0102
          All files
      ∩ Exclude
          ID: STAN-0103
          All files
      ∩ Exclude
          ID: STAN-0105
          All files
      ∩ Exclude
          ID: STAN-0206
          All files
      ∩ Exclude
          ID: STAN-0208
          All files
      ∩ Exclude
          ID: STAN-0209
          All files
      ∩ Exclude
          ID: STAN-0212
          All files
      ∩ Exclude
          ID: STAN-0213
          All files
      ∩ Exclude
          ID: STAN-0302
          All files
    
    With the following warnings:
      * [Warning] No CLI option specified for: checks
      * [Warning] configChecks is set through the source: TOML
      * [Warning] No TOML value is specified for key: remove
      * [Warning] No CLI option specified for: remove
      * [Warning] configRemoved is set through the source: TOML
      * [Warning] No TOML value is specified for key: ignore
      * [Warning] No CLI option specified for: ignore
      * [Warning] configIgnored is set through the source: TOML

  ⓘ Using the following .cabal file: /home/facundo/tweag/liquidhaskell/liquid-fixpoint/liquid-fixpoint.cabal

stan: nodeInfo
CallStack (from HasCallStack):
  error, called at src/Relude/Debug.hs:296:11 in relude-1.2.1.0-ea787ea216b250f63edab15a196f92bee0e612410323d35bd7a6caf35e8a006b:Relude.Debug
  error, called at src/Stan/Hie/Compat904.hs:56:24 in stan-0.1.0.2-047d71517a9ed4112306c36676510f2dac5e6e6778c6939e0d43dc4a27ad3220:Stan.Hie.Compat904

The error is rather uninformative to me. Is there anything I could do about it?

@0rphee
Copy link
Contributor

0rphee commented Dec 2, 2023

This also seems to happen in 9.6.3, with hls: haskell/haskell-language-server#3885

@0rphee
Copy link
Contributor

0rphee commented Dec 10, 2023

In this case, after changing the offending lines https://github.com/kowainik/stan/blob/ddcd461be0bfe3ff7d5353ff6f5d64fb0536c38e/src/Stan/Hie/Compat904.hs#L52C1-L58C74
to

nodeInfo :: HieAST a -> NodeInfo a
nodeInfo h = case (lookup' SourceInfo, lookup' GeneratedInfo) of
  (Nothing, Nothing) -> 
                        let a = error "nodeInfo Nothing Nothing" 
                        in 
                          -- NodeInfo S.empty [] M.empty
                          a

  (Just n1, Nothing) -> n1
  (Nothing, Just b) -> let a = error "nodeInfo Nothing Just" 
                       in 
                          -- b
                          a
  (Just n1, Just{}) -> n1
  where lookup' k = Map.lookup k (getSourcedNodeInfo (sourcedNodeInfo h))

gives us

stan: nodeInfo Nothing Just
CallStack (from HasCallStack):
  error, called at src/Relude/Debug.hs:296:11 in rld-1.2.1.0-8bb4440e:Relude.Debug
  error, called at src/Stan/Hie/Compat904.hs:63:32 in stn-0.1.0.2-89eeeecd:Stan.Hie.Compat904

For liquid-fixpoint and ghcide in hls, the error happens with the Nothing, Just b pattern match. And if i change it to return the value from the Just, it does alright, no errors are thrown and tests also pass. I only know of these two cases, but I do not know what would be the right thing to do...

Returning the value from the Just might be a good enough solution though @tomjaguarpaw .

@tomjaguarpaw
Copy link
Collaborator

Thanks for reporting this @facundominguez. Sorry for not responding earlier. I didn't have notifications on for this repository so I was only notified when I was mentioned. And thanks for jumping on this @0rphee.

This code is in CompatXXX for 9.0 onwards, so I suspect the same failing examples will fail in all those GHC versions. We need a minimal reproducer that we can add to our test cases. One thing that we could apply as an emergency fix is return an empty NodeInfo. At least then people can still use stan, even if it ends up ignoring some parts of the file.

@tomjaguarpaw
Copy link
Collaborator

I guess we should replace nodeInfo with this implementation: https://hackage.haskell.org/package/ghc-9.8.1/docs/src/GHC.Iface.Ext.Utils.html#nodeInfo

@tomjaguarpaw
Copy link
Collaborator

tomjaguarpaw added a commit to tomjaguarpaw/stan that referenced this issue Dec 10, 2023
There seem to be some cases in which SourceInfo doesn't exist, and
those led to run time crashes.

See, for example

* kowainik#541
* haskell/haskell-language-server#3885

Fixes: kowainik#541
@tomjaguarpaw
Copy link
Collaborator

Fixed and released to Hackage: https://hackage.haskell.org/package/stan-0.1.1.0


I managed to track this down to Language/Fixpoint/Types/Refinements.hs but I didn't find a smaller reproducer than that, unfortunately.

@facundominguez
Copy link
Author

Thanks @tomjaguarpaw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants