[m-rev.] for review: separate out semantic checks for fact tables
Julien Fischer
jfischer at opturion.com
Thu Jun 10 21:36:14 AEST 2021
On Thu, 10 Jun 2021, Zoltan Somogyi wrote:
> Separate semantic checks on fact table preds ...
>
> from code generation for them.
...
> compiler/typecheck_errors.m:
> If a predicate has a fact_table for it, then its clauses (actually,
> foreign_procs) are supposed to be provided by the compiler;
> the absence of user-supplied clauses is to be expected.
> If, due to incompatility between the predicate's declarations
s/incompatility/incompatibility/
> and the requirements of fact tables, the compiler cannot generate
> those foreign_procs, do not generate an error message about
> the absence of clauses, since such an error message would be misleading.
> The problem *will* be reported by fact_table.m.
...
> diff --git a/compiler/fact_table.m b/compiler/fact_table.m
> index b73e43055..14a991412 100644
> --- a/compiler/fact_table.m
> +++ b/compiler/fact_table.m
...
> +
> + % Initialise list of fact argument information. Input and output flags
> + % are initialised to `no' and filled in correctly by
> + % infer_determinism_pass_1.
> + %
> +:- pred init_fact_arg_infos(pred_info::in, list(mer_type)::in,
> + list(fact_arg_info)::out,
> + list(error_spec)::in, list(error_spec)::out) is det.
> +
> +init_fact_arg_infos(_, [], [], !Specs).
> +init_fact_arg_infos(PredInfo, [Type | Types], [Info | Infos], !Specs) :-
> + ( if
> + Type = builtin_type(BuiltinType),
> + (
> + BuiltinType = builtin_type_int(int_type_int),
> + FactArgTypePrime = fact_arg_type_int
> + ;
> + BuiltinType = builtin_type_float,
> + FactArgTypePrime = fact_arg_type_float
> + ;
> + BuiltinType = builtin_type_string,
> + FactArgTypePrime = fact_arg_type_string
> + )
> + then
> + FactArgType = FactArgTypePrime
> + else
> + pred_info_get_typevarset(PredInfo, TVarSet),
> + TypeStr = mercury_type_to_string(TVarSet, print_name_only, Type),
> + pred_info_get_context(PredInfo, Context),
> + Pieces = [words("Error: type"), quote(TypeStr),
> + words("is not allows in fact tables."),
s/allows/allowed/
> + words("The only types allowed in fact tables are"),
> + quote("int"), suffix(","), quote("float"), suffix(","),
> + words("and"), quote("string"), suffix("."), nl],
> + add_error_context_and_pieces(Context, Pieces, !Specs),
> + FactArgType = fact_arg_type_int % Dummy; won't be used.
> + ),
> + Info = fact_arg_info(FactArgType,
> + is_not_input_for_any_mode, is_not_in_or_output_for_any_mode),
> + init_fact_arg_infos(PredInfo, Types, Infos, !Specs).
The rest looks fine.
Julien.
More information about the reviews
mailing list