-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add support for annotating types with layouts. #1
Add support for annotating types with layouts. #1
Conversation
026aac9
to
cb5145e
Compare
ddd0221
to
80f1849
Compare
This is now in an intermediate state as I'm adding more layout annotations. The first two commits are good, but please wait for general review. I will unmark this as a Draft and post here when it's ready for proper review. |
cb3ef64
to
7d94fd6
Compare
7d94fd6
to
ba63ad9
Compare
ba63ad9
to
335b077
Compare
This is now ready for review. There are tests failing in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks mostly good. I think there is one issue, which is to do with check_poly_univars
and mutually defined types. For example, this currently checks:
type ('a : immediate) t_imm
type s = { f : ('a : value) . 'a -> 'a u }
and 'a u = 'a t_imm
I think we want to reject this. (Or if we want to accept it, s
should get the type {f : ('a : immediate). 'a -> 'a u}
, but it gets value
).
The problem is that both make_poly_univars
and check_poly_univars
happen inside the call to transl_simple_type
in transl_labels
, and that happens in an environment where we haven't yet discovered that u
's parameter must be immediate. There's a similar problem for gadt constructors.
I don't see a super easy solution, and it's further complicated by the fact that we aren't even doing layout checks when these types are translated (because they are delayed for later). Three possible but annoying solutions:
- It might be possible to remember these univar checks and perform them later, after we do all the delayed layout checks (though I'd have to think a little harder about what information ends up in what environment). This seems easiest if possible
- We could retranslate these types for the purpose of performing this check once we have an appropriate environment and have performed the circularity checks. This seems like a bad idea for performance reasons.
- We could figure out what we're going to do about "lower bounds" for layouts, which we already want for efficiency and I think could solve this (if
u
's parameter gets a lower bound ofvalue
while translatings
's body, then when we could get an error when translatingu
).
I'm happy to think more about this - I really want to get out this review today, so I haven't spent much time on it.
I've put some other comments and design questions throughout, but overall things look good other than this issue. There are a few things that seem a bit awkward, but which I've mostly held off on commenting on because I expect they will change when we eliminate the modifications to the parse tree and move to the new extension mechanism (e.g., there are lots of places where we're using a pair of lists of vars and layout annotations where it seems cleaner to have a list of pairs).
typing/typedtree.mli
Outdated
@@ -755,7 +762,7 @@ and constructor_declaration = | |||
{ | |||
cd_id: Ident.t; | |||
cd_name: string loc; | |||
cd_vars: string loc list; | |||
cd_vars: (string * layout_annotation option) list; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess since this typechecks the loc
information wasn't used anywhere, but I wonder if it wouldn't be nice to keep and use to give better located errors when something fails in layout checking, instead of indicating the whole quantified type. (and in Text_decl
below, as well). Though I guess if we do that here we'd want to do it in all places you can have quantifiers like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's about right. I removed the loc
to make code reuse easier. Making different decisions about this in different places is annoying. I'm all for adding more locations to report better errors, but I think we should do so separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable.
For example, this adds support for [(int : immediate)], [(string list : value)], and [(type 'a t : immediate)]. The full syntax is at https://docpub/JD/p/surface-syntax-for-unboxed-types/db6b3168-1985-302e-155c-e2b59c8f40bf#layout-annotations Also, fix up pretty-printing to show more layouts.
335b077
to
30153c6
Compare
OK. I think I've resolved everything here. OK to merge? |
efcac41
to
1ad4ef0
Compare
Small update: it was decided not to merge this for now, because we're hoping to release a version of unboxed types without annotation support. |
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch.
Superseded by ocaml-flambda/flambda-backend#1417 |
Initial implementation of layout annotations This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch. Rename ~reason to ~context for annotations (only) Move layout annotations into aliases This now prevents e.g. [(int : immediate)] but allows [int as ('a : immediate)], as discussed with the type-systems group. Add control over printing verbosity Move alias over to jane-syntax architecture Move variable layout annotation into jane-syntax Support for annotations on _ Check layout annotation during conversion Handle type parameters uniformly Convert Ptyp_poly to use jane-syntax architecture Comments from Antal Move annotations on extension constructors into JS Combine unboxed constants with other layouts Newtypes are now in jane-syntax. Constructor declarations in jane-syntax Make testsuite pass Some minor cleanup of old XXXs. Some cleanup from review A little cleanup in Jane_syntax from review Fix compilation with dune-based build Incorporate test case from old PR, improving msg Respond to Antal's review More review fixes Move test that now passes Responses to comments rename test Remove "assert false" in favor of "Misc.fatal_error" Add comment about generic parameters transl_type_param_layout --> get_type_param_layout Rename error constructors Remove module that will interfere with merging
This commit also includes various improvements to jane-syntax. Documentation coming in a separate commit. This commit has been rebased to include the following commits: Pprintast now depends on Printast Initial implementation of layout annotations This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch. Rename ~reason to ~context for annotations (only) Move layout annotations into aliases This now prevents e.g. [(int : immediate)] but allows [int as ('a : immediate)], as discussed with the type-systems group. Add control over printing verbosity Move alias over to jane-syntax architecture Move variable layout annotation into jane-syntax Support for annotations on _ Check layout annotation during conversion Handle type parameters uniformly Convert Ptyp_poly to use jane-syntax architecture Comments from Antal Move annotations on extension constructors into JS Combine unboxed constants with other layouts Newtypes are now in jane-syntax. Constructor declarations in jane-syntax Make testsuite pass Some minor cleanup of old XXXs. Some cleanup from review A little cleanup in Jane_syntax from review Fix compilation with dune-based build Incorporate test case from old PR, improving msg Respond to Antal's review More review fixes Move test that now passes Responses to comments rename test Remove "assert false" in favor of "Misc.fatal_error" Add comment about generic parameters transl_type_param_layout --> get_type_param_layout Rename error constructors Remove module that will interfere with merging
* Add layout annotations to the language. This commit also includes various improvements to jane-syntax. Documentation coming in a separate commit. This commit has been rebased to include the following commits: Pprintast now depends on Printast Initial implementation of layout annotations This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch. Rename ~reason to ~context for annotations (only) Move layout annotations into aliases This now prevents e.g. [(int : immediate)] but allows [int as ('a : immediate)], as discussed with the type-systems group. Add control over printing verbosity Move alias over to jane-syntax architecture Move variable layout annotation into jane-syntax Support for annotations on _ Check layout annotation during conversion Handle type parameters uniformly Convert Ptyp_poly to use jane-syntax architecture Comments from Antal Move annotations on extension constructors into JS Combine unboxed constants with other layouts Newtypes are now in jane-syntax. Constructor declarations in jane-syntax Make testsuite pass Some minor cleanup of old XXXs. Some cleanup from review A little cleanup in Jane_syntax from review Fix compilation with dune-based build Incorporate test case from old PR, improving msg Respond to Antal's review More review fixes Move test that now passes Responses to comments rename test Remove "assert false" in favor of "Misc.fatal_error" Add comment about generic parameters transl_type_param_layout --> get_type_param_layout Rename error constructors Remove module that will interfere with merging * Remove call to make_params in enter_type * Keep minimizer compatible * Format chameleon
* Add layout annotations to the language. This commit also includes various improvements to jane-syntax. Documentation coming in a separate commit. This commit has been rebased to include the following commits: Pprintast now depends on Printast Initial implementation of layout annotations This was taken from ccasin/ocaml-jst#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch. Rename ~reason to ~context for annotations (only) Move layout annotations into aliases This now prevents e.g. [(int : immediate)] but allows [int as ('a : immediate)], as discussed with the type-systems group. Add control over printing verbosity Move alias over to jane-syntax architecture Move variable layout annotation into jane-syntax Support for annotations on _ Check layout annotation during conversion Handle type parameters uniformly Convert Ptyp_poly to use jane-syntax architecture Comments from Antal Move annotations on extension constructors into JS Combine unboxed constants with other layouts Newtypes are now in jane-syntax. Constructor declarations in jane-syntax Make testsuite pass Some minor cleanup of old XXXs. Some cleanup from review A little cleanup in Jane_syntax from review Fix compilation with dune-based build Incorporate test case from old PR, improving msg Respond to Antal's review More review fixes Move test that now passes Responses to comments rename test Remove "assert false" in favor of "Misc.fatal_error" Add comment about generic parameters transl_type_param_layout --> get_type_param_layout Rename error constructors Remove module that will interfere with merging * Remove call to make_params in enter_type * Keep minimizer compatible * Format chameleon
* Add layout annotations to the language. This commit also includes various improvements to jane-syntax. Documentation coming in a separate commit. This commit has been rebased to include the following commits: Pprintast now depends on Printast Initial implementation of layout annotations This was taken from ccasin#1, but rebased and cleaned. There are a handful of failing tests, still, but they're all newly introduced in this patch. Rename ~reason to ~context for annotations (only) Move layout annotations into aliases This now prevents e.g. [(int : immediate)] but allows [int as ('a : immediate)], as discussed with the type-systems group. Add control over printing verbosity Move alias over to jane-syntax architecture Move variable layout annotation into jane-syntax Support for annotations on _ Check layout annotation during conversion Handle type parameters uniformly Convert Ptyp_poly to use jane-syntax architecture Comments from Antal Move annotations on extension constructors into JS Combine unboxed constants with other layouts Newtypes are now in jane-syntax. Constructor declarations in jane-syntax Make testsuite pass Some minor cleanup of old XXXs. Some cleanup from review A little cleanup in Jane_syntax from review Fix compilation with dune-based build Incorporate test case from old PR, improving msg Respond to Antal's review More review fixes Move test that now passes Responses to comments rename test Remove "assert false" in favor of "Misc.fatal_error" Add comment about generic parameters transl_type_param_layout --> get_type_param_layout Rename error constructors Remove module that will interfere with merging * Remove call to make_params in enter_type * Keep minimizer compatible * Format chameleon
* Fix ghost locations in modular extension AST nodes * Add missing ghostification Thank you, Carl! * Comment update about ghostiness (+ word-wrapping) * Add ghostify function (#1) * Add `Location.ghostify` * Update the parser's `make_ghost` to save an allocation in some cases * Promote parser.ml * Mark the inner mutable arrays for iarrays as ghost * Add comment about ghostification for comprehensions * Explain that ppxlib is where the ghostiness requirement is enforced * Use `Ast_helper.default_loc` to default the generated locations * Restore propagating the location, now via `Ast_helper.default_loc` * Drop obsolete comment * Rewrite advisory comment about locations
For example, this adds support for [(int : immediate)] and
[(string list : value)].
This is the first part of layout annotations. See the test case for a hint of what's to come! But this can still be merged as is, if we like.