[m-rev.] for post-commit review: clean up code that adds pred and mode decls to HLDS
Julien Fischer
jfischer at opturion.com
Wed May 19 11:55:05 AEST 2021
On Wed, 19 May 2021, Zoltan Somogyi wrote:
> Simplify adding pred and mode decls to HLDS.
...
> diff --git a/compiler/add_pred.m b/compiler/add_pred.m
> index d6b930e77..cfc2fd5e1 100644
> --- a/compiler/add_pred.m
> +++ b/compiler/add_pred.m
> @@ -116,16 +118,98 @@
> :- import_module term.
> :- import_module varset.
>
> -module_add_pred_decl(PredStatus, NeedQual, ItemPredDecl, MaybePredProcId,
> - !ModuleInfo, !Specs) :-
> - ItemPredDecl = item_pred_decl_info(PredSymName, PredOrFunc, TypesAndModes,
> - WithType, WithInst, MaybeDetism, Origin, TypeVarSet, InstVarSet,
> - ExistQVars, Purity, Constraints, Context, SeqNum),
> +module_add_pred_decl(ItemMercuryStatus, PredStatus, NeedQual, ItemPredDecl,
> + MaybePredProcId, !ModuleInfo, !Specs) :-
> + ItemPredDecl = item_pred_decl_info(PredSymName, PredOrFunc,
> + ArgTypesAndModes, WithType, WithInst, MaybeDetism,
> + Origin, TypeVarSet, InstVarSet, ExistQVars, Purity, Constraints,
> + Context, SeqNum),
> % Any WithType and WithInst annotations should have been expanded
> % and the type and/or inst put into TypesAndModes by equiv_type.m.
> expect(unify(WithType, no), $pred, "WithType != no"),
> expect(unify(WithInst, no), $pred, "WithInst != no"),
>
> + PredName = unqualify_name(PredSymName),
> + ( if PredName = "" then
> + Pieces = [words("Error: you cannot declare a"),
> + words(pred_or_func_to_full_str(PredOrFunc)),
> + words("whose name is a variable."), nl],
> + Spec = simplest_spec($pred, severity_error, phase_parse_tree_to_hlds,
> + Context, Pieces),
> + !:Specs = [Spec | !.Specs],
> + MaybePredProcId = no
> + else
> + split_types_and_modes(ArgTypesAndModes, ArgTypes, MaybeArgModes0),
> + list.length(ArgTypes, PredFormArity),
> + ( if
> + PredOrFunc = pf_predicate,
> + MaybeArgModes0 = yes(ArgModes0),
> + % If a predicate declaration has no arguments ano no determinism,
s/ano/and/
> + % then it has none of the components of a mode declaration.
> + ArgModes0 = [],
That's fine otherwise.
Julien.
More information about the reviews
mailing list