[m-rev.] for review: convert parse trees to strings

Julien Fischer jfischer at opturion.com
Wed Nov 1 17:59:08 AEDT 2023


On Wed, 1 Nov 2023, Julien Fischer wrote:

> On Wed, 1 Nov 2023, Zoltan Somogyi wrote:
>
>>  On 2023-11-01 16:08 +11:00 AEDT, "Julien Fischer" <jfischer at opturion.com>
>>  wrote:
>>>>  The internal representation of this pragma would record the name
>>>>  of the module in which the pragma appears. (This would happen regardless
>>>>  of whether it appears in a .m or in a .intN file.) The compiler would
>>>>  then apply the type specialization described by the second arg
>>>>  to all predicates and functions in that module that have the
>>>>  type constraint in the first arg.
>>>
>>>  So it only applies to a single module?
>>
>>  What is your alternative?
>
> What prompted my question was the arrangement I have in mercury_json,
> where most of the work is subcontracted to (private) submodules.  That's
> not uncommon -- the examples in the compiler and term_io are just not
> large enough to warrent it. My suggestion would be that at minimum, the
> optimisation should apply to a module plus its child modules.

All that said, the situation in mercury_json is more general than what
your proposal covers, in that it has:

1. Multiple class constraints on most of the predicates that would need
    to be specialised, typically these

    stream.line_oriented(Stream, State),
    stream.unboxed_reader(Stream, char, State, Error),
    stream.putback(Stream, char, State, Error)

2. Some of the type variables are shared between constraints.

3. Some of the constraint arguments are ground.

Multiple constraints could be dealt with by making the first argument
a list, e.g.

   :- pragma type_spec_constrained_preds(
        [line_oriented(Stream, State),
         unboxed_reader(Stream, Unit, State, Error)
         putback(Stream, Unit, State, Error)],
        [Stream = io.text_output_stream, Unit = char,
         State = io.state, Error = io.error]).

(Indeed, by making the second arg. a list of of lists of type variable
asssigments, a user could request multiple specialisations in a single
pragma.)

Julien.


More information about the reviews mailing list