[m-rev.] for post-commit review: input spec and tabling/sharing/reuse

Julien Fischer jfischer at opturion.com
Sat Aug 29 00:50:47 AEST 2026


> Stop input specialization for procs with tabling, sharing or reuse.
>
> compiler/input_specialization.m:
>     If any procedure in a predicate has a tabled, structure_sharing
>     or structure_reuse pragma for it, then generate a diagnostic
>     reporting this fact, and do not input specialize the predicate.
>
> compiler/mercury_compile_front_end.m:
>     Handle the diagnostics that input_specialization.m can now return.
>
> diff --git a/compiler/input_specialization.m b/compiler/input_specialization.m
> index 77c992834..83ab41256 100644
> --- a/compiler/input_specialization.m
> +++ b/compiler/input_specialization.m

...

> @@ -245,6 +294,124 @@ find_args_to_specialize(InModuleMap, ArgNum, [ArgType | ArgTypes],
>
>  %---------------------------------------------------------------------------%
>
> +:- pred report_any_incompatibilities(pred_info::in, list(diag_spec)::out)
> +    is det.
> +
> +report_any_incompatibilities(PredInfo0, Specs) :-
> +    pred_info_get_proc_table(PredInfo0, ProcTable0),
> +    map.foldl4(acc_proc_eval_methods_structs, ProcTable0,
> +        [], NormalProcIds, [], TabledProcIds, no, Sharing, no, Reuse),
> +    pred_info_get_context(PredInfo0, Context),
> +    (
> +        TabledProcIds = [_ | _],
> +        (
> +            NormalProcIds = [],
> +            (
> +                TabledProcIds = [_],
> +                ProcsDesc = [words("its only procedure is tabled,")]
> +            ;
> +                TabledProcIds = [_, _ | _],
> +                ProcsDesc = [words("all of its procedures are tabled,")]
> +            )
> +        ;
> +            NormalProcIds = [_ | _],
> +            ProcsDesc = [words("some of its procedures are tabled,")]
> +        ),
> +        TabledPredPieces = describe_one_pred_info_name(yes(color_subject),
> +            should_not_module_qualify, [], PredInfo0),
> +        % This incompatability comes from add_pragma_tabling.m adding

s/incompatability/incompatibility/

> +        % to the HLDS global target language variables and auxiliary predicates
> +        % whose names include the original proc_ids of the tabled procedures.
> +        TabledPieces = [words("Error:")] ++ TabledPredPieces ++
> +            [words("could have its modes input specialized, but")] ++
> +            color_as_incorrect(ProcsDesc) ++
> +            [words("and input specialization and tabling"),
> +            words("are mutually exclusive."), nl],
> +        TabledSpec = spec($pred, severity_error, phase_input_spec,
> +            Context, TabledPieces),
> +        TabledSpecs = [TabledSpec]

That looks fine otherwise.

Julien.


More information about the reviews mailing list