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

Initial stab at documenting the kind system #3559

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ccasin
Copy link
Contributor

@ccasin ccasin commented Feb 7, 2025

As title.

This is a draft PR because at a minimum there are some bits left to be filled in. But, also, I think we need some discussion about how various bits of the system should be presented. Here, I've tried to present things uniformly as they really are (or will be in a few weeks), so that a whole bunch of special cases aren't needed. But in practice our system obscures this reality a bit (for example, around nullability), and I'm not sure how best to handle that.

I've tried to write this more as useful documentation than as a complete reference.

Copy link
Collaborator

@goldfirere goldfirere left a comment

Choose a reason for hiding this comment

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

I think this is fantastic.

by a tagged integer), because they are unboxed types like `float#` or `int32#`,
or because they are allocated elsewhere.

The axis has two possible values, with `external < internal`. Here, `external`
Copy link
Collaborator

Choose a reason for hiding this comment

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

It actually has 3 possible values: external_ < external64 < internal, so that immediate64 can be mod external64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

I added a note about external64 and jsoo/wasm - you may want to check its accuracy.

Comment on lines +332 to +335
CR ccasinghino: I'm imagining the "with kinds" section above to be a practical
introduction to why we have with kinds and how to write them. It probably should
not cover the details of how we compute the kind of type. Is it worth explaining
that down here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not in great detail. But I do think there should be some commentary mentioning at least these highlights:

  • The default kind for type t is value
  • The kind for an extensible type is value
  • The kind for a boxed variant with no fields is immediate
  • The kind for a boxed record or variant with no mutable fields (but at least one field) is immutable_data with <<all the fields>>
  • The kind for a boxed record or variant with at least one mutable field is mutable_data with <<all the fields>>
  • The kind for an unboxed record is <<product of the fields' layouts>> mod <<everything>> with <<all the fields>>
  • The kind for an [@@unboxed] record or variant is <<layout of the payload>> mod <<everything>> with <<the field>> (by further special decree, this with does take nullability into account!)
  • The kind for an unboxed tuple is <<layout of the components>> mod <<everything>> with <<the components>>
  • The kind for a closed polymorphic variant with no fields is immediate
  • The kind of a function is value mod aliased contended
  • The kind for other types is value
  • Kinds for other types may improve over time. For example, we expect to change the kind of a boxed tuple to be immutable_data with <<the components>>. Similarly, we expect to improve on the kinds of polymorphic variants and first-class modules.
  • The kind of a private abbreviation is the kind of its right-hand side. We expect to allow users to give a private abbreviation a superkind of its right-hand side (thus improving abstraction) soon.

A full specification of how with-bounds interact with subsumption is probably beyond the scope of this document. I can produce some hand-wavy text about how we try our best here if you like.

@mshinwell mshinwell added typing documentation Improvements or additions to documentation labels Feb 10, 2025
@ccasin
Copy link
Contributor Author

ccasin commented Feb 14, 2025

OK, I've integrated most of the feedback here - thanks for catching all those typos. A couple notes:

Nullability: I've reworked the doc to just not mention nullability at all until the section on it. Despite my earlier whinging, I think this works out fine, and everything remains accurate, likely due to the good design choice to have things as they are. @dkalinichenko-js may want to check the nullability section for accuracy.

With-kinds: This is the remaining thing. I've realized I have no idea what the current syntax is. I propose we ask someone familiar with the current implementation (@glittershark , maybe?) to fill in that part of this doc. (You can just push to this branch)

@glittershark
Copy link
Member

glittershark commented Feb 19, 2025

With-kinds: This is the remaining thing. I've realized I have no idea what the current syntax is. I propose we ask someone familiar with the current implementation (@glittershark , maybe?) to fill in that part of this doc. (You can just push to this branch)

I'll gladly do this, ideally sometime next week (or if you want it sooner, @liam923 or @goldfirere might have time before then?)

@liam923
Copy link
Contributor

liam923 commented Feb 19, 2025

I'll gladly do this, ideally sometime next week (or if you want it sooner, @liam923 or @goldfirere might have time before then?)

I don't think I'd be able to get around to it before next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants