Files
mercury/tests/dppd/transpose_impl.m
Zoltan Somogyi a0760327b6 Do stricter checking of mode and determinism declarations.
Specifically, we now do three new checks:

BAD_DETISM: We now generate error messages for predicate declarations
that specify a determinism without also specifying argument modes.

BAD_PREDMODE: We now generate error messages for standalone mode declarations
for predicates whose predicate declaration includes modes for the arguments.

BAD_MODE_SECTION: We now generate error messages for standalone mode
declarations that are not in the same section as the predicate's (or
function's) type declaration.

compiler/hlds_pred.m:
    Add a slot to the pred_sub_info. If the predicate is explicitly defined by
    the user in the current module, this contains the id of the section that
    contains its predicate declaration (for the BAD_MODE_SECTION check)
    and whether that predicate declaration also had modes for the arguments
    (for the BAD_PREDMODE check).

compiler/add_pred.m:
    When adding adding new predicate declarations, perform the BAD_DETISM
    check, and record the info needed for the BAD_PREDMODE and BAD_MODE_SECTION
    checks.

    When adding adding new mode declarations, perform the BAD_PREDMODE
    and BAD_MODE_SECTION checks.

compiler/add_class.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/dep_par_conj.m:
compiler/higher_order.m:
compiler/make_hlds_passes.m:
compiler/table_gen.m:
compiler/unused_args.m:
    Conform to the changes above.

mdbcomp/builtin_modules.m:
    Add a utility predicate for use by new code in add_pred.m.

compiler/comp_unit_interface.m:
compiler/goal_util.m:
compiler/prog_rename.m:
compiler/quantification.m:
deep_profiler/program_representation_utils.m:
library/calendar.m:
library/mutvar.m:
library/pretty_printer.m:
library/random.m:
library/set_ctree234.m:
library/solutions.m:
library/stream.string_writer.m:
profiler/globals.m:
tests/accumulator/nonrec.m:
tests/accumulator/out_to_in.m:
tests/declarative_debugging/library_forwarding.m:
tests/dppd/applast_impl.m:
tests/dppd/grammar_impl.m:
tests/dppd/regexp.m:
tests/dppd/transpose_impl.m:
tests/hard_coded/copy_pred.m:
tests/hard_coded/ho_func_default_inst.m:
tests/recompilation/unchanged_pred_nr_2.m.1:
tests/recompilation/unchanged_pred_nr_2.m.2:
tests/valid/det_switch.m:
tests/valid/inlining_bug.m:
    Delete determinism declarations from predicate and function declarations
    that have no argument mode information, since the BAD_DETISM check
    now makes these errors.

tests/valid/two_pragma_c_codes.m:
    Move some mode declarations to the right section, since the
    BAD_MODE_SECTION check now generates an error for the old code.

tests/invalid/typeclass_bad_method_mode.{m,err_exp}:
    New test case to test for the BAD_PREDMODE check.

tests/invalid/mode_decl_in_wrong_section.{m,err_exp}:
    New test case to test for the BAD_MODE_SECTION check.

tests/invalid/bad_detism.err_exp:
    Add an expected output for this old, but never enabled test case,
    which tests for new check BAD_DETISM.

tests/invalid/Mmakefile:
    Enable the new test cases.

tests/invalid/typeclass_dup_method_mode.m:
    This test case used to have two bugs. One is now by itself in the new
    typeclass_bad_method_mode.m test case, so modify it to contain only
    the other (indistinguishable modes).

tests/invalid/func_errors.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/undef_lambda_mode.err_exp:
tests/invalid/undef_type_mode_qual.err_exp:
    Expect an extra error message from the BAD_DETISM check.
2016-01-13 02:03:16 +11:00

47 lines
1.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module transpose_impl.
:- interface.
:- import_module list.
:- pred transpose(list(list(T)), list(list(T))).
:- mode transpose(in(matrix9), out) is nondet.
:- mode transpose(in, out) is nondet.
:- inst matrix9 == bound([list9, ground, ground]).
:- inst list9 == bound([ground, ground, ground, ground, ground, ground, ground,
ground, ground]).
:- inst [A | B]
---> [A | B].
:- inst []
---> [].
:- implementation.
transpose(Xs, []) :-
nullrows(Xs).
transpose(Xs, [Y | Ys]) :-
makerow(Xs, Y, Zs),
transpose(Zs, Ys).
:- pred makerow(list(list(T)), list(T), list(list(T))).
:- mode makerow(in, out, out) is semidet.
:- mode makerow(in(matrix9), out, out) is semidet.
makerow([], [], []).
makerow([[X | Xs] | Ys], [X | Xs1], [Xs | Zs]) :-
makerow(Ys, Xs1, Zs).
:- pred nullrows(list(list(T))).
:- mode nullrows(in) is semidet.
:- mode nullrows(in(list9)) is semidet.
nullrows([]).
nullrows([[] | Ns]) :-
nullrows(Ns).