[m-rev.] for review: use explicit streams in fact_table.m

Julien Fischer jfischer at opturion.com
Mon Jun 7 21:11:13 AEST 2021


On Mon, 7 Jun 2021, Zoltan Somogyi wrote:

> Use explicit streams in fact_table.m.

...

> --- a/compiler/fact_table.m
> +++ b/compiler/fact_table.m

...

> +check_fact_term(FileStream, FileName, MaybeProgressStream, FactTableSize,
> +        ModuleInfo, PredInfo, FactArgInfos, FactNum, Term,
> +        ProcStreams, MaybeOutput, Result, !Errors, !IO) :-
> +    (
> +        Term = term.variable(_, _),
> +        io.get_line_number(FileStream, LineNum, !IO),
> +        Context = term.context(FileName, LineNum),
> +        Msg = "Error: term is not a fact.",
> +        add_error_report(Context, [words(Msg)], !Errors),
> +        Result = error
> +    ;
> +        Term = term.functor(Functor, ArgTerms0, Context),
> +        ( if Functor = term.atom(FunctorAtom) then
> +            PredOrFunc = pred_info_is_pred_or_func(PredInfo),
> +            pred_info_get_name(PredInfo, PredName),
> +            ( if
> +                (
> +                    PredOrFunc = pf_predicate,
> +                    FunctorAtom = PredName,
> +                    ArgTerms = ArgTerms0
> +                ;
> +                    PredOrFunc = pf_function,
> +                    FunctorAtom = "=",
> +                    ArgTerms0 = [BeforeEqualTerm, ResultTerm],
> +                    BeforeEqualTerm =
> +                        term.functor(term.atom(PredName), BeforeEqualTerms, _),
> +                    ArgTerms = BeforeEqualTerms ++ [ResultTerm]
> +                )
> +            then
> +                check_fact_term_2(MaybeProgressStream, FactTableSize,
> +                    ModuleInfo, PredInfo, FactArgInfos,
> +                    FactNum, ArgTerms, Context, ProcStreams, MaybeOutput,
> +                    Result, !Errors, !IO)
> +            else
> +                pred_info_get_orig_arity(PredInfo, PredFormArity),
> +                user_arity_pred_form_arity(PredOrFunc,
> +                    user_arity(UserArityInt), pred_form_arity(PredFormArity)),
> +                PFStr = pred_or_func_to_full_str(PredOrFunc),
> +                string.format("Error: invalid clause for %s `%s/%d'.",
> +                    [s(PFStr), s(PredName), i(UserArityInt)], Msg),

It's an existing problem, but there are specific components in error_util
that should be used in the above error message.

...

> 
> @@ -913,29 +979,25 @@ infer_proc_determinism_pass_1([ProcID | ProcIDs], ModuleInfo, !ProcTable,
>          % Put it off till the second pass.
>          InferredDetism = not_yet,
>          % Add to list and check in pass 2.
> +        MaybeAllInProc0 = no,
>          !:CheckProcs = [ProcID | !.CheckProcs],
> -        WriteHashTables0 = yes,
> -        WriteDataTable0 = yes,
> -        MaybeAllInProc0 = no
> +        !:WriteHashTables = write_hash_tables,
> +        !:WriteDataTable = write_data_table
>      ;
>          ModeType = other,           % mode error
>          InferredDetism = error,
> +        MaybeAllInProc0 = no,
>          proc_info_get_context(ProcInfo0, Context),
>          Msg = "Error: only `in' and `out' modes are currently " ++
>              "supported in fact tables.",

Ditto here.

...

> -    % infer_determinism_pass_2(ProcFiles, Globals, ExistsAllInMode,
> +    % infer_determinism_pass_2(ModuleInfo, ExistsAllInMode, ProcFiles,
>      %   !ProcTable, !IO):
>      %
>      % Run `sort' on each sort file to see if the keys are unique.
>      % If they are, the procedure is semidet, otherwise it is nondet.
>      % Return the updated proc_table.
>      %
> -:- pred infer_determinism_pass_2(assoc_list(proc_id, string)::in, globals::in,
> -    bool::in, proc_table::in, proc_table::out, io::di, io::uo) is det.
> +:- pred infer_determinism_pass_2(module_info::in, all_in_mode::in,
> +    assoc_list(proc_id, string)::in,
> +    proc_table::in, proc_table::out, io::di, io::uo) is det.
> 
> -infer_determinism_pass_2([], _, _, !ProcTable, !IO).
> -infer_determinism_pass_2([ProcID - FileName | ProcFiles], Globals,
> -        ExistsAllInMode, !ProcTable, !IO) :-
> +infer_determinism_pass_2(_, _, [], !ProcTable, !IO).
> +infer_determinism_pass_2(ModuleInfo, ExistsAllInMode,
> +        [ProcID - FileName | ProcFiles], !ProcTable, !IO) :-
>      map.lookup(!.ProcTable, ProcID, ProcInfo0),
> -    make_command_string(string.format(
> +    % XXX This sends the output to the *input* file.
> +    % This works in the usual implementations of sort,
> +    % since you have to finish reading the input before you can generate
> +    % any part of the output, but it is not *guaranteed* to work,
> +    % since sort may *open* the output file before finishing reading.

The other issue here is that it only works on systems that actually provide the
sort and cut utilties.

The diff is fine.

Julien.


More information about the reviews mailing list