Skip to content

Omit kind sigs where kind is uninteresting, even when parens are involved#4137

Merged
JordanMartinez merged 17 commits intopurescript:masterfrom
JordanMartinez:fixUninterestingKindsWhenParensIncluded
Jul 16, 2021
Merged

Omit kind sigs where kind is uninteresting, even when parens are involved#4137
JordanMartinez merged 17 commits intopurescript:masterfrom
JordanMartinez:fixUninterestingKindsWhenParensIncluded

Conversation

@JordanMartinez
Copy link
Copy Markdown
Contributor

@JordanMartinez JordanMartinez commented Jul 6, 2021

Description of the change

Fixes #4136


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

Copy link
Copy Markdown
Member

@kl0tl kl0tl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also drop sorts annotations from developper written kinds?

isUninteresting keyword = \case
P.TypeApp _ t1 t2 | t1 == kindFunctionType ->
-- `Type -> ...`
P.TypeApp _ (P.TypeApp _ (P.TypeConstructor () Prim.Function) ty) t2 | isKindPrimType ty ->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to account for the case where an application is wrapped in parens, like (Type -> Type), otherwise we deem such kinds interesting and they show up in the generated docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning if we have something like this?

data Foo :: (Type -> Type)
data Foo a = Foo a

which is the same as writing the uninteresting kind signature below:

data Foo :: Type -> Type
data Foo a = Foo a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly, data Foo :: (Type -> Type) should be treated like data Foo :: Type -> Type but the kind is currently documented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that mean accounting for various other situations, too? I'm starting to wonder if this is really worth doing and if we should instead say, "Yeah, just don't do that."

As examples of other things:

-- or any uninteresting kind where the whole thing is wrapped in parens
data Foo1 :: (Type -> Type -> Type)
data Foo1 a b = Foo1 a b


-- or any uninteresting kind where the the tail part is wrapped in parens
data Foo2 :: Type -> (Type -> Type)
data Foo2 a b = Foo2 a b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes those kinds should be uninteresting too. It should only be a matter of adding a P.ParensInType _ ty -> isUninteresting ty case to isUninteresting though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and added tests for it. I haven't tested this locally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover data Foo :: (->) Type Type? Or data Foo :: ((->) Type) Type, or, for that matter, data Foo :: ((((->)) Type)) Type?

These are profoundly obnoxious edge cases, but if they cause problems, maybe the thing to do is just strip out all parens using a traversal before calling isUninteresting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'll add a test for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest commit adds these three tests, the latter two of which currently fail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, stripping those parenthesis out and then solving the problem with the original approach was much easier than trying to account for them at the same time.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

JordanMartinez commented Jul 9, 2021

Note: while I was working on this PR, I also learned that the parens situation will be displayed in the kind signature if it's included in an interesting kind signature. For example:

data Foo :: forall k. k -> (Type)
data Foo a = Foo

will be rendered as the above, not as below:

data Foo :: forall k. k -> Type
data Foo a = Foo

I'm not sure whether it's really worth it to remove the parenthesis because I doubt this will happen in practice.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Should we also drop sorts annotations from developper written kinds?

Meaning, if the developer writes

data Foo (a :: Type) = Foo a

then we render the following?

data Foo a = Foo a

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Just added a test for this. It passed but nothing changed in my code:

data DataSortAnnotation (a :: Type) = DataSortAnnotation a

@rhendric
Copy link
Copy Markdown
Member

data DataSortAnnotation (a :: Type) = DataSortAnnotation a

That's still a kind annotation. I think a sort annotation would be the :: Type in

foreign import data DataSortAnnotation :: forall (k :: Type). k -> Type

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Mm... I'm not so sure. Harry said something about this that makes me think otherwise...?

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Changelog entry has been added now that #4132 is in.

@rhendric
Copy link
Copy Markdown
Member

The changelog file name should start with fix, not bug.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

This PR should be ready for another review when someone has a moment.

Copy link
Copy Markdown
Member

@kl0tl kl0tl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should render

foreign import data DataSortAnnotation :: forall (k :: Type). k -> Type

as

foreign import data DataSortAnnotation :: forall k. k -> Type

for consistency with inferred kinds, but that’s not really related to this pull request so it can happen in another one (and perhaps it should rather be done by a formatter). Ditto for extraneous parens in interesting kinds.

This looks great though, thank you!

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

I still think we should render

Isn't that handled in #4121? Since the declaration is FFI, #4121 first converts that to a data declaration and then runs it through the code that removes the sort annotation.

Regardless, thanks for the review. Merging!

@JordanMartinez JordanMartinez merged commit 2b9c7a6 into purescript:master Jul 16, 2021
@JordanMartinez JordanMartinez deleted the fixUninterestingKindsWhenParensIncluded branch July 16, 2021 13:36
@kl0tl
Copy link
Copy Markdown
Member

kl0tl commented Jul 16, 2021

Isn't that handled in #4121? Since the declaration is FFI, #4121 first converts that to a data declaration and then runs it through the code that removes the sort annotation.

This doesn’t seem to be the case: on 73ff5f6 we render

Capture d’écran 2021-07-16 à 18 33 54

for

foreign import data DataSortAnnotation :: forall (k :: Type). k -> Type

because we only drop sort annotations for inferred kinds.

@JordanMartinez
Copy link
Copy Markdown
Contributor Author

Gotcha. I've reported this as a bug in #4160

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

Successfully merging this pull request may close these issues.

Still omit uninteresting kind signatures from HTML docs when redundant parenthesis are involved

3 participants