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

Control -infer-with-bounds from an attribute #3610

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions parsing/builtin_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ let builtin_attrs =
; "nolabels"
; "flambda_oclassic"
; "flambda_o3"
; "infer_with_bounds"
; "afl_inst_ratio"
; "local_opt"
; "curry"; "extension.curry"
Expand Down Expand Up @@ -571,6 +572,11 @@ let flambda_o3_attribute attr =
~name:"flambda_o3"
~f:(fun () -> if Config.flambda || Config.flambda2 then Clflags.set_o3 ())

let infer_with_bounds_attribute attr =
clflags_attribute_without_payload' attr
~name:"infer_with_bounds"
~f:(fun () -> Clflags.infer_with_bounds := true)

let inline_attribute attr =
when_attribute_is ["inline"; "ocaml.inline"] attr ~f:(fun () ->
let err_msg =
Expand Down Expand Up @@ -635,6 +641,7 @@ let parse_standard_interface_attributes attr =
principal_attribute attr;
noprincipal_attribute attr;
nolabels_attribute attr;
infer_with_bounds_attribute attr;
zero_alloc_attribute ~in_signature:true attr;
unsafe_allow_any_mode_crossing_attribute attr

Expand All @@ -647,6 +654,7 @@ let parse_standard_implementation_attributes attr =
afl_inst_ratio_attribute attr;
flambda_o3_attribute attr;
flambda_oclassic_attribute attr;
infer_with_bounds_attribute attr;
zero_alloc_attribute ~in_signature:false attr;
unsafe_allow_any_mode_crossing_attribute attr

Expand Down
36 changes: 36 additions & 0 deletions testsuite/tests/typing-jkind-bounds/attribute.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(* TEST
expect;
flags = "-extension layouts_alpha";
*)

type 'a t1 = { x : 'a }

[@@@infer_with_bounds]

type 'a t2 = { x : 'a }

[%%expect{|
type 'a t1 = { x : 'a; }
type 'a t2 = { x : 'a; }
|}]

let use_portable (_ @ portable) = ()

[%%expect{|
val use_portable : 'a @ portable -> unit = <fun>
|}]

let f1 (x : int t1 @@ nonportable) = use_portable x

[%%expect{|
Line 1, characters 50-51:
1 | let f1 (x : int t1 @@ nonportable) = use_portable x
^
Error: This value is "nonportable" but expected to be "portable".
|}]

let f2 (x : int t2 @@ nonportable) = use_portable x

[%%expect{|
val f2 : int t2 -> unit = <fun>
|}]
Loading