-
Notifications
You must be signed in to change notification settings - Fork 78
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
with-kinds #3284
base: main
Are you sure you want to change the base?
with-kinds #3284
Conversation
Parser Change ChecklistThis PR modifies the parser. Please check that the following tests are updated:
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). |
ab43d23
to
540cc23
Compare
07eb6ed
to
a0096f3
Compare
a0096f3
to
32dbf8c
Compare
540cc23
to
05c3424
Compare
ad170e9
to
011331a
Compare
16e83fa
to
70cf6eb
Compare
This causes trouble after with-kinds, because we get a jkind error where a kind error would be much, much clearer.
70cf6eb
to
25eadb9
Compare
This is now ready for review. 🎉 🎁 🎄 I have updated the top comment with a review plan, involving @rtjoa, @ccasin, @liam923, and @riaqn (and a tiny bit for @lpw25). @dkalinichenko-js could likely do some review, too, but given the fact that @liam923 and @riaqn have already taken a spin at the implementation here, it seems to make the most sense to have them review. But if the review burden here seems too high, looping in @dkalinichenko-js is a possible way to spread it out. |
This seems to be what we want; there was a comment here saying we shouldn't have any baggage but I think that was incorrect. And in fact, using Ctype.type_equal to check type equality makes a number of tests pass that we had marked as expecting to pass.
@goldfirere Please review: |
As a meta-point, I think someone should review that the review tasks @goldfirere assigned are exhaustive. That is, make sure all changes are actually getting reviewed. I think |
This reversion was motivated by trying to post the change upstream and pushback there. It turns out it's unnecessary. |
Decent point. Anyone is welcome to double-check this. But I should not: jkind_intf did not change in this patch, so there's no evidence I actually missed anything. :) |
|
OK. I believe I've responded to all comments up until now. Back to reviewers. |
I found a valid program that gets rejected by these changes:
|
As discussed in person, existential unboxed gadts allow a type to escape its scope as the existential will then appear in the with-bounds. |
|
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.
The change in a20a171 is fine, but I would like to understand the bug it fixes better.
class type sexp_of = | ||
object | ||
method array : ('a -> t) -> ('a array -> t) | ||
end |
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.
Why is the test being changed from a class to an array?
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 accidentally added the test in a different commit. But the test didn't actually pass -- that code won't even parse (because it's missing the =
). So the change you see here is just fixing the test to parse, and then showing that it isn't accepted.
If memory serves, this is a reduction of a problem that arose during bootstrapping.
The method array has type "'a. ('a -> t) -> 'a array -> t" | ||
but is expected to have type "'a. ('a -> t) -> 'a array -> t" | ||
Type "'a" is not compatible with type "'a0" | ||
class type sexp_of = object method array : ('a -> t) -> 'a array -> t end |
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.
The change in the commit is fine, but do we understand how it fixes the problem? I want to be sure we are missing another place where it should be resetting univar_pairs
, or nested calls to functions that aren’t reentrant.
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 went through all uses of univar_pairs
to use the protect-refs approach on all of them, not just the specific places that caused the bug. I sadly don't now remember which specific one it was. I suppose I could remove the fix and re-debug if you wanted more information.
Add a new flag, -infer-with-bounds, which enables inference of with-bounds (called "baggage" as of this commit, but to be renamed to with-bounds later) on type declarations. This defaults to false, and has to be turned on per-compilation-unit, because we are concerned about the performance impact of rolling out with-kind inference and want to do so gradually. If the flag is off, we restore the original inferred kinds prior to the introduction of with-bounds.
About to rebase en route to merging. State before the rebase is preserved at https://github.com/goldfirere/flambda-backend/tree/with-kinds-before-rebase |
This adds
with
-kinds to the compiler.It is a very preliminary version. Importantly, you should not use an actual
with
-kind in your code and expect anything to work. Instead, this just provides inferredwith
-kinds, but that should be sufficient for looking through lists,option
s, and arrays.A rebase of this work (at https://github.com/ocaml-flambda/flambda-backend/tree/aspsmith/with-kinds-on-portable-stdlib) has been observed to build Base and Core, and this passes all the tests in the compiler testsuite. It is thus ready for review.
It is strongly suspected not to be performant enough for merging, though this fact has not been adequately assessed. I expect to follow this PR with another one to improve its performance. Search for an internal doc titled "Normalization for with-kinds" for more thoughts on how to do this. But nevertheless, I think this PR is now (Dec 24 '24) ready for correctness review.
Review is roughly by commit, as I enumerate:
narrow_to_manifest_jkind
to useestimate_type_jkind
instead oftype_jkind_purely
. I don't remember my incentive for doing so, other than my general animosity towardtype_jkind_purely
(as documented in an internal doc titled "Let's kill type_jkind_purely"). You'll see some test case changes; please check these for reasonableness. The last commit undoes this change (restoring the use oftype_jkind_purely
) along with a long comment explaining why and how to do better. The last commit also contains several other small changes, mostly in response to unboxed-records work. (Some of the changes are not from that; feel free to delegate review of some files to @liam923 or @riaqn.) Some of the changes involve differences in behavior between principal-mode and non-principal-mode; these differences echo differences elsewhere and will be addressed later. (We basically don't care so much about principal mode.)from_subst
feature ofunify_var
in favor of thein_subst_mode
check (which came temporally afterfrom_subst
but serves the same purpose and is propagated further). The change was necessary withwith
-kinds.with
-kinds. Not anymore.with
-kinds to unboxed records and includes the deletion of the reimplementation ofestimate_type_jkind
.templates
test has already been approved by @lukemaurer. (This test is about parameterized modules.)univar_pairs
in ctype.And that's everything.
Now to break down the review of the main payload. The high-level overview is that much of this code was actually written by @liam923 and @riaqn in an early version of
with
-kinds. They should review. I break down where I have taken their code essentially as-is and where I have changed it (necessitating further review). The places where I took the code as-is do not need further review, as I reviewed the code as I adapted it. You can find your previous work at https://github.com/goldfirere/flambda-backend/pull/3/files.jane/doc
: @riaqn. These are updates to the uniqueness documentation in light ofwith
-kinds.parsing
: @liam923. Just some comments.testsuite
: @liam923. You're the most familiar with tests here -- as well as the expected use ofwith
-kinds in base and core. I believe you probably already reviewedwith.ml
while you were writing new tests.tools
: @liam923. This is a tiny change. (The reason for the eta-expansion is to avoid the value restriction.)ctype.ml
/ctype.mli
: I think @riaqn. (I'm not sure exactly which of you did which pieces.)instance_parameterized_kind
,instance_declaration
,jkind_subst
, andis_principal
are unchanged from your previous work.estimate_type_jkind
just has a small tweak compared to previous work (but would benefit from quick review)type_jkind_purely_if_principal
is unchangedconstrain_type_jkind
just uses a different approach to gettingtype_equal
than previously; pretty boring.check_decl_jkind
andconstrain_decl_jkind
have been moved to the bottom of the file so that they could accesstype_equal
(before I made the ref). Maybe this decision should be reversed.intersect_type_jkind
and below are new; please review with care.includecore.ml
: @riaqn. The mode-cross stuff could use your expertise (though looks straightforward). The change intype_declarations
is harder, but I already went over the basic idea with @ccasin (who agrees the approach is sound).jkind_axis.ml
/jkind_axis.mli
: @riaqn. This is very directly inspired by previous work, but I added a bunch more functions toAxis_collection
.jkind_types.ml
/jkind_types.mli
: @riaqn. This is mostly boilerplate-y, but there is some stuff with left/right logic that you are the expert in.jkind.ml
/jkind.mli
/printtyp.ml
: Some combination of @liam923 and @riaqn (please work this out).Bound.reduce_baggage
, which is a completely fresh reimplementation ofreduce_bound
from previous work.of_user_written_annotation_unchecked_level
are very close to prior work; compare the two to reduce review burden.add_portability_and_contention_crossing
were a bit tricky in order to try to get decent behavior from this feature.for_boxed_record
,for_boxed_variant
are new and deserve scrutiny. These functions power the inference ofwith
-kinds; an error here could easily lead to unsoundness.round_up
function is new; see usage sites for more context.sub_jkind_l
function is horrid, but still needs to be sound. It will get improved later yet deserves a careful read-through here, too.mode.ml
/mode_intf.mli
: @riaqn. This is just some refactoring.predef.ml
/predef.mli
: Either @liam923 or @riaqn. This is basically all new (but easy).subst.ml
: Either @liam923 or @riaqn. This was easier than prior work due to Use constant sorts in transl #3266.typecore.ml
: Probably @riaqn. These changes are straightforward adaptations to the new types exposed byJkind
.typedecl.ml
/typedecl.mli
: Not sure. I recommend either @liam923 or @riaqn take a spin, but if the going gets tough, let's loop in @ccasin. This file was hard, as you will see by the trail of comments I have left.typemode.ml
/typemode.mli
: Whoever did this the first time around. I basically just adapted the prior work here. Only light review required.misc.ml
/misc.mli
: Anyone. I guess this is what happens when Jane Street hires a Haskeller.datarepr.ml
,typedecl_separability.ml
,typemod.ml
,typeopt.ml
,types.ml
,types.mli
): Anyone. These are all small changes.Thanks, all!