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

Restructure modal and with-bounds (fka baggage) in jkind #3457

Open
wants to merge 14 commits into
base: aspsmith/untype-jkind
Choose a base branch
from

Conversation

glittershark
Copy link
Member

@glittershark glittershark commented Jan 9, 2025

This commit contains a significant restructuring of the modal upper bounds and with-bounds (which is the new name for what was previously called "baggage") in the innards of Jkind.t

Previously, jkinds morally consisted of:

  • a layout
  • a map from axis, to a pair of upper bound and a list of types (the with-bounds
    for that axis)

now, we instead have, morally:

  • a layout
  • a map from axis to the upper bound for that axis
  • a list of (type, modality) pairs, where the modality is effectively providing us the way that the type operates on the axis

This behavior is both much closer to the syntactic representation of jkinds, making it simpler both to construct and to print, and probably more efficient, since the usual behavior is that a type appears on the with-bounds for all axes (this is only not the case in the presence of modalities)

The test changes are mostly innocuous:

  1. Printing changed slightly when illegal crossing is used - actually I'm reasonably sure that this change fixed printing of kind annotations for types with illegal crossing
  2. We're no longer deduplicating types for printing kinds (we used to do this only when constructing outcometrees); this will come back later as we do deduplication of with-bounds at construction time.
  3. We actually got better at printing kinds in general, eg we're now better at figuring out built-in aliases to print under some with-bounds.

Past the actual internals of with-bounds, we frequently /reconstruct/ the list-of-types-per-axis shape, eg in subsumption - this is mostly done to avoid this commit getting too large and hairy, and in follow-up I plan on refactoring to do more algorithms such as bound extension holistically rather than per-axis, which ought to also realize more performance gains here.

note for reviewers: the last commit is a cherry-pick from main to get CI passing, and can be ignored. The two other commits can easily be reviewed separately.

@glittershark glittershark added the modes Work on modes. There's some overlap with the `multicore` label, but not strictly so. label Jan 9, 2025
typing/jkind_types.mli Outdated Show resolved Hide resolved
@glittershark glittershark marked this pull request as ready for review January 9, 2025 17:18
@glittershark glittershark changed the title Restructure modal and with-bounds (fka baggage) in jkind Restructure modal and with-bounds (fka baggage) in jkind Jan 9, 2025
@glittershark glittershark force-pushed the aspsmith/untype-jkind branch from aaa1601 to 1af69a4 Compare January 14, 2025 21:07
@glittershark glittershark force-pushed the aspsmith/transpose-jkind branch from 5ce9f8b to 6270b24 Compare January 14, 2025 21:13
typing/jkind_axis.mli Outdated Show resolved Hide resolved
typing/jkind_axis.mli Outdated Show resolved Hide resolved
typing/jkind_axis.ml Outdated Show resolved Hide resolved
typing/jkind_axis.mli Outdated Show resolved Hide resolved
typing/jkind_axis.mli Outdated Show resolved Hide resolved
typing/jkind_types.mli Show resolved Hide resolved
typing/jkind_types.ml Outdated Show resolved Hide resolved
typing/jkind_types.ml Outdated Show resolved Hide resolved
typing/jkind.ml Outdated Show resolved Hide resolved
typing/jkind.ml Outdated Show resolved Hide resolved
@goldfirere
Copy link
Collaborator

I have reviewed the latest four commits ("Apply suggestions from code review"..."remove pointless magic"), with no further comments.

Move the current version of Jkind_axis.Axis_collection, which wraps a type
indexed on the specific axis, into `Axis_collection.Indexed`, and make
`Axis_collection.t` unindexed. I already have one use case (in printing for
jkinds) which doesn't care about the specific axis in the type, and I'm about to
introduce another, and this feels like a natural structure.
@glittershark glittershark force-pushed the aspsmith/transpose-jkind branch from 1f20220 to 970e1f4 Compare January 23, 2025 19:01
@glittershark glittershark force-pushed the aspsmith/untype-jkind branch from 1af69a4 to 20d0d08 Compare January 23, 2025 19:01
Copy link

github-actions bot commented Jan 23, 2025

Parser Change Checklist

This PR modifies the parser. Please check that the following tests are updated:

  • parsetree/source_jane_street.ml

This test should have examples of every new bit of syntax you are adding. Feel free to just check the box if your PR does not actually change the syntax (because it is refactoring the parser, say).

@glittershark glittershark force-pushed the aspsmith/transpose-jkind branch from 970e1f4 to 1571935 Compare January 23, 2025 19:45
glittershark and others added 6 commits January 23, 2025 14:48
This commit contains a significant restructuring of the modal upper bounds and
with-bounds (which is the new name for what was previously called "baggage") in
the innards of Jkind.t

Previously, jkinds morally consisted of:

- a layout
- a map from axis, to a pair of upper bound and a list of types (the with-bounds
  for that axis)

now, we instead have, morally:
- a layout
- a map from axis to the upper bound for that axis
- a list of (type, modality) pairs, where the modality is effectively providing
  us the way that the type operates on the axis

This behavior is both much closer to the syntactic representation of jkinds,
making it simpler both to construct and to print, and probably more efficient,
since the usual behavior is that a type appears on the with-bounds for all
axes (this is only not the case in the presence of modalities)

The test changes are mostly innocuous:

1. Printing changed slightly when illegal crossing is used - actually I'm
   reasonably sure that this change *fixed* printing of kind annotations for
   types with illegal crossing
2. We're no longer deduplicating types for printing kinds (we used to do this
   only when constructing outcometrees); this will come back later as we do
   deduplication of with-bounds at construction time.
3. We actually got better at printing kinds in general, eg we're now better at
   figuring out built-in aliases to print under some with-bounds.

Past the actual internals of with-bounds, we frequently /reconstruct/ the
list-of-types-per-axis shape, eg in subsumption - this is mostly done to avoid
this commit getting too large and hairy, and in follow-up I plan on refactoring
to do more algorithms such as bound extension holistically rather than per-axis,
which ought to also realize more performance gains here.
[CI] Use setup-ocaml v3 for ocamlformat workflow
Co-authored-by: Richard Eisenberg <[email protected]>
@glittershark glittershark force-pushed the aspsmith/transpose-jkind branch from 1571935 to 3ea7efe Compare January 23, 2025 19:48
@glittershark

This comment was marked as resolved.

@glittershark glittershark marked this pull request as draft January 24, 2025 19:06
@glittershark glittershark force-pushed the aspsmith/transpose-jkind branch from fb3f76c to e6c6bc4 Compare January 24, 2025 19:26
@glittershark
Copy link
Member Author

4f424dc needs review (by @goldfirere )

@glittershark glittershark marked this pull request as ready for review January 24, 2025 19:57
let bound1 = Bounds.get ~axis sub.jkind.upper_bounds in
let bound2 = Bounds.get ~axis super.jkind.upper_bounds in
let with_bounds1 =
With_bounds.types_on_axis ~axis sub.jkind.with_bounds
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does some work, and it will be wasted effort if the second shortcut below is taken.

With_bounds.types_on_axis ~axis sub.jkind.with_bounds
in
(* If bound1 is min and has no with-bounds, we're good. *)
(Bound_ops.le bound1 Bound_ops.min && List.length with_bounds1 = 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

List.compare_length_with is a tad more efficient. (Basically any use of List.length is probably wrong, in my book.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modes Work on modes. There's some overlap with the `multicore` label, but not strictly so.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants