@@ -38,6 +38,10 @@ let is_local_attribute = function
3838 | {txt =("local" |"ocaml.local" )} -> true
3939 | _ -> false
4040
41+ let is_check_attribute = function
42+ | {txt =("check" |"ocaml.check" )} -> true
43+ | _ -> false
44+
4145let find_attribute p attributes =
4246 let inline_attribute, other_attributes =
4347 List. partition (fun a -> p a.Parsetree. attr_name) attributes
@@ -197,6 +201,20 @@ let parse_local_attribute attr =
197201 ]
198202 payload
199203
204+ let parse_check_attribute attr =
205+ match attr with
206+ | None -> Default_check
207+ | Some {Parsetree. attr_name = {txt; loc} ; attr_payload = payload } ->
208+ parse_id_payload txt loc
209+ ~default: Default_check
210+ ~empty: Default_check
211+ [
212+ " noeffects" , Noeffects_check ;
213+ " noalloc" , Noalloc_check ;
214+ " noalloc_exn" , Noalloc_exn_check ;
215+ ]
216+ payload
217+
200218let get_inline_attribute l =
201219 let attr, _ = find_attribute is_inline_attribute l in
202220 parse_inline_attribute attr
@@ -209,6 +227,10 @@ let get_local_attribute l =
209227 let attr, _ = find_attribute is_local_attribute l in
210228 parse_local_attribute attr
211229
230+ let get_check_attribute l =
231+ let attr, _ = find_attribute is_check_attribute l in
232+ parse_check_attribute attr
233+
212234let check_local_inline loc attr =
213235 match attr.local, attr.inline with
214236 | Always_local , (Always_inline | Available_inline | Unroll _ ) ->
@@ -270,6 +292,23 @@ let add_local_attribute expr loc attributes =
270292 (Warnings. Misplaced_attribute " local" );
271293 expr
272294
295+ let add_check_attribute expr loc attributes =
296+ match expr, get_check_attribute attributes with
297+ | expr , Default_check -> expr
298+ | Lfunction ({ attr = { stub = false } as attr } as funct ), check ->
299+ begin match attr.check with
300+ | Default_check -> ()
301+ | Noalloc_check | Noalloc_exn_check | Noeffects_check ->
302+ Location. prerr_warning loc
303+ (Warnings. Duplicated_attribute " check" )
304+ end ;
305+ let attr = { attr with check } in
306+ Lfunction { funct with attr }
307+ | expr , (Noalloc_check | Noalloc_exn_check | Noeffects_check ) ->
308+ Location. prerr_warning loc
309+ (Warnings. Misplaced_attribute " check" );
310+ expr
311+
273312(* Get the [@inlined] attribute payload (or default if not present).
274313 It also returns the expression without this attribute. This is
275314 used to ensure that this attribute is not misplaced: If it
@@ -382,4 +421,7 @@ let add_function_attributes lam loc attr =
382421 let lam =
383422 add_local_attribute lam loc attr
384423 in
424+ let lam =
425+ add_check_attribute lam loc attr
426+ in
385427 lam
0 commit comments