[m-rev.] for review: pragma status checks
Julien Fischer
jfischer at opturion.com
Sat Sep 24 19:09:25 AEST 2022
On Sat, 24 Sep 2022, Zoltan Somogyi wrote:
> Fix the handling of status in add_pragma.m.
>
> compiler/add_pragma.m:
> The status checks in this module used to check for only one
> of the four possible combinations of <is pragma exported, is the
> pred the pragma is for expored>, even though we may want to generate
> errors or warnings in three of those combinations. Fix this.
>
> If an ambiguous pragma applies to more than one predicate, handle
> the status checks of each separately.
>
> When adding fact table pragmas to the HLDS, replace several lines
> of code that reuse an existing largish predicate with the single line
> of code from that predicate that we actually need.
>
> Stop representing the statuses of pragmas using the pred_status type,
> since the item_mercury_status that all items come with is adequate
> for all our needs, and is impossible to confuse with the status
> of the pred_info they refer to.
...
> diff --git a/compiler/add_pragma.m b/compiler/add_pragma.m
> index 624462f33..6ab9b71d1 100644
> --- a/compiler/add_pragma.m
> +++ b/compiler/add_pragma.m
> @@ -2135,34 +2080,128 @@ maybe_warn_about_pfumm_unknown(ModuleInfo, PragmaName, PFUMM, SymName, Context,
...
> + PragmaExported = no,
> + % Case 3: ok for impl pragmas, warning for decl pragmas.
> + (
> + StatusClass = psc_decl,
> + PredNamePieces = describe_one_pred_info_name(
> + should_not_module_qualify, PredInfo),
> + Pieces = [words("Warning: since the")] ++
> + PredNamePieces ++ [words("is exported, the"),
> + pragma_decl(PragmaName), words("declaration for it"),
> + words("should also be exported."), nl],
> + Spec = simplest_spec($pred, severity_warning,
> + phase_parse_tree_to_hlds, Context, Pieces),
> + !:Specs = [Spec | !.Specs]
> + ;
> + StatusClass = psc_impl
> + )
> + ;
> + PragmaExported = yes,
> + % Case 4: ok for decl pragmas, error for impl pragmas.
> + (
> + StatusClass = psc_decl
> + ;
> + StatusClass = psc_impl,
> + % NOTE We never generate this error message, because
> + % the parser generate an error message for any impl
s/generate/generates/
> + % pragmas in interfaces, and declines to add them
> + % to the parse tree. Indeed, parse_tree_module_src type,
*the* parse_tree_module_src type
> + % which represents the parse trees of source modules,
> + % cannot represent impl pragmas in interface sections.
> + Pieces = [words("Error: a"),
> + pragma_decl(PragmaName), words("declaration"),
> + words("may not be exported, even if"),
> + words("the predicate or function it refers to"),
> + words("is exported."), nl],
> + Spec = simplest_spec($pred, severity_error,
> + phase_parse_tree_to_hlds, Context, Pieces),
> + !:Specs = [Spec | !.Specs]
> + )
> + )
> + )
That looks fine otherwise.
Julien.
More information about the reviews
mailing list