Skip to content

Commit a937c43

Browse files
committed
Simplify
1 parent b738319 commit a937c43

5 files changed

Lines changed: 19 additions & 14 deletions

File tree

compiler/ml/builtin_attributes.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ let warning_scope ?ppwarning ?report_attribute_errors attrs f =
228228
Warnings.restore prev;
229229
raise exn
230230

231+
let warning_scope_without_attribute_diagnostics attrs f =
232+
warning_scope ~ppwarning:false ~report_attribute_errors:false attrs f
233+
231234
let warn_on_literal_pattern =
232235
List.exists (function
233236
| {txt = "ocaml.warn_on_literal_pattern" | "warn_on_literal_pattern"; _}, _

compiler/ml/builtin_attributes.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ val warning_scope :
100100
is executed.
101101
*)
102102

103+
val warning_scope_without_attribute_diagnostics :
104+
Parsetree.attributes -> (unit -> 'a) -> 'a
105+
(** Like [warning_scope], but suppresses diagnostics that have already been
106+
emitted during the frontend warning-attribute pass (such as
107+
[@@ppwarning] and malformed warning payloads). The warning settings are
108+
still applied to the nested computation.
109+
*)
110+
103111
val warn_on_literal_pattern : Parsetree.attributes -> bool
104112
val explicit_arity : Parsetree.attributes -> bool
105113

compiler/ml/translcore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ let extract_directive_for_fn exp =
686686
else None)
687687

688688
let rec transl_exp e =
689-
Builtin_attributes.warning_scope ~ppwarning:false
690-
~report_attribute_errors:false e.exp_attributes (fun () ->
689+
Builtin_attributes.warning_scope_without_attribute_diagnostics
690+
e.exp_attributes (fun () ->
691691
List.iter (Translattribute.check_attribute e) e.exp_attributes;
692692
transl_exp0 e)
693693

compiler/ml/translmod.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,8 @@ and transl_structure loc fields cc rootpath final_env = function
449449
| Tstr_primitive _ | Tstr_type _ | Tstr_modtype _ | Tstr_open _ ->
450450
transl_structure loc fields cc rootpath final_env rem
451451
| Tstr_attribute x ->
452-
Builtin_attributes.warning_scope ~ppwarning:false
453-
~report_attribute_errors:false [x] (fun () ->
454-
transl_structure loc fields cc rootpath final_env rem))
452+
Builtin_attributes.warning_scope_without_attribute_diagnostics [x]
453+
(fun () -> transl_structure loc fields cc rootpath final_env rem))
455454

456455
(* Update forward declaration in Translcore *)
457456
let _ = Translcore.transl_module := transl_module

compiler/ml/typemod.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,8 @@ and transl_signature env sg =
870870
let trem, rem, final_env = transl_sig newenv srem in
871871
(mksig (Tsig_include incl) env loc :: trem, sg @ rem, final_env)
872872
| Psig_attribute x ->
873-
(* The frontend pre-pass already emitted @@ppwarning and malformed
874-
@@warning diagnostics; only thread the warning state here so the
875-
remaining signature items see the right settings. *)
876-
Builtin_attributes.warning_scope ~ppwarning:false
877-
~report_attribute_errors:false [x] (fun () ->
873+
Builtin_attributes.warning_scope_without_attribute_diagnostics [x]
874+
(fun () ->
878875
let trem, rem, final_env = transl_sig env srem in
879876
(mksig (Tsig_attribute x) env loc :: trem, rem, final_env))
880877
| Psig_extension (ext, _attrs) ->
@@ -1608,10 +1605,8 @@ and type_structure ?(toplevel = false) funct_body anchor env sstr scope =
16081605
Cmt_format.set_saved_types
16091606
(Cmt_format.Partial_structure_item str :: previous_saved_types);
16101607
let str_rem, sig_rem, final_env =
1611-
(* Floating warning-attribute diagnostics are handled in the frontend
1612-
pass; this scope only applies their effect to following items. *)
1613-
Builtin_attributes.warning_scope ~ppwarning:false
1614-
~report_attribute_errors:false [x] (fun () -> type_struct env srem)
1608+
Builtin_attributes.warning_scope_without_attribute_diagnostics [x]
1609+
(fun () -> type_struct env srem)
16151610
in
16161611
(str :: str_rem, sig_rem, final_env)
16171612
| pstr :: srem ->

0 commit comments

Comments
 (0)