[m-rev.] for review: printing higher order values and typeinfos in the debugger
Zoltan Somogyi
zs at cs.mu.OZ.AU
Fri Feb 22 18:47:18 AEDT 2002
On 22-Feb-2002, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> I will send a relative diff addressing these issues, and the others you
> raised, later today.
Here is the relative diff, together with a diff of the log message.
Zoltan.
--- OldLog Fri Feb 22 18:41:54 2002
+++ Log Fri Feb 22 18:46:07 2002
@@ -1,3 +1,4 @@
+
Estimated hours taken: 48
Branches: main
@@ -11,6 +12,14 @@
"print_optionals", that toggles the printing of optional values. For now,
the only optional values are typeinfos.
+NEWS:
+ Mention the new capability and the new predicates in the library.
+
+ Mention the predicates added previously that allow the caller to
+ specify how non-canonical terms should be handled, since the change
+ in their semantics that we anticipated when they were added has now
+ happened, and their semantics should now be more stable.
+
browser/browser_info.m:
Use the predicates in the deconstruct.m instead of std_util,
to make the choice of noncanonical term method handling explicit.
@@ -40,6 +49,12 @@
ordinary terms, with the function symbol being the name of the type
constructor and the arguments being the type constructor's arguments.
+runtime/mercury_type_info.[ch]:
+ Add a new function, MR_collapse_ctor_equivalences, for use by
+ mercury_ml_expand_body.h.
+
+ Delete a redundant function comment.
+
library/deconstruct.m:
Document the changes in the behavior of the predicates defined in this
module as a result of the change to mercury_ml_expand_body.h.
@@ -84,10 +99,14 @@
Pass the new parameter of MR_trace_browse_all_on_level.
trace/mercury_trace_internal.c:
- Implement the "print_optionals" command.
+ Implement the "print_optionals" command, and document both it
+ and the "proc_stats" command whose documentation was omitted.
doc/user_guide.texi:
- Document the "print_optionals" command.
+ Document the "print_optionals" and "proc_stats" command.
+
+tests/debugger/mdb_command_test.inp:
+ Test the documentation of "print_optionals" and "proc_stats".
tests/debugger/higher_order.{m,inp,exp,exp2}:
A new test case to exercise the ability to print higher order values.
diff -u browser/browse.m browser/browse.m
--- browser/browse.m 21 Feb 2002 12:57:00 -0000
+++ browser/browse.m 22 Feb 2002 04:41:30 -0000
@@ -533,10 +533,8 @@
[]
;
io__write_string("("),
- io__write_list(Args, ", ",
- pred(U::in, S0::di, S::uo) is cc_multi :-
- io__write_univ(Stream, include_details_cc, U,
- S0, S)),
+ io__write_list(Args, ", ", pred(U::in, di, uo) is cc_multi -->
+ io__write_univ(Stream, include_details_cc, U)),
io__write_string(")")
),
(
diff -u compiler/pd_debug.m compiler/pd_debug.m
--- compiler/pd_debug.m 21 Feb 2002 13:26:28 -0000
+++ compiler/pd_debug.m 22 Feb 2002 04:42:42 -0000
@@ -161,11 +161,9 @@
pd_debug__write_pred_proc_id_list(PredProcIds) -->
pd_info_get_module_info(ModuleInfo),
- pd_debug__do_io(
- pred(S0::di, S::uo) is det :-
+ pd_debug__do_io(pred(di, uo) is det -->
io__write_list(PredProcIds, ", ",
- pd_debug__write_pred_proc_id(ModuleInfo),
- S0, S)
+ pd_debug__write_pred_proc_id(ModuleInfo))
).
:- pred pd_debug__write_pred_proc_id(module_info::in, pred_proc_id::in,
diff -u compiler/rl_analyse.m compiler/rl_analyse.m
--- compiler/rl_analyse.m 21 Feb 2002 13:29:12 -0000
+++ compiler/rl_analyse.m 22 Feb 2002 04:44:17 -0000
@@ -241,12 +241,10 @@
io__state::di, io__state::uo) is det.
rl_analyse__dump_block_data_map(Analysis, Blocks, BlockDataMap, Globals) -->
- rl_analyse__do_io(
- pred(S0::di, S::uo) is det :-
+ rl_analyse__do_io(pred(di, uo) is det -->
io__write_list(Blocks, "\n",
rl_analyse__dump_block_data(Analysis,
- BlockDataMap, Globals),
- S0, S)
+ BlockDataMap, Globals))
).
:- pred rl_analyse__dump_block_data(rl_analysis(T, U, V)::rl_analysis,
diff -u library/deconstruct.m library/deconstruct.m
--- library/deconstruct.m 21 Feb 2002 15:36:46 -0000
+++ library/deconstruct.m 22 Feb 2002 05:12:09 -0000
@@ -55,7 +55,8 @@
% the [....] shorthand.
% - for user-defined types with user-defined equality, the
% functor will be of the form <<module:type/arity>>/0, except
- % with include_details_cc.
+ % with include_details_cc, in which case the type will be
+ % handled as if it had standard equality.
% - for integers, the string is a base 10 number;
% positive integers have no sign.
% - for floats, the string is a floating point, base 10 number;
@@ -63,7 +64,10 @@
% - for strings, the string, inside double quotation marks
% - for characters, the character inside single quotation marks
% - for predicates, the string <<predicate>>, and for functions,
- % the string <<function>>, except with include_details_cc.
+ % the string <<function>>, except with include_details_cc,
+ % in which case it will be the predicate or function name.
+ % (The predicate or function name will be artificial for
+ % predicate and function values created by lambda expressions.)
% - for tuples, the string {}.
% - for arrays, the string <<array>>.
%
@@ -72,13 +76,15 @@
% - for user defined types with standard equality, the arity
% of the functor.
% - for user defined types with user-defined equality, zero,
- % except with include_details_cc.
+ % except with include_details_cc, in which case the type
+ % will be handled as if it had standard equality.
% - for integers, zero.
% - for floats, zero.
% - for strings, zero.
% - for characters, zero.
% - for predicates and functions, zero, except with
- % include_details_cc.
+ % include_details_cc, in which case it will be the number of
+ % arguments hidden in the closure.
% - for tuples, the number of elements in the tuple.
% - for arrays, the number of elements in the array.
diff -u runtime/mercury_ml_expand_body.h runtime/mercury_ml_expand_body.h
--- runtime/mercury_ml_expand_body.h 21 Feb 2002 06:36:21 -0000
+++ runtime/mercury_ml_expand_body.h 22 Feb 2002 07:33:41 -0000
@@ -874,22 +874,29 @@
break;
case MR_TYPECTOR_REP_TYPEINFO:
+ {
+ MR_TypeInfo data_type_info;
+ MR_TypeCtorInfo data_type_ctor_info;
+ MR_Word *arg_type_infos;
+ int num_args;
+
if (noncanon == MR_NONCANON_ABORT) {
/* XXX should throw an exception */
MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
": attempt to deconstruct noncanonical term");
- } else if (noncanon == MR_NONCANON_ALLOW) {
- handle_functor_name("<<typeinfo>>");
- handle_zero_arity_args();
- } else {
- /* the noncanonicality is due to type equivalences */
+ }
- MR_TypeInfo data_type_info;
- MR_TypeCtorInfo data_type_ctor_info;
- MR_Word *arg_type_infos;
- int num_args;
+ /*
+ ** The only source of noncanonicality in typeinfos is due
+ ** to type equivalences, so we can eliminate noncanonicality
+ ** by expanding out equivalences.
+ */
data_type_info = (MR_TypeInfo) *data_word_ptr;
+ if (noncanon == MR_NONCANON_ALLOW) {
+ data_type_info = MR_collapse_equivalences(data_type_info);
+ }
+
data_type_ctor_info =
MR_TYPEINFO_GET_TYPE_CTOR_INFO(data_type_info);
handle_functor_name(MR_type_ctor_name(data_type_ctor_info));
@@ -941,7 +948,7 @@
if (0 <= chosen && chosen < expand_info->arity) {
MR_Word *arg_vector;
- arg_vector = (MR_Word *) *data_word_ptr;
+ arg_vector = (MR_Word *) data_type_info;
expand_info->chosen_index_exists = MR_TRUE;
expand_info->chosen_value_ptr = &arg_type_infos[chosen];
expand_info->chosen_type_info = type_info;
@@ -954,19 +961,40 @@
break;
case MR_TYPECTOR_REP_TYPECTORINFO:
+ {
+ MR_TypeCtorInfo data_type_ctor_info;
+
+ /*
+ ** The only source of noncanonicality in typeinfos is due
+ ** to type equivalences, Unfortunately, for type_ctor_infos,
+ ** there is another source: after expanding out equivalences,
+ ** the resulting `type' may be a type variable. Since the
+ ** printable representation of this type variable is arbitrary,
+ ** we avoid noncanonicality by always printing it the same way.
+ ** Note that the outermost type_ctor_info cannot be a variable.
+ */
+
if (noncanon == MR_NONCANON_ABORT) {
/* XXX should throw an exception */
MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
": attempt to deconstruct noncanonical term");
- } else if (noncanon == MR_NONCANON_ALLOW) {
- handle_functor_name("<<typectorinfo>>");
- handle_zero_arity_args();
- } else {
- MR_TypeCtorInfo data_type_ctor_info;
+ }
+
data_type_ctor_info = (MR_TypeCtorInfo) *data_word_ptr;
- handle_functor_name(MR_type_ctor_name(data_type_ctor_info));
- handle_zero_arity_args();
+
+ if (noncanon == MR_NONCANON_ALLOW) {
+ data_type_ctor_info =
+ MR_collapse_ctor_equivalences(data_type_ctor_info);
+ }
+
+ if (data_type_ctor_info == NULL) {
+ handle_functor_name("<<typevariable>>");
+ } else {
+ handle_functor_name(MR_type_ctor_name(data_type_ctor_info));
+ }
+
+ handle_zero_arity_args();
}
break;
diff -u trace/mercury_trace_internal.c trace/mercury_trace_internal.c
--- trace/mercury_trace_internal.c 21 Feb 2002 16:22:34 -0000
+++ trace/mercury_trace_internal.c 22 Feb 2002 05:32:07 -0000
@@ -137,6 +137,21 @@
static MR_bool MR_trace_internal_interacting = MR_FALSE;
+static MR_bool MR_saved_io_tabling_enabled;
+
+/*
+** We include values of sometimes-useful types such as typeinfos in the set of
+** variables whose values we collect at events for possible later printing
+** only if MR_print_optionals is true.
+*/
+
+static MR_bool MR_print_optionals = MR_FALSE;
+
+/*
+** MR_context_position specifies whether we print context at events,
+** and if so, where.
+*/
+
static MR_Context_Position MR_context_position = MR_CONTEXT_AFTER;
typedef struct MR_Line_Struct {
@@ -283,10 +298,6 @@
static MR_bool MR_trace_valid_command(const char *word);
-MR_bool MR_saved_io_tabling_enabled;
-
-MR_bool MR_print_optionals = MR_FALSE;
-
MR_Code *
MR_trace_event_internal(MR_Trace_Cmd_Info *cmd, MR_bool interactive,
MR_Event_Info *event_info)
diff -u trace/mercury_trace_vars.c trace/mercury_trace_vars.c
--- trace/mercury_trace_vars.c 21 Feb 2002 16:16:17 -0000
+++ trace/mercury_trace_vars.c 22 Feb 2002 05:06:03 -0000
@@ -184,7 +184,8 @@
MR_trace_always_ignored_type_ctors[] =
{
#ifndef MR_HIGHLEVEL_CODE
- /* we ignore these until the debugger can handle their varying arity */
+ /* we ignore these until the browser can handle their varying arity, */
+ /* or their definitions are updated. XXX */
&mercury_data_type_desc__type_ctor_info_type_desc_0,
&mercury_data_type_desc__type_ctor_info_type_ctor_desc_0,
&mercury_data_private_builtin__type_ctor_info_typeclass_info_1,
only in patch2:
--- tests/debugger/mdb_command_test.inp 31 Oct 2001 17:53:45 -0000 1.16
+++ tests/debugger/mdb_command_test.inp 21 Feb 2002 19:11:39 -0000
@@ -46,6 +46,8 @@
table_io xyzzy xyzzy xyzzy xyzzy xyzzy
proc_stats xyzzy xyzzy xyzzy xyzzy xyzzy
label_stats xyzzy xyzzy xyzzy xyzzy xyzzy
+proc_stats xyzzy xyzzy xyzzy xyzzy xyzzy
+print_optionals xyzzy xyzzy xyzzy xyzzy xyzzy
source xyzzy xyzzy xyzzy xyzzy xyzzy
save xyzzy xyzzy xyzzy xyzzy xyzzy
quit xyzzy xyzzy xyzzy xyzzy xyzzy
only in patch2:
--- runtime/mercury_type_info.h 18 Feb 2002 07:01:22 -0000 1.85
+++ runtime/mercury_type_info.h 22 Feb 2002 07:12:26 -0000
@@ -1243,6 +1243,19 @@
*/
extern MR_TypeInfo MR_collapse_equivalences(MR_TypeInfo type_info);
+
+/*
+** MR_collapse_ctor_equivalences expands out all the top-level equivalences in
+** the argument type constructor. It guarantees that the returned type
+** constructor will not have a MR_TYPE_CTOR_REP_EQUIV* representation.
+** However, it is possible that a chain of equivalences ends in a type
+** variable. If this happens, MR_collapse_ctor_equivalences will return NULL.
+**
+** You need to wrap MR_{save/restore}_transient_hp() around
+** calls to this function.
+*/
+
+extern MR_TypeCtorInfo MR_collapse_ctor_equivalences(MR_TypeCtorInfo tci);
/*
** MR_create_type and MR_make_type_info both turn a pseudo typeinfo into
only in patch2:
--- runtime/mercury_type_info.c 30 Jan 2002 05:09:01 -0000 1.47
+++ runtime/mercury_type_info.c 22 Feb 2002 07:18:39 -0000
@@ -223,17 +223,6 @@
return MR_COMPARE_EQUAL;
}
- /*
- ** MR_collapse_equivalences:
- **
- ** Keep looking past equivalences until there are no more.
- ** This only looks past equivalences of the top level type, not
- ** the argument typeinfos.
- **
- ** You need to wrap MR_{save/restore}_transient_hp() around
- ** calls to this function.
- */
-
MR_TypeInfo
MR_collapse_equivalences(MR_TypeInfo maybe_equiv_type_info)
{
@@ -256,6 +245,29 @@
}
return maybe_equiv_type_info;
+}
+
+MR_TypeCtorInfo
+MR_collapse_ctor_equivalences(MR_TypeCtorInfo type_ctor_info)
+{
+ MR_PseudoTypeInfo pseudo_type_info;
+
+ /* Look past equivalences */
+ while (MR_type_ctor_rep(type_ctor_info) == MR_TYPECTOR_REP_EQUIV_GROUND
+ || MR_type_ctor_rep(type_ctor_info) == MR_TYPECTOR_REP_EQUIV)
+ {
+
+ pseudo_type_info = MR_type_ctor_layout(type_ctor_info).
+ layout_equiv;
+ if (MR_PSEUDO_TYPEINFO_IS_VARIABLE(pseudo_type_info)) {
+ return NULL;
+ }
+
+ type_ctor_info =
+ MR_PSEUDO_TYPEINFO_GET_TYPE_CTOR_INFO(pseudo_type_info);
+ }
+
+ return type_ctor_info;
}
/*
only in patch2:
--- NEWS 19 Feb 2002 09:25:23 -0000 1.244
+++ NEWS 22 Feb 2002 07:44:02 -0000
@@ -68,10 +68,18 @@
* `io__read_file' and `io__read_file_as_string' now have better error
handling. The result types have changed, so code using these predicates
will need minor modifications.
-
* We've added predicates `io__input_stream_foldl', `io__input_stream_foldl_io'
and `io__input_stream_foldl2_io', which apply a predicate to each character
of an input stream in turn.
+* We've added versions of `io__print', `io__write' and `io__write_univ'
+ that allow the caller to specify how they should treat values of noncanonical
+ types, e.g. types in which a single semantic value may have more than one
+ syntactic expression.
+* We've added four new predicates to allow programs to retrieve current
+ streams: `io__current_input_stream', `io__current_output_stream',
+ `io__current_binary_input_stream', and `io__current_binary_output_stream'.
+* We've added a predicate to io.m to return the last modification time
+ of a file: `io__file_modification_time'.
* We've added four functions to list.m for mapping functions over
corresponding members of lists: list__map_corresponding/3,
@@ -129,9 +137,6 @@
comparison of values of type `tm' whose `tm_dst' fields are identical
is equivalent to comparison of the times those values represent.
-* We've added a predicate to io.m to return the last modification time
- of a file (io__file_modification_time).
-
* We've added a predicate `std_util__map_maybe/3' and a function
`std_util__map_maybe/2' to apply a predicate or a function to
a value stored in a term of type `std_util__maybe'.
@@ -177,6 +182,12 @@
Changes to the Mercury implementation:
+* The Mercury compiler can now perform smart recompilation, enabled by the
+ `--smart-recompilation' option. With smart recompilation, when the
+ interface of a module changes, only modules which use the changed
+ declarations are recompiled. Smart recompilation does not yet work
+ with `--intermodule-optimization'.
+
* We've added a new compiler option `--warn-non-tail-recursion', which
causes the compiler to issue a warning about any directly recursive
call that is not a tail call.
@@ -188,11 +199,7 @@
* You can now navigate terms in the debugger by argument name as well as by
argument number.
-* The Mercury compiler can now perform smart recompilation, enabled by the
- `--smart-recompilation' option. With smart recompilation, when the
- interface of a module changes, only modules which use the changed
- declarations are recompiled. Smart recompilation does not yet work
- with `--intermodule-optimization'.
+* The debugger can now print higher order values.
* We've added a 'view' command to `mdb', which opens a `vim' window and
in it displays the current source location, updated at each event. This
--------------------------------------------------------------------------
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