[m-rev.] for review: track subterms through partial unifications
Ian MacLarty
maclarty at cs.mu.OZ.AU
Tue Sep 6 15:56:10 AEST 2005
On Sun, 4 Sep 2005, Zoltan Somogyi wrote:
> On 03-Sep-2005, Ian MacLarty <maclarty at cs.mu.OZ.AU> wrote:
> > For review by anyone.
>
> I don't think this diff is right, but it is better to discuss this in person.
>
Here is the interdiff:
diff -u browser/declarative_execution.m browser/declarative_execution.m
--- browser/declarative_execution.m 2 Sep 2005 10:53:44 -0000
+++ browser/declarative_execution.m 5 Sep 2005 07:58:23 -0000
@@ -1592,11 +1592,20 @@
read_atomic_info(VarNumRep, Bytecode, Label, !Pos,
Info, AtomicGoal, Goal)
;
- GoalType = goal_partial_unify,
+ GoalType = goal_partial_construct,
read_var(VarNumRep, Bytecode, !Pos, Var),
read_cons_id(Bytecode, Label, !Pos, ConsId),
read_maybe_vars(VarNumRep, Bytecode, !Pos, MaybeVars),
- AtomicGoal = unify_partial_rep(Var, ConsId,
+ AtomicGoal = partial_construct_rep(Var, ConsId,
+ MaybeVars),
+ read_atomic_info(VarNumRep, Bytecode, Label, !Pos,
+ Info, AtomicGoal, Goal)
+ ;
+ GoalType = goal_partial_deconstruct,
+ read_var(VarNumRep, Bytecode, !Pos, Var),
+ read_cons_id(Bytecode, Label, !Pos, ConsId),
+ read_maybe_vars(VarNumRep, Bytecode, !Pos, MaybeVars),
+ AtomicGoal = partial_deconstruct_rep(Var, ConsId,
MaybeVars),
read_atomic_info(VarNumRep, Bytecode, Label, !Pos,
Info, AtomicGoal, Goal)
diff -u browser/declarative_tree.m browser/declarative_tree.m
--- browser/declarative_tree.m 3 Sep 2005 06:25:58 -0000
+++ browser/declarative_tree.m 6 Sep 2005 05:32:21 -0000
@@ -1616,8 +1616,42 @@
Store, ProcRep, Origin)
)
;
- AtomicGoal = unify_partial_rep(_CellVar, _Cons, MaybeFieldVars),
- ( list.member(Var0, BoundVars) ->
+ AtomicGoal = partial_deconstruct_rep(_, _, MaybeFieldVars),
+ (
+ list.member(Var0, BoundVars),
+ TermPath0 = [TermPathStep0 | TermPath]
+ ->
+ list.index1_det(MaybeFieldVars, TermPathStep0,
+ MaybeVar),
+ (
+ MaybeVar = yes(Var),
+ %
+ % This partial deconstruction bound the
+ % TermPathStep0'th argument of
+ % Var0.
+ %
+ traverse_primitives(Prims, Var, TermPath,
+ Store, ProcRep, Origin)
+ ;
+ MaybeVar = no,
+ %
+ % This partial deconstruction did not
+ % bind the TermPathStep0'th argument,
+ % so continue looking for the
+ % unification which did.
+ %
+ traverse_primitives(Prims, Var0, TermPath0,
+ Store, ProcRep, Origin)
+ )
+ ;
+ traverse_primitives(Prims, Var0, TermPath0,
+ Store, ProcRep, Origin)
+ )
+ ;
+ AtomicGoal = partial_construct_rep(_, _, MaybeFieldVars),
+ (
+ list.member(Var0, BoundVars)
+ ->
(
TermPath0 = [],
Origin = primitive_op(File, Line, unification)
@@ -1628,7 +1662,7 @@
(
MaybeVar = yes(Var),
%
- % This partial unification bound the
+ % The partial construction bound the
% TermPathStep0'th argument of
% Var0.
%
@@ -1638,14 +1672,17 @@
;
MaybeVar = no,
%
- % This partial unfication did not
- % bind the TermPathStep0'th argument,
- % so continue looking for the
- % unification which did.
+ % We got to the construction
+ % which bound the outer most functor
+ % of Var0 without finding the
+ % unification which bound the
+ % TermPathStep0'th argument of that
+ % functor. So something has gone
+ % wrong.
%
- traverse_primitives(Prims, Var0,
- TermPath0, Store, ProcRep,
- Origin)
+ throw(internal_error(
+ "traverse_primitives",
+ "input argument not found"))
)
)
;
diff -u compiler/prog_rep.m compiler/prog_rep.m
--- compiler/prog_rep.m 2 Sep 2005 10:18:55 -0000
+++ compiler/prog_rep.m 5 Sep 2005 08:45:43 -0000
@@ -49,6 +49,7 @@
:- import_module backend_libs__bytecode_data.
:- import_module check_hlds__inst_match.
+:- import_module check_hlds__mode_util.
:- import_module hlds__code_model.
:- import_module hlds__hlds_data.
:- import_module mdbcomp__prim_data.
@@ -162,7 +163,7 @@
;
Uni = construct(Var, ConsId, Args, ArgModes, _, _, _),
cons_id_to_byte_list(ConsId, !StackInfo, ConsIdBytes),
- ( list.all_true(rhs_is_input(Info), ArgModes) ->
+ ( list.all_true(lhs_final_is_ground(Info), ArgModes) ->
Bytes = [goal_type_to_byte(goal_construct)] ++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
@@ -170,7 +171,7 @@
AtomicBytes
;
filter_input_args(Info, ArgModes, Args, MaybeArgs),
- Bytes = [goal_type_to_byte(goal_partial_unify)] ++
+ Bytes = [goal_type_to_byte(goal_partial_construct)] ++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
maybe_vars_to_byte_list(Info, MaybeArgs) ++
@@ -181,7 +182,7 @@
cons_id_to_byte_list(ConsId, !StackInfo, ConsIdBytes),
( list.member(Var, BoundVars) ->
filter_input_args(Info, ArgModes, Args, MaybeArgs),
- Bytes = [goal_type_to_byte(goal_partial_unify)] ++
+ Bytes = [goal_type_to_byte(goal_partial_deconstruct)]++
var_to_byte_list(Info, Var) ++
ConsIdBytes ++
maybe_vars_to_byte_list(Info, MaybeArgs) ++
@@ -287,10 +288,15 @@
% these should have been expanded out by now
error("goal_expr_to_byte_list: unexpected shorthand").
+:- pred lhs_final_is_ground(prog_rep__info::in, uni_mode::in) is semidet.
+
+lhs_final_is_ground(Info, (_ - _) -> (LHSFinalInst - _)) :-
+ inst_is_ground(Info ^ module_info, LHSFinalInst).
+
:- pred rhs_is_input(prog_rep__info::in, uni_mode::in) is semidet.
-rhs_is_input(Info, (_ - RHSInitialInst) -> (_ - _)) :-
- inst_is_bound(Info ^ module_info, RHSInitialInst).
+rhs_is_input(Info, (_ - RHSInitialInst) -> (_ - RHSFinalInst)) :-
+ mode_is_input(Info ^ module_info, RHSInitialInst -> RHSFinalInst).
:- pred filter_input_args(prog_rep__info::in, list(uni_mode)::in,
list(prog_var)::in, list(maybe(prog_var))::out) is det.
diff -u mdbcomp/program_representation.m mdbcomp/program_representation.m
--- mdbcomp/program_representation.m 3 Sep 2005 08:46:00 -0000
+++ mdbcomp/program_representation.m 6 Sep 2005 02:34:37 -0000
@@ -96,12 +96,26 @@
list(var_rep)
)
%
- % A partial unification of the form
+ % A partial deconstruction of the form
% X = f(Y_1, Y_2, ..., Y_n)
- % Where some of the Y_i are free after the unification
- % and X is more instanciated after the unification.
+ % where X is more instanciated after the unification
+ % than before.
%
- ; unify_partial_rep(
+ ; partial_deconstruct_rep(
+ var_rep, % X
+ cons_id_rep, % f
+ % The list of Y_i's. Y_i's which are
+ % input are wrapped in `yes', while the other
+ % Y_i positions are `no'.
+ list(maybe(var_rep))
+ )
+ %
+ % A partial construction of the form
+ % X = f(Y_1, Y_2, ..., Y_n)
+ % where X is free before the unification and bound,
+ % but not ground, after the unification.
+ %
+ ; partial_construct_rep(
var_rep, % X
cons_id_rep, % f
% The list of Y_i's. Y_i's which are
@@ -277,7 +291,8 @@
; goal_scope
; goal_construct
; goal_deconstruct
- ; goal_partial_unify
+ ; goal_partial_construct
+ ; goal_partial_deconstruct
; goal_assign
; goal_cast
; goal_simple_test
@@ -314,7 +329,8 @@
atomic_goal_generates_event(unify_construct_rep(_, _, _)) = no.
atomic_goal_generates_event(unify_deconstruct_rep(_, _, _)) = no.
-atomic_goal_generates_event(unify_partial_rep(_, _, _)) = no.
+atomic_goal_generates_event(partial_construct_rep(_, _, _)) = no.
+atomic_goal_generates_event(partial_deconstruct_rep(_, _, _)) = no.
atomic_goal_generates_event(unify_assign_rep(_, _)) = no.
atomic_goal_generates_event(unify_simple_test_rep(_, _)) = no.
atomic_goal_generates_event(cast_rep(_, _)) = no.
@@ -358,7 +374,8 @@
atomic_goal_identifiable(unify_construct_rep(_, _, _)) = no.
atomic_goal_identifiable(unify_deconstruct_rep(_, _, _)) = no.
-atomic_goal_identifiable(unify_partial_rep(_, _, _)) = no.
+atomic_goal_identifiable(partial_construct_rep(_, _, _)) = no.
+atomic_goal_identifiable(partial_deconstruct_rep(_, _, _)) = no.
atomic_goal_identifiable(unify_assign_rep(_, _)) = no.
atomic_goal_identifiable(unify_simple_test_rep(_, _)) = no.
atomic_goal_identifiable(cast_rep(_, _)) = no.
@@ -471,15 +488,16 @@
goal_type_byte(6, goal_scope).
goal_type_byte(7, goal_construct).
goal_type_byte(8, goal_deconstruct).
-goal_type_byte(9, goal_partial_unify).
-goal_type_byte(10, goal_assign).
-goal_type_byte(11, goal_cast).
-goal_type_byte(12, goal_simple_test).
-goal_type_byte(13, goal_foreign).
-goal_type_byte(14, goal_ho_call).
-goal_type_byte(15, goal_method_call).
-goal_type_byte(16, goal_plain_call).
-goal_type_byte(17, goal_builtin_call).
+goal_type_byte(9, goal_partial_construct).
+goal_type_byte(10, goal_partial_deconstruct).
+goal_type_byte(11, goal_assign).
+goal_type_byte(12, goal_cast).
+goal_type_byte(13, goal_simple_test).
+goal_type_byte(14, goal_foreign).
+goal_type_byte(15, goal_ho_call).
+goal_type_byte(16, goal_method_call).
+goal_type_byte(17, goal_plain_call).
+goal_type_byte(18, goal_builtin_call).
%-----------------------------------------------------------------------------%
--- CVSLOG.old 2005-09-05 22:51:07.000000000 +1000
+++ CVSLOG 2005-09-05 22:53:00.000000000 +1000
@@ -3,7 +3,7 @@
Allow subterms to be tracked through partial unifications in the
declarative debugger.
-This involves adding a new type of atomic goal to the program representation
+This involves adding new types of atomic goals to the program representation
stored with the executable of programs compiled with `--trace rep'.
Remove the ``unsafe'' from the cast goal representation to bring the program
@@ -17,8 +17,8 @@
compiler/prog_rep.m:
If a construction or deconstruction unification is a partial
- unification then generate the new goal type instead of a construction
- or deconstruction.
+ unification then generate a partial construction or deconstruction
+ goal type.
Make atomic_goal_info_to_byte_list return the list of variables bound
by the atomic goal so we can check if a deconstruction is a
Ian.
--------------------------------------------------------------------------
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