kowainik / stan

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

Performance Issue on "Lazy" Class Constraint #326

Closed fendor closed 4 years ago

fendor commented 4 years ago

Built stan from source, current master.

Executed on the https://github.com/haskell/haskell-language-server code-base. Generated .hie files via adding -fwrite-ide-info and -hiedir=.hie to ghc-options for the library stanza.

 ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 ┃  ✦ ID:            OBS-STAN-0206-9g9o2m-99:32
 ┃  ✦ Severity:      Performance
 ┃  ✦ Inspection ID: STAN-0206
 ┃  ✦ Name:          Data types with non-strict fields
 ┃  ✦ Description:   Defining lazy fields in data types can lead to unexpected space leaks
 ┃  ✦ Category:      #SpaceLeak #Syntax
 ┃  ✦ File:          src/Ide/Types.hs
 ┃  
 ┃    98 ┃ 
 ┃    99 ┃ data PluginCommand = forall a. (FromJSON a) =>
 ┃   100 ┃                                ^^^^^^^^^^^^
 ┃  
 ┃  💡 Possible solution:
 ┃      ⍟ Add '!' before the type, e.g. !Int or !(Maybe Bool)
 ┃      ⍟ Enable the 'StrictData' extension: {-# LANGUAGE StrictData #-}
 ┃
 ┃~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This seems wrong to me, and I also cant add the Strictness Annotation to the class constraint.

Relevant definitions:

newtype CommandId = CommandId T.Text
  deriving (Show, Read, Eq, Ord)
instance IsString CommandId where
  fromString = CommandId . T.pack

data PluginCommand = forall a. (FromJSON a) =>
  PluginCommand { commandId   :: CommandId
                , commandDesc :: T.Text
                , commandFunc :: CommandFunction a
                }

type CommandFunction a = LSP.LspFuncs Config
                       -> IdeState
                       -> a
                       -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
chshersh commented 4 years ago

@fendor Thanks for reporting the problem. It looks like the current implementation of this inspection can be improved to handle such cases. Just for the sake of having the full context, what version of GHC were you using to build Stan and produce HIE files for your project?

fendor commented 4 years ago

I am using GHC 8.8.3