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 0206 should not fire for type data #544

Open
noughtmare opened this issue Dec 8, 2023 · 2 comments
Open

Stan 0206 should not fire for type data #544

noughtmare opened this issue Dec 8, 2023 · 2 comments

Comments

@noughtmare
Copy link

noughtmare commented Dec 8, 2023

I have this code:

{-# LANGUAGE TypeData #-}

infixr :->
type data PCFType = PCFType :-> PCFType | Nat

And Stan reports:

 ✲ Name:        Data types with non-strict fields
 ✲ Description: Defining lazy fields in data types can lead to unexpected space leaks
 ✲ Severity:    Performance
 ✲ Category:    #SpaceLeak #Syntax
Possible solutions:
  - Add '!' before the type, e.g. !Int or !(Maybe Bool)
  - Enable the 'StrictData' extension: {-# LANGUAGE StrictData #-}
stan(STAN-0206)

But strictness fields are not allowed in type data declarations.

@tomjaguarpaw
Copy link
Collaborator

Thanks, I agree this is a bug. I suspect it will only be fixed if there's a volunteer contribution.

@noughtmare
Copy link
Author

I've looked into it a bit and I think the change should be somewhere here:

matchLazyField node = memptyIfFalse
-- return empty list if it's not a data type
(hieMatchPatternAst hie node dataDecl)
-- get list of all constructors
$ let constructors = filter
(\n -> hieMatchPatternAst hie n constructor)
(nodeChildren node)
in case constructors of
-- no constructors = not observations
[] -> mempty
-- single constructor
[c] -> S.concatMap matchField $ extractFields False c
-- multiple constructors = analyse everything
cs -> S.concatMap (S.concatMap matchField . extractFields True) cs

But I don't quite know what to change yet.

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

2 participants