kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
562 stars 48 forks source link

"stan: nodeInfo" with ghc-9.4.7 #541

Closed facundominguez closed 6 months ago

facundominguez commented 7 months ago

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 commented 7 months ago

This also seems to happen in 9.6.3, with hls: https://github.com/haskell/haskell-language-server/issues/3885

0rphee commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

WIP fixing this here: https://github.com/tomjaguarpaw/stan/tree/nodeInfo

tomjaguarpaw commented 6 months ago

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 commented 6 months ago

Thanks @tomjaguarpaw!