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

Unboxed records #3229

Merged
merged 19 commits into from
Dec 5, 2024
Merged

Unboxed records #3229

merged 19 commits into from
Dec 5, 2024

Conversation

rtjoa
Copy link
Contributor

@rtjoa rtjoa commented Nov 5, 2024

Add support for unboxed records (construction, functional updates, projection, pattern matching), whose types have product jkinds. For example:

type 'a with_idx : value & immediate = #{ data : 'a ; i : int }
let idx #{ data = _ ; i } = i
let inc r = #{ r with i = r.#i + 1 }

The fields of unboxed records have a separate namespace from record fields. While fields can be mutable, we don't yet support updating them.

Implementation decisions

Unboxed record types are distinct from record types, rather than being yet another record_representation.

  • Having separate codepaths is likely to be less error-prone than adding another record_representation, which we might not always match on in the right places.
  • The majority of the duplication this causes is ameliorated by making label_description abstract over the type for record representations, which is now either record_representation or record_unboxed_product_representation. This allowed nearly all shared logic to be parameterized by the record "form," with the most notable exception being in lambda/matching.ml.

A (temporary) jkind-checking algorithm that interleaves looking through unboxed types and type expressions constructors.

  • See the comment on type_jkind_deep in typing/ctype.ml.
  • We could have instead updated constrain_type_jkind to return a jkind estimate, but this would require significant changes. Instead, we use this somewhat duplicative solution, as it will be removable once we support kind-polymorphic type declarations.

Future work

  • Declaring a boxed record t also declares its unboxed version t#, when doing so would be well-founded.
  • The signature item type t boxes value & value declares the kinds of both t and t# and indicates that they are linked.
  • Unboxed record fields can be mutated (only when the unboxed record is nested within a boxed record).
  • Infinite-size unboxed records give better type errors (see testsuite/tests/typing-layouts-unboxed-records/recursive.ml).

Review: @ccasin

Copy link

github-actions bot commented Nov 5, 2024

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).

@rtjoa rtjoa force-pushed the rtjoa.basic_unboxed_records branch from 7be53ee to 70be641 Compare November 5, 2024 19:13
@rtjoa rtjoa changed the title Basic unboxed records [WIP] Basic unboxed records Nov 5, 2024
@rtjoa rtjoa force-pushed the rtjoa.basic_unboxed_records branch 4 times, most recently from 7ac8450 to dacc5d7 Compare November 6, 2024 17:04
@rtjoa rtjoa requested a review from ccasin November 6, 2024 17:04
@rtjoa rtjoa changed the title [WIP] Basic unboxed records Basic unboxed records Nov 6, 2024
@rtjoa rtjoa force-pushed the rtjoa.basic_unboxed_records branch from dacc5d7 to 6f41f22 Compare November 6, 2024 17:22
@rtjoa rtjoa marked this pull request as ready for review November 6, 2024 17:55
@rtjoa rtjoa force-pushed the rtjoa.basic_unboxed_records branch 16 times, most recently from e5e3ea5 to aeae90b Compare November 11, 2024 16:52
@rtjoa rtjoa force-pushed the rtjoa.basic_unboxed_records branch from 5031588 to a75d1fe Compare December 3, 2024 19:02
@rtjoa rtjoa changed the title Basic unboxed records Unboxed records Dec 4, 2024
lambda/translcore.ml Outdated Show resolved Hide resolved
typing/typecore.ml Outdated Show resolved Hide resolved
@ccasin ccasin merged commit d330dfe into main Dec 5, 2024
21 checks passed
@ccasin ccasin deleted the rtjoa.basic_unboxed_records branch December 5, 2024 18:05
rtjoa added a commit that referenced this pull request Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants