[m-rev.] for review: Fix codegen for subtype field names in high-level data grades.

Zoltan Somogyi zoltan.somogyi at runbox.com
Tue Apr 30 19:27:00 AEST 2024


On 2024-04-30 17:08 +10:00 AEST, "Peter Wang" <novalazy at gmail.com> wrote:
> diff --git a/compiler/hlds_data.m b/compiler/hlds_data.m
> index 4ba19cdf5..d53bd3362 100644
> --- a/compiler/hlds_data.m
> +++ b/compiler/hlds_data.m
> @@ -982,11 +982,20 @@ set_type_defn_prev_errors(X, !Defn) :-
>  :- type constructor_arg_repn
>      --->    ctor_arg_repn(
>                  car_field_name      :: maybe(ctor_field_name),
> +                % car_maybe_base_arg says whether this constructor argument
> +                % belongs to a subtype. If so, it must have a corresponding
> +                % constructor argument in the base type, which may or may not
> +                % have a field name.
> +                car_maybe_base_arg  :: maybe_base_ctor_arg,
>                  car_type            :: mer_type,
>                  car_pos_width       :: arg_pos_width,
>                  car_context         :: prog_context
>              ).
>  
> +:- type maybe_base_ctor_arg
> +    --->    no_base_ctor_arg
> +    ;       base_ctor_arg(maybe(ctor_field_name)).

I intend to review the rest of this diff, but before I do, I would like
to know why you chose this approach over the approach I thought
would have been the obvious one, which would be to have the subtype
inherit all the field names for its subset of data constructors from its supertype.
One could either forbid the subtype declarations containing field names,
or just forbid them from having field names that differ from the supertype,
but either way, the supertype's field names would be available to be used
both by programmers, and by the code generator.

The approach used by the type definition above is more flexible than that,
in that it allows subtypes to have (user-facing) field names that differ from
the supertype's names for the same fields. What I would like to know is:
in what kinds of scenarios would this capability be more helpful than confusing?
The reason why I ask is that I can't think of any.

Zoltan.


More information about the reviews mailing list