mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 20:03:44 +00:00
Estimated hours taken: 220
Aditi update syntax, type and mode checking.
Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.
compiler/hlds_goal.m:
Merge `higher_order_call' and `class_method_call' into a single
`generic_call' goal type. This also has alternatives for the
various Aditi builtins for which type declarations can't
be written.
Remove the argument types field from higher-order/class method calls.
It wasn't used often, and wasn't updated by optimizations
such as inlining. The types can be obtained from the vartypes
field of the proc_info.
Add a `lambda_eval_method' field to lambda_goals.
Add a field to constructions to identify which RL code fragment should
be used for an top-down Aditi closure.
Add fields to constructions to hold structure reuse information.
This is currently ignored -- the changes to implement structure
reuse will be committed to the alias branch.
This is included here to avoid lots of CVS conflicts caused by
changing the definition of `hlds_goal' twice.
Add a field to `some' goals to specify whether the quantification
can be removed. This is used to make it easier to ensure that
indexes are used for updates.
Add a field to lambda_goals to describe whether the modes were
guessed by the compiler and may need fixing up after typechecking
works out the argument types.
Add predicate `hlds_goal__generic_call_id' to work out a call_id
for a generic call for use in error messages.
compiler/purity.m:
compiler/post_typecheck.m:
Fill in the modes of Aditi builtin calls and closure constructions.
This needs to know which are the `aditi__state' arguments, so
it must be done after typechecking.
compiler/prog_data.m:
Added `:- type sym_name_and_arity ---> sym_name/arity'.
Add a type `lambda_eval_method', which describes how a closure
is to be executed. The alternatives are normal Mercury execution,
bottom-up execution by Aditi and top-down execution by Aditi.
compiler/prog_out.m:
Add predicate `prog_out__write_sym_name_and_arity', which
replaces duplicated inline code in a few places.
compiler/hlds_data.m:
Add a `lambda_eval_method' field to `pred_const' cons_ids and
`pred_closure_tag' cons_tags.
compiler/hlds_pred.m:
Remove type `pred_call_id', replace it with type `simple_call_id',
which combines a `pred_or_func' and a `sym_name_and_arity'.
Add a type `call_id' which describes all the different types of call,
including normal calls, higher-order and class-method calls
and Aditi builtins.
Add `aditi_top_down' to the type `marker'.
Remove `aditi_interface' from type `marker'. Interfacing to
Aditi predicates is now handled by `generic_call' hlds_goals.
Add a type `rl_exprn_id' which identifies a predicate to
be executed top-down by Aditi.
Add a `maybe(rl_exprn_id)' field to type `proc_info'.
Add predicate `adjust_func_arity' to convert between the arity
of a function to its arity as a predicate.
Add predicates `get_state_args' and `get_state_args_det' to
extract the DCG state arguments from an argument list.
Add predicate `pred_info_get_call_id' to get a `simple_call_id'
for a predicate for use in error messages.
compiler/hlds_out.m:
Write the new representation for call_ids.
Add a predicate `hlds_out__write_call_arg_id' which
replaces similar code in mode_errors.m and typecheck.m.
compiler/prog_io_goal.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on pred expressions.
compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
Add predicates
- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
(moved from prog_io_pragma.m).
- `prog_io_util:parse_pred_or_func_name_and_arity to parse
`pred SymName/Arity' or `func SymName/Arity'.
- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
a clause head (moved from prog_io_pragma.m).
compiler/type_util.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on higher-order types.
Add predicates `construct_higher_order_type',
`construct_higher_order_pred_type' and
`construct_higher_order_func_type' to avoid some code duplication.
compiler/mode_util.m:
Add predicate `unused_mode/1', which returns `builtin:unused'.
Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
`aditi_uo_mode/0' which return `in', `in', and `out', but will
be changed to return `di', `ui' and `uo' when alias tracking
is implemented.
compiler/goal_util.m:
Add predicate `goal_util__generic_call_vars' which returns
any arguments to a generic_call which are not in the argument list,
for example the closure passed to a higher-order call or
the typeclass_info for a class method call.
compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
Add builtin labels for the Aditi update operations.
compiler/hlds_module.m:
Add predicate predicate_table_search_pf_sym, used for finding
possible matches for a call with the wrong number of arguments.
compiler/intermod.m:
Don't write predicates which build `aditi_top_down' goals,
because there is currently no way to tell importing modules
which RL code fragment to use.
compiler/simplify.m:
Obey the `cannot_remove' field of explicit quantification goals.
compiler/make_hlds.m:
Parse Aditi updates.
Don't typecheck clauses for which syntax errors in Aditi updates
are found - this avoids spurious "undefined predicate `aditi_insert/3'"
errors.
Factor out some common code to handle terms of the form `Head :- Body'.
Factor out common code in the handling of pred and func expressions.
compiler/typecheck.m:
Typecheck Aditi builtins.
Allow the argument types of matching predicates to be adjusted
when typechecking the higher-order arguments of Aditi builtins.
Change `typecheck__resolve_pred_overloading' to take a list of
argument types rather than a `map(var, type)' and a list of
arguments to allow a transformation to be performed on the
argument types before passing them.
compiler/error_util.m:
Move the part of `report_error_num_args' which writes
"wrong number of arguments (<x>; expected <y>)" from
typecheck.m for use by make_hlds.m when reporting errors
for Aditi builtins.
compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
Modecheck Aditi builtins.
compiler/lambda.m:
Handle the markers for predicates introduced for
`aditi_top_down' and `aditi_bottom_up' lambda expressions.
compiler/polymorphism.m:
Add extra type_infos to `aditi_insert' calls
describing the tuple to insert.
compiler/call_gen.m:
Generate code for Aditi builtins.
compiler/unify_gen.m:
compiler/bytecode_gen.m:
Abort on `aditi_top_down' and `aditi_bottom_up' lambda
expressions - code generation for them is not yet implemented.
compiler/magic.m:
Use the `aditi_call' generic_call rather than create
a new procedure for each Aditi predicate called from C.
compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
Move some utility code used by magic.m and call_gen.m into rl.m.
Remove an XXX comment about reference counting being not yet
implemented - Evan has fixed that.
library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
used as qualifiers on lambda expressions.
Add infix operator `==>' to separate the tuples in an
`aditi_modify' call.
compiler/follow_vars.m:
Thread a `map(prog_var, type)' through, needed because
type information is no longer held in higher-order call goals.
compiler/table_gen.m:
Use the `make_*_construction' predicates in hlds_goal.m
to construct constants.
compiler/*.m:
Trivial changes to add extra fields to hlds_goal structures.
doc/reference_manual.texi:
Document Aditi updates.
Use @samp{pragma base_relation} instead of
@samp{:- pragma base_relation} throughout the Aditi documentation
to be consistent with other parts of the reference manual.
tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
Test case.
tests/valid/Mmakefile:
Remove some hard-coded --intermodule-optimization rules which are
no longer needed because `mmake depend' is now run in this directory.
tests/invalid/*.err_exp:
Fix expected output for changes in reporting of call_ids
in typecheck.m.
tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
Test error messages for Aditi updates.
tests/valid/aditi.m:
tests/invalid/aditi.m:
Cut down version of extras/aditi/aditi.m to provide basic declarations
for Aditi compilation such as `aditi__state' and the modes
`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
somewhere would remove the need for these.
875 lines
30 KiB
Mathematica
875 lines
30 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1994-1999 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.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% File: mode_info.m.
|
|
% Main author: fjh.
|
|
|
|
% This file defines the mode_info data structure, which is used to hold
|
|
% the information we need during mode analysis.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module mode_info.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds_module, hlds_pred, hlds_goal, hlds_data, instmap.
|
|
:- import_module prog_data, mode_errors, delay_info, (inst).
|
|
:- import_module map, list, set, bool, assoc_list, std_util.
|
|
|
|
:- interface.
|
|
|
|
% The mode_info data structure and access predicates.
|
|
|
|
% XXX `side' is not used
|
|
:- type mode_context
|
|
---> call(
|
|
call_id,
|
|
int % argument number (offset so that
|
|
% the real arguments start at number 1
|
|
% whereas the type_info arguments
|
|
% have numbers <= 0).
|
|
)
|
|
; unify(
|
|
unify_context, % original source of the unification
|
|
side % LHS or RHS
|
|
)
|
|
/**** Not yet used
|
|
; unify_arg(
|
|
unify_context,
|
|
side,
|
|
cons_id,
|
|
int
|
|
)
|
|
****/
|
|
; uninitialized.
|
|
|
|
:- type side ---> left ; right.
|
|
|
|
:- type call_context
|
|
---> unify(unify_context)
|
|
; call(call_id).
|
|
|
|
:- type var_lock_reason
|
|
---> negation
|
|
; if_then_else
|
|
; lambda(pred_or_func)
|
|
; par_conj
|
|
.
|
|
|
|
% Specify how to process goals - using either
|
|
% modes.m or unique_modes.m.
|
|
:- type how_to_check_goal
|
|
---> check_modes
|
|
; check_unique_modes
|
|
.
|
|
|
|
% Is mode analysis allowed to change which procedure of a predicate
|
|
% is called. It may not change the called procedure after deforestation
|
|
% has performed a generalisation step, since that could result
|
|
% in selecting a less efficient mode, or one which doesn't even
|
|
% have the same termination behaviour.
|
|
% Also, when rechecking a goal after adding extra goals, it is
|
|
% not necessary to choose again which procedure is to be called.
|
|
:- type may_change_called_proc
|
|
---> may_change_called_proc
|
|
; may_not_change_called_proc.
|
|
|
|
:- type locked_vars == assoc_list(var_lock_reason, set(prog_var)).
|
|
|
|
:- type mode_info.
|
|
|
|
:- pred mode_info_init(io__state, module_info, pred_id, proc_id, prog_context,
|
|
set(prog_var), instmap, how_to_check_goal,
|
|
may_change_called_proc, mode_info).
|
|
:- mode mode_info_init(di, in, in, in, in, in, in, in, in,
|
|
mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_io_state(mode_info, io__state).
|
|
:- mode mode_info_get_io_state(mode_info_get_io_state, uo) is det.
|
|
|
|
:- pred mode_info_set_io_state(mode_info, io__state, mode_info).
|
|
:- mode mode_info_set_io_state(mode_info_set_io_state, di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_module_info(mode_info, module_info).
|
|
:- mode mode_info_get_module_info(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_module_info(mode_info, module_info, mode_info).
|
|
:- mode mode_info_set_module_info(mode_info_di, in, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_preds(mode_info, pred_table).
|
|
:- mode mode_info_get_preds(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_modes(mode_info, mode_table).
|
|
:- mode mode_info_get_modes(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_insts(mode_info, inst_table).
|
|
:- mode mode_info_get_insts(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_predid(mode_info, pred_id).
|
|
:- mode mode_info_get_predid(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_procid(mode_info, proc_id).
|
|
:- mode mode_info_get_procid(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_context(mode_info, prog_context).
|
|
:- mode mode_info_get_context(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_context(prog_context, mode_info, mode_info).
|
|
:- mode mode_info_set_context(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_mode_context(mode_info, mode_context).
|
|
:- mode mode_info_get_mode_context(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_mode_context(mode_context, mode_info, mode_info).
|
|
:- mode mode_info_set_mode_context(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_set_call_context(call_context, mode_info, mode_info).
|
|
:- mode mode_info_set_call_context(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_set_call_arg_context(int, mode_info, mode_info).
|
|
:- mode mode_info_set_call_arg_context(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_unset_call_context(mode_info, mode_info).
|
|
:- mode mode_info_unset_call_context(mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_instmap(mode_info, instmap).
|
|
:- mode mode_info_get_instmap(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_dcg_get_instmap(instmap, mode_info, mode_info).
|
|
:- mode mode_info_dcg_get_instmap(out, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_set_instmap(instmap, mode_info, mode_info).
|
|
:- mode mode_info_set_instmap(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_locked_vars(mode_info, locked_vars).
|
|
:- mode mode_info_get_locked_vars(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_locked_vars(mode_info, locked_vars, mode_info).
|
|
:- mode mode_info_set_locked_vars(mode_info_di, in, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_errors(mode_info, list(mode_error_info)).
|
|
:- mode mode_info_get_errors(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_num_errors(mode_info, int).
|
|
:- mode mode_info_get_num_errors(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_errors(list(mode_error_info), mode_info, mode_info).
|
|
:- mode mode_info_set_errors(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_add_live_vars(set(prog_var), mode_info, mode_info).
|
|
:- mode mode_info_add_live_vars(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_remove_live_vars(set(prog_var), mode_info, mode_info).
|
|
:- mode mode_info_remove_live_vars(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_var_list_is_live(list(prog_var), mode_info, list(is_live)).
|
|
:- mode mode_info_var_list_is_live(in, mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_var_is_live(mode_info, prog_var, is_live).
|
|
:- mode mode_info_var_is_live(mode_info_ui, in, out) is det.
|
|
|
|
:- pred mode_info_var_is_nondet_live(mode_info, prog_var, is_live).
|
|
:- mode mode_info_var_is_nondet_live(mode_info_ui, in, out) is det.
|
|
|
|
:- pred mode_info_get_liveness(mode_info, set(prog_var)).
|
|
:- mode mode_info_get_liveness(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_liveness_2(list(set(prog_var)), set(prog_var),
|
|
set(prog_var)).
|
|
:- mode mode_info_get_liveness_2(in, in, out) is det.
|
|
|
|
:- pred mode_info_get_varset(mode_info, prog_varset).
|
|
:- mode mode_info_get_varset(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_varset(prog_varset, mode_info, mode_info).
|
|
:- mode mode_info_set_varset(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_instvarset(mode_info, inst_varset).
|
|
:- mode mode_info_get_instvarset(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_get_var_types(mode_info, map(prog_var, type)).
|
|
:- mode mode_info_get_var_types(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_var_types(map(prog_var, type), mode_info, mode_info).
|
|
:- mode mode_info_set_var_types(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_types_of_vars(mode_info, list(prog_var), list(type)).
|
|
:- mode mode_info_get_types_of_vars(mode_info_ui, in, out) is det.
|
|
|
|
:- pred mode_info_lock_vars(var_lock_reason, set(prog_var),
|
|
mode_info, mode_info).
|
|
:- mode mode_info_lock_vars(in, in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_unlock_vars(var_lock_reason, set(prog_var),
|
|
mode_info, mode_info).
|
|
:- mode mode_info_unlock_vars(in, in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_var_is_locked(mode_info, prog_var, var_lock_reason).
|
|
:- mode mode_info_var_is_locked(mode_info_ui, in, out) is semidet.
|
|
|
|
:- pred mode_info_var_is_locked_2(locked_vars, prog_var, var_lock_reason).
|
|
:- mode mode_info_var_is_locked_2(in, in, out) is semidet.
|
|
|
|
:- pred mode_info_get_delay_info(mode_info, delay_info).
|
|
:- mode mode_info_get_delay_info(mode_info_no_io, out) is det.
|
|
|
|
:- pred mode_info_set_delay_info(delay_info, mode_info, mode_info).
|
|
:- mode mode_info_set_delay_info(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_live_vars(mode_info, list(set(prog_var))).
|
|
:- mode mode_info_get_live_vars(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_live_vars(list(set(prog_var)), mode_info, mode_info).
|
|
:- mode mode_info_set_live_vars(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_nondet_live_vars(mode_info, list(set(prog_var))).
|
|
:- mode mode_info_get_nondet_live_vars(mode_info_no_io, out) is det.
|
|
|
|
:- pred mode_info_set_nondet_live_vars(list(set(prog_var)),
|
|
mode_info, mode_info).
|
|
:- mode mode_info_set_nondet_live_vars(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_last_checkpoint_insts(mode_info,
|
|
assoc_list(prog_var, inst)).
|
|
:- mode mode_info_get_last_checkpoint_insts(mode_info_no_io, out) is det.
|
|
|
|
:- pred mode_info_set_last_checkpoint_insts(assoc_list(prog_var, inst),
|
|
mode_info, mode_info).
|
|
:- mode mode_info_set_last_checkpoint_insts(in, mode_info_di, mode_info_uo)
|
|
is det.
|
|
|
|
:- pred mode_info_get_parallel_vars(list(pair(set(prog_var))), mode_info,
|
|
mode_info).
|
|
:- mode mode_info_get_parallel_vars(out, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_set_parallel_vars(list(pair(set(prog_var))), mode_info,
|
|
mode_info).
|
|
:- mode mode_info_set_parallel_vars(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_changed_flag(mode_info, bool).
|
|
:- mode mode_info_get_changed_flag(mode_info_no_io, out) is det.
|
|
|
|
:- pred mode_info_set_changed_flag(bool, mode_info, mode_info).
|
|
:- mode mode_info_set_changed_flag(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_how_to_check(mode_info, how_to_check_goal).
|
|
:- mode mode_info_get_how_to_check(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_how_to_check(how_to_check_goal, mode_info, mode_info).
|
|
:- mode mode_info_set_how_to_check(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_get_may_change_called_proc(mode_info,
|
|
may_change_called_proc).
|
|
:- mode mode_info_get_may_change_called_proc(mode_info_ui, out) is det.
|
|
|
|
:- pred mode_info_set_may_change_called_proc(may_change_called_proc,
|
|
mode_info, mode_info).
|
|
:- mode mode_info_set_may_change_called_proc(in,
|
|
mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_set_checking_extra_goals(bool, mode_info, mode_info).
|
|
:- mode mode_info_set_checking_extra_goals(in,
|
|
mode_info_di, mode_info_uo) is det.
|
|
|
|
% Find the simple_call_id to use in error messages
|
|
% for the given pred_id.
|
|
:- pred mode_info_get_call_id(mode_info, pred_id, simple_call_id).
|
|
:- mode mode_info_get_call_id(mode_info_ui, in, out) is det.
|
|
|
|
/*
|
|
:- inst uniq_mode_info = bound_unique(
|
|
mode_info(
|
|
unique,
|
|
ground, ground, ground,
|
|
ground, ground, ground, ground,
|
|
ground, ground, ground, ground,
|
|
ground, ground, ground, ground,
|
|
ground
|
|
)
|
|
).
|
|
*/
|
|
:- inst uniq_mode_info = ground.
|
|
|
|
:- mode mode_info_uo :: free -> uniq_mode_info.
|
|
:- mode mode_info_ui :: uniq_mode_info -> uniq_mode_info.
|
|
:- mode mode_info_di :: uniq_mode_info -> dead.
|
|
|
|
% Some fiddly modes used when we want to extract
|
|
% the io_state from a mode_info struct and then put it back again.
|
|
|
|
/*
|
|
:- inst mode_info_no_io = bound_unique(
|
|
mode_info(
|
|
dead, ground, ground, ground,
|
|
ground, ground, ground, ground,
|
|
ground, ground, ground, ground,
|
|
ground, ground, ground, ground,
|
|
ground
|
|
)
|
|
).
|
|
*/
|
|
:- inst mode_info_no_io = ground.
|
|
|
|
:- mode mode_info_get_io_state :: uniq_mode_info -> mode_info_no_io.
|
|
:- mode mode_info_no_io :: mode_info_no_io -> mode_info_no_io.
|
|
:- mode mode_info_set_io_state :: mode_info_no_io -> dead.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% record a mode error (and associated context info) in the mode_info.
|
|
|
|
:- pred mode_info_error(set(prog_var), mode_error, mode_info, mode_info).
|
|
:- mode mode_info_error(in, in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- pred mode_info_add_error(mode_error_info, mode_info, mode_info).
|
|
:- mode mode_info_add_error(in, mode_info_di, mode_info_uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module delay_info, mode_errors, mode_util.
|
|
:- import_module term, varset.
|
|
:- import_module require, std_util, queue.
|
|
|
|
:- type mode_info
|
|
---> mode_info(
|
|
io__state,
|
|
module_info,
|
|
pred_id, % The pred we are checking
|
|
proc_id, % The mode which we are checking
|
|
prog_varset, % The variables in the current proc
|
|
map(prog_var, type),
|
|
% The types of the variables
|
|
prog_context, % The line number of the subgoal we
|
|
% are currently checking
|
|
mode_context, % A description of where in the
|
|
% goal the error occurred
|
|
instmap, % The current instantiatedness
|
|
% of the variables
|
|
locked_vars, % The "locked" variables,
|
|
% i.e. variables which cannot be
|
|
% further instantiated inside a
|
|
% negated context
|
|
delay_info, % info about delayed goals
|
|
list(mode_error_info),
|
|
% The mode errors found
|
|
|
|
list(set(prog_var)), % The live variables,
|
|
% i.e. those variables which may be referenced again on forward
|
|
% execution or after shallow backtracking. (By shallow
|
|
% backtracking, I mean semidet backtracking in a negation,
|
|
% if-then-else, or semidet disjunction within the current
|
|
% predicate.)
|
|
|
|
list(set(prog_var)),
|
|
% The nondet-live variables,
|
|
% i.e. those variables which may be referenced again after deep
|
|
% backtracking TO THE CURRENT EXECUTION POINT. These are the
|
|
% variables which need to be made mostly_unique rather than
|
|
% unique when we get to a nondet disjunction or a nondet call.
|
|
% We do not include variables which may be referenced again
|
|
% after backtracking to a point EARLIER THAN the current
|
|
% execution point, since those variables will *already* have
|
|
% been marked as mostly_unique rather than unique.)
|
|
|
|
assoc_list(prog_var, inst),
|
|
% This field is used by the checkpoint code when debug_modes is on.
|
|
% It has the instmap that was current at the last mode checkpoint,
|
|
% so that checkpoints do not print out the insts of variables
|
|
% whose insts have not changed since the last checkpoint.
|
|
% This field will always contain an empty list if debug_modes is off,
|
|
% since its information is not needed then.
|
|
|
|
list(pair(set(prog_var), set(prog_var))),
|
|
% A stack of pairs of sets of variables used to mode-check
|
|
% parallel conjunctions. The first set is the nonlocals of
|
|
% the parallel conjunction. The second set is a subset of the
|
|
% first, and is the set of variables that have been [further]
|
|
% bound inside the current parallel conjunct - the stack is for
|
|
% the correct handling of nested parallel conjunctions.
|
|
|
|
bool, % Changed flag
|
|
% If `yes', then we may need
|
|
% to repeat mode inference.
|
|
|
|
how_to_check_goal,
|
|
|
|
may_change_called_proc,
|
|
% Is mode analysis allowed
|
|
% to change which procedure
|
|
% is called?
|
|
|
|
bool % Are we rechecking a goal after
|
|
% introducing unifications for
|
|
% complicated sub-unifications
|
|
% or an implied mode?
|
|
% If so, redoing the mode check
|
|
% should not introduce more
|
|
% extra unifications.
|
|
).
|
|
|
|
% The normal inst of a mode_info struct: ground, with
|
|
% the io_state and the struct itself unique, but with
|
|
% multiple references allowed for the other parts.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Initialize the mode_info
|
|
|
|
mode_info_init(IOState, ModuleInfo, PredId, ProcId, Context,
|
|
LiveVars, InstMapping0, HowToCheck, MayChangeProc, ModeInfo) :-
|
|
mode_context_init(ModeContext),
|
|
LockedVars = [],
|
|
delay_info__init(DelayInfo),
|
|
ErrorList = [],
|
|
% look up the varset and var types
|
|
module_info_preds(ModuleInfo, Preds),
|
|
map__lookup(Preds, PredId, PredInfo),
|
|
pred_info_procedures(PredInfo, Procs),
|
|
map__lookup(Procs, ProcId, ProcInfo),
|
|
proc_info_varset(ProcInfo, VarSet),
|
|
proc_info_vartypes(ProcInfo, VarTypes),
|
|
|
|
LiveVarsList = [LiveVars],
|
|
NondetLiveVarsList = [LiveVars],
|
|
|
|
Changed = no,
|
|
|
|
CheckingExtraGoals = no,
|
|
|
|
ModeInfo = mode_info(
|
|
IOState, ModuleInfo, PredId, ProcId, VarSet, VarTypes,
|
|
Context, ModeContext, InstMapping0, LockedVars, DelayInfo,
|
|
ErrorList, LiveVarsList, NondetLiveVarsList, [], [],
|
|
Changed, HowToCheck, MayChangeProc, CheckingExtraGoals
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Lots of very boring access predicates.
|
|
|
|
mode_info_get_io_state(
|
|
mode_info(IOState0,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
IOState) :-
|
|
% XXX
|
|
unsafe_promise_unique(IOState0, IOState).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_io_state(mode_info(_,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
|
|
IOState0,
|
|
mode_info(IOState,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)) :-
|
|
% XXX
|
|
unsafe_promise_unique(IOState0, IOState).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_module_info(
|
|
mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
ModuleInfo).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_module_info(mode_info(A,_,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
|
|
ModuleInfo,
|
|
mode_info(A,ModuleInfo,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_preds(
|
|
mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
Preds) :-
|
|
module_info_preds(ModuleInfo, Preds).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_modes(
|
|
mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
Modes) :-
|
|
module_info_modes(ModuleInfo, Modes).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_insts(
|
|
mode_info(_,ModuleInfo,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
Insts) :-
|
|
module_info_insts(ModuleInfo, Insts).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_predid(mode_info(_,_,PredId,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
PredId).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_procid(mode_info(_,_,_,ProcId,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
ProcId).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_varset(mode_info(_,_,_,_,VarSet,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
VarSet).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_varset(VarSet,
|
|
mode_info(A,B,C,D,_,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,VarSet,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_var_types(
|
|
mode_info(_,_,_,_,_,VarTypes,_,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
VarTypes).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_var_types(VTypes,
|
|
mode_info(A,B,C,D,E,_,G,H,I,J,K,L,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,VTypes,G,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_context(mode_info(_,_,_,_,_,_,Context,_,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
Context).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_context(Context,
|
|
mode_info(A,B,C,D,E,F,_,H,I,J,K,L,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,Context,H,I,J,K,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_mode_context(
|
|
mode_info(_,_,_,_,_,_,_,ModeContext,_,_,_,_,_,_,_,_,_,_,_,_),
|
|
ModeContext).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_mode_context(ModeContext,
|
|
mode_info(A,B,C,D,E,F,G,_,I,J,K,L,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,ModeContext,I,J,K,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_call_context(unify(UnifyContext)) -->
|
|
mode_info_set_mode_context(unify(UnifyContext, left)).
|
|
mode_info_set_call_context(call(CallId)) -->
|
|
mode_info_set_mode_context(call(CallId, 0)).
|
|
|
|
mode_info_set_call_arg_context(ArgNum, ModeInfo0, ModeInfo) :-
|
|
mode_info_get_mode_context(ModeInfo0, ModeContext0),
|
|
( ModeContext0 = call(CallId, _) ->
|
|
mode_info_set_mode_context(call(CallId, ArgNum),
|
|
ModeInfo0, ModeInfo)
|
|
; ModeContext0 = unify(_UnifyContext, _Side) ->
|
|
% This only happens when checking that the typeinfo variables
|
|
% for polymorphic complicated unifications are ground.
|
|
% For that case, we don't care about the ArgNum.
|
|
ModeInfo = ModeInfo0
|
|
;
|
|
error("mode_info_set_call_arg_context")
|
|
).
|
|
|
|
mode_info_unset_call_context -->
|
|
mode_info_set_mode_context(uninitialized).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_instmap(mode_info(_,_,_,_,_,_,_,_,InstMap,_,_,_,_,_,_,_,_,_,_,_),
|
|
InstMap).
|
|
|
|
% mode_info_dcg_get_instmap/3 is the same as mode_info_get_instmap/2
|
|
% except that it's easier to use inside a DCG.
|
|
|
|
mode_info_dcg_get_instmap(InstMap, ModeInfo, ModeInfo) :-
|
|
mode_info_get_instmap(ModeInfo, InstMap).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_instmap( InstMap,
|
|
mode_info(A,B,C,D,E,F,G,H,InstMap0,J,
|
|
DelayInfo0,L,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,InstMap,J,
|
|
DelayInfo,L,M,N,O,P,Q,R,S,T)) :-
|
|
( instmap__is_unreachable(InstMap), instmap__is_reachable(InstMap0) ->
|
|
delay_info__bind_all_vars(DelayInfo0, DelayInfo)
|
|
;
|
|
DelayInfo = DelayInfo0
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_locked_vars(
|
|
mode_info(_,_,_,_,_,_,_,_,_,LockedVars,_,_,_,_,_,_,_,_,_,_),
|
|
LockedVars).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_locked_vars( mode_info(A,B,C,D,E,F,G,H,I,_,K,L,M,N,O,P,Q,R,S,T),
|
|
LockedVars,
|
|
mode_info(A,B,C,D,E,F,G,H,I,LockedVars,K,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_errors(mode_info(_,_,_,_,_,_,_,_,_,_,_,Errors,_,_,_,_,_,_,_,_),
|
|
Errors).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_num_errors(
|
|
mode_info(_,_,_,_,_,_,_,_,_,_,_,Errors,_,_,_,_,_,_,_,_),
|
|
NumErrors) :-
|
|
list__length(Errors, NumErrors).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_set_errors(Errors,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,_,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,Errors,M,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% We keep track of the live variables and the nondet-live variables
|
|
% a bag, represented as a list of sets of vars.
|
|
% This allows us to easily add and remove sets of variables.
|
|
% It's probably not maximally efficient.
|
|
|
|
% Add a set of vars to the bag of live vars and
|
|
% the bag of nondet-live vars.
|
|
|
|
mode_info_add_live_vars(NewLiveVars,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
|
|
LiveVars0,NondetLiveVars0,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
|
|
LiveVars,NondetLiveVars,O,P,Q,R,S,T)) :-
|
|
|
|
LiveVars = [NewLiveVars | LiveVars0],
|
|
NondetLiveVars = [NewLiveVars | NondetLiveVars0].
|
|
|
|
% Remove a set of vars from the bag of live vars and
|
|
% the bag of nondet-live vars.
|
|
|
|
mode_info_remove_live_vars(OldLiveVars, ModeInfo0, ModeInfo) :-
|
|
ModeInfo0 = mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
|
|
LiveVars0, NondetLiveVars0,O,P,Q,R,S,T),
|
|
ModeInfo1 = mode_info(A,B,C,D,E,F,G,H,I,J,K,L,
|
|
LiveVars, NondetLiveVars,O,P,Q,R,S,T),
|
|
(
|
|
list__delete_first(LiveVars0, OldLiveVars, LiveVars1),
|
|
list__delete_first(NondetLiveVars0, OldLiveVars,
|
|
NondetLiveVars1)
|
|
->
|
|
LiveVars = LiveVars1,
|
|
NondetLiveVars = NondetLiveVars1
|
|
;
|
|
error("mode_info_remove_live_vars: failed")
|
|
),
|
|
% when a variable becomes dead, we may be able to wake
|
|
% up a goal which is waiting on that variable
|
|
set__to_sorted_list(OldLiveVars, VarList),
|
|
mode_info_get_delay_info(ModeInfo1, DelayInfo0),
|
|
delay_info__bind_var_list(VarList, DelayInfo0, DelayInfo),
|
|
mode_info_set_delay_info(DelayInfo, ModeInfo1, ModeInfo).
|
|
|
|
% Check whether a list of variables are live or not
|
|
|
|
mode_info_var_list_is_live([], _, []).
|
|
mode_info_var_list_is_live([Var | Vars], ModeInfo, [Live | Lives]) :-
|
|
mode_info_var_is_live(ModeInfo, Var, Live),
|
|
mode_info_var_list_is_live(Vars, ModeInfo, Lives).
|
|
|
|
% Check whether a variable is live or not
|
|
|
|
mode_info_var_is_live(
|
|
mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,_,_,_,_,_,_,_),
|
|
Var, Result) :-
|
|
(
|
|
% some [LiveVars]
|
|
list__member(LiveVars, LiveVarsList),
|
|
set__member(Var, LiveVars)
|
|
->
|
|
Result = live
|
|
;
|
|
Result = dead
|
|
).
|
|
|
|
% Check whether a variable is nondet_live or not.
|
|
|
|
mode_info_var_is_nondet_live(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,
|
|
NondetLiveVarsList,_,_,_,_,_,_), Var, Result) :-
|
|
(
|
|
% some [LiveVars]
|
|
list__member(LiveVars, NondetLiveVarsList),
|
|
set__member(Var, LiveVars)
|
|
->
|
|
Result = live
|
|
;
|
|
Result = dead
|
|
).
|
|
|
|
mode_info_get_liveness(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,
|
|
_,_,_,_,_,_,_), LiveVars) :-
|
|
set__init(LiveVars0),
|
|
mode_info_get_liveness_2(LiveVarsList, LiveVars0, LiveVars).
|
|
|
|
mode_info_get_liveness_2([], LiveVars, LiveVars).
|
|
mode_info_get_liveness_2([LiveVarsSet | LiveVarsList], LiveVars0, LiveVars) :-
|
|
set__union(LiveVars0, LiveVarsSet, LiveVars1),
|
|
mode_info_get_liveness_2(LiveVarsList, LiveVars1, LiveVars).
|
|
|
|
mode_info_get_live_vars(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,
|
|
_,_,_,_,_,_,_), LiveVarsList).
|
|
|
|
mode_info_set_live_vars(LiveVarsList,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,_,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,LiveVarsList,N,O,P,Q,R,S,T)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Since we don't yet handle polymorphic modes, the inst varset
|
|
% is always empty.
|
|
|
|
mode_info_get_instvarset(_ModeInfo, InstVarSet) :-
|
|
varset__init(InstVarSet).
|
|
|
|
mode_info_get_types_of_vars(ModeInfo, Vars, TypesOfVars) :-
|
|
mode_info_get_var_types(ModeInfo, VarTypes),
|
|
map__apply_to_list(Vars, VarTypes, TypesOfVars).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% The locked variables are stored as a stack
|
|
% of sets of variables. A variable is locked if it is
|
|
% a member of any of the sets. To lock a set of vars, we just
|
|
% push them on the stack, and to unlock a set of vars, we just
|
|
% pop them off the stack. The stack is implemented as a list.
|
|
|
|
mode_info_lock_vars(Reason, Vars, ModeInfo0, ModeInfo) :-
|
|
mode_info_get_locked_vars(ModeInfo0, LockedVars),
|
|
mode_info_set_locked_vars(ModeInfo0, [Reason - Vars | LockedVars],
|
|
ModeInfo).
|
|
|
|
mode_info_unlock_vars(Reason, Vars, ModeInfo0, ModeInfo) :-
|
|
mode_info_get_locked_vars(ModeInfo0, LockedVars0),
|
|
(
|
|
LockedVars0 = [Reason - TheseVars | LockedVars1],
|
|
set__equal(TheseVars, Vars)
|
|
->
|
|
LockedVars = LockedVars1
|
|
;
|
|
error("mode_info_unlock_vars: some kind of nesting error")
|
|
),
|
|
mode_info_set_locked_vars(ModeInfo0, LockedVars, ModeInfo).
|
|
|
|
mode_info_var_is_locked(ModeInfo, Var, Reason) :-
|
|
mode_info_get_locked_vars(ModeInfo, LockedVarsList),
|
|
mode_info_var_is_locked_2(LockedVarsList, Var, Reason).
|
|
|
|
mode_info_var_is_locked_2([ThisReason - Set | Sets], Var, Reason) :-
|
|
(
|
|
set__member(Var, Set)
|
|
->
|
|
Reason = ThisReason
|
|
;
|
|
mode_info_var_is_locked_2(Sets, Var, Reason)
|
|
).
|
|
|
|
mode_info_get_delay_info(
|
|
mode_info(_,_,_,_,_,_,_,_,_,_,DelayInfo,_,_,_,_,_,_,_,_,_),
|
|
DelayInfo).
|
|
|
|
mode_info_set_delay_info(DelayInfo,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,_,L,M,N,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,DelayInfo,L,M,N,O,P,Q,R,S,T)).
|
|
|
|
mode_info_get_nondet_live_vars(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,
|
|
NondetLiveVars,_,_,_,_,_,_), NondetLiveVars).
|
|
|
|
mode_info_set_nondet_live_vars(NondetLiveVars,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,_,O,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,NondetLiveVars,O,P,Q,R,S,T)).
|
|
|
|
mode_info_get_last_checkpoint_insts(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,
|
|
LastCheckpointInsts,_,_,_,_,_), LastCheckpointInsts).
|
|
|
|
mode_info_set_last_checkpoint_insts(LastCheckpointInsts,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,_,P,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,
|
|
LastCheckpointInsts,P,Q,R,S,T)).
|
|
|
|
mode_info_get_parallel_vars(PVars, ModeInfo, ModeInfo) :-
|
|
ModeInfo = mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,PVars,_,_,_,_).
|
|
|
|
mode_info_set_parallel_vars(PVars,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,_,Q,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,PVars,Q,R,S,T)).
|
|
|
|
mode_info_get_changed_flag(
|
|
mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,Changed,_,_,_),
|
|
Changed).
|
|
|
|
mode_info_set_changed_flag(Changed,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,_,R,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Changed,R,S,T)).
|
|
|
|
mode_info_get_how_to_check(
|
|
mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,How,_,_),
|
|
How).
|
|
|
|
mode_info_set_how_to_check(How,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,_,S,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,How,S,T)).
|
|
|
|
mode_info_get_may_change_called_proc(
|
|
mode_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,MayChange,_),
|
|
MayChange).
|
|
|
|
mode_info_set_may_change_called_proc(MayChange,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,_,T),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,MayChange,T)).
|
|
|
|
mode_info_set_checking_extra_goals(Checking,
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,Checking0),
|
|
mode_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,Checking)) :-
|
|
( Checking0 = yes, Checking = yes ->
|
|
% This should never happen - once the extra goals are
|
|
% introduced, rechecking the goal should not introduce
|
|
% more extra goals.
|
|
error(
|
|
"mode analysis: rechecking extra goals adds more extra goals")
|
|
;
|
|
true
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_get_call_id(ModeInfo, PredId, CallId) :-
|
|
mode_info_get_module_info(ModeInfo, ModuleInfo),
|
|
module_info_pred_info(ModuleInfo, PredId, PredInfo),
|
|
pred_info_get_call_id(PredInfo, CallId).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mode_info_error(Vars, ModeError, ModeInfo0, ModeInfo) :-
|
|
mode_info_get_context(ModeInfo0, Context),
|
|
mode_info_get_mode_context(ModeInfo0, ModeContext),
|
|
ModeErrorInfo = mode_error_info(Vars, ModeError, Context, ModeContext),
|
|
mode_info_add_error(ModeErrorInfo, ModeInfo0, ModeInfo).
|
|
|
|
mode_info_add_error(ModeErrorInfo, ModeInfo0, ModeInfo) :-
|
|
mode_info_get_errors(ModeInfo0, Errors0),
|
|
list__append(Errors0, [ModeErrorInfo], Errors),
|
|
mode_info_set_errors(Errors, ModeInfo0, ModeInfo).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|