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

Nullability in value_kind #3626

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
x100 x101 x102 x103 x104 x105 x106 x107 x108 x109 x110 x111 x112 x113
x114 x115 x116 x117 x118 x119 x120 x121 x122 x123 x124 x125 x126
(function {nlocal = 1} x127 x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1 x2)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x2)))
local_param_after_split =
(function {nlocal = 0} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14
x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31
Expand All @@ -40,8 +40,7 @@
x100 x101 x102 x103 x104 x105 x106 x107 x108 x109 x110 x111 x112 x113
x114 x115 x116 x117 x118 x119 x120 x121 x122 x123 x124 x125 x126
(function {nlocal = 2} x127 x128 x129 x130[L] x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1
x130)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x130)))
local_param_just_after_split =
(function {nlocal = 0} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14
x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31
Expand All @@ -62,8 +61,7 @@
x100 x101 x102 x103 x104 x105 x106 x107 x108 x109 x110 x111 x112 x113
x114 x115 x116 x117 x118 x119 x120 x121 x122 x123 x124 x125 x126
(function {nlocal = 5} x127[L] x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1
x127)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x127)))
local_param_just_before_split =
(function {nlocal = 1} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14
x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31
Expand All @@ -85,8 +83,7 @@
x114 x115 x116 x117 x118 x119 x120 x121 x122 x123 x124 x125 x126[L]
: local
(function[L] {nlocal = 5} x127 x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1
x126)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x126)))
local_param_before_split =
(function {nlocal = 119} x1 x2 x3 x4 x5 x6 x7 x8[L] x9 x10 x11 x12 x13
x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30
Expand All @@ -108,7 +105,7 @@
x113 x114 x115 x116 x117 x118 x119 x120 x121 x122 x123 x124 x125 x126
: local
(function[L] {nlocal = 5} x127 x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1 x8)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x8)))
two_splits =
(function {nlocal = 0} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14
x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31
Expand Down Expand Up @@ -149,8 +146,7 @@
x227 x228 x229 x230 x231 x232 x233 x234 x235 x236 x237 x238 x239
x240 x241 x242 x243 x244 x245 x246 x247 x248 x249 x250 x251 x252
(function {nlocal = 1} x253 x254 x255 x256 x257 x258
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1
x258))))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x258))))
two_splits_local_param =
(function {nlocal = 0} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14
x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31
Expand Down Expand Up @@ -193,8 +189,7 @@
x240 x241 x242 x243 x244 x245 x246 x247 x248 x249 x250 x251 x252
: local
(function[L] {nlocal = 6} x253 x254 x255 x256 x257 x258
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*) x1
x152))))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1 x152))))
create_local =
(function {nlocal = 1} param[int]
[(consts ())
Expand Down Expand Up @@ -222,8 +217,8 @@
x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116 x117
x118 x119 x120 x121 x122 x123 x124 x125 x126 : local
(function[L] {nlocal = 5} x127 x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x2)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x2)))
local_param_after_split =
(function[L] {nlocal = 126} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11
x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27
Expand All @@ -246,8 +241,8 @@
x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116 x117
x118 x119 x120 x121 x122 x123 x124 x125 x126 : local
(function[L] {nlocal = 5} x127 x128 x129 x130[L] x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x130)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x130)))
local_param_just_after_split =
(function[L] {nlocal = 126} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11
x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27
Expand All @@ -270,8 +265,8 @@
x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116 x117
x118 x119 x120 x121 x122 x123 x124 x125 x126 : local
(function[L] {nlocal = 5} x127[L] x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x127)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x127)))
local_param_just_before_split =
(function[L] {nlocal = 126} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11
x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27
Expand All @@ -294,8 +289,8 @@
x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116 x117
x118 x119 x120 x121 x122 x123 x124 x125 x126[L] : local
(function[L] {nlocal = 5} x127 x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x126)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x126)))
local_param_before_split =
(function[L] {nlocal = 126} x1 x2 x3 x4 x5 x6 x7 x8[L] x9 x10 x11
x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27
Expand All @@ -318,8 +313,8 @@
x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116 x117
x118 x119 x120 x121 x122 x123 x124 x125 x126 : local
(function[L] {nlocal = 5} x127 x128 x129 x130 x131
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x8)))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x8)))
two_splits =
(function[L] {nlocal = 126} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11
x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27
Expand Down Expand Up @@ -367,8 +362,8 @@
x242 x243 x244 x245 x246 x247 x248 x249 x250 x251 x252
: local
(function[L] {nlocal = 6} x253 x254 x255 x256 x257 x258
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x258))))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x258))))
two_splits_local_param =
(function[L] {nlocal = 126} x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11
x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27
Expand Down Expand Up @@ -416,8 +411,8 @@
x241 x242 x243 x244 x245 x246 x247 x248 x249 x250 x251 x252
: local
(function[L] {nlocal = 6} x253 x254 x255 x256 x257 x258
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 (*,*)
x1 x152)))))
[(consts ()) (non_consts ([0: *, *]))](makelocalblock 0 x1
x152)))))
(makelocalblock 0 (*,*,*,*,*,*,*,*,*,*,*,*,*,*) no_local_params
no_local_params__local_returning local_param_after_split
local_param_after_split__local_returning
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/tmc/readable_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ let[@tail_mod_cons] rec map_stutter f xs =
(non_consts ([0: *,
[(consts (0))
(non_consts ([0: *, *]))]]))])
(apply f (makeblock 0 (*) (field_imm 0 xs))) 24029))
(apply f (makeblock 0 (field_imm 0 xs))) 24029))
(seq (apply map_stutter_dps block 1 f (field_imm 1 xs)) block))
0)))
map_stutter_dps
Expand All @@ -320,7 +320,7 @@ let[@tail_mod_cons] rec map_stutter f xs =
(seq (setfield_ptr(heap-init)_computed dst offset block)
(if xs
(let
(block0_arg0 = (apply f (makeblock 0 (*) (field_imm 0 xs)))
(block0_arg0 = (apply f (makeblock 0 (field_imm 0 xs)))
block =
(makemutable 0 (*,[(consts (0))
(non_consts ([0: *,
Expand Down
15 changes: 15 additions & 0 deletions testsuite/tests/typing-layouts-or-null/segfault.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(* TEST
flags = "-O3";
native;
*)

let[@inline] id f = fun x -> f x;;

let () =
id
(fun value ->
match value with
| Null -> ()
| This _ -> assert false)
Null
;;
16 changes: 16 additions & 0 deletions typing/jkind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,22 @@ let set_externality_upper_bound jk externality_upper_bound =
}
}

let only_nullability = Axis_set.singleton (Nonmodal Nullability)

let get_nullability ~jkind_of_type jk =
let ( ({ layout = _; mod_bounds; with_bounds = No_with_bounds } :
Allowance.right_only jkind_desc),
_ ) =
Layout_and_axes.normalize ~mode:Ignore_best ~jkind_of_type
~map_type_info:(fun _ ti ->
{ relevant_axes =
(* Optimization: We only care about the externality axis *)
Axis_set.intersection ti.relevant_axes only_nullability
})
jk.jkind
in
Mod_bounds.get mod_bounds ~axis:(Nonmodal Nullability)

let set_layout jk layout = { jk with jkind = { jk.jkind with layout } }

let get_annotation jk = jk.annotation
Expand Down
6 changes: 6 additions & 0 deletions typing/jkind.mli
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ val get_externality_upper_bound :
val set_externality_upper_bound :
Types.jkind_r -> Jkind_axis.Externality.t -> Types.jkind_r

(** Gets the nullability from a jkind. *)
val get_nullability :
jkind_of_type:(Types.type_expr -> Types.jkind_l option) ->
'd Types.jkind ->
Jkind_axis.Nullability.t

(** Sets the layout in a jkind. *)
val set_layout : 'd Types.jkind -> Sort.t Layout.t -> 'd Types.jkind

Expand Down
Loading