Skip to content

Commit

Permalink
flambda-backend: Zero alloc misplaced attr warning (ocaml-flambda#2153)
Browse files Browse the repository at this point in the history
* Fix missing warning for misplaced attribute

* Add a test
  • Loading branch information
gretay-js authored Dec 14, 2023
1 parent b74ea89 commit 0b6b2f9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lambda/translattribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ let is_opaque_attribute =
[ ["opaque"; "ocaml.opaque"], true ]


let find_attribute p attributes =
let find_attribute ?mark_used p attributes =
let inline_attribute =
Builtin_attributes.filter_attributes
Builtin_attributes.filter_attributes ?mark:mark_used
(Builtin_attributes.Attributes_filter.create p)
attributes
in
Expand Down Expand Up @@ -461,9 +461,9 @@ let add_local_attribute expr loc attributes =
end
| _ -> expr

let assume_zero_alloc attributes =
let assume_zero_alloc ?mark_used attributes =
let p = Zero_alloc in
let attr = find_attribute (is_property_attribute p) attributes in
let attr = find_attribute ?mark_used (is_property_attribute p) attributes in
match parse_property_attribute attr p with
| Default_check -> false
| Ignore_assert_all _ -> false
Expand All @@ -478,7 +478,7 @@ let get_assume_zero_alloc ~with_warnings attributes =
that affect [Scoped_location] settings before translation
of expressions in that scope.
Warnings will be produced by [add_check_attribute]. *)
Warnings.without_warnings (fun () -> assume_zero_alloc attributes)
Warnings.without_warnings (fun () -> assume_zero_alloc ~mark_used:false attributes)

let add_check_attribute expr loc attributes =
let to_string = function
Expand Down
4 changes: 2 additions & 2 deletions parsing/builtin_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,11 @@ module Attributes_filter = struct
let create (t : t) = t
end

let filter_attributes (nms_and_conds : Attributes_filter.t) attrs =
let filter_attributes ?(mark=true) (nms_and_conds : Attributes_filter.t) attrs =
List.filter (fun a ->
List.exists (fun (nms, cond) ->
if List.mem a.attr_name.txt nms
then (mark_used a.attr_name; cond)
then (if mark then mark_used a.attr_name; cond)
else false)
nms_and_conds
) attrs
Expand Down
1 change: 1 addition & 0 deletions parsing/builtin_attributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ end
count as misplaced if the compiler could use it in some configuration.
*)
val filter_attributes :
?mark:bool ->
Attributes_filter.t -> Parsetree.attributes -> Parsetree.attributes

val warn_on_literal_pattern: Parsetree.attributes -> bool
Expand Down

0 comments on commit 0b6b2f9

Please sign in to comment.