[m-rev.] for review: Define behaviour of string.to_char_list (and rev) on ill-formed sequences.

Peter Wang novalazy at gmail.com
Wed Oct 23 10:30:09 AEDT 2019


On Wed, 23 Oct 2019 05:04:20 +1100 (AEDT), "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> This diff implements my proposal, and is for post commit review by Peter.
> 

> diff --git a/NEWS b/NEWS
> index 82bcaa356..a5e1c887a 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -231,6 +231,13 @@ Changes to the Mercury language:
>    predicates and/or functions that programmers should consider using
>    instead of the obsolete predicate or function.
>  
> +* We have added an `obsolete_proc' pragma. While the `obsolete' pragma
> +  declares all modes of a predicate or function to be obsolete, the
> +  `obsolete_proc' pragma declares only one mode of a predicate or function
> +  to be obsolete. Like the updated version of the `obsolete' pragma,
> +  the `obsolete_proc' pragma may have a second argument naming one or more
> +  suggested replacements.
> +
>  * The Java backend now supports defining foreign types as primitive Java
>    types.

The way I understood your proposal was that `pragma obsolete' would
accept either a NAME/ARITY specification or a NAME(MODES) specification,
like `pragma type_spec' and the undocumented `pragma require_tail_recursion'.

> diff --git a/compiler/parse_pragma.m b/compiler/parse_pragma.m
> index 6463999cc..c73a4f86c 100644
> --- a/compiler/parse_pragma.m
> +++ b/compiler/parse_pragma.m
> @@ -1219,8 +1226,56 @@ parse_pragma_obsolete(ModuleName, PragmaTerms, ErrorTerm, VarSet,
>          ),
>          Pieces = [words("Error: a"), pragma_decl("obsolete"),
>              words("declaration should have one or two arguments."), nl],
> -        Spec = error_spec(severity_error, phase_term_to_parse_tree,
> -            [simple_msg(get_term_context(ErrorTerm), [always(Pieces)])]),
> +        Spec = simplest_spec(severity_error, phase_term_to_parse_tree,
> +            get_term_context(ErrorTerm), Pieces),
> +        MaybeIOM = error1([Spec])
> +   ).
> +
> +:- pred parse_pragma_obsolete_proc(module_name::in, list(term)::in, term::in,
> +    varset::in, prog_context::in, int::in, maybe1(item_or_marker)::out) is det.
> +
> +parse_pragma_obsolete_proc(ModuleName, PragmaTerms, ErrorTerm, VarSet,
> +        Context, SeqNum, MaybeIOM) :-
> +    (
> +        (
> +            PragmaTerms = [PredAndModesTerm],
> +            MaybeObsoleteInFavourOf = ok1([])
> +        ;
> +            PragmaTerms = [PredAndModesTerm, ObsoleteInFavourOfTerm],
> +            parse_pragma_obsolete_in_favour_of(ObsoleteInFavourOfTerm,
> +                VarSet, MaybeObsoleteInFavourOf)
> +        ),
> +        PredAndModesContextPieces = cord.from_list(
> +            [words("In first  arguments of"), pragma_decl("obsolete_proc"),
> +            words("declaration:")]),

first argument

> +        parse_pred_or_func_and_arg_modes(yes(ModuleName), VarSet,
> +            PredAndModesContextPieces, PredAndModesTerm, MaybePredAndModes),
> +        ( if
> +            MaybePredAndModes = ok3(PredName, PredOrFunc, Modes),
> +            MaybeObsoleteInFavourOf = ok1(ObsoleteInFavourOf)
> +        then
> +            PredNameModesPF = pred_name_modes_pf(PredName, Modes, PredOrFunc),
> +            ObsoletePragma =
> +                pragma_info_obsolete_proc(PredNameModesPF, ObsoleteInFavourOf),
> +            Pragma = pragma_obsolete_proc(ObsoletePragma),
> +            ItemPragma = item_pragma_info(Pragma, item_origin_user,
> +                Context, SeqNum),
> +            Item = item_pragma(ItemPragma),
> +            MaybeIOM = ok1(iom_item(Item))
> +        else
> +            Specs =
> +                get_any_errors3(MaybePredAndModes) ++
> +                get_any_errors1(MaybeObsoleteInFavourOf),
> +            MaybeIOM = error1(Specs)
> +        )
> +    ;
> +        ( PragmaTerms = []
> +        ; PragmaTerms = [_, _, _ | _]
> +        ),
> +        Pieces = [words("Error: a"), pragma_decl("obsolete_proc"),
> +            words("declaration should have one or two arguments."), nl],
> +        Spec = simplest_spec(severity_error, phase_term_to_parse_tree,
> +            get_term_context(ErrorTerm), Pieces),
>          MaybeIOM = error1([Spec])
>     ).

> diff --git a/tests/invalid/obsolete_proc_pragma.m b/tests/invalid/obsolete_proc_pragma.m
> index e69de29bb..70d67867e 100644
> --- a/tests/invalid/obsolete_proc_pragma.m
> +++ b/tests/invalid/obsolete_proc_pragma.m
> @@ -0,0 +1,61 @@
> +%---------------------------------------------------------------------------%
> +% vim: ts=4 sw=4 et ft=mercury
> +%---------------------------------------------------------------------------%
> +%
> +% Test error message for misformed pragam declaration.

pragma

The rest looks fine. Thanks!

Peter


More information about the reviews mailing list