[m-rev.] for review: separate type_details_sub from type_details_du
Peter Wang
novalazy at gmail.com
Sat Oct 2 13:09:52 AEST 2021
On Sat, 02 Oct 2021 05:46:22 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> Separate subtypes from du types in parse trees.
> diff --git a/compiler/check_type_inst_mode_defns.m b/compiler/check_type_inst_mode_defns.m
> index 6c5751eef..8185be599 100644
> --- a/compiler/check_type_inst_mode_defns.m
> +++ b/compiler/check_type_inst_mode_defns.m
> @@ -319,7 +327,55 @@ check_type_ctor_defns(InsistOnDefn,
> map.det_insert(TypeCtor, CheckedDefn, !TypeCtorCheckedMap)
> else if
> % TypeCtor is NOT defined as a solver or equivalence type.
> - % Is there a du type definition ...
> + % Is there a subtype definition ...
> + ( if
> + % ... in the interface?
> + IntSubMaybeDefn = yes(IntSubDefn)
> + then
> + SubDefn = IntSubDefn,
> + SubSection = ms_interface,
> + SubWhere = "interface"
> + else if
> + % ... in the implementation?
> + ImpSubMaybeDefn = yes(ImpSubDefn)
> + then
> + SubDefn = ImpSubDefn,
> + SubSection = ms_implementation,
> + SubWhere = "implementation"
> + else
> + fail
> + )
> + then
> + report_any_redundant_abstract_type_in_imp(TypeCtor, SubWhere,
> + ImpAbstractStdMaybeDefn, !Specs),
> + list.foldl(
> + report_any_incompatible_type_definition(TypeCtor,
> + SubDefn ^ td_context, "subtype", SubWhere),
> + [IntContextDu, IntContextAbstractSolver,
> + ImpContextDu, ImpContextAbstractSolver],
> + !Specs),
> +
> + % A subtype's representation is controlled entirely by the
> + % representation of its base type. It cannot have its own
> + % representation specifications for its constructors.
> + ForeignDefns = get_maybe_type_defns([IntMaybeDefnC, ImpMaybeDefnC,
> + IntMaybeDefnJava, ImpMaybeDefnJava,
> + IntMaybeDefnCsharp, ImpMaybeDefnCsharp]),
> + list.foldl(subtype_report_any_foreign_type(TypeCtor, SubDefn),
> + ForeignDefns, !Specs),
> + list.foldl(subtype_report_any_foreign_enum(TypeCtor, SubDefn),
> + ImpEnums, !Specs),
> +
> + decide_subtype_status(TypeCtor, SubDefn, SubSection,
> + IntAbstractStdMaybeDefn, Status, SrcDefnsInt, SrcDefnsImp),
> + CheckedStdDefn = std_mer_type_subtype(Status, SubDefn),
> + SrcDefns = src_defns_std(SrcDefnsInt, SrcDefnsImp, []),
> +
> + CheckedDefn = checked_defn_std(CheckedStdDefn, SrcDefns),
> + map.det_insert(TypeCtor, CheckedDefn, !TypeCtorCheckedMap)
> + else if
> + % TypeCtor is NOT defined as a solver type, equivalence type,
> + % or subtype Is there a du type definition ...
Add ".".
> diff --git a/compiler/parse_type_defn.m b/compiler/parse_type_defn.m
> index 0f3fa91d2..d28ac438d 100644
> --- a/compiler/parse_type_defn.m
> +++ b/compiler/parse_type_defn.m
> @@ -211,33 +224,72 @@ parse_du_type_defn(ModuleName, VarSet, HeadTerm, BodyTerm, Context, SeqNum,
...
> + (
> + MaybeDirectArgIs = no
> + ;
> + MaybeDirectArgIs = yes(_),
> + DirectArgTypeCtor =
> + type_ctor(TypeSymName, list.length(Params)),
> + DirectArgPieces = [words("Error: the subtype"),
> + unqual_type_ctor(DirectArgTypeCtor),
> + words("is not allowed to have its own"),
> + quote("where direct_arg is"), words("annotation"),
Add ";".
> + words("it must inherit its representation"),
> + words("from its supertype."), nl],
> + DirectArgSpec = simplest_spec($pred, severity_error,
> + phase_parse_tree_to_hlds, Context, DirectArgPieces),
> + !:Specs = [DirectArgSpec | !.Specs]
> + )
> + ;
The rest looks fine.
Peter
More information about the reviews
mailing list