[m-rev.] nondet & multi code managed by ssdb

Peter Wang novalazy at gmail.com
Thu Nov 1 15:17:59 AEDT 2007


On 2007-11-01, Olivier Annet <oan at missioncriticalit.com> wrote:
> Hi,
> 
> could someone can review my code before commit.
> 
> Thank you.
> 
> 
> ===================================================================
> 
> 
> Estimated hours taken: 15
> Branches: main
> 
> The source-to-source debugger is able to managed multi, nondet, cc_multi and 
> cc_nondet code now.

Make the source-to-source debugger transformation handle
nondeterministic procedures.

> 
> compiler/mercury_compile.m:
> 	Run the automatic determinism analysis because I have a problem with my
> 	manual determinism. I'm going to optimize it later.

Move this to the end as it's the least important change.

> 
> compiler/ssdebug.m:
> 	Addition of code to managed the nondet and multi procedures.

Add code to transform nondeterministic procedures.

Add stuff about
    - not wrapping impure procedures with redundant promise_impure scopes
    - flattening conjunctions
    - whatever else

> ssdb/ssdb.m:
> 	Modification of the code due to the introduction of the redo port.

Maybe something like:

    Handle redo ports properly.  They were not handled properly before
    because only det and semidet procedures were supported.

> 
> Index: compiler/mercury_compile.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
> retrieving revision 1.452
> diff -u -r1.452 mercury_compile.m
> --- compiler/mercury_compile.m	4 Oct 2007 09:04:42 -0000	1.452
> +++ compiler/mercury_compile.m	1 Nov 2007 02:31:42 -0000
> @@ -3191,7 +3191,10 @@
>          process_all_nonimported_procs(
>              update_module_io(ssdebug.process_proc), !HLDS, !IO),
>          maybe_write_string(Verbose, "% done.\n", !IO),
> -        maybe_report_stats(Stats, !IO)
> +        maybe_report_stats(Stats, !IO),
> +
> +        determinism_pass(!HLDS, _Specs),
> +	true

Delete the true and add an XXX.

[for other readers: I added this because the ssdb transformation doesn't
have the right determinisms on the compound goals that it introduces.]

> Index: compiler/ssdebug.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/ssdebug.m,v
> retrieving revision 1.8
> diff -u -r1.8 ssdebug.m
> --- compiler/ssdebug.m	30 Oct 2007 00:51:23 -0000	1.8
> +++ compiler/ssdebug.m	1 Nov 2007 02:31:43 -0000
> @@ -193,16 +193,16 @@
>          process_proc_semi(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO)
>      ;
>          Determinism = detism_multi,
> -        error("determ_multi: not yet implemented in ssdb")
> +        process_proc_nondet(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO)
>      ; 
>          Determinism = detism_non,
> -        error("determ_non: not yet implemented in ssdb")
> +        process_proc_nondet(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO)
>      ; 
>          Determinism = detism_cc_multi,
> -        error("determ_cc_multi: not yet implemented in ssdb")
> +        process_proc_det(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO)
>      ; 
>          Determinism = detism_cc_non,
> -        error("detism_cc_non: not yet implemented in ssdb")
> +        process_proc_semi(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO)

You can reduce the code duplication like this:

    ( Determinism = detism_multi
    ; Determinism = detism_non
    ),
    process_proc_nondet(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO)

> @@ -286,26 +286,22 @@
>  
>          %
>          % Organize the order of the generated code.
> -        %
> +        % XXX Need optimization in list append.
> +        goal_to_conj_list(BodyGoal1, BodyGoalList),
>          ConjGoals = ProcIdGoals ++ CallArgListGoals ++ 
> -            [HandleEventCallGoal, BodyGoal1 | ExitArgListGoals] ++ 
> +            [HandleEventCallGoal] ++ BodyGoalList ++ ExitArgListGoals ++ 
>              [HandleEventExitGoal | RenamingGoals],
>  
> -        goal_info_init(GoalInfoWP),
> -        GoalWithoutPurity = hlds_goal(conj(plain_conj, ConjGoals), GoalInfoWP),
> +        % Set the determinism.
> +        Determinism = detism_det,
> +        goal_info_init(GoalInfo0),
> +        goal_info_set_determinism(Determinism, GoalInfo0, GoalInfo),
> +        
> +        conj_list_to_goal(ConjGoals, GoalInfo, GoalWithoutPurity),
>  
> -        %
> -        % Get the purity of the goal.
> -        %
> +        % Goal => promise_purity(Goal).
>          Purity = goal_info_get_purity(BodyGoalInfo0),

Write that comment as a sentence.

>  
> +    %
> +    % Source-to-source transformation for a nondet goal.

nondeterministic procedure.

> +    %
> +:- pred process_proc_nondet(pred_id::in, proc_id::in,
> +    proc_info::in, proc_info::out, module_info::in, module_info::out,
> +    io::di, io::uo) is det.
> +
> +process_proc_nondet(PredId, ProcId, !ProcInfo, !ModuleInfo, !IO) :-
> +    proc_info_get_goal(!.ProcInfo, BodyGoal0),
> +    get_hlds_goal_info(BodyGoal0) = BodyGoalInfo0,
> +
> +    some [!PredInfo, !Varset, !Vartypes] (
> +        proc_info_get_varset(!.ProcInfo, !:Varset),
> +        proc_info_get_vartypes(!.ProcInfo, !:Vartypes),
> +
> +        %
> +        % Make the ssdb_proc_id.
> +        %
> +        module_info_pred_info(!.ModuleInfo, PredId, !:PredInfo),
> +        make_proc_id_construction(!.PredInfo, !.ProcInfo, ProcIdGoals, 
> +            ProcIdVar, !Varset, !Vartypes),
> +        
> +        %
> +        % Get the list of head var iables and their type.

variables.

You don't get their types.

> +        %
> +        proc_info_get_headvars(!.ProcInfo, HeadVars),
> +        proc_info_get_initial_instmap(!.ProcInfo, !.ModuleInfo, InitInstMap),
> +
> +        %
> +        % Make a list which records the value for each of the head variables at
> +        % the call port.
> +        %
> +        make_arg_list(0, InitInstMap, HeadVars, map.init, CallArgListVar, 
> +            CallArgListGoals, !ModuleInfo, !ProcInfo, !PredInfo, !Varset, 
> +            !Vartypes, map.init, BoundVarDescsAtCall),
> +
> +        %
> +        % Generate the call to handle_event_call(ProcId, VarList).
> +        %
> +        make_handle_event_call(ProcIdVar, CallArgListVar, HandleEventCallGoal, 
> +            !ModuleInfo, !Varset, !Vartypes),
> +
> +        %
> +        % Get the updated InstMap.
> +        %
> +        update_instmap(BodyGoal0, InitInstMap, FinalInstMap),

Get the instmap at the end of the procedure.

> +
> +        %
> +        % Rename the output variables.
> +        %

You might want to say why, although if it's described elsewhere that's
okay.

> +        proc_info_instantiated_head_vars(!.ModuleInfo, !.ProcInfo, 
> +            InstantiatedVars),
> +        goal_info_get_instmap_delta(BodyGoalInfo0) = InstMapDelta,
> +        create_renaming(InstantiatedVars, InstMapDelta, !Varset, !Vartypes, 
> +            RenamingGoals, _NewVars, Renaming),
> +        rename_some_vars_in_goal(Renaming, BodyGoal0, BodyGoal1),
> +        
> +        %
> +        % Make the variable list at the exit port. It's currently a completely 
> +        % new list instead of adding on to the list generated for the call 
> +        % port.
> +        %
> +        make_arg_list(0, FinalInstMap, HeadVars, Renaming, ExitArgListVar, 
> +            ExitArgListGoals, !ModuleInfo, !ProcInfo, !PredInfo, !Varset, 
> +            !Vartypes, BoundVarDescsAtCall, _BoundVarDescsAtExit),
> +
> +        %
> +        % Generate the call to handle_event_exit(ProcId, VarList).
> +        %
> +        make_handle_event_exit(ProcIdVar, ExitArgListVar, HandleEventExitGoal, 
> +            !ModuleInfo, !Varset, !Vartypes),
> +        
> +        %
> +        % Generate the call to handle_event_redo(ProcId, VarList).
> +        %
> +        make_handle_event_redo(ProcIdVar, ExitArgListVar, HandleEventRedoGoal,
> +            !ModuleInfo, !Varset, !Vartypes),
> +
> +        %
> +        % Generate the list of argument at the fail port.

arguments

> +
> +	GoalWithoutPurity = hlds_goal(conj(plain_conj, 
> +	    ProcIdGoals ++ [DisjGoal2]), GoalInfo),
> +
> +        % Goal => promise_purity(Goal).

As above.

> +        Purity = goal_info_get_purity(BodyGoalInfo0),
> +
> +	set_goal_purity(Purity, GoalInfo, GoalWithoutPurity, Goal),        
> +
> +        commit_goal_changes(Goal, PredId, ProcId, !.PredInfo, !ProcInfo,
> +            !ModuleInfo, !.Varset, !.Vartypes)
> +    ).
> +	
> +
> +:- pred set_goal_purity(purity::in, hlds_goal_info::in, hlds_goal::in, 
> +    hlds_goal::out) is det.

Rename this to wrap_with_purity_scope or similar to reflect what it
actually does.

Explain why the scope is not introduced for impure procedures.

> +
> +set_goal_purity(Purity, GoalInfo, GoalWithoutPurity, Goal) :-
> +    ( 
> +	Purity = purity_impure 
> +    ->
> +	Goal = GoalWithoutPurity
> +    ;
> +	ScopeReason = promise_purity(dont_make_implicit_promises, Purity),
> +	Goal = hlds_goal(scope(ScopeReason, GoalWithoutPurity), GoalInfo)
> +    ).

Write that as a switch.

> @@ -477,10 +619,7 @@
>  make_handle_event_call(ProcIdVar, ArgListVar, HandleEventGoal, !ModuleInfo, 
>      !Varset, !Vartypes) :-
>  
> -    SSDBModule = mercury_ssdb_builtin_module,
> -    Features = [],
> -    InstMapSrc = [],
> -    Context = term.context_init,
> +    init_simple_call_handle_event(SSDBModule, Features, InstMapSrc, Context),
>      goal_util.generate_simple_call(SSDBModule, "handle_event_call", 
>          pf_predicate, only_mode, detism_det, purity_impure, 
>          [ProcIdVar, ArgListVar], Features, InstMapSrc, !.ModuleInfo, Context, 

The way to make these make_handle_event_* predicates share code would be
to have them call a shared predicate passing the name of the predicate
to call as an argument.

Peter

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list