[m-rev.] For post-commit review: Add determinism to all goals in procrep bytecode.
Paul Bone
pbone at csse.unimelb.edu.au
Wed Aug 13 16:59:44 AEST 2008
For post-commit review by Zoltan.
Note that this change will break some of the tests for the declartive
debugger. I'll fix those seperatly.
Estimated hours taken:
Branches: main
Modify the bytecode used by the deep profiler and declarative debugger to
include the determinism of each goal, not just atomic goals. This increases
the size of the compiler's bytecode by 0.8% and the compiler's bytecode by
0.1%.
mdbcomp/program_representation.m:
Introduce field names for members of the proc_defn_rep structure.
Introduce determinism field to proc_defn_rep structure.
Renamed goal_rep type to goal_expr_rep, created new goal_rep type
containing a goal_expr_rep and a detism_rep.
Removed detism_rep field from atomic_goal_rep function symbol.
Read determinism information after each goal, for that goal.
No-longer read determinism information within atomic goals.
Incremented procrep bytecode version number.
compiler/prog_rep.m:
represent_proc_as_bytecodes now takes an extra argument, the determinism
of the procedure that it's creating bytecode for.
Now writes determinism bytecode after each goal, rather than just for
atomic goals.
compiler/stack_layout.m:
Call represent_proc_as_bytecodes with the determinism or the procedure.
runtime/mercury_deep_profiler.m:
Incremented procrep bytecode version number.
browser/declarative_tree.m:
Conform to changes in mdbcomp/program_representation.m.
Modify some code to use record syntax so it's not impacted in the future
by unrelated changes to these program_representation data structures.
deep_profiler/mdprof_procrep.m:
Print determinism information for each procedure and most goals.
Determinisms of conjunctions and negations are not printed to avoid
cluttering the output. Often the determinism of these goals can be
determined by inspecting the inner goal(s).
Conform to changes in mdbcomp/program_representation.m
Index: browser/declarative_tree.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/declarative_tree.m,v
retrieving revision 1.56
diff -u -p -r1.56 declarative_tree.m
--- browser/declarative_tree.m 12 Aug 2008 02:51:06 -0000 1.56
+++ browser/declarative_tree.m 13 Aug 2008 02:42:56 -0000
@@ -907,7 +907,8 @@ trace_dependency_in_proc_defn_rep(Store,
StartLoc = cur_goal,
Contour = Contour0
),
- ProcDefnRep = proc_defn_rep(HeadVars, GoalRep, _),
+ HeadVars = ProcDefnRep ^ pdr_head_vars,
+ GoalRep = ProcDefnRep ^ pdr_goal,
is_traced_grade(AllTraced),
MaybePrims = make_primitive_list(Store, [goal_and_path(GoalRep, empty)],
Contour, StartPath, ArgNum, TotalArgs, HeadVars, AllTraced, []),
@@ -944,9 +945,12 @@ trace_dependency_in_proc_defn_rep(Store,
:- pred proc_defn_rep_is_catch_impl(proc_defn_rep::in) is semidet.
proc_defn_rep_is_catch_impl(ProcDefnRep) :-
- ProcDefnRep = proc_defn_rep([A, B, C, D],
- atomic_goal_rep(_, "exception.m", _, [D],
- plain_call_rep("exception", "builtin_catch", [A, B, C, D])), _).
+ GoalRep = ProcDefnRep ^ pdr_goal,
+ HeadVars = ProcDefnRep ^ pdr_head_vars,
+ GoalExprRep = GoalRep ^ goal_expr_rep,
+ HeadVars = [A, B, C, D],
+ GoalExprRep = atomic_goal_rep("exception.m", _, [D],
+ plain_call_rep("exception", "builtin_catch", [A, B, C, D])).
:- pred find_chain_start(S::in, R::in, arg_pos::in, term_path::in,
dependency_chain_start(R)::out) is det <= annotated_trace(S, R).
@@ -1233,21 +1237,22 @@ next_goal_generates_internal_event([goal
match_goal_to_contour_event(Store, Goal, Path, GoalPaths, Contour, MaybeEnd,
ArgNum, TotalArgs, HeadVars, AllTraced, Primitives0) = MaybePrims :-
+ Goal = goal_rep(GoalExpr, _),
(
- Goal = conj_rep(Conjs),
+ GoalExpr = conj_rep(Conjs),
add_paths_to_conjuncts(Conjs, Path, 1, ConjPaths),
MaybePrims = make_primitive_list(Store, ConjPaths ++ GoalPaths,
Contour, MaybeEnd, ArgNum, TotalArgs, HeadVars, AllTraced,
Primitives0)
;
- Goal = scope_rep(InnerGoal, MaybeCut),
+ GoalExpr = scope_rep(InnerGoal, MaybeCut),
InnerPath = cord.snoc(Path, step_scope(MaybeCut)),
InnerAndPath = goal_and_path(InnerGoal, InnerPath),
MaybePrims = make_primitive_list(Store, [InnerAndPath | GoalPaths],
Contour, MaybeEnd, ArgNum, TotalArgs, HeadVars, AllTraced,
Primitives0)
;
- Goal = atomic_goal_rep(_, File, Line, BoundVars, AtomicGoal),
+ GoalExpr = atomic_goal_rep(File, Line, BoundVars, AtomicGoal),
GeneratesEvent = atomic_goal_generates_event_like_call(AtomicGoal),
(
GeneratesEvent = yes(AtomicGoalArgs),
@@ -1263,7 +1268,7 @@ match_goal_to_contour_event(Store, Goal,
MaybeEnd, ArgNum, TotalArgs, HeadVars, AllTraced, Primitives1)
)
;
- Goal = disj_rep(Disjs),
+ GoalExpr = disj_rep(Disjs),
(
Contour = [_ - ContourHeadNode | ContourTail],
(
@@ -1287,7 +1292,7 @@ match_goal_to_contour_event(Store, Goal,
"mismatch on disj"))
)
;
- Goal = switch_rep(_SwitchVar, Cases),
+ GoalExpr = switch_rep(_SwitchVar, Cases),
(
Contour = [_ - ContourHeadNode | ContourTail],
ContourHeadNode = node_switch(_, Label),
@@ -1308,7 +1313,7 @@ match_goal_to_contour_event(Store, Goal,
"mismatch on switch"))
)
;
- Goal = ite_rep(Cond, Then, Else),
+ GoalExpr = ite_rep(Cond, Then, Else),
(
Contour = [_ - ContourHeadNode | ContourTail],
ContourHeadNode = node_cond(_, Label, _),
@@ -1345,7 +1350,7 @@ match_goal_to_contour_event(Store, Goal,
"mismatch on if-then-else"))
)
;
- Goal = negation_rep(NegGoal),
+ GoalExpr = negation_rep(NegGoal),
(
Contour = [_ - ContourHeadNode | ContourTail],
ContourHeadNode = node_neg_succ(_, _, _)
@@ -1575,7 +1580,7 @@ find_variable_in_args(Args, ArgNum, Tota
subterm_origin(edt_node(R))::out) is det <= annotated_trace(S, R).
traverse_primitives([], Var0, TermPath0, _, ProcDefnRep, Origin) :-
- ProcDefnRep = proc_defn_rep(HeadVars, _, _),
+ HeadVars = ProcDefnRep ^ pdr_head_vars,
ArgPos = find_arg_pos(HeadVars, Var0),
Origin = origin_input(ArgPos, TermPath0).
traverse_primitives([Prim | Prims], Var0, TermPath0, Store, ProcDefnRep,
Index: compiler/prog_rep.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_rep.m,v
retrieving revision 1.61
diff -u -p -r1.61 prog_rep.m
--- compiler/prog_rep.m 12 Aug 2008 02:51:06 -0000 1.61
+++ compiler/prog_rep.m 13 Aug 2008 02:42:56 -0000
@@ -56,7 +56,7 @@
%
:- pred represent_proc_as_bytecodes(list(prog_var)::in, hlds_goal::in,
instmap::in, vartypes::in, var_num_map::in, module_info::in,
- include_variable_table::in,
+ include_variable_table::in, determinism::in,
stack_layout_info::in, stack_layout_info::out, list(int)::out) is det.
%---------------------------------------------------------------------------%
@@ -93,7 +93,7 @@
).
represent_proc_as_bytecodes(HeadVars, Goal, InstMap0, VarTypes, VarNumMap,
- ModuleInfo, IncludeVarTable, !StackInfo, ProcRepBytes) :-
+ ModuleInfo, IncludeVarTable, ProcDetism, !StackInfo, ProcRepBytes) :-
Goal = hlds_goal(_, GoalInfo),
Context = goal_info_get_context(GoalInfo),
term.context_file(Context, FileName),
@@ -103,8 +103,9 @@ represent_proc_as_bytecodes(HeadVars, Go
string_to_byte_list(FileName, FileNameBytes, !StackInfo),
goal_to_byte_list(Goal, InstMap0, Info, GoalBytes, !StackInfo),
+ DetismByte = represent_determinism(ProcDetism),
ProcRepBytes0 = FileNameBytes ++ VarTableBytes ++
- vars_to_byte_list(Info, HeadVars) ++ GoalBytes,
+ vars_to_byte_list(Info, HeadVars) ++ GoalBytes ++ [DetismByte],
int32_to_byte_list(list.length(ProcRepBytes0) + 4, LimitBytes),
ProcRepBytes = LimitBytes ++ ProcRepBytes0.
@@ -202,31 +203,22 @@ compiler_introduced_varname(VarName) :-
goal_to_byte_list(hlds_goal(GoalExpr, GoalInfo), InstMap0, Info, Bytes,
!StackInfo) :-
- goal_expr_to_byte_list(GoalExpr, GoalInfo, InstMap0, Info, Bytes,
- !StackInfo).
-
-:- pred goal_expr_to_byte_list(hlds_goal_expr::in, hlds_goal_info::in,
- instmap::in, prog_rep_info::in, list(int)::out,
- stack_layout_info::in, stack_layout_info::out) is det.
-
-goal_expr_to_byte_list(GoalExpr, GoalInfo, InstMap0, Info, Bytes,
- !StackInfo) :-
(
GoalExpr = conj(ConjType, Goals),
expect(unify(ConjType, plain_conj), this_file,
"non-plain conjunction and declarative debugging"),
conj_to_byte_list(Goals, InstMap0, Info, ConjBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_conj)] ++
+ ExprBytes = [goal_type_to_byte(goal_conj)] ++
length_to_byte_list(Goals) ++ ConjBytes
;
GoalExpr = disj(Goals),
disj_to_byte_list(Goals, InstMap0, Info, DisjBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_disj)] ++
+ ExprBytes = [goal_type_to_byte(goal_disj)] ++
length_to_byte_list(Goals) ++ DisjBytes
;
GoalExpr = negation(SubGoal),
goal_to_byte_list(SubGoal, InstMap0, Info, SubGoalBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_neg)] ++ SubGoalBytes
+ ExprBytes = [goal_type_to_byte(goal_neg)] ++ SubGoalBytes
;
GoalExpr = if_then_else(_, Cond, Then, Else),
Cond = hlds_goal(_, CondGoalInfo),
@@ -235,7 +227,7 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
goal_to_byte_list(Cond, InstMap0, Info, CondBytes, !StackInfo),
goal_to_byte_list(Then, InstMap1, Info, ThenBytes, !StackInfo),
goal_to_byte_list(Else, InstMap0, Info, ElseBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_ite)] ++
+ ExprBytes = [goal_type_to_byte(goal_ite)] ++
CondBytes ++ ThenBytes ++ ElseBytes
;
GoalExpr = unify(_, _, _, Uni, _),
@@ -243,7 +235,7 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
AtomicBytes, BoundVars, !StackInfo),
(
Uni = assign(Target, Source),
- Bytes = [goal_type_to_byte(goal_assign)] ++
+ ExprBytes = [goal_type_to_byte(goal_assign)] ++
var_to_byte_list(Info, Target) ++
var_to_byte_list(Info, Source) ++
AtomicBytes
@@ -251,14 +243,14 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
Uni = construct(Var, ConsId, Args, ArgModes, _, _, _),
cons_id_to_byte_list(ConsId, ConsIdBytes, !StackInfo),
( list.all_true(lhs_final_is_ground(Info), ArgModes) ->
- Bytes = [goal_type_to_byte(goal_construct)] ++
+ ExprBytes = [goal_type_to_byte(goal_construct)] ++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
vars_to_byte_list(Info, Args) ++
AtomicBytes
;
filter_input_args(Info, ArgModes, Args, MaybeArgs),
- Bytes = [goal_type_to_byte(goal_partial_construct)] ++
+ ExprBytes = [goal_type_to_byte(goal_partial_construct)] ++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
maybe_vars_to_byte_list(Info, MaybeArgs) ++
@@ -269,13 +261,13 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
cons_id_to_byte_list(ConsId, ConsIdBytes, !StackInfo),
( list.member(Var, BoundVars) ->
filter_input_args(Info, ArgModes, Args, MaybeArgs),
- Bytes = [goal_type_to_byte(goal_partial_deconstruct)]++
+ ExprBytes = [goal_type_to_byte(goal_partial_deconstruct)]++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
maybe_vars_to_byte_list(Info, MaybeArgs) ++
AtomicBytes
;
- Bytes = [goal_type_to_byte(goal_deconstruct)] ++
+ ExprBytes = [goal_type_to_byte(goal_deconstruct)] ++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
vars_to_byte_list(Info, Args) ++
@@ -283,7 +275,7 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
)
;
Uni = simple_test(Var1, Var2),
- Bytes = [goal_type_to_byte(goal_simple_test)] ++
+ ExprBytes = [goal_type_to_byte(goal_simple_test)] ++
var_to_byte_list(Info, Var1) ++
var_to_byte_list(Info, Var2) ++
AtomicBytes
@@ -294,7 +286,7 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
;
GoalExpr = switch(SwitchVar, _, Cases),
cases_to_byte_list(Cases, InstMap0, Info, CasesBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_switch)] ++
+ ExprBytes = [goal_type_to_byte(goal_switch)] ++
var_to_byte_list(Info, SwitchVar) ++
length_to_byte_list(Cases) ++ CasesBytes
;
@@ -308,20 +300,20 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
MaybeCut = 1
),
goal_to_byte_list(SubGoal, InstMap0, Info, GoalBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_scope)] ++ [MaybeCut] ++ GoalBytes
+ ExprBytes = [goal_type_to_byte(goal_scope)] ++ [MaybeCut] ++ GoalBytes
;
GoalExpr = generic_call(GenericCall, Args, _, _),
atomic_goal_info_to_byte_list(GoalInfo, InstMap0, Info,
AtomicBytes, _BoundVars, !StackInfo),
(
GenericCall = higher_order(PredVar, _, _, _),
- Bytes = [goal_type_to_byte(goal_ho_call)] ++
+ ExprBytes = [goal_type_to_byte(goal_ho_call)] ++
var_to_byte_list(Info, PredVar) ++
vars_to_byte_list(Info, Args) ++
AtomicBytes
;
GenericCall = class_method(Var, MethodNum, _, _),
- Bytes = [goal_type_to_byte(goal_method_call)] ++
+ ExprBytes = [goal_type_to_byte(goal_method_call)] ++
var_to_byte_list(Info, Var) ++
method_num_to_byte_list(MethodNum) ++
vars_to_byte_list(Info, Args) ++
@@ -329,14 +321,14 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
;
GenericCall = event_call(EventName),
string_to_byte_list(EventName, EventNameBytes, !StackInfo),
- Bytes = [goal_type_to_byte(goal_event_call)] ++
+ ExprBytes = [goal_type_to_byte(goal_event_call)] ++
EventNameBytes ++
vars_to_byte_list(Info, Args) ++
AtomicBytes
;
GenericCall = cast(_),
( Args = [InputArg, OutputArg] ->
- Bytes = [goal_type_to_byte(goal_cast)] ++
+ ExprBytes = [goal_type_to_byte(goal_cast)] ++
var_to_byte_list(Info, OutputArg) ++
var_to_byte_list(Info, InputArg) ++
AtomicBytes
@@ -356,7 +348,7 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
string_to_byte_list(PredName, PredNameBytes, !StackInfo),
(
Builtin = not_builtin,
- Bytes = [goal_type_to_byte(goal_plain_call)] ++
+ ExprBytes = [goal_type_to_byte(goal_plain_call)] ++
ModuleNameBytes ++
PredNameBytes ++
vars_to_byte_list(Info, Args) ++
@@ -365,7 +357,7 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
( Builtin = inline_builtin
; Builtin = out_of_line_builtin
),
- Bytes = [goal_type_to_byte(goal_builtin_call)] ++
+ ExprBytes = [goal_type_to_byte(goal_builtin_call)] ++
ModuleNameBytes ++
PredNameBytes ++
vars_to_byte_list(Info, Args) ++
@@ -376,13 +368,19 @@ goal_expr_to_byte_list(GoalExpr, GoalInf
ArgVars = list.map(foreign_arg_var, Args),
atomic_goal_info_to_byte_list(GoalInfo, InstMap0, Info,
AtomicBytes, _BoundVars, !StackInfo),
- Bytes = [goal_type_to_byte(goal_foreign)] ++
+ ExprBytes = [goal_type_to_byte(goal_foreign)] ++
vars_to_byte_list(Info, ArgVars) ++ AtomicBytes
;
GoalExpr = shorthand(_),
% These should have been expanded out by now.
unexpected(this_file, "goal_expr_to_byte_list: unexpected shorthand")
- ).
+ ),
+
+ % Include determinism in the bytecode.
+ Detism = goal_info_get_determinism(GoalInfo),
+ DetismByte = represent_determinism(Detism),
+
+ Bytes = ExprBytes ++ [DetismByte].
:- pred lhs_final_is_ground(prog_rep_info::in, uni_mode::in) is semidet.
@@ -419,7 +417,6 @@ filter_input_args(_, [_ | _], [], _) :-
atomic_goal_info_to_byte_list(GoalInfo, InstMap0, Info, Bytes, BoundVars,
!StackInfo) :-
- Detism = goal_info_get_determinism(GoalInfo),
Context = goal_info_get_context(GoalInfo),
term.context_file(Context, FileName0),
( FileName0 = Info ^ pri_filename ->
@@ -434,8 +431,7 @@ atomic_goal_info_to_byte_list(GoalInfo,
Info ^ pri_module_info, ChangedVars),
set.to_sorted_list(ChangedVars, BoundVars),
string_to_byte_list(FileName, FileNameBytes, !StackInfo),
- Bytes = [represent_determinism(Detism)] ++
- FileNameBytes ++
+ Bytes = FileNameBytes ++
lineno_to_byte_list(LineNo) ++
vars_to_byte_list(Info, BoundVars).
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.142
diff -u -p -r1.142 stack_layout.m
--- compiler/stack_layout.m 12 Aug 2008 02:51:06 -0000 1.142
+++ compiler/stack_layout.m 13 Aug 2008 02:42:58 -0000
@@ -573,7 +573,8 @@ construct_proc_layout(ProcLayoutInfo, In
IncludeVarTable = do_not_include_variable_table
),
represent_proc_as_bytecodes(HeadVars, Goal, InstMap, VarTypes,
- VarNumMap, ModuleInfo, IncludeVarTable, !Info, ProcBytes)
+ VarNumMap, ModuleInfo, IncludeVarTable, Detism, !Info,
+ ProcBytes)
;
ProcBytes = []
),
Index: deep_profiler/mdprof_procrep.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/mdprof_procrep.m,v
retrieving revision 1.3
diff -u -p -r1.3 mdprof_procrep.m
--- deep_profiler/mdprof_procrep.m 12 Aug 2008 02:51:07 -0000 1.3
+++ deep_profiler/mdprof_procrep.m 13 Aug 2008 02:42:58 -0000
@@ -94,16 +94,18 @@ print_module(ModuleRep, !IO) :-
print_proc(ProcRep, !IO) :-
ProcRep = proc_rep(ProcLabel, ProcDefnRep),
- ProcDefnRep = proc_defn_rep(ArgVarReps, GoalRep, VarTable),
- print_proc_label(ProcLabel, !IO),
+ ProcDefnRep = proc_defn_rep(ArgVarReps, GoalRep, VarTable, Detism),
+ print_proc_label(Detism, ProcLabel, !IO),
print_args(VarTable, ArgVarReps, !IO),
io.write_string(" :-\n", !IO),
print_goal(VarTable, 1, GoalRep, !IO),
io.nl(!IO).
-:- pred print_proc_label(string_proc_label::in, io::di, io::uo) is det.
+:- pred print_proc_label(detism_rep::in, string_proc_label::in, io::di, io::uo)
+ is det.
-print_proc_label(ProcLabel, !IO) :-
+print_proc_label(Detism, ProcLabel, !IO) :-
+ print_detism(Detism, !IO),
(
ProcLabel = str_ordinary_proc_label(PredFunc, DeclModule, _DefModule,
Name, Arity, Mode),
@@ -114,12 +116,12 @@ print_proc_label(ProcLabel, !IO) :-
PredFunc = pf_function,
PF = "func"
),
- io.format("%s %s.%s/%d-%d",
+ io.format(" %s %s.%s/%d-%d",
[s(PF), s(DeclModule), s(Name), i(Arity), i(Mode)], !IO)
;
ProcLabel = str_special_proc_label(TypeName, TypeModule, _DefModule,
Name, Arity, Mode),
- io.format("%s for %s.%s/%d-%d",
+ io.format(" %s for %s.%s/%d-%d",
[s(Name), s(TypeModule), s(TypeName), i(Arity), i(Mode)], !IO)
).
@@ -129,28 +131,32 @@ print_proc_label(ProcLabel, !IO) :-
is det.
print_goal(VarTable, Indent, GoalRep, !IO) :-
+ GoalRep = goal_rep(GoalExprRep, DetismRep),
(
- GoalRep = conj_rep(ConjGoalReps),
+ GoalExprRep = conj_rep(ConjGoalReps),
print_conj(VarTable, Indent, ConjGoalReps, !IO)
;
- GoalRep = disj_rep(DisjGoalReps),
+ GoalExprRep = disj_rep(DisjGoalReps),
indent(Indent, !IO),
- io.write_string("(\n", !IO),
+ print_detism(DetismRep, !IO),
+ io.write_string(" (\n", !IO),
print_disj(VarTable, Indent, DisjGoalReps, no, !IO),
indent(Indent, !IO),
io.write_string(")\n", !IO)
;
- GoalRep = switch_rep(SwitchVarRep, CasesRep),
+ GoalExprRep = switch_rep(SwitchVarRep, CasesRep),
indent(Indent, !IO),
+ print_detism(DetismRep, !IO),
lookup_var_name(VarTable, SwitchVarRep, SwitchVarName),
- io.format("( switch on %s\n", [s(SwitchVarName)], !IO),
+ io.format(" ( switch on %s\n", [s(SwitchVarName)], !IO),
print_switch(VarTable, Indent, CasesRep, no, !IO),
indent(Indent, !IO),
io.write_string(")\n", !IO)
;
- GoalRep = ite_rep(CondRep, ThenRep, ElseRep),
+ GoalExprRep = ite_rep(CondRep, ThenRep, ElseRep),
indent(Indent, !IO),
- io.write_string("(\n", !IO),
+ print_detism(DetismRep, !IO),
+ io.write_string(" (\n", !IO),
print_goal(VarTable, Indent + 1, CondRep, !IO),
indent(Indent, !IO),
io.write_string("->\n", !IO),
@@ -161,16 +167,17 @@ print_goal(VarTable, Indent, GoalRep, !I
indent(Indent, !IO),
io.write_string(")\n", !IO)
;
- GoalRep = negation_rep(SubGoalRep),
+ GoalExprRep = negation_rep(SubGoalRep),
indent(Indent, !IO),
io.write_string("not (\n", !IO),
print_goal(VarTable, Indent + 1, SubGoalRep, !IO),
indent(Indent, !IO),
io.write_string(")\n", !IO)
;
- GoalRep = scope_rep(SubGoalRep, MaybeCut),
+ GoalExprRep = scope_rep(SubGoalRep, MaybeCut),
indent(Indent, !IO),
- io.write_string("scope", !IO),
+ print_detism(DetismRep, !IO),
+ io.write_string(" scope", !IO),
(
MaybeCut = scope_is_cut
;
@@ -182,9 +189,9 @@ print_goal(VarTable, Indent, GoalRep, !I
indent(Indent, !IO),
io.write_string(")\n", !IO)
;
- GoalRep = atomic_goal_rep(_DetismRep, _FileName, _LineNumber,
+ GoalExprRep = atomic_goal_rep(_FileName, _LineNumber,
_BoundVars, AtomicGoalRep),
- print_atomic_goal(VarTable, Indent, AtomicGoalRep, !IO)
+ print_atomic_goal(VarTable, Indent, DetismRep, AtomicGoalRep, !IO)
).
:- pred print_conj(var_table::in, int::in, list(goal_rep)::in, io::di, io::uo)
@@ -256,11 +263,12 @@ print_cons_id_and_arity(Indent, ConsIdAr
%-----------------------------------------------------------------------------%
-:- pred print_atomic_goal(var_table::in, int::in, atomic_goal_rep::in,
- io::di, io::uo) is det.
+:- pred print_atomic_goal(var_table::in, int::in, detism_rep::in,
+ atomic_goal_rep::in, io::di, io::uo) is det.
-print_atomic_goal(VarTable, Indent, AtomicGoalRep, !IO) :-
+print_atomic_goal(VarTable, Indent, DetismRep, AtomicGoalRep, !IO) :-
indent(Indent, !IO),
+ print_detism(DetismRep, !IO),
(
(
AtomicGoalRep = unify_construct_rep(VarRep, ConsIdRep, ArgReps),
@@ -270,7 +278,7 @@ print_atomic_goal(VarTable, Indent, Atom
UnifyOp = "=>"
),
lookup_var_name(VarTable, VarRep, VarName),
- io.format("%s %s %s", [s(VarName), s(UnifyOp), s(ConsIdRep)], !IO),
+ io.format(" %s %s %s", [s(VarName), s(UnifyOp), s(ConsIdRep)], !IO),
print_args(VarTable, ArgReps, !IO)
;
(
@@ -283,51 +291,51 @@ print_atomic_goal(VarTable, Indent, Atom
UnifyOp = "=>"
),
lookup_var_name(VarTable, VarRep, VarName),
- io.format("%s %s %s", [s(VarName), s(UnifyOp), s(ConsIdRep)], !IO),
+ io.format(" %s %s %s", [s(VarName), s(UnifyOp), s(ConsIdRep)], !IO),
print_maybe_args(VarTable, MaybeArgReps, !IO)
;
AtomicGoalRep = unify_assign_rep(TargetRep, SourceRep),
lookup_var_name(VarTable, TargetRep, TargetName),
lookup_var_name(VarTable, SourceRep, SourceName),
- io.format("%s := %s", [s(TargetName), s(SourceName)], !IO)
+ io.format(" %s := %s", [s(TargetName), s(SourceName)], !IO)
;
AtomicGoalRep = cast_rep(TargetRep, SourceRep),
lookup_var_name(VarTable, TargetRep, TargetName),
lookup_var_name(VarTable, SourceRep, SourceName),
- io.format("cast %s to %s", [s(SourceName), s(TargetName)], !IO)
+ io.format(" cast %s to %s", [s(SourceName), s(TargetName)], !IO)
;
AtomicGoalRep = unify_simple_test_rep(TargetRep, SourceRep),
lookup_var_name(VarTable, TargetRep, TargetName),
lookup_var_name(VarTable, SourceRep, SourceName),
- io.format("%s == %s", [s(SourceName), s(TargetName)], !IO)
+ io.format(" %s == %s", [s(SourceName), s(TargetName)], !IO)
;
AtomicGoalRep = pragma_foreign_code_rep(Args),
- io.write_string("foreign_proc(", !IO),
+ io.write_string(" foreign_proc(", !IO),
print_args(VarTable, Args, !IO),
io.write_string(")", !IO)
;
AtomicGoalRep = higher_order_call_rep(HOVarRep, Args),
lookup_var_name(VarTable, HOVarRep, HOVarName),
- io.format("%s(", [s(HOVarName)], !IO),
+ io.format(" %s(", [s(HOVarName)], !IO),
print_args(VarTable, Args, !IO),
io.write_string(")", !IO)
;
AtomicGoalRep = method_call_rep(TCIVarRep, MethodNumber, Args),
lookup_var_name(VarTable, TCIVarRep, TCIVarName),
- io.format("method %d of %s(", [i(MethodNumber), s(TCIVarName)], !IO),
+ io.format(" method %d of %s(", [i(MethodNumber), s(TCIVarName)], !IO),
print_args(VarTable, Args, !IO),
io.write_string(")", !IO)
;
AtomicGoalRep = plain_call_rep(Module, Pred, Args),
- io.format("%s.%s", [s(Module), s(Pred)], !IO),
+ io.format(" %s.%s", [s(Module), s(Pred)], !IO),
print_args(VarTable, Args, !IO)
;
AtomicGoalRep = builtin_call_rep(Module, Pred, Args),
- io.format("builtin %s.%s", [s(Module), s(Pred)], !IO),
+ io.format(" builtin %s.%s", [s(Module), s(Pred)], !IO),
print_args(VarTable, Args, !IO)
;
AtomicGoalRep = event_call_rep(Event, Args),
- io.format("event %s", [s(Event)], !IO),
+ io.format(" event %s", [s(Event)], !IO),
print_args(VarTable, Args, !IO)
),
io.nl(!IO).
@@ -394,6 +402,36 @@ indent(N, !IO) :-
indent(N - 1, !IO)
).
+:- pred print_detism(detism_rep::in, io::di, io::uo) is det.
+
+print_detism(Detism, !IO) :-
+ (
+ Detism = det_rep,
+ DetismStr = "det"
+ ;
+ Detism = semidet_rep,
+ DetismStr = "semidet"
+ ;
+ Detism = nondet_rep,
+ DetismStr = "nondet"
+ ;
+ Detism = multidet_rep,
+ DetismStr = "multi"
+ ;
+ Detism = cc_nondet_rep,
+ DetismStr = "cc_nondet"
+ ;
+ Detism = cc_multidet_rep,
+ DetismStr = "cc_multi"
+ ;
+ Detism = erroneous_rep,
+ DetismStr = "erroneous"
+ ;
+ Detism = failure_rep,
+ DetismStr = "failure"
+ ),
+ io.write_string(DetismStr, !IO).
+
%-----------------------------------------------------------------------------%
:- end_module mdprof_procrep.
%-----------------------------------------------------------------------------%
Index: mdbcomp/program_representation.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/mdbcomp/program_representation.m,v
retrieving revision 1.33
diff -u -p -r1.33 program_representation.m
--- mdbcomp/program_representation.m 12 Aug 2008 02:51:08 -0000 1.33
+++ mdbcomp/program_representation.m 13 Aug 2008 02:42:59 -0000
@@ -65,8 +65,8 @@
:- type proc_rep
---> proc_rep(
- pr_id :: string_proc_label,
- pr_defn :: proc_defn_rep
+ pr_id :: string_proc_label,
+ pr_defn :: proc_defn_rep
).
% A string_proc_label is a data structure that uniquely identifies a
@@ -111,16 +111,26 @@
---> proc_defn_rep(
% The head variables, in order, including the ones introduced
% by the compiler.
- list(var_rep),
+ pdr_head_vars :: list(var_rep),
% The procedure body.
- goal_rep,
+ pdr_goal :: goal_rep,
% The variable table.
- var_table
+ pdr_var_table :: var_table,
+
+ % The determinism of the procedure, this may be different from
+ % procedure's goal's determinism.
+ pdr_detism :: detism_rep
).
:- type goal_rep
+ ---> goal_rep(
+ goal_expr_rep :: goal_expr_rep,
+ goal_detism_rep :: detism_rep
+ ).
+
+:- type goal_expr_rep
---> conj_rep(
list(goal_rep) % The conjuncts in the original order.
)
@@ -144,7 +154,6 @@
maybe_cut
)
; atomic_goal_rep(
- detism_rep,
string, % Filename of context.
int, % Line number of context.
list(var_rep), % The sorted list of the variables
@@ -601,14 +610,19 @@ call_does_not_generate_events(ModuleName
)
).
-goal_generates_internal_event(conj_rep(_)) = no.
-goal_generates_internal_event(disj_rep(_)) = yes.
-goal_generates_internal_event(switch_rep(_, _)) = yes.
-goal_generates_internal_event(ite_rep(_, _, _)) = yes.
-goal_generates_internal_event(negation_rep(_)) = yes.
-goal_generates_internal_event(scope_rep(_, _)) = no.
+goal_generates_internal_event(goal_rep(GoalExpr, _)) =
+ goal_expr_generates_internal_event(GoalExpr).
+
+:- func goal_expr_generates_internal_event(goal_expr_rep) = bool.
+
+goal_expr_generates_internal_event(conj_rep(_)) = no.
+goal_expr_generates_internal_event(disj_rep(_)) = yes.
+goal_expr_generates_internal_event(switch_rep(_, _)) = yes.
+goal_expr_generates_internal_event(ite_rep(_, _, _)) = yes.
+goal_expr_generates_internal_event(negation_rep(_)) = yes.
+goal_expr_generates_internal_event(scope_rep(_, _)) = no.
% Atomic goals may generate interface events, not internal events.
-goal_generates_internal_event(atomic_goal_rep(_, _, _, _, _)) = no.
+goal_expr_generates_internal_event(atomic_goal_rep(_, _, _, _)) = no.
atomic_goal_identifiable(unify_construct_rep(_, _, _)) = no.
atomic_goal_identifiable(unify_deconstruct_rep(_, _, _)) = no.
@@ -881,7 +895,7 @@ read_prog_rep_file(FileName, Result, !IO
%
:- func procrep_id_string = string.
-procrep_id_string = "Mercury deep profiler procrep version 2\n".
+procrep_id_string = "Mercury deep profiler procrep version 3\n".
:- pred read_module_reps(bytecode::in,
list(module_rep)::in, list(module_rep)::out,
@@ -936,7 +950,8 @@ read_proc_rep(ByteCode, StringTable, Pro
read_var_table(ByteCode, StringTable, VarNumRep, VarTable, !Pos),
read_vars(VarNumRep, ByteCode, HeadVars, !Pos),
read_goal(VarNumRep, ByteCode, StringTable, Info, Goal, !Pos),
- ProcDefnRep = proc_defn_rep(HeadVars, Goal, VarTable),
+ read_determinism(ByteCode, Detism, !Pos),
+ ProcDefnRep = proc_defn_rep(HeadVars, Goal, VarTable, Detism),
require(unify(!.Pos, StartPos + Size),
"trace_read_proc_defn_rep: limit mismatch"),
ProcRep = proc_rep(ProcLabel, ProcDefnRep).
@@ -1035,7 +1050,8 @@ trace_read_proc_defn_rep(Bytes, LabelLay
read_var_table(ByteCode, StringTable, VarNumRep, VarTable, !Pos),
read_vars(VarNumRep, ByteCode, HeadVars, !Pos),
read_goal(VarNumRep, ByteCode, StringTable, Info, Goal, !Pos),
- ProcDefnRep = proc_defn_rep(HeadVars, Goal, VarTable),
+ read_determinism(ByteCode, Detism, !Pos),
+ ProcDefnRep = proc_defn_rep(HeadVars, Goal, VarTable, Detism),
require(unify(!.Pos, Size),
"trace_read_proc_defn_rep: limit mismatch")
).
@@ -1054,33 +1070,33 @@ read_goal(VarNumRep, ByteCode, StringTab
(
GoalType = goal_conj,
read_goals(VarNumRep, ByteCode, StringTable, Info, Goals, !Pos),
- Goal = conj_rep(Goals)
+ GoalExpr = conj_rep(Goals)
;
GoalType = goal_disj,
read_goals(VarNumRep, ByteCode, StringTable, Info, Goals, !Pos),
- Goal = disj_rep(Goals)
+ GoalExpr = disj_rep(Goals)
;
GoalType = goal_neg,
read_goal(VarNumRep, ByteCode, StringTable, Info, SubGoal, !Pos),
- Goal = negation_rep(SubGoal)
+ GoalExpr = negation_rep(SubGoal)
;
GoalType = goal_ite,
read_goal(VarNumRep, ByteCode, StringTable, Info, Cond, !Pos),
read_goal(VarNumRep, ByteCode, StringTable, Info, Then, !Pos),
read_goal(VarNumRep, ByteCode, StringTable, Info, Else, !Pos),
- Goal = ite_rep(Cond, Then, Else)
+ GoalExpr = ite_rep(Cond, Then, Else)
;
GoalType = goal_switch,
read_var(VarNumRep, ByteCode, Var, !Pos),
read_cases(VarNumRep, ByteCode, StringTable, Info, Cases, !Pos),
- Goal = switch_rep(Var, Cases)
+ GoalExpr = switch_rep(Var, Cases)
;
GoalType = goal_assign,
read_var(VarNumRep, ByteCode, Target, !Pos),
read_var(VarNumRep, ByteCode, Source, !Pos),
AtomicGoal = unify_assign_rep(Target, Source),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_construct,
read_var(VarNumRep, ByteCode, Var, !Pos),
@@ -1088,7 +1104,7 @@ read_goal(VarNumRep, ByteCode, StringTab
read_vars(VarNumRep, ByteCode, ArgVars, !Pos),
AtomicGoal = unify_construct_rep(Var, ConsId, ArgVars),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_deconstruct,
read_var(VarNumRep, ByteCode, Var, !Pos),
@@ -1096,7 +1112,7 @@ read_goal(VarNumRep, ByteCode, StringTab
read_vars(VarNumRep, ByteCode, ArgVars, !Pos),
AtomicGoal = unify_deconstruct_rep(Var, ConsId, ArgVars),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_partial_construct,
read_var(VarNumRep, ByteCode, Var, !Pos),
@@ -1104,7 +1120,7 @@ read_goal(VarNumRep, ByteCode, StringTab
read_maybe_vars(VarNumRep, ByteCode, MaybeVars, !Pos),
AtomicGoal = partial_construct_rep(Var, ConsId, MaybeVars),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_partial_deconstruct,
read_var(VarNumRep, ByteCode, Var, !Pos),
@@ -1112,14 +1128,14 @@ read_goal(VarNumRep, ByteCode, StringTab
read_maybe_vars(VarNumRep, ByteCode, MaybeVars, !Pos),
AtomicGoal = partial_deconstruct_rep(Var, ConsId, MaybeVars),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_simple_test,
read_var(VarNumRep, ByteCode, Var1, !Pos),
read_var(VarNumRep, ByteCode, Var2, !Pos),
AtomicGoal = unify_simple_test_rep(Var1, Var2),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_scope,
read_byte(ByteCode, MaybeCutByte, !Pos),
@@ -1131,14 +1147,14 @@ read_goal(VarNumRep, ByteCode, StringTab
error("read_goal: bad maybe_cut")
),
read_goal(VarNumRep, ByteCode, StringTable, Info, SubGoal, !Pos),
- Goal = scope_rep(SubGoal, MaybeCut)
+ GoalExpr = scope_rep(SubGoal, MaybeCut)
;
GoalType = goal_ho_call,
read_var(VarNumRep, ByteCode, Var, !Pos),
read_vars(VarNumRep, ByteCode, Args, !Pos),
AtomicGoal = higher_order_call_rep(Var, Args),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_method_call,
read_var(VarNumRep, ByteCode, Var, !Pos),
@@ -1146,14 +1162,14 @@ read_goal(VarNumRep, ByteCode, StringTab
read_vars(VarNumRep, ByteCode, Args, !Pos),
AtomicGoal = method_call_rep(Var, MethodNum, Args),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_cast,
read_var(VarNumRep, ByteCode, OutputVar, !Pos),
read_var(VarNumRep, ByteCode, InputVar, !Pos),
AtomicGoal = cast_rep(OutputVar, InputVar),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_plain_call,
read_string_via_offset(ByteCode, StringTable, ModuleName, !Pos),
@@ -1161,7 +1177,7 @@ read_goal(VarNumRep, ByteCode, StringTab
read_vars(VarNumRep, ByteCode, Args, !Pos),
AtomicGoal = plain_call_rep(ModuleName, PredName, Args),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_builtin_call,
read_string_via_offset(ByteCode, StringTable, ModuleName, !Pos),
@@ -1169,37 +1185,33 @@ read_goal(VarNumRep, ByteCode, StringTab
read_vars(VarNumRep, ByteCode, Args, !Pos),
AtomicGoal = builtin_call_rep(ModuleName, PredName, Args),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
+ AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_event_call,
read_string_via_offset(ByteCode, StringTable, EventName, !Pos),
read_vars(VarNumRep, ByteCode, Args, !Pos),
AtomicGoal = event_call_rep(EventName, Args),
read_atomic_info(VarNumRep, ByteCode, StringTable,
- Info, AtomicGoal, Goal, !Pos)
+ Info, AtomicGoal, GoalExpr, !Pos)
;
GoalType = goal_foreign,
read_vars(VarNumRep, ByteCode, Args, !Pos),
AtomicGoal = pragma_foreign_code_rep(Args),
read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
- AtomicGoal, Goal, !Pos)
- )
+ AtomicGoal, GoalExpr, !Pos)
+ ),
+ read_determinism(ByteCode, Detism, !Pos),
+ Goal = goal_rep(GoalExpr, Detism)
;
error("read_goal: invalid goal type")
).
:- pred read_atomic_info(var_num_rep::in, bytecode::in, string_table::in,
- read_proc_rep_info::in, atomic_goal_rep::in, goal_rep::out,
+ read_proc_rep_info::in, atomic_goal_rep::in, goal_expr_rep::out,
int::in, int::out) is semidet.
-read_atomic_info(VarNumRep, ByteCode, StringTable, Info, AtomicGoal, Goal,
+read_atomic_info(VarNumRep, ByteCode, StringTable, Info, AtomicGoal, GoalExpr,
!Pos) :-
- read_byte(ByteCode, DetismByte, !Pos),
- ( determinism_representation(DetismPrime, DetismByte) ->
- Detism = DetismPrime
- ;
- error("read_atomic_info: bad detism")
- ),
read_string_via_offset(ByteCode, StringTable, FileName0, !Pos),
( FileName0 = "" ->
FileName = Info ^ filename
@@ -1208,7 +1220,7 @@ read_atomic_info(VarNumRep, ByteCode, St
),
read_lineno(ByteCode, LineNo, !Pos),
read_vars(VarNumRep, ByteCode, BoundVars, !Pos),
- Goal = atomic_goal_rep(Detism, FileName, LineNo, BoundVars, AtomicGoal).
+ GoalExpr = atomic_goal_rep(FileName, LineNo, BoundVars, AtomicGoal).
:- pred read_goals(var_num_rep::in, bytecode::in, string_table::in,
read_proc_rep_info::in, list(goal_rep)::out, int::in, int::out) is semidet.
@@ -1367,6 +1379,17 @@ read_var_num_rep(ByteCode, VarNumRep, !P
error("read_var_num_rep: unknown var_num_rep")
).
+:- pred read_determinism(bytecode::in, detism_rep::out, int::in, int::out)
+ is semidet.
+
+read_determinism(ByteCode, Detism, !Pos) :-
+ read_byte(ByteCode, DetismByte, !Pos),
+ ( determinism_representation(DetismPrime, DetismByte) ->
+ Detism = DetismPrime
+ ;
+ error("read_goal: bad detism")
+ ).
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: runtime/mercury_deep_profiling.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
retrieving revision 1.31
diff -u -p -r1.31 mercury_deep_profiling.c
--- runtime/mercury_deep_profiling.c 12 Aug 2008 02:51:08 -0000 1.31
+++ runtime/mercury_deep_profiling.c 13 Aug 2008 02:42:59 -0000
@@ -711,7 +711,7 @@ MR_write_out_procrep_id_string(FILE *fp)
** Must be the same as procrep_id_string in
** mdbcomp/program_representation.m
*/
- const char *id_string = "Mercury deep profiler procrep version 2\n";
+ const char *id_string = "Mercury deep profiler procrep version 3\n";
fputs(id_string, fp);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20080813/7c00432e/attachment.sig>
More information about the reviews
mailing list