From 2f85a4b4270c99cf6aa2d8604ed298799a96d9fd Mon Sep 17 00:00:00 2001 From: Zoltan Somogyi Date: Mon, 12 Jan 2009 01:46:49 +0000 Subject: [PATCH] Make the compiler bootstrap again in term size profiling grades. Estimated hours taken: 3 Branches: main Make the compiler bootstrap again in term size profiling grades. compiler/llds_out.m: Don't output a stray & that introduces a C syntax error. This code was invoked only in term size profiling grades. library/thread.semaphore.m: Replace the use of a C macro that isn't defined in term size profiling grades with a macro that *is* defined. runtime/mercury_term_size.c: Handle the dummy type_ctor_rep added recently. trace/mercury_trace_vars.c: Update the code that prints the sizes of the terms bound to variables (which is enabled only in term size profiling grades) to handle the changes made when I added user event attributes. tests/debugger/tailrec1.exp2: Add a new expected output for this case that also prints the variables added by the term size profiling transformation. tests/debugger/term_size_words.{m,exp}: Update this test case for the old breakup of std_util.m and the changes in the printing of floats. --- compiler/llds_out.m | 3 +- library/thread.semaphore.m | 4 +- runtime/mercury_term_size.c | 11 ++- tests/debugger/tailrec1.exp2 | 129 +++++++++++++++++++++++++++++ tests/debugger/term_size_words.exp | 14 ++-- tests/debugger/term_size_words.m | 75 +++++++++-------- trace/mercury_trace_vars.c | 27 +++--- 7 files changed, 205 insertions(+), 58 deletions(-) create mode 100644 tests/debugger/tailrec1.exp2 diff --git a/compiler/llds_out.m b/compiler/llds_out.m index 93816dd7a..773b22438 100644 --- a/compiler/llds_out.m +++ b/compiler/llds_out.m @@ -1,7 +1,7 @@ %-----------------------------------------------------------------------------% % vim: ft=mercury ts=4 sw=4 et %-----------------------------------------------------------------------------% -% Copyright (C) 1996-2008 The University of Melbourne. +% Copyright (C) 1996-2009 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. %-----------------------------------------------------------------------------% @@ -5339,7 +5339,6 @@ output_rval_const(llconst_data_addr(DataAddr, MaybeOffset), !IO) :- MaybeOffset = yes(Offset), io.write_string("((", !IO), output_llds_type_cast(data_ptr, !IO), - io.write_string("&", !IO), output_data_addr(DataAddr, !IO), io.write_string(") + ", !IO), io.write_int(Offset, !IO), diff --git a/library/thread.semaphore.m b/library/thread.semaphore.m index 3097b26fa..002b88258 100644 --- a/library/thread.semaphore.m +++ b/library/thread.semaphore.m @@ -1,7 +1,7 @@ %-----------------------------------------------------------------------------% % vim: ft=mercury ts=4 sw=4 et %-----------------------------------------------------------------------------% -% Copyright (C) 2000-2001,2003-2004, 2006-2007 The University of Melbourne. +% Copyright (C) 2000-2001,2003-2004, 2006-2007, 2009 The University of Melbourne. % This file may only be copied under the terms of the GNU Library General % Public License - see the file COPYING.LIB in the Mercury distribution. %-----------------------------------------------------------------------------% @@ -114,7 +114,7 @@ new(Semaphore, !IO) :- MR_Word sem_mem; ML_Semaphore *sem; - MR_incr_hp(sem_mem, + MR_alloc_heap(sem_mem, MR_round_up(sizeof(ML_Semaphore), sizeof(MR_Word))); sem = (ML_Semaphore *) sem_mem; sem->count = Count; diff --git a/runtime/mercury_term_size.c b/runtime/mercury_term_size.c index 830903e40..2542f2557 100644 --- a/runtime/mercury_term_size.c +++ b/runtime/mercury_term_size.c @@ -2,7 +2,7 @@ ** vim:ts=4 sw=4 expandtab */ /* -** Copyright (C) 2003-2005, 2007 The University of Melbourne. +** Copyright (C) 2003-2005, 2007, 2009 The University of Melbourne. ** This file may only be copied under the terms of the GNU Library General ** Public License - see the file COPYING.LIB in the Mercury distribution. */ @@ -331,6 +331,15 @@ try_again: #endif return 1; + case MR_TYPECTOR_REP_DUMMY: +#ifdef MR_DEBUG_TERM_SIZES + if (MR_heapdebug && MR_lld_print_enabled) { + printf("MR_term_size: dummy %p\n", + (void *) term); + } +#endif + return 0; + case MR_TYPECTOR_REP_VOID: MR_fatal_error("MR_term_size: VOID"); diff --git a/tests/debugger/tailrec1.exp2 b/tests/debugger/tailrec1.exp2 new file mode 100644 index 000000000..9e73cdd23 --- /dev/null +++ b/tests/debugger/tailrec1.exp2 @@ -0,0 +1,129 @@ + E1: C1 CALL pred tailrec1.main/2-0 (det) tailrec1.m:17 +mdb> echo on +Command echo enabled. +mdb> register --quiet +mdb> table_io allow +mdb> table_io start +I/O tabling started. +mdb> context none +Contexts will not be printed. +mdb> break tailrec1_read_line + 0: + stop interface pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> continue + E2: C2 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E3: C2 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> print * + Stream (arg 1) stream(0, input, text, file("tailrec1.data")) + Line (arg 2) "This" +mdb> stack + 0 pred tailrec1.tailrec1_read_line/4-0 (det) + 1 pred tailrec1.tailrec1_read_strings/5-0 (det) + 2 pred tailrec1.main/2-0 (det) +mdb> stack -d + 0 E2 C2 3 pred tailrec1.tailrec1_read_line/4-0 (det) (empty) + 1 E4 C3 2 pred tailrec1.tailrec1_read_strings/5-0 (det) c1; + 2 E1 C1 1 pred tailrec1.main/2-0 (det) c3;s2-2;c3; +mdb> continue + E5: C4 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E6: C4 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> stack + 0 pred tailrec1.tailrec1_read_line/4-0 (det) + 1 2x pred tailrec1.tailrec1_read_strings/5-0 (det) + 3 pred tailrec1.main/2-0 (det) +mdb> stack -d + 0 E5 C4 4 pred tailrec1.tailrec1_read_line/4-0 (det) (empty) + 1 E7 C5 3 pred tailrec1.tailrec1_read_strings/5-0 (det) c1; + 3 E1 C1 1 pred tailrec1.main/2-0 (det) c3;s2-2;c3; +mdb> continue + E8: C6 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E9: C6 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> continue + E10: C7 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E11: C7 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> step + E12: C8 COND pred tailrec1.tailrec1_read_strings/5-0 (det) c2;?; +mdb> step + E13: C8 ELSE pred tailrec1.tailrec1_read_strings/5-0 (det) c2;e; +mdb> step + E14: C9 TAIL pred tailrec1.tailrec1_read_strings/5-0 (det) c2;e;c8; +mdb> print * + Stream (arg 1) stream(0, input, text, file("tailrec1.data")) + STATE_VARIABLE_Words_0 (arg 2) ["a", "is", "This"] + FinalSizeVar25 8 + KnownSize 2 + STATE_VARIABLE_Words_1 ["list", "a", "is", "This"] + SizeVar23 6 + Word "list" +mdb> continue + E15: C10 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E16: C10 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> continue + E17: C11 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E18: C11 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> print * + Stream (arg 1) stream(0, input, text, file("tailrec1.data")) + Line (arg 2) "words" +mdb> retry -f + E17: C11 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> stack + 0 pred tailrec1.tailrec1_read_line/4-0 (det) + 1 6x pred tailrec1.tailrec1_read_strings/5-0 (det) + 7 pred tailrec1.main/2-0 (det) +mdb> stack -d + 0 E17 C11 8 pred tailrec1.tailrec1_read_line/4-0 (det) (empty) + 1 E19 C12 7 pred tailrec1.tailrec1_read_strings/5-0 (det) c1; + 7 E1 C1 1 pred tailrec1.main/2-0 (det) c3;s2-2;c3; +mdb> finish + E18: C11 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> print * + Stream (arg 1) stream(0, input, text, file("tailrec1.data")) + Line (arg 2) "words" +mdb> level 1 +Ancestor level set to 1: + 1 pred tailrec1.tailrec1_read_strings/5-0 (det) +mdb> print * + Stream (arg 1) stream(0, input, text, file("tailrec1.data")) + STATE_VARIABLE_Words_0 (arg 2) ["of", "list", "a", "is", "This"] +mdb> level 2 +The stack frame of that call has been reused. +mdb> retry -f 3 +cannot retry a call whose stack frame has been reused +mdb> retry -f 1 + E19: C12 CALL pred tailrec1.tailrec1_read_strings/5-0 (det) +mdb> stack + 0 6x pred tailrec1.tailrec1_read_strings/5-0 (det) + 6 pred tailrec1.main/2-0 (det) +mdb> stack -d + 0 E19 C12 7 pred tailrec1.tailrec1_read_strings/5-0 (det) (empty) + 6 E1 C1 1 pred tailrec1.main/2-0 (det) c3;s2-2;c3; +mdb> continue + E17: C11 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E18: C11 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> continue + E20: C13 CALL pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> finish + E21: C13 EXIT pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> step + E22: C14 COND pred tailrec1.tailrec1_read_strings/5-0 (det) c2;?; +mdb> next + E23: C14 THEN pred tailrec1.tailrec1_read_strings/5-0 (det) c2;t; +mdb> next 3 +Due to the reuse of stack frames by tail recursive procedures, +this command is a no-op from this port. +mdb> delete * + 0: E stop interface pred tailrec1.tailrec1_read_line/4-0 (det) +mdb> continue +words +of +list +a +is +This +6 diff --git a/tests/debugger/term_size_words.exp b/tests/debugger/term_size_words.exp index 19219c42c..47f83e697 100644 --- a/tests/debugger/term_size_words.exp +++ b/tests/debugger/term_size_words.exp @@ -1,4 +1,4 @@ - E1: C1 CALL pred term_size_words.main/2-0 (det) term_size_words.m:18 + E1: C1 CALL pred term_size_words.main/2-0 (det) term_size_words.m:23 mdb> echo on Command echo enabled. mdb> register --quiet @@ -27,10 +27,10 @@ mdb> finish mdb> print * IntList (arg 1) [1, 2, 3] DoubleIntList (arg 2) [1, 2, 3, 1, 2, 3] - FloatList (arg 3) [1.00000000000000, 2.00000000000000, 3.00000000000000] - PairList (arg 4) [-(1, 1.00000000000000), -(2, 2.00000000000000), -(3, 3.00000000000000)] + FloatList (arg 3) [1.0, 2.0, 3.0] + PairList (arg 4) [1 - 1.0, 2 - 2.0, 3 - 3.0] UnivList (arg 5) [univ_cons(1), univ_cons(2), univ_cons(3)] - Univ (arg 6) univ_cons(node(node(leaf, 2, -/2, leaf), 1, -(1.00000000000000, "one"), leaf)) + Univ (arg 6) univ_cons(node(node(leaf, 2, -/2, leaf), 1, -(1.0, "one"), leaf)) mdb> term_size * IntList 6 DoubleIntList 12 @@ -43,7 +43,7 @@ mdb> continue -n -S ["a", "bb", "ccc"] node(leaf, "one", 1, node(leaf, "two", 2, leaf)) [1, 2, 3, 1, 2, 3] -[1.00000000000000, 2.00000000000000, 3.00000000000000] -[1 - 1.00000000000000, 2 - 2.00000000000000, 3 - 3.00000000000000] +[1.0, 2.0, 3.0] +[1 - 1.0, 2 - 2.0, 3 - 3.0] [univ_cons(1), univ_cons(2), univ_cons(3)] -univ_cons(node(node(leaf, 2, 2.00000000000000 - "two", leaf), 1, 1.00000000000000 - "one", leaf)) +univ_cons(node(node(leaf, 2, 2.0 - "two", leaf), 1, 1.0 - "one", leaf)) diff --git a/tests/debugger/term_size_words.m b/tests/debugger/term_size_words.m index d32247c63..8fe06804f 100644 --- a/tests/debugger/term_size_words.m +++ b/tests/debugger/term_size_words.m @@ -1,62 +1,67 @@ +% vim: ts=4 sw=4 et ft=mercury + :- module term_size_words. :- interface. :- import_module io. -:- pred main(io__state, io__state). -:- mode main(di, uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. -:- import_module std_util, list, int, float. +:- import_module float. +:- import_module int. +:- import_module list. +:- import_module pair. +:- import_module univ. :- type tree(K, V) - ---> leaf - ; node(tree(K, V), K, V, tree(K, V)). + ---> leaf + ; node(tree(K, V), K, V, tree(K, V)). main(!IO) :- - static(IntList, StringList, Tree), - dynamic(IntList, DoubleIntList, FloatList, PairList, UnivList, Univ), - io__write(IntList, !IO), - io__nl(!IO), - io__write(StringList, !IO), - io__nl(!IO), - io__write(Tree, !IO), - io__nl(!IO), - io__write(DoubleIntList, !IO), - io__nl(!IO), - io__write(FloatList, !IO), - io__nl(!IO), - io__write(PairList, !IO), - io__nl(!IO), - io__write(UnivList, !IO), - io__nl(!IO), - io__write(Univ, !IO), - io__nl(!IO). + static(IntList, StringList, Tree), + dynamic(IntList, DoubleIntList, FloatList, PairList, UnivList, Univ), + io.write(IntList, !IO), + io.nl(!IO), + io.write(StringList, !IO), + io.nl(!IO), + io.write(Tree, !IO), + io.nl(!IO), + io.write(DoubleIntList, !IO), + io.nl(!IO), + io.write(FloatList, !IO), + io.nl(!IO), + io.write(PairList, !IO), + io.nl(!IO), + io.write(UnivList, !IO), + io.nl(!IO), + io.write(Univ, !IO), + io.nl(!IO). % Return some static terms. :- pred static(list(int)::out, list(string)::out, tree(string, int)::out) - is det. + is det. static(IntList, StringList, Tree) :- - IntList = [1,2,3], - StringList = ["a", "bb", "ccc"], - Tree = node(leaf, "one", 1, node(leaf, "two", 2, leaf)). + IntList = [1,2,3], + StringList = ["a", "bb", "ccc"], + Tree = node(leaf, "one", 1, node(leaf, "two", 2, leaf)). % Return some dynamic terms. :- pred dynamic(list(int)::in, list(int)::out, list(float)::out, - list(pair(int, float))::out, list(univ)::out, univ::out) is det. + list(pair(int, float))::out, list(univ)::out, univ::out) is det. dynamic(IntList, DoubleIntList, FloatList, PairList, UnivList, Univ) :- - list__append(IntList, IntList, DoubleIntList), - FloatList = list__map(float, IntList), - PairList = list__map(pair_float, IntList), - UnivList = list__map(convert_type_to_univ, IntList), - Univ = convert_type_to_univ( - node(node(leaf, 2, 2.0 - "two", leaf), 1, 1.0 - "one", leaf)). + list.append(IntList, IntList, DoubleIntList), + FloatList = list.map(float, IntList), + PairList = list.map(pair_float, IntList), + UnivList = list.map(convert_type_to_univ, IntList), + Univ = convert_type_to_univ( + node(node(leaf, 2, 2.0 - "two", leaf), 1, 1.0 - "one", leaf)). :- func pair_float(int) = pair(int, float). @@ -65,4 +70,4 @@ pair_float(Int) = Int - float(Int). :- func convert_type_to_univ(T) = univ. convert_type_to_univ(T) = Univ :- - type_to_univ(T, Univ). + type_to_univ(T, Univ). diff --git a/trace/mercury_trace_vars.c b/trace/mercury_trace_vars.c index 110a886ef..49c5161c8 100644 --- a/trace/mercury_trace_vars.c +++ b/trace/mercury_trace_vars.c @@ -2,7 +2,7 @@ ** vim: ts=4 sw=4 expandtab */ /* -** Copyright (C) 1999-2008 The University of Melbourne. +** Copyright (C) 1999-2009 The University of Melbourne. ** This file may only be copied under the terms of the GNU Library General ** Public License - see the file COPYING.LIB in the Mercury distribution. */ @@ -108,10 +108,10 @@ typedef enum { } MR_ValueKind; typedef struct { - MR_ValueKind MR_value_kind; - MR_KindDetails MR_value_details; - MR_TypeInfo MR_value_type; - MR_Word MR_value_value; + MR_ValueKind MR_value_kind; + MR_KindDetails MR_value_details; + MR_TypeInfo MR_value_type; + MR_Word MR_value_value; } MR_ValueDetails; #define MR_value_var MR_value_details.MR_details_var @@ -1524,13 +1524,15 @@ MR_trace_print_size_one(FILE *out, char *word_spec) do { fprintf(out, "%20s: %6u\n", - MR_point.MR_point_vars[var_num].MR_var_fullname, + MR_point.MR_point_vars[var_num].MR_value_var.MR_var_fullname, MR_term_size(MR_point.MR_point_vars[var_num].MR_value_type, MR_point.MR_point_vars[var_num].MR_value_value)); var_num++; } while (var_num < MR_point.MR_point_var_count && + MR_point.MR_point_vars[var_num].MR_value_kind + == MR_VALUE_PROG_VAR && MR_streq(var_spec.MR_var_spec_name, - MR_point.MR_point_vars[var_num].MR_var_fullname)); + MR_point.MR_point_vars[var_num].MR_value_var.MR_var_fullname)); } else { fprintf(out, "%20s: %6u\n", name, type_info, value); } @@ -1554,10 +1556,13 @@ MR_trace_print_size_all(FILE *out) } for (var_num = 0; var_num < MR_point.MR_point_var_count; var_num++) { - fprintf(out, "%-20s %6u\n", - MR_point.MR_point_vars[var_num].MR_var_fullname, - MR_term_size(MR_point.MR_point_vars[var_num].MR_value_type, - MR_point.MR_point_vars[var_num].MR_value_value)); + if (MR_point.MR_point_vars[var_num].MR_value_kind == MR_VALUE_PROG_VAR) + { + fprintf(out, "%-20s %6u\n", + MR_point.MR_point_vars[var_num].MR_value_var.MR_var_fullname, + MR_term_size(MR_point.MR_point_vars[var_num].MR_value_type, + MR_point.MR_point_vars[var_num].MR_value_value)); + } } return NULL;