[m-rev.] for review: trace builtin and private_builtin

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Dec 7 00:29:08 AEDT 2005



On Tue, 6 Dec 2005, Ian MacLarty wrote:

> For review by anyone.
>
> Estiamted hours taken: 4

s/Estiamated/Estimated/

> Branches: main
>
> Trace builtin and private_builtin (with the exception of external predicates
> and those that are polymorhphic, but have no extra type_info arguments).
>
> This allows subterms to be traced through calls to predicates in builtin
> and private_builtin and fixes an assertion failure in the declarative debugger
> that was triggered when an untraced builtin called a traced predicate
> (the debugger would then think the events from the traced predicate were
> child events of the parent of the untraced predicate, which would cause the
> assertion failure).
>
> compiler/code_gen.m:
> compiler/hlds_pred.m:
> compiler/mercury_compile.m:
> compiler/ml_code_util.m:
> compiler/polymorphism.m:
> compiler/stack_layout.m:
> compiler/term_constr_initial.m:
> mdbcomp/prim_data.m:
> mdbcomp/program_representation.m:
> 	Move no_type_info_builtin from compiler/hlds_pred.m to
> 	mdbcomp/program_representation.m, so that the debugger can call it
> 	to see what builtin polymorphic predicates do not have extra type_info
> 	arguments.
>
> 	Define pred_is_external to be true for predicates defined with
> 	:- external.  The debugger needs to know not to expect any events for
> 	such predicates.
>
> 	Trace the builtin and private_builtin modules.
>
> tests/debugger/loopcheck.exp3:
> tests/debugger/uci.exp2:
> tests/debugger/uci_index.exp:
> 	Changes to expected output due to the fact that builtins are now
> 	traced.
>
> tests/debugger/declarative/Mmakefile:
> tests/debugger/declarative/typed_unify.exp:
> tests/debugger/declarative/typed_unify.inp:
> tests/debugger/declarative/typed_unify.m:
> 	Test tracking of a subterm through a builtin.
>

...

> Index: compiler/stack_layout.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
> retrieving revision 1.109
> diff -u -r1.109 stack_layout.m
> --- compiler/stack_layout.m	28 Oct 2005 02:10:36 -0000	1.109
> +++ compiler/stack_layout.m	28 Nov 2005 18:48:19 -0000
> @@ -87,6 +87,7 @@
>  :- import_module ll_backend.llds_out.
>  :- import_module ll_backend.prog_rep.
>  :- import_module ll_backend.trace.
> +:- import_module mdbcomp.program_representation.
>  :- import_module parse_tree.prog_out.
>  :- import_module parse_tree.prog_util.
>
> @@ -421,8 +422,9 @@
>      ).
>
>  :- pred find_valid_return_context(
> -    assoc_list(code_addr, pair(prog_context, goal_path))::in,
> -    code_addr::out, prog_context::out, goal_path::out) is semidet.
> +    assoc_list(code_addr, pair(prog_context, hlds.hlds_goal.goal_path))::in,

One level of module qualification should be sufficent to differentiate
between hlds_goal.goal_path and program_representation.goal_path.

(On an unrelated note: are these two versions of the goal_path type that
different that we need two of them?  Superficially they look similar.)

...

> Index: mdbcomp/program_representation.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/mdbcomp/program_representation.m,v
> retrieving revision 1.9
> diff -u -r1.9 program_representation.m
> --- mdbcomp/program_representation.m	19 Oct 2005 05:39:08 -0000	1.9
> +++ mdbcomp/program_representation.m	5 Dec 2005 18:23:02 -0000
> @@ -35,7 +35,12 @@
>
>  :- interface.
>
> -:- import_module char, list, std_util, bool.
> +:- import_module mdbcomp.prim_data.
> +
> +:- import_module bool.
> +:- import_module char.
> +:- import_module list.
> +:- import_module std_util.
>
>      % A representation of the goal we execute. These need to be generated
>      % statically and stored inside the executable.
> @@ -177,11 +182,12 @@
>      %
>  :- func goal_generates_internal_event(goal_rep) = bool.
>
> -    % call_is_primitive(ModuleName, PredName): succeeds iff a call to the
> -    % named predicate behaves like a primitive operation, in the sense that
> -    % it does not generate events.
> +    % call_does_not_generate_events(ModuleName, PredName, Arity): succeeds iff
> +    % a call to the named predicate will not generate events in a debugging
> +    % grade.
>      %
> -:- pred call_is_primitive(string::in, string::in) is semidet.
> +:- pred call_does_not_generate_events(string::in, string::in, int::in)
> +    is semidet.
>
>      % The atomic goal's module, name and arity.
>  :- type atomic_goal_id
> @@ -315,6 +321,21 @@
>  :- mode var_num_rep_byte(in, out) is det.
>  :- mode var_num_rep_byte(out, in) is semidet.
>
> +    % Some predicates that operate on polymorphic values do not need
> +    % the type_infos describing the types bound to the variables.
> +    % It is of course faster not to pass type_infos to such predicates
> +    % (especially since may also be able to avoid constructing those
> +    % type_infos), and it can also be easier for a compiler module
> +    % (e.g. common.m, size_prof.m) that generates calls to such predicates
> +    % not to have to create those type_infos.
> +    %
> +    % All the predicates for whose names no_type_info_builtin succeeds
> +    % are defined by compiler implementors. They are all predicates
> +    % implemented by foreign language code in the standard library.
> +    % For some, but not all, the compiler generates code inline.
> +    %
> +:- pred no_type_info_builtin(module_name::in, string::in, int::in) is semidet.
> +
>  %-----------------------------------------------------------------------------%
>
>  :- implementation.
> @@ -323,8 +344,6 @@
>  :- import_module require.
>  :- import_module string.
>
> -:- import_module mdbcomp.prim_data.
> -
>  atomic_goal_generates_event(unify_construct_rep(_, _, _)) = no.
>  atomic_goal_generates_event(unify_deconstruct_rep(_, _, _)) = no.
>  atomic_goal_generates_event(partial_construct_rep(_, _, _)) = no.
> @@ -337,21 +356,26 @@
>  atomic_goal_generates_event(method_call_rep(_, _, Args)) = yes(Args).
>  atomic_goal_generates_event(builtin_call_rep(_, _, _)) = no.
>  atomic_goal_generates_event(plain_call_rep(ModuleName, PredName, Args)) =
> -    ( call_is_primitive(ModuleName, PredName) ->
> -        % These calls behave as primitives and do not generate events.
> +    ( call_does_not_generate_events(ModuleName, PredName, list.length(Args)) ->
>          no
>      ;
>          yes(Args)
>      ).
>
> -call_is_primitive(ModuleName, PredName) :-
> +call_does_not_generate_events(ModuleName, PredName, Arity) :-
>      (
>          string_to_sym_name(ModuleName, ".", SymModuleName),
> -        any_mercury_builtin_module(SymModuleName)
> +        non_traced_mercury_builtin_module(SymModuleName)
> +    ;
> +        % The debugger cannot handle calls to polymorphic builtins that
> +        % do not take a type_info argument, so such calls are not traced.
> +        string_to_sym_name(ModuleName, ".", SymModuleName),
> +        no_type_info_builtin(SymModuleName, PredName, Arity)
> +    ;
> +        pred_is_external(ModuleName, PredName, Arity)
>      ;
> -        % The following are also treated as primitive since events from
> -        % compiler generated predicates are not included in the annotated trace
> -        % at the moment.
> +        % Events from compiler generated predicates are not included in the
> +        % annotated trace at the moment.
>          (
>              PredName = "__Unify__"
>          ;
> @@ -503,3 +527,59 @@
>  var_num_rep_byte(short, 1).
>
>  %-----------------------------------------------------------------------------%
> +
> +no_type_info_builtin(ModuleName, PredName, Arity) :-
> +    no_type_info_builtin_2(ModuleNameType, PredName, Arity),
> +    (
> +        ModuleNameType = builtin,
> +        mercury_public_builtin_module(ModuleName)
> +    ;
> +        ModuleNameType = private_builtin,
> +        mercury_private_builtin_module(ModuleName)
> +    ;
> +        ModuleNameType = table_builtin,
> +        mercury_table_builtin_module(ModuleName)
> +    ;
> +        ModuleNameType = term_size_prof_builtin,
> +        mercury_term_size_prof_builtin_module(ModuleName)
> +    ).
> +
> +:- type builtin_mod
> +    --->    builtin
> +    ;       private_builtin
> +    ;       table_builtin
> +    ;       term_size_prof_builtin.
> +
> +:- pred no_type_info_builtin_2(builtin_mod::out, string::in, int::in)
> +    is semidet.
> +
> +no_type_info_builtin_2(private_builtin, "store_at_ref", 2).
> +no_type_info_builtin_2(private_builtin, "unsafe_type_cast", 2).
> +no_type_info_builtin_2(builtin, "unsafe_promise_unique", 2).
> +no_type_info_builtin_2(private_builtin,
> +    "superclass_from_typeclass_info", 3).
> +no_type_info_builtin_2(private_builtin,
> +    "instance_constraint_from_typeclass_info", 3).
> +no_type_info_builtin_2(private_builtin,
> +    "type_info_from_typeclass_info", 3).
> +no_type_info_builtin_2(private_builtin,
> +    "unconstrained_type_info_from_typeclass_info", 3).
> +no_type_info_builtin_2(table_builtin, "table_restore_any_answer", 3).
> +no_type_info_builtin_2(table_builtin, "table_lookup_insert_enum", 4).
> +no_type_info_builtin_2(table_builtin, "table_lookup_insert_typeinfo", 3).
> +no_type_info_builtin_2(table_builtin, "table_lookup_insert_typeclassinfo", 3).
> +no_type_info_builtin_2(term_size_prof_builtin, "increment_size", 2).
> +
> +    % True iff the given predicate is defined with an :- external
> +    % declaration.  Note that the arity includes the hidden type info
> +    % arguments for polymorphic predicates.
> +    %
> +:- pred pred_is_external(string::in, string::in, int::in) is semidet.
> +
> +pred_is_external("exception", "builtin_catch", 4).
> +pred_is_external("exception", "builtin_throw", 1).
> +pred_is_external("builtin", "unify", 3).
> +pred_is_external("builtin", "compare", 4).
> +pred_is_external("builtin", "compare_representation", 4).
> +

It would be worth adding a pointer to this predicate in builtin and exception
to the effect that if the implementation of these predicates is changed then
this predicate may need to be updated.

That's fine otherwise.

Cheers,
Julien.

--------------------------------------------------------------------------
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