mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 8
Branches: main
Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.
The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.
compiler/det_analysis.m:
Keep track of goals to the right of the current goal that could fail,
and include them in the error representation if required.
compiler/det_report.m:
Include the list of failing goals to the right in the representations
of determinism errors involving committed committed choice goals.
Convert the last part of this module that wasn't using error_util
to use error_util. Make most parts of this module just construct
error message specifications; print those specifications (using
error_util) in only a few places.
compiler/hlds_out.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
compiler/compiler_util.m:
Error_util is still changing reasonably often, and yet it is
included in lots of modules, most of which need only a few simple
non-parse-tree-related predicates from it (e.g. unexpected).
Move those predicates to a new module, compiler_util.m. This also
eliminates some undesirable dependencies from libs to parse_tree.
compiler/libs.m:
Include compiler_util.m.
compiler/notes/compiler_design.html:
Document compiler_util.m, and fix the documentation of some other
modules.
compiler/*.m:
Import compiler_util instead of or in addition to error_util.
To make this easier, consistently use . instead of __ for module
qualifying module names.
tests/invalid/det_errors_cc.{m,err_exp}:
Add this new test case to test the error messages for cc contexts.
tests/invalid/det_errors_deet.{m,err_exp}:
Add this new test case to test the error messages for unifications
inside function symbols.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
Change the expected output to conform to the change in det_report.m,
which is now more consistent.
89 lines
3.7 KiB
Mathematica
89 lines
3.7 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2000, 2003-2005 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% This module defines the `code_model' data type, and associated procedures.
|
|
% The `code_model' type is a simplified version of the `determinism' type
|
|
% that is defined in prog_data.m. It ignores most of the distinctions in
|
|
% the determinism type and keeps only the distinctions that are important
|
|
% for code generation.
|
|
%
|
|
% We define this in a different module than the `determinism' type because
|
|
% it is only used by some of the different back-ends, not all of them.
|
|
% It is used by the MLDS, LLDS, and bytecode back-ends, but not by the
|
|
% Aditi-RL back-end.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hlds__code_model.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds.hlds_goal.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- type code_model
|
|
---> model_det % functional & total
|
|
; model_semi % just functional
|
|
; model_non. % not functional
|
|
|
|
:- pred determinism_to_code_model(determinism, code_model).
|
|
:- mode determinism_to_code_model(in, out) is det.
|
|
:- mode determinism_to_code_model(out, in) is multi.
|
|
|
|
:- pred proc_info_interface_code_model(proc_info::in, code_model::out) is det.
|
|
|
|
:- pred goal_info_get_code_model(hlds_goal_info::in, code_model::out) is det.
|
|
|
|
% Construct a representation of the interface determinism of a procedure.
|
|
% The code we have chosen is not sequential; instead it encodes the various
|
|
% properties of each determinism. This must match the encoding of
|
|
% MR_Determinism in mercury_stack_layout.h.
|
|
%
|
|
% The 8 bit is set iff the context is first_solution.
|
|
% The 4 bit is set iff the min number of solutions is more than zero.
|
|
% The 2 bit is set iff the max number of solutions is more than zero.
|
|
% The 1 bit is set iff the max number of solutions is more than one.
|
|
%
|
|
:- func represent_determinism(determinism) = int.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module mdbcomp.program_representation.
|
|
:- import_module int.
|
|
|
|
determinism_to_code_model(det, model_det).
|
|
determinism_to_code_model(semidet, model_semi).
|
|
determinism_to_code_model(nondet, model_non).
|
|
determinism_to_code_model(multidet, model_non).
|
|
determinism_to_code_model(cc_nondet, model_semi).
|
|
determinism_to_code_model(cc_multidet, model_det).
|
|
determinism_to_code_model(erroneous, model_det).
|
|
determinism_to_code_model(failure, model_semi).
|
|
|
|
proc_info_interface_code_model(ProcInfo, CodeModel) :-
|
|
proc_info_interface_determinism(ProcInfo, Determinism),
|
|
determinism_to_code_model(Determinism, CodeModel).
|
|
|
|
goal_info_get_code_model(GoalInfo, CodeModel) :-
|
|
goal_info_get_determinism(GoalInfo, Determinism),
|
|
determinism_to_code_model(Determinism, CodeModel).
|
|
|
|
represent_determinism(det) = detism_rep(det_rep).
|
|
represent_determinism(semidet) = detism_rep(semidet_rep).
|
|
represent_determinism(nondet) = detism_rep(nondet_rep).
|
|
represent_determinism(multidet) = detism_rep(multidet_rep).
|
|
represent_determinism(erroneous) = detism_rep(erroneous_rep).
|
|
represent_determinism(failure) = detism_rep(failure_rep).
|
|
represent_determinism(cc_nondet) = detism_rep(cc_nondet_rep).
|
|
represent_determinism(cc_multidet) = detism_rep(cc_multidet_rep).
|
|
|
|
%-----------------------------------------------------------------------------%
|