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

Performance Issue on "Lazy" Class Constraint #326

Closed
fendor opened this issue Jun 27, 2020 · 2 comments · Fixed by #332
Closed

Performance Issue on "Lazy" Class Constraint #326

fendor opened this issue Jun 27, 2020 · 2 comments · Fixed by #332
Assignees
Labels
bug 🪲 Something isn't working

Comments

@fendor
Copy link

fendor commented Jun 27, 2020

Built stan from source, current master.

Executed on the https:/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 chshersh added the bug 🪲 Something isn't working label Jun 28, 2020
@chshersh
Copy link
Contributor

@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
Copy link
Author

fendor commented Jun 28, 2020

I am using GHC 8.8.3

@chshersh chshersh added this to the 0.1.0.0: Custom inspections milestone Jun 28, 2020
@vrom911 vrom911 self-assigned this Jun 28, 2020
chshersh pushed a commit that referenced this issue Jun 28, 2020
* [#326] Handle constraints before constructors in STAN-0206 (strict fields)

Resolves #326

* Add more constraint examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants