[m-rev.] for review: improve mode error messages
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat Aug 10 00:28:55 AEST 2002
Estimated hours taken: 4
Branches: main
Improve the display of insts in mode error messages.
In particular, fully expand all compiler-defined insts;
places where recursive insts refer to themselves are printed as "...".
compiler/mode_errors.m:
Change the argument of output_inst from instvar_set to mode_info,
so that it can have access to the module_info's inst_table.
Call mercury_output_expanded_inst instead of mercury_output_inst.
compiler/mercury_to_mercury.m:
Add new procedures mercury_output_expanded_inst, for use by
mode_errors.m, and mercury_expanded_inst_to_string, for consistency
with the rest of the interface.
These procedures take an extra module_info argument.
They output the inst in a format where all compiler-defined insts
have been expanded out; recursive insts have their self-referential
parts printed out as elipses ("...").
compiler/mode_util.m:
Change strip_builtin_qualifiers_from_inst so that it handles
compiler-defined insts properly, rather than just deleting
typed_ground and typed_inst insts and ignoring the rest.
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
Update error messages to reflect the new output.
Workspace: /home/ceres/fjh/ws-ceres2/mercury
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.219
diff -u -d -r1.219 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m 26 Jul 2002 04:18:21 -0000 1.219
+++ compiler/mercury_to_mercury.m 9 Aug 2002 14:23:32 -0000
@@ -43,7 +43,7 @@
:- interface.
:- import_module parse_tree__prog_data, (parse_tree__inst).
-:- import_module hlds__hlds_goal, hlds__hlds_data.
+:- import_module hlds__hlds_goal, hlds__hlds_data, hlds__hlds_module.
:- import_module libs__globals.
:- import_module bool, std_util, list, io, varset, term.
@@ -206,6 +206,8 @@
% Output an inst in a format that makes it easy to read
% but may not be valid Mercury.
+ % The `int' argument specifies the indentation level.
+ % (These routines are used with `--debug-modes'.)
:- pred mercury_output_structured_inst(inst, int, inst_varset,
io__state, io__state).
@@ -213,16 +215,37 @@
:- func mercury_structured_inst_to_string(inst, int, inst_varset) = string.
+ % Output an inst in a format where all compiler-defined insts
+ % have been expanded out; recursive insts have their self-referential
+ % parts printed out as elipses ("...").
+ % (These routines are used for outputting insts in mode errors.)
+
+:- pred mercury_output_expanded_inst(inst, inst_varset, module_info,
+ io__state, io__state).
+:- mode mercury_output_expanded_inst(in, in, in, di, uo) is det.
+
+:- func mercury_expanded_inst_to_string(inst, inst_varset, module_info)
+ = string.
+
+ % Output an inst in a format that is valid Mercury.
+ % (These routines are used to create `.int' files, etc.)
+
:- pred mercury_output_inst(inst, inst_varset, io__state, io__state).
:- mode mercury_output_inst(in, in, di, uo) is det.
:- func mercury_inst_to_string(inst, inst_varset) = string.
+ % Output a cons_id, parenthesizing it if necessary
+
:- pred mercury_output_cons_id(cons_id, needs_brackets, io__state, io__state).
:- mode mercury_output_cons_id(in, in, di, uo) is det.
:- func mercury_cons_id_to_string(cons_id, needs_brackets) = string.
+ % Output a mode / list of modes / uni_mode,
+ % in a format that is valid Mercury.
+ % (These routines are used to create `.int' files, etc.)
+
:- pred mercury_output_mode(mode, inst_varset, io__state, io__state).
:- mode mercury_output_mode(in, in, di, uo) is det.
@@ -244,6 +267,8 @@
:- func mercury_uni_mode_list_to_string(list(uni_mode), inst_varset) = string.
+ % Output a determinism, in a format that is valid Mercury.
+
:- pred mercury_output_det(determinism, io__state, io__state).
:- mode mercury_output_det(in, di, uo) is det.
@@ -329,7 +354,8 @@
:- import_module parse_tree__prog_out, parse_tree__prog_util, hlds__hlds_pred.
:- import_module hlds__hlds_out, hlds__instmap.
-:- import_module recompilation__version, check_hlds__purity.
+:- import_module recompilation__version.
+:- import_module check_hlds__purity, check_hlds__mode_util.
:- import_module transform_hlds__term_util.
:- import_module libs__options, transform_hlds__termination.
:- import_module backend_libs__foreign.
@@ -947,13 +973,13 @@
mercury_format_structured_inst_list(Insts, Indent0, VarSet).
mercury_output_inst_list(Insts, VarSet) -->
- mercury_format_inst_list(Insts, VarSet).
+ mercury_format_inst_list(Insts, simple_inst_info(VarSet)).
mercury_inst_list_to_string(Insts, VarSet) = String :-
- mercury_format_inst_list(Insts, VarSet, "", String).
+ mercury_format_inst_list(Insts, simple_inst_info(VarSet), "", String).
-:- pred mercury_format_inst_list(list(inst)::in, inst_varset::in,
- U::di, U::uo) is det <= output(U).
+:- pred mercury_format_inst_list(list(inst)::in, InstInfo::in,
+ U::di, U::uo) is det <= (output(U), inst_info(InstInfo)).
mercury_format_inst_list([], _) --> [].
mercury_format_inst_list([Inst | Insts], VarSet) -->
@@ -1012,7 +1038,8 @@
add_string(")\n")
;
add_string("(pred("),
- mercury_format_mode_list(Modes, VarSet),
+ mercury_format_mode_list(Modes,
+ simple_inst_info(VarSet)),
add_string(") is "),
mercury_format_det(Det),
add_string(")\n")
@@ -1024,10 +1051,11 @@
add_string("((func) = ")
;
add_string("(func("),
- mercury_format_mode_list(ArgModes, VarSet),
+ mercury_format_mode_list(ArgModes,
+ simple_inst_info(VarSet)),
add_string(") = ")
),
- mercury_format_mode(RetMode, VarSet),
+ mercury_format_mode(RetMode, simple_inst_info(VarSet)),
add_string(" is "),
mercury_format_det(Det),
add_string(")\n")
@@ -1044,7 +1072,8 @@
mercury_format_structured_inst(constrained_inst_vars(Vars, Inst), Indent,
VarSet) -->
mercury_format_tabs(Indent),
- mercury_format_constrained_inst_vars(Vars, Inst, VarSet),
+ mercury_format_constrained_inst_vars(Vars, Inst,
+ simple_inst_info(VarSet)),
add_string("\n").
mercury_format_structured_inst(abstract_inst(Name, Args), Indent, VarSet) -->
mercury_format_structured_inst_name(user_inst(Name, Args), Indent,
@@ -1055,14 +1084,83 @@
mercury_format_tabs(Indent),
add_string("not_reached\n").
+% We use the following type class to share code between mercury_output_inst,
+% which outputs inst in Mercury syntax, and mercury_output_expanded_inst,
+% which is the same except that it expands any compiler-defined insts
+% (except those which have already been encountered).
+%
+% (XXX Perhaps we should use the same sort of technique to also avoid
+% code duplication with mercury_format_structured_inst.)
+
+:- typeclass inst_info(InstInfo) where [
+ (func instvarset(InstInfo) = inst_varset),
+ (pred format_defined_inst(inst_name::in, InstInfo::in,
+ U::di, U::uo) is det <= output(U))
+].
+
+:- type simple_inst_info
+ ---> simple_inst_info(sii_varset :: inst_varset).
+
+:- instance inst_info(simple_inst_info) where [
+ func(instvarset/1) is sii_varset,
+ pred(format_defined_inst/4) is mercury_format_inst_name
+].
+
+:- instance inst_info(expanded_inst_info) where [
+ func(instvarset/1) is eii_varset,
+ pred(format_defined_inst/4) is mercury_format_expanded_defined_inst
+].
+
+:- type expanded_inst_info
+ ---> expanded_inst_info(
+ eii_varset :: inst_varset,
+ eii_module_info :: module_info,
+ eii_expansions :: set(inst_name)
+ % the set of already-expanded insts;
+ % further occurrences of these will
+ % be output as "..."
+ ).
+
+:- pred mercury_format_expanded_defined_inst(inst_name::in,
+ expanded_inst_info::in, U::di, U::uo) is det <= output(U).
+
+mercury_format_expanded_defined_inst(InstName, ExpandedInstInfo) -->
+ ( { set__member(InstName, ExpandedInstInfo ^ eii_expansions) } ->
+ add_string("...")
+ ; { InstName = user_inst(_, _) } ->
+ % don't expand user-defined insts, just output them as is
+ % (we do expand any compiler-defined insts that occur
+ % in the arguments of the user-defined inst, however)
+ mercury_format_inst_name(InstName, ExpandedInstInfo)
+ ;
+ { inst_lookup(ExpandedInstInfo ^ eii_module_info, InstName,
+ Inst) },
+ { set__insert(ExpandedInstInfo ^ eii_expansions, InstName,
+ Expansions) },
+ mercury_format_inst(Inst,
+ ExpandedInstInfo ^ eii_expansions := Expansions)
+ ).
+
+
+mercury_output_expanded_inst(Inst, VarSet, ModuleInfo) -->
+ { set__init(Expansions) },
+ mercury_format_inst(Inst,
+ expanded_inst_info(VarSet, ModuleInfo, Expansions)).
+
+mercury_expanded_inst_to_string(Inst, VarSet, ModuleInfo) = String :-
+ set__init(Expansions),
+ mercury_format_inst(Inst,
+ expanded_inst_info(VarSet, ModuleInfo, Expansions),
+ "", String).
+
mercury_output_inst(Inst, VarSet) -->
- mercury_format_inst(Inst, VarSet).
+ mercury_format_inst(Inst, simple_inst_info(VarSet)).
mercury_inst_to_string(Inst, VarSet) = String :-
- mercury_format_inst(Inst, VarSet, "", String).
+ mercury_format_inst(Inst, simple_inst_info(VarSet), "", String).
-:- pred mercury_format_inst((inst)::in, inst_varset::in,
- U::di, U::uo) is det <= output(U).
+:- pred mercury_format_inst((inst)::in, InstInfo::in,
+ U::di, U::uo) is det <= (output(U), inst_info(InstInfo)).
mercury_format_inst(any(Uniq), _) -->
mercury_format_any_uniqueness(Uniq).
@@ -1070,12 +1168,12 @@
add_string("free").
mercury_format_inst(free(_T), _) -->
add_string("free(with some type)").
-mercury_format_inst(bound(Uniq, BoundInsts), VarSet) -->
+mercury_format_inst(bound(Uniq, BoundInsts), InstInfo) -->
mercury_format_uniqueness(Uniq, "bound"),
add_string("("),
- mercury_format_bound_insts(BoundInsts, VarSet),
+ mercury_format_bound_insts(BoundInsts, InstInfo),
add_string(")").
-mercury_format_inst(ground(Uniq, GroundInstInfo), VarSet) -->
+mercury_format_inst(ground(Uniq, GroundInstInfo), InstInfo) -->
(
{ GroundInstInfo = higher_order(pred_inst_info(PredOrFunc,
Modes, Det)) },
@@ -1094,7 +1192,7 @@
add_string(")")
;
add_string("(pred("),
- mercury_format_mode_list(Modes, VarSet),
+ mercury_format_mode_list(Modes, InstInfo),
add_string(") is "),
mercury_format_det(Det),
add_string(")")
@@ -1106,11 +1204,11 @@
add_string("((func)")
;
add_string("(func("),
- mercury_format_mode_list(ArgModes, VarSet),
+ mercury_format_mode_list(ArgModes, InstInfo),
add_string(")")
),
add_string(" = "),
- mercury_format_mode(RetMode, VarSet),
+ mercury_format_mode(RetMode, InstInfo),
add_string(" is "),
mercury_format_det(Det),
add_string(")")
@@ -1119,14 +1217,14 @@
{ GroundInstInfo = none },
mercury_format_uniqueness(Uniq, "ground")
).
-mercury_format_inst(inst_var(Var), VarSet) -->
- mercury_format_var(Var, VarSet, no).
-mercury_format_inst(constrained_inst_vars(Vars, Inst), VarSet) -->
- mercury_format_constrained_inst_vars(Vars, Inst, VarSet).
-mercury_format_inst(abstract_inst(Name, Args), VarSet) -->
- mercury_format_inst_name(user_inst(Name, Args), VarSet).
-mercury_format_inst(defined_inst(InstName), VarSet) -->
- mercury_format_inst_name(InstName, VarSet).
+mercury_format_inst(inst_var(Var), InstInfo) -->
+ mercury_format_var(Var, InstInfo ^ instvarset, no).
+mercury_format_inst(constrained_inst_vars(Vars, Inst), InstInfo) -->
+ mercury_format_constrained_inst_vars(Vars, Inst, InstInfo).
+mercury_format_inst(abstract_inst(Name, Args), InstInfo) -->
+ mercury_format_inst_name(user_inst(Name, Args), InstInfo).
+mercury_format_inst(defined_inst(InstName), InstInfo) -->
+ format_defined_inst(InstName, InstInfo).
mercury_format_inst(not_reached, _) -->
add_string("not_reached").
@@ -1248,47 +1346,49 @@
mercury_format_tabs(Indent),
add_string(")\n").
-:- pred mercury_format_inst_name(inst_name::in, inst_varset::in,
- U::di, U::uo) is det <= output(U).
+:- pred mercury_format_inst_name(inst_name::in, InstInfo::in,
+ U::di, U::uo) is det <= (output(U), inst_info(InstInfo)).
-mercury_format_inst_name(user_inst(Name, Args), VarSet) -->
+mercury_format_inst_name(user_inst(Name, Args), InstInfo) -->
( { Args = [] } ->
mercury_format_bracketed_sym_name(Name)
;
mercury_format_sym_name(Name),
add_string("("),
- mercury_format_inst_list(Args, VarSet),
+ mercury_format_inst_list(Args, InstInfo),
add_string(")")
).
-mercury_format_inst_name(merge_inst(InstA, InstB), VarSet) -->
+mercury_format_inst_name(merge_inst(InstA, InstB), InstInfo) -->
add_string("$merge_inst("),
- mercury_format_inst_list([InstA, InstB], VarSet),
+ mercury_format_inst_list([InstA, InstB], InstInfo),
add_string(")").
-mercury_format_inst_name(shared_inst(InstName), VarSet) -->
+mercury_format_inst_name(shared_inst(InstName), InstInfo) -->
add_string("$shared_inst("),
- mercury_format_inst_name(InstName, VarSet),
+ mercury_format_inst_name(InstName, InstInfo),
add_string(")").
-mercury_format_inst_name(mostly_uniq_inst(InstName), VarSet) -->
+mercury_format_inst_name(mostly_uniq_inst(InstName), InstInfo) -->
add_string("$mostly_uniq_inst("),
- mercury_format_inst_name(InstName, VarSet),
+ mercury_format_inst_name(InstName, InstInfo),
add_string(")").
-mercury_format_inst_name(unify_inst(Liveness, InstA, InstB, Real), VarSet) -->
+mercury_format_inst_name(unify_inst(Liveness, InstA, InstB, Real),
+ InstInfo) -->
add_string("$unify("),
( { Liveness = live } ->
add_string("live, ")
;
add_string("dead, ")
),
- mercury_format_inst_list([InstA, InstB], VarSet),
+ mercury_format_inst_list([InstA, InstB], InstInfo),
( { Real = real_unify } ->
add_string(", real")
;
add_string(", fake")
),
add_string(")").
-mercury_format_inst_name(ground_inst(InstName, IsLive, Uniq, Real), VarSet) -->
+mercury_format_inst_name(ground_inst(InstName, IsLive, Uniq, Real),
+ InstInfo) -->
add_string("$ground("),
- mercury_format_inst_name(InstName, VarSet),
+ mercury_format_inst_name(InstName, InstInfo),
add_string(", "),
( { IsLive = live } ->
add_string("live, ")
@@ -1302,9 +1402,9 @@
add_string(", fake")
),
add_string(")").
-mercury_format_inst_name(any_inst(InstName, IsLive, Uniq, Real), VarSet) -->
+mercury_format_inst_name(any_inst(InstName, IsLive, Uniq, Real), InstInfo) -->
add_string("$any("),
- mercury_format_inst_name(InstName, VarSet),
+ mercury_format_inst_name(InstName, InstInfo),
add_string(", "),
( { IsLive = live } ->
add_string("live, ")
@@ -1318,19 +1418,19 @@
add_string(", fake")
),
add_string(")").
-mercury_format_inst_name(typed_ground(Uniqueness, Type), _VarSet) -->
+mercury_format_inst_name(typed_ground(Uniqueness, Type), _InstInfo) -->
add_string("$typed_ground("),
mercury_format_uniqueness(Uniqueness, "shared"),
add_string(", "),
{ varset__init(TypeVarSet) },
mercury_format_term(Type, TypeVarSet, no),
add_string(")").
-mercury_format_inst_name(typed_inst(Type, InstName), VarSet) -->
+mercury_format_inst_name(typed_inst(Type, InstName), InstInfo) -->
add_string("$typed_inst("),
{ varset__init(TypeVarSet) },
mercury_format_term(Type, TypeVarSet, no),
add_string(", "),
- mercury_format_inst_name(InstName, VarSet),
+ mercury_format_inst_name(InstName, InstInfo),
add_string(")").
:- pred mercury_format_uniqueness(uniqueness::in, string::in,
@@ -1390,24 +1490,24 @@
VarSet)
).
-:- pred mercury_format_bound_insts(list(bound_inst)::in, inst_varset::in,
- U::di, U::uo) is det <= output(U).
+:- pred mercury_format_bound_insts(list(bound_inst)::in, InstInfo::in,
+ U::di, U::uo) is det <= (output(U), inst_info(InstInfo)).
mercury_format_bound_insts([], _) --> [].
-mercury_format_bound_insts([functor(ConsId, Args) | BoundInsts], VarSet) -->
+mercury_format_bound_insts([functor(ConsId, Args) | BoundInsts], InstInfo) -->
( { Args = [] } ->
mercury_format_cons_id(ConsId, needs_brackets)
;
mercury_format_cons_id(ConsId, does_not_need_brackets),
add_string("("),
- mercury_format_inst_list(Args, VarSet),
+ mercury_format_inst_list(Args, InstInfo),
add_string(")")
),
( { BoundInsts = [] } ->
[]
;
add_string(" ; "),
- mercury_format_bound_insts(BoundInsts, VarSet)
+ mercury_format_bound_insts(BoundInsts, InstInfo)
).
mercury_output_cons_id(ConsId, NeedsBrackets) -->
@@ -1480,17 +1580,18 @@
add_string("<table_io_decl>").
:- pred mercury_format_constrained_inst_vars(set(inst_var)::in, (inst)::in,
- inst_varset::in, U::di, U::uo) is det <= output(U).
+ InstInfo::in, U::di, U::uo) is det
+ <= (output(U), inst_info(InstInfo)).
-mercury_format_constrained_inst_vars(Vars0, Inst, VarSet) -->
+mercury_format_constrained_inst_vars(Vars0, Inst, InstInfo) -->
( { set__remove_least(Vars0, Var, Vars1) } ->
add_string("("),
- mercury_format_var(Var, VarSet, no),
+ mercury_format_var(Var, InstInfo ^ instvarset, no),
add_string(" =< "),
- mercury_format_constrained_inst_vars(Vars1, Inst, VarSet),
+ mercury_format_constrained_inst_vars(Vars1, Inst, InstInfo),
add_string(")")
;
- mercury_format_inst(Inst, VarSet)
+ mercury_format_inst(Inst, InstInfo)
).
:- pred mercury_format_mode_defn(inst_varset::in, sym_name::in,
@@ -1503,26 +1604,26 @@
{ construct_qualified_term(Name, ArgTerms, Context, ModeTerm) },
mercury_format_term(ModeTerm, VarSet, no),
add_string(") :: "),
- mercury_format_mode(Mode, VarSet),
+ mercury_format_mode(Mode, simple_inst_info(VarSet)),
add_string(".\n").
mercury_output_mode_list(Modes, VarSet) -->
- mercury_format_mode_list(Modes, VarSet).
+ mercury_format_mode_list(Modes, simple_inst_info(VarSet)).
mercury_mode_list_to_string(Modes, VarSet) = String :-
- mercury_format_mode_list(Modes, VarSet, "", String).
+ mercury_format_mode_list(Modes, simple_inst_info(VarSet), "", String).
-:- pred mercury_format_mode_list(list(mode)::in, inst_varset::in,
- U::di, U::uo) is det <= output(U).
+:- pred mercury_format_mode_list(list(mode)::in, InstInfo::in,
+ U::di, U::uo) is det <= (output(U), inst_info(InstInfo)).
-mercury_format_mode_list([], _VarSet) --> [].
-mercury_format_mode_list([Mode | Modes], VarSet) -->
- mercury_format_mode(Mode, VarSet),
+mercury_format_mode_list([], _InstInfo) --> [].
+mercury_format_mode_list([Mode | Modes], InstInfo) -->
+ mercury_format_mode(Mode, InstInfo),
( { Modes = [] } ->
[]
;
add_string(", "),
- mercury_format_mode_list(Modes, VarSet)
+ mercury_format_mode_list(Modes, InstInfo)
).
mercury_output_uni_mode_list(UniModes, VarSet) -->
@@ -1554,20 +1655,20 @@
U::di, U::uo) is det <= output(U).
mercury_format_uni_mode((InstA1 - InstB1 -> InstA2 - InstB2), VarSet) -->
- mercury_format_mode((InstA1 -> InstA2), VarSet),
+ mercury_format_mode((InstA1 -> InstA2), simple_inst_info(VarSet)),
add_string(" = "),
- mercury_format_mode((InstB1 -> InstB2), VarSet).
+ mercury_format_mode((InstB1 -> InstB2), simple_inst_info(VarSet)).
mercury_output_mode(Mode, VarSet) -->
- mercury_format_mode(Mode, VarSet).
+ mercury_format_mode(Mode, simple_inst_info(VarSet)).
mercury_mode_to_string(Mode, VarSet) = String :-
- mercury_format_mode(Mode, VarSet, "", String).
+ mercury_format_mode(Mode, simple_inst_info(VarSet), "", String).
-:- pred mercury_format_mode((mode)::in, inst_varset::in,
- U::di, U::uo) is det <= output(U).
+:- pred mercury_format_mode((mode)::in, InstInfo::in,
+ U::di, U::uo) is det <= (output(U), inst_info(InstInfo)).
-mercury_format_mode((InstA -> InstB), VarSet) -->
+mercury_format_mode((InstA -> InstB), InstInfo) -->
(
%
% check for higher-order pred or func modes, and output them
@@ -1577,21 +1678,21 @@
_Modes, _Det))) },
{ InstB = InstA }
->
- mercury_format_inst(InstA, VarSet)
+ mercury_format_inst(InstA, InstInfo)
;
add_string("("),
- mercury_format_inst(InstA, VarSet),
+ mercury_format_inst(InstA, InstInfo),
add_string(" -> "),
- mercury_format_inst(InstB, VarSet),
+ mercury_format_inst(InstB, InstInfo),
add_string(")")
).
-mercury_format_mode(user_defined_mode(Name, Args), VarSet) -->
+mercury_format_mode(user_defined_mode(Name, Args), InstInfo) -->
( { Args = [] } ->
mercury_format_bracketed_sym_name(Name)
;
mercury_format_sym_name(Name),
add_string("("),
- mercury_format_inst_list(Args, VarSet),
+ mercury_format_inst_list(Args, InstInfo),
add_string(")")
).
@@ -2175,7 +2276,7 @@
{ Modes = [_|_] },
mercury_format_sym_name(PredName),
add_string("("),
- mercury_format_mode_list(Modes, VarSet),
+ mercury_format_mode_list(Modes, simple_inst_info(VarSet)),
add_string(")")
;
{ Modes = [] },
@@ -2184,7 +2285,7 @@
(
{ MaybeWithInst = yes(WithInst) },
add_string(" `with_inst` ("),
- mercury_format_inst(WithInst, VarSet),
+ mercury_format_inst(WithInst, simple_inst_info(VarSet)),
add_string(")")
;
{ MaybeWithInst = no }
@@ -2235,14 +2336,14 @@
{ Modes = [_|_] },
mercury_format_sym_name(FuncName),
add_string("("),
- mercury_format_mode_list(Modes, VarSet),
+ mercury_format_mode_list(Modes, simple_inst_info(VarSet)),
add_string(")")
;
{ Modes = [] },
mercury_format_bracketed_sym_name(FuncName)
),
add_string(" = "),
- mercury_format_mode(RetMode, VarSet),
+ mercury_format_mode(RetMode, simple_inst_info(VarSet)),
mercury_format_det_annotation(MaybeDet).
:- pred mercury_format_det_annotation(maybe(determinism)::in, U::di, U::uo)
@@ -2884,7 +2985,7 @@
add_string(" :: "),
% XXX Fake the inst varset
{ varset__init(InstVarSet) },
- mercury_format_mode(Mode, InstVarSet),
+ mercury_format_mode(Mode, simple_inst_info(InstVarSet)),
( { Vars = [] } ->
[]
;
@@ -3013,19 +3114,20 @@
mercury_format_pragma_import(Name, PredOrFunc, ModeList, Attributes,
C_Function) -->
{ varset__init(Varset) }, % the varset isn't really used.
+ { InstInfo = simple_inst_info(Varset) },
add_string(":- pragma import("),
mercury_format_sym_name(Name),
(
{ PredOrFunc = function },
{ pred_args_to_func_args(ModeList, ArgModes, RetMode) },
add_string("("),
- mercury_format_mode_list(ArgModes, Varset),
+ mercury_format_mode_list(ArgModes, InstInfo),
add_string(") = "),
- mercury_format_mode(RetMode, Varset)
+ mercury_format_mode(RetMode, InstInfo)
;
{ PredOrFunc = predicate },
add_string("("),
- mercury_format_mode_list(ModeList, Varset),
+ mercury_format_mode_list(ModeList, InstInfo),
add_string(")")
),
add_string(", "),
@@ -3040,19 +3142,20 @@
mercury_format_pragma_export(Name, PredOrFunc, ModeList, C_Function) -->
{ varset__init(Varset) }, % the varset isn't really used.
+ { InstInfo = simple_inst_info(Varset) },
add_string(":- pragma export("),
mercury_format_sym_name(Name),
(
{ PredOrFunc = function },
{ pred_args_to_func_args(ModeList, ArgModes, RetMode) },
add_string("("),
- mercury_format_mode_list(ArgModes, Varset),
+ mercury_format_mode_list(ArgModes, InstInfo),
add_string(") = "),
- mercury_format_mode(RetMode, Varset)
+ mercury_format_mode(RetMode, InstInfo)
;
{ PredOrFunc = predicate },
add_string("("),
- mercury_format_mode_list(ModeList, Varset),
+ mercury_format_mode_list(ModeList, InstInfo),
add_string(")")
),
add_string(", "),
Index: compiler/mode_errors.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_errors.m,v
retrieving revision 1.72
diff -u -d -r1.72 mode_errors.m
--- compiler/mode_errors.m 20 Mar 2002 12:36:53 -0000 1.72
+++ compiler/mode_errors.m 9 Aug 2002 11:45:12 -0000
@@ -406,12 +406,11 @@
write_merge_error_list([Var - Insts | Errors], ModeInfo) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
prog_out__write_context(Context),
io__write_string(" `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' :: "),
- output_inst_list(Insts, InstVarSet),
+ output_inst_list(Insts, ModeInfo),
io__write_string(".\n"),
write_merge_error_list(Errors, ModeInfo).
@@ -432,7 +431,6 @@
report_mode_error_bind_var(ModeInfo, Reason, Var, VarInst, Inst) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" scope error: "),
@@ -456,11 +454,11 @@
io__write_string(" Variable `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" expected instantiatedness was `"),
- output_inst(Inst, InstVarSet),
+ output_inst(Inst, ModeInfo),
io__write_string("'.\n"),
globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
( { VerboseErrors = yes } ->
@@ -493,13 +491,12 @@
report_mode_error_non_local_lambda_var(ModeInfo, Var, VarInst) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error: variable `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" expected instantiatedness for non-local variables\n"),
@@ -519,7 +516,6 @@
{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error: arguments `"),
@@ -527,7 +523,7 @@
io__write_string("'\n"),
prog_out__write_context(Context),
io__write_string(" have insts `"),
- output_inst_list(Insts, InstVarSet),
+ output_inst_list(Insts, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" which does not match any of the valid modes for\n"),
@@ -563,7 +559,6 @@
report_mode_error_no_matching_mode(ModeInfo, Vars, Insts) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error: arguments `"),
@@ -571,7 +566,7 @@
io__write_string("'\n"),
prog_out__write_context(Context),
io__write_string(" have insts `"),
- output_inst_list(Insts, InstVarSet),
+ output_inst_list(Insts, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" which does not match any of the modes for "),
@@ -592,13 +587,12 @@
Arity) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error: variable `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
( { PredOrFunc = predicate },
@@ -618,7 +612,6 @@
report_mode_error_poly_unify(ModeInfo, Var, VarInst) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" in polymorphically-typed unification:\n"),
@@ -626,7 +619,7 @@
io__write_string(" mode error: variable `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(
@@ -664,17 +657,16 @@
report_mode_error_var_has_inst(ModeInfo, Var, VarInst, Inst) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error: variable `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" expected instantiatedness was `"),
- output_inst(Inst, InstVarSet),
+ output_inst(Inst, ModeInfo),
io__write_string("'.\n").
:- pred report_mode_error_implied_mode(mode_info, prog_var, inst, inst,
@@ -689,7 +681,6 @@
( { ErrorcheckOnly = no } ->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" sorry, implied modes not implemented.\n"),
@@ -697,11 +688,11 @@
io__write_string(" Variable `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" expected instantiatedness was `"),
- output_inst(Inst, InstVarSet),
+ output_inst(Inst, ModeInfo),
io__write_string("'.\n")
;
[]
@@ -782,7 +773,6 @@
report_mode_error_unify_var_var(ModeInfo, X, Y, InstX, InstY) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error in unification of `"),
@@ -794,13 +784,13 @@
io__write_string(" Variable `"),
mercury_output_var(X, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(InstX, InstVarSet),
+ output_inst(InstX, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" variable `"),
mercury_output_var(Y, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(InstY, InstVarSet),
+ output_inst(InstY, ModeInfo),
io__write_string("'.\n").
%-----------------------------------------------------------------------------%
@@ -813,7 +803,6 @@
report_mode_error_unify_var_lambda(ModeInfo, X, InstX, InstY) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error in unification of `"),
@@ -823,11 +812,11 @@
io__write_string(" Variable `"),
mercury_output_var(X, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(InstX, InstVarSet),
+ output_inst(InstX, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" lambda expression has instantiatedness `"),
- output_inst(InstY, InstVarSet),
+ output_inst(InstY, ModeInfo),
io__write_string("'.\n").
%-----------------------------------------------------------------------------%
@@ -841,7 +830,6 @@
-->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
@@ -854,7 +842,7 @@
io__write_string(" Variable `"),
mercury_output_var(X, VarSet, no),
io__write_string("' has instantiatedness `"),
- output_inst(InstX, InstVarSet),
+ output_inst(InstX, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" term `"),
@@ -865,7 +853,7 @@
io__write_string(" has instantiatedness `"),
mercury_output_cons_id(ConsId, does_not_need_brackets),
io__write_string("("),
- output_inst_list(ArgInsts, InstVarSet),
+ output_inst_list(ArgInsts, ModeInfo),
io__write_string(")")
;
io__write_string("' has instantiatedness `"),
@@ -912,7 +900,6 @@
report_mode_error_final_inst(ModeInfo, ArgNum, Var, VarInst, Inst, Reason) -->
{ mode_info_get_context(ModeInfo, Context) },
{ mode_info_get_varset(ModeInfo, VarSet) },
- { mode_info_get_instvarset(ModeInfo, InstVarSet) },
mode_info_write_context(ModeInfo),
prog_out__write_context(Context),
io__write_string(" mode error: argument "),
@@ -931,12 +918,12 @@
io__write_string(" Final instantiatedness of `"),
mercury_output_var(Var, VarSet, no),
io__write_string("' was `"),
- output_inst(VarInst, InstVarSet),
+ output_inst(VarInst, ModeInfo),
io__write_string("',\n"),
prog_out__write_context(Context),
io__write_string(" expected final instantiatedness was `"),
- output_inst(Inst, InstVarSet),
+ output_inst(Inst, ModeInfo),
io__write_string("'.\n").
@@ -1137,19 +1124,27 @@
%-----------------------------------------------------------------------------%
-:- pred output_inst((inst), inst_varset, io__state, io__state).
-:- mode output_inst(in, in, di, uo) is det.
+:- pred output_inst((inst), mode_info, io__state, io__state).
+:- mode output_inst(in, mode_info_ui, di, uo) is det.
-output_inst(Inst0, VarSet) -->
+output_inst(Inst0, ModeInfo) -->
{ strip_builtin_qualifiers_from_inst(Inst0, Inst) },
- mercury_output_inst(Inst, VarSet).
+ { mode_info_get_instvarset(ModeInfo, InstVarSet) },
+ { mode_info_get_module_info(ModeInfo, ModuleInfo) },
+ mercury_output_expanded_inst(Inst, InstVarSet, ModuleInfo).
-:- pred output_inst_list(list(inst), inst_varset, io__state, io__state).
+:- pred output_inst_list(list(inst), mode_info, io__state, io__state).
:- mode output_inst_list(in, in, di, uo) is det.
-output_inst_list(Insts0, VarSet) -->
- { strip_builtin_qualifiers_from_inst_list(Insts0, Insts) },
- mercury_output_inst_list(Insts, VarSet).
+output_inst_list([], _) --> [].
+output_inst_list([Inst | Insts], ModeInfo) -->
+ output_inst(Inst, ModeInfo),
+ ( { Insts = [] } ->
+ []
+ ;
+ io__write_string(", "),
+ output_inst_list(Insts, ModeInfo)
+ ).
%-----------------------------------------------------------------------------%
Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.145
diff -u -d -r1.145 mode_util.m
--- compiler/mode_util.m 30 Jun 2002 17:06:31 -0000 1.145
+++ compiler/mode_util.m 9 Aug 2002 14:02:37 -0000
@@ -1732,9 +1732,8 @@
strip_builtin_qualifiers_from_inst(bound(Uniq, BoundInsts0),
bound(Uniq, BoundInsts)) :-
strip_builtin_qualifiers_from_bound_inst_list(BoundInsts0, BoundInsts).
-strip_builtin_qualifiers_from_inst(defined_inst(Name0), Inst) :-
- strip_builtin_qualifiers_from_inst_name(Name0,
- defined_inst(Name0), Inst).
+strip_builtin_qualifiers_from_inst(defined_inst(Name0), defined_inst(Name)) :-
+ strip_builtin_qualifiers_from_inst_name(Name0, Name).
strip_builtin_qualifiers_from_inst(abstract_inst(Name0, Args0),
abstract_inst(Name, Args)) :-
strip_builtin_qualifier_from_sym_name(Name0, Name),
@@ -1754,24 +1753,40 @@
BoundInst = functor(ConsId, Insts),
list__map(strip_builtin_qualifiers_from_inst, Insts0, Insts).
-:- pred strip_builtin_qualifiers_from_inst_name(inst_name::in, (inst)::in,
- (inst)::out) is det.
+:- pred strip_builtin_qualifiers_from_inst_name(inst_name::in, inst_name::out)
+ is det.
-strip_builtin_qualifiers_from_inst_name(InstName0, Inst0, Inst) :-
- ( InstName0 = user_inst(SymName0, Insts0) ->
- strip_builtin_qualifier_from_sym_name(SymName0, SymName),
- strip_builtin_qualifiers_from_inst_list(Insts0, Insts),
- Inst = defined_inst(user_inst(SymName, Insts))
- ; InstName0 = typed_inst(_, InstName1) ->
- % Don't output the $typed_inst in error messages.
- strip_builtin_qualifiers_from_inst_name(InstName1, Inst0, Inst)
- ; InstName0 = typed_ground(Uniq, _Type) ->
- % Don't output the $typed_ground in error messages.
- Inst = ground(Uniq, none)
- ;
- % for the compiler-generated insts, don't bother.
- Inst = Inst0
- ).
+strip_builtin_qualifiers_from_inst_name(user_inst(SymName0, Insts0),
+ user_inst(SymName, Insts)) :-
+ strip_builtin_qualifier_from_sym_name(SymName0, SymName),
+ strip_builtin_qualifiers_from_inst_list(Insts0, Insts).
+strip_builtin_qualifiers_from_inst_name(merge_inst(InstA0, InstB0),
+ merge_inst(InstA, InstB)) :-
+ strip_builtin_qualifiers_from_inst(InstA0, InstA),
+ strip_builtin_qualifiers_from_inst(InstB0, InstB).
+strip_builtin_qualifiers_from_inst_name(unify_inst(Live, InstA0, InstB0, Real),
+ unify_inst(Live, InstA, InstB, Real)) :-
+ strip_builtin_qualifiers_from_inst(InstA0, InstA),
+ strip_builtin_qualifiers_from_inst(InstB0, InstB).
+strip_builtin_qualifiers_from_inst_name(
+ ground_inst(InstName0, Live, Uniq, Real),
+ ground_inst(InstName, Live, Uniq, Real)) :-
+ strip_builtin_qualifiers_from_inst_name(InstName0, InstName).
+strip_builtin_qualifiers_from_inst_name(
+ any_inst(InstName0, Live, Uniq, Real),
+ any_inst(InstName, Live, Uniq, Real)) :-
+ strip_builtin_qualifiers_from_inst_name(InstName0, InstName).
+strip_builtin_qualifiers_from_inst_name(shared_inst(InstName0),
+ shared_inst(InstName)) :-
+ strip_builtin_qualifiers_from_inst_name(InstName0, InstName).
+strip_builtin_qualifiers_from_inst_name(mostly_uniq_inst(InstName0),
+ mostly_uniq_inst(InstName)) :-
+ strip_builtin_qualifiers_from_inst_name(InstName0, InstName).
+strip_builtin_qualifiers_from_inst_name(typed_ground(Uniq, Type),
+ typed_ground(Uniq, Type)).
+strip_builtin_qualifiers_from_inst_name(typed_inst(Type, InstName0),
+ typed_inst(Type, InstName)) :-
+ strip_builtin_qualifiers_from_inst_name(InstName0, InstName).
:- pred strip_builtin_qualifiers_from_ground_inst_info(ground_inst_info::in,
ground_inst_info::out) is det.
Index: tests/invalid/merge_ground_any.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/merge_ground_any.err_exp,v
retrieving revision 1.2
diff -u -d -r1.2 merge_ground_any.err_exp
--- tests/invalid/merge_ground_any.err_exp 21 Jun 2002 16:47:35 -0000 1.2
+++ tests/invalid/merge_ground_any.err_exp 9 Aug 2002 14:07:08 -0000
@@ -1,5 +1,5 @@
merge_ground_any.m:013: In clause for `pass(in, in(merge_ground_any:hpair(ground, any)), out(merge_ground_any:hpair(ground, any)))':
merge_ground_any.m:013: mode error: argument 5 did not get sufficiently instantiated.
merge_ground_any.m:013: Final instantiatedness of `X' was `bound(merge_ground_any:'+'(ground, ground) ; merge_ground_any:'-'(ground, any))',
-merge_ground_any.m:013: expected final instantiatedness was `merge_ground_any:hpair(ground, any)'.
+merge_ground_any.m:013: expected final instantiatedness was `bound(merge_ground_any:'-'(ground, any))'.
For more information, try recompiling with `-E'.
Index: tests/invalid/polymorphic_unification.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/polymorphic_unification.err_exp,v
retrieving revision 1.5
diff -u -d -r1.5 polymorphic_unification.err_exp
--- tests/invalid/polymorphic_unification.err_exp 21 Jun 2002 16:47:36 -0000 1.5
+++ tests/invalid/polymorphic_unification.err_exp 9 Aug 2002 14:06:56 -0000
@@ -1,5 +1,5 @@
polymorphic_unification.m:019: In clause for `p(in, ((list:list_skel) -> dead))':
polymorphic_unification.m:019: in polymorphically-typed unification:
-polymorphic_unification.m:019: mode error: variable `X' has instantiatedness `(list:list_skel)',
+polymorphic_unification.m:019: mode error: variable `X' has instantiatedness `bound([] ; '[|]'(free, list:list_skel(free)))',
polymorphic_unification.m:019: expected instantiatedness was `ground' or `any'.
For more information, try recompiling with `-E'.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list