-
Notifications
You must be signed in to change notification settings - Fork 77
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 a new attribute for allowing any mode crossing #3424
Conversation
a6c01ea
to
05de766
Compare
We might have those reasons when we have |
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 continue to think this is not quite the right implementation for this feature. For one, it allows (I think) a type to have a lower kind than its manifest. (Maybe not? The narrow_to_manifest_jkind
comes after this, so maybe it's ok -- but subtle.) Another problem is that the new kind is not checked in the inclusion check. That is, I think something like this might be accepted:
module M : sig
type t : value mod contended = { mutable x : int } [@@unsafe_allow_any_mode_crossing]
end = struct
type t = { mutable x : int }
end
Maybe that's OK? But it's pretty strange.
Instead of this approach, I really think it would be better to put the mode-crossing behavior in the type_kind
. The syntax for this is anyone's design -- I'm fine just ripping the mode crossing from the existing jkind annotation (and erroring if that jkind annotation doesn't exist). (My proposal for putting this in the type_kind wasn't about syntax, but only about semantics.) Yet the mode-crossing behavior is really part of the concrete definition of this type, which is what the type_kind
is meant to represent. I think it should be needed only for records and variants, not abstract or open kinds.
yeah, I think that's reasonable; at the very least we should test that this doesn't allow crossing more than the manifest (though I could see us wanting that!)
I think this is ok, and don't necessarily also feel that it's strange - but I'm happy to defer to you on this; it's easy enough to check
If we do something like: diff --git a/typing/types.ml b/typing/types.ml
index b9f363f2cc..e02d59e526 100644
--- a/typing/types.ml
+++ b/typing/types.ml
@@ -275,12 +275,15 @@ type type_declaration =
and type_decl_kind =
(label_declaration, label_declaration, constructor_declaration) type_kind
+and unsafe_mode_crossing =
+ { modal_upper_bounds : Mode.Alloc.Const.t }
+
and ('lbl, 'lbl_flat, 'cstr) type_kind =
Type_abstract of type_origin
- | Type_record of 'lbl list * record_representation
+ | Type_record of 'lbl list * record_representation * unsafe_mode_crossing option
| Type_record_unboxed_product of
- 'lbl_flat list * record_unboxed_product_representation
- | Type_variant of 'cstr list * variant_representation
+ 'lbl_flat list * record_unboxed_product_representation * unsafe_mode_crossing option
+ | Type_variant of 'cstr list * variant_representation * unsafe_mode_crossing option
| Type_open
and tag = Ordinary of {src_index: int; (* Unique name (per type) *) then the process of figuring out the "full" kind of a |
a8f61b7
to
426e45d
Compare
Putting this in the So my thought is to make the change you've proposed above (with Yet another way to think about this: if there is at least one Does that add up for you? As for
let me rephrase it a bit:
I believe the old implementation here accepts the first but not the second, which strikes me as strange. |
426e45d
to
48bb71c
Compare
I'm convinced. That change is now done (in the last commit, which is the only new one after a rebase on |
0bc6180
to
f9cccbb
Compare
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.
Timing out. More later.
Replace the [@@unsafe_allow_any_kind_in_{impl,intf}] attributes with a new [@@unsafe_allow_any_mode_crossing] attribute. This is different in that it: 1. Works on the type declaration, not the inclusion check, so is more powerful - it can be used to illegally mode cross types defined in the same module, or illegally mode cross non-abstract types in interfaces. The latter especially is necessary to fully subsume -allow-illegal-crossing in stdlib 2. Only allows changing the modal bounds of a kind, not the layout - it's unclear that anyone should ever want to unsafely change the layout of a kind; I personally can't think of any sound reason to do so. Some [past discussion][0] on the specific syntax for this attribute suggested specifying the bounds directly on the attribute, rather than using the jkind annotation, but I and others feel reasonably strongly that this way of doing things is a better design for the sake of consistency. [0]: #3385 (comment)
For types that set it, or *would have* set it (eg because the whole compilation unit set -allow-illegal-crossing)
f9cccbb
to
e3d49c0
Compare
Add a field to (the relevant variants of) type_kind, which tracks the (extended) modal upper bounds of a kind introduced by the usage of the [@@unsafe_allow_any_mode_crossing] attribute. This allows us to check this in eg the inclusion check, and forbid extending the upper bounds of a type /only/ by constraining it to a signature. Also, this moves more towards a world where `decl.type_jkind` is "morally" just a memo of the type's kind, where everything about the kind /could/ ostensibly be computed by looking at the type_kind. A few extra test cases checking that we cant do this have also been added to `allow_any.ml`
Specifically, require strict equality of bounds, and the attribute present on both sides.
2a33c6d
to
8dbca65
Compare
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.
OK. Done reviewing (including the two commits that arrived between review parts).
Plus a test that broke before I did this.
Back to you @glittershark. Nearly there! |
Replace the
[@@unsafe_allow_any_kind_in_{impl,intf}]
attributes with a new[@@unsafe_allow_any_mode_crossing]
attribute. This is different in that it:Some past discussion on the specific syntax for this attribute suggested specifying the bounds directly on the attribute, rather than using the jkind annotation, but I and others (@tdelvecchio-jsc, @ccasin) feel that this approach is a better design for the sake of consistency and ease-of-use.