Ocaml_parsing.Builtin_attributesSupport for the builtin attributes:
Warning: this module is unstable and part of compiler-libs.
register_attr must be called on the locations of all attributes that should be tracked for the purpose of misplaced attribute warnings. In particular, it should be called on all attributes that are present in the source program except those that are contained in the payload of another attribute (because these may be left behind by a ppx and intentionally ignored by the compiler).
The current_phase argument indicates when this function is being called
Ast_invariants module. This is used to ensure that we track only attributes from the final version of the parse tree: we skip adding attributes seen at parse time if we can see that a ppx will be run later, because the Ast_invariants check is always run on the result of a ppx.Note that the Ast_invariants check is also run on parse trees created from marshalled ast files if no ppx is being used, ensuring we don't miss attributes in that case.
val register_attr : current_phase -> string Location.loc -> unitval mark_payload_attrs_used : Parsetree.payload -> unitMarks the attributes hiding in the payload of another attribute used, for the purposes of misplaced attribute warnings (see comment on current_phase above). In the parser, it's simplest to add these to the table and remove them later, rather than threading through state tracking whether we're in an attribute payload.
Issue misplaced attribute warnings for all attributes created with mk_internal but not yet marked used. Does nothing if compilation is stopped before lambda due to command-line flags.
Some attributes, like deprecation markers, do not affect the compilation of the definition on which they appear, but rather result in warnings on future uses of that definition. This is implemented by moving the raw attributes into the environment, where they will be noticed on future accesses.
To make misplaced attribute warnings work appropriately for these attributes, we mark them "used" when they are moved into the environment. This is done with the helper functions in this section.
val mark_alert_used : Parsetree.attribute -> unitMarks the attribute used for the purposes of misplaced attribute warnings if it is an alert. Call this when moving things allowed to have alert attributes into the environment.
val mark_alerts_used : Parsetree.attributes -> unitThe same as List.iter mark_alert_used.
val mark_warn_on_literal_pattern_used : Parsetree.attributes -> unitMarks "warn_on_literal_pattern" attributes used for the purposes of misplaced attribute warnings. Call this when moving constructors into the environment.
val mark_deprecated_mutable_used : Parsetree.attributes -> unitMarks "deprecated_mutable" attributes used for the purposes of misplaced attribute warnings. Call this when moving labels of mutable fields into the environment.
val mark_zero_alloc_attribute_checked : string -> Location.t -> unitWarning 53 helpers for zero alloc
Zero_alloc attributes are checked in late stages of compilation in the backend. Registering them helps detect code that is not checked, because it is optimized away by the middle-end.
val check_alerts : Location.t -> Parsetree.attributes -> string -> unitval check_alerts_inclusion :
def:Location.t ->
use:Location.t ->
Location.t ->
Parsetree.attributes ->
Parsetree.attributes ->
string ->
unitval alerts_of_attrs : Parsetree.attributes -> Merlin_utils.Misc.alertsFind alerts (and mark them used, wrt misplaced attribute warnings)
val alerts_of_sig :
mark:bool ->
Parsetree.signature ->
Merlin_utils.Misc.alertsval alerts_of_str :
mark:bool ->
Parsetree.structure ->
Merlin_utils.Misc.alertsval check_deprecated_mutable :
Location.t ->
Parsetree.attributes ->
string ->
unitval check_deprecated_mutable_inclusion :
def:Location.t ->
use:Location.t ->
Location.t ->
Parsetree.attributes ->
Parsetree.attributes ->
string ->
unitval error_of_extension : Parsetree.extension -> Location.errorval warning_attribute : ?ppwarning:bool -> Parsetree.attribute -> unitApply warning settings from the specified attribute. "ocaml.warning"/"ocaml.warnerror" (and variants without the prefix) are processed and marked used for warning 53. Other attributes are ignored.
Also implement ocaml.ppwarning (unless ~ppwarning:false is passed).
val warning_scope :
?ppwarning:bool ->
Parsetree.attributes ->
(unit -> 'a) ->
'aExecute a function in a new scope for warning settings. This means that the effect of any call to warning_attribute during the execution of this function will be discarded after execution.
The function also takes a list of attributes which are processed with warning_attribute in the fresh scope before the function is executed.
val has_attribute : string -> Parsetree.attributes -> boolhas_attribute name attrs is true if an attribute with name name or "ocaml." ^ name is present in attrs. It marks that attribute used for the purposes of misplaced attribute warnings.
select_attributes actions attrs finds the elements of attrs that appear in actions and either returns them or just marks them used, according to the corresponding attr_action.
Each element (nm, action) of the actions list is an attribute along with an attr_action specifying what to do with that attribute. The action is used to accommodate different compiler configurations. If an attribute is used only in some compiler configurations, it's important that we still look for it and mark it used when compiling with other configurations. Otherwise, we would issue spurious misplaced attribute warnings.
val select_attributes :
(string * attr_action) list ->
Parsetree.attributes ->
Parsetree.attributesval attr_equals_builtin : Parsetree.attribute -> string -> boolattr_equals_builtin attr s is true if the name of the attribute is s or "ocaml." ^ s. This is useful for manually inspecting attribute names, but note that doing so will not result in marking the attribute used for the purpose of warning 53, so it is usually preferrable to use has_attribute or select_attributes.
val warn_on_literal_pattern : Parsetree.attributes -> boolval explicit_arity : Parsetree.attributes -> boolval has_unboxed : Parsetree.attributes -> boolval has_boxed : Parsetree.attributes -> boolval has_unsafe_allow_any_mode_crossing : Parsetree.attributes -> boolval parse_standard_interface_attributes : Parsetree.attribute -> unitval parse_standard_implementation_attributes : Parsetree.attribute -> unitThe attribute placed on the inner Ptyp_arrow node in x -> (y -> z) (meaning the y -> z node) to indicate parenthesization. This is relevant for locals, as local_ x -> (y -> z) is different than local_ x -> y -> z.
val curry_attr : Location.t -> Parsetree.attributeval has_local_opt : Parsetree.attributes -> boolval has_layout_poly : Parsetree.attributes -> boolval has_curry : Parsetree.attributes -> boolval has_or_null_reexport : Parsetree.attributes -> boolval tailcall :
Parsetree.attributes ->
([ `Tail | `Nontail | `Tail_if_possible ] option, [ `Conflict ]) resultval jkind_attribute_to_string : jkind_attribute -> stringval jkind_attribute_of_string : string -> jkind_attribute optionval jkind : Parsetree.attributes -> jkind_attribute Location.loc optionval error_message_attr : Parsetree.attributes -> string optionFinds the first "error_message" attribute, marks it as used, and returns its string payload. Returns None if no such attribute is present.
There should be at most one "error_message" attribute, additional ones are sliently ignored. *
val get_int_payload : Parsetree.payload -> (int, unit) Result.tget_int_payload is a helper for working with attribute payloads. Given a payload that consist of a structure containing exactly
PStr [
{pstr_desc =
Pstr_eval (Pexp_constant (Pconst_integer(i, None)), [])
}
]it returns i.
val get_optional_bool_payload :
Parsetree.payload ->
(bool option, unit) Result.tget_optional_bool_payload is a helper for working with attribute payloads. It behaves like get_int_payload, except that it looks for a boolean constant rather than an int constant, and returns None rather than Error if the payload is empty.
val parse_optional_id_payload :
string ->
Location.t ->
empty:'a ->
(string * 'a) list ->
Parsetree.payload ->
('a, unit) Result.tparse_id_payload is a helper for parsing information from an attribute whose payload is an identifier. If the given payload consists of a single identifier, that identifier is looked up in the association list. The result is returned, if it exists. The empty value is returned if the payload is empty. Otherwise, Error () is returned and a warning is issued.
type zero_alloc_check = {strict : bool;opt : bool;arity : int;loc : Location.t;custom_error_msg : string option;}type zero_alloc_assume = {strict : bool;never_returns_normally : bool;never_raises : bool;arity : int;loc : Location.t;}type zero_alloc_attribute = | Default_zero_alloc| Ignore_assert_all| Check of zero_alloc_check| Assume of zero_alloc_assumeval get_zero_alloc_attribute :
in_signature:bool ->
on_application:bool ->
default_arity:int ->
Parsetree.attributes ->
zero_alloc_attributeval zero_alloc_attribute_only_assume_allowed :
zero_alloc_attribute ->
zero_alloc_assume optionval assume_zero_alloc :
inferred:bool ->
zero_alloc_assume ->
Ocaml_utils.Zero_alloc_utils.Assume_info.ttype tracing_probe = {name : string;name_loc : Location.t;enabled_at_init : bool;arg : Parsetree.expression;}val get_tracing_probe_payload :
Parsetree.payload ->
(tracing_probe, unit) resultval get_eval_payload : Parsetree.payload -> (Parsetree.core_type, unit) resultGets the payload of a eval extension node which evaluates quotes, for example: %eval: int
val has_atomic : Parsetree.attributes -> bool