[m-rev.] for review: constraint propagation [2]

Simon Taylor stayl at cs.mu.OZ.AU
Sun Aug 12 00:02:29 AEST 2001


On 11-Aug-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> The relative diff looks fine.
> There's just one point that bothers me a bit:
> 
> On 11-Aug-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > compiler/det_analsysis.m:
> > 	Disable reporting of errors and warnings when rerunning
> > 	determinism analysis after constraint propagation.
> ...
> > --- compiler/det_analysis.m	2001/04/07 14:04:34	1.150
> > +++ compiler/det_analysis.m	2001/08/07 10:52:08
> ...
> > -global_final_pass(ModuleInfo0, ProcList, Debug, ModuleInfo) -->
> > +global_final_pass(ReportErrors, ModuleInfo0, ProcList, Debug, ModuleInfo) -->
> >  	global_inference_single_pass(ProcList, Debug, ModuleInfo0, ModuleInfo1,
> >  		[], Msgs, unchanged, _),
> > -	det_report_and_handle_msgs(Msgs, ModuleInfo1, ModuleInfo2),
> > -	global_checking_pass(ProcList, ModuleInfo2, ModuleInfo).
> > +	( { ReportErrors = yes } ->
> > +		det_report_and_handle_msgs(Msgs, ModuleInfo1, ModuleInfo2),
> > +		global_checking_pass(ProcList, ModuleInfo2, ModuleInfo)
> > +	;
> > +		{ ModuleInfo = ModuleInfo1 }
> > +	).
> 
> I understand why disabling reporting of warnings makes sense,
> but it might be nice to have some sanity checking to ensure
> that constraint propagation preserves determinism correctness.

I've undone the change to det_analysis.m.
I'll commmit this now.

Simon.


Estimated hours taken: 90

Constraint propagation.

compiler/constraint.m:
	Push constraints left and inwards as much as possible
	within a goal. This module has been completely rewritten.

compiler/deforest.m:
	Push constraints within a goal before processing it.

	Make specialized versions for calls with constrained outputs.

	Rerun determinism inference on specialized versions
	when constraint propagation has been run, because the
	determinism can change from nondet to semidet.

compiler/pd_util.m:
	Add pd_util__propagate_constraints, which uses constraint.m
	to push constraints within a goal.

	Add some documentation for the exported predicates.

compiler/pd_term.m:
	Add support for checking termination of the optimization process
	for constraint propagation, which differs from deforestation
	in that the conjunctions selected for optimization don't
	necessarily have a call at both ends.

compiler/pd_debug.m:
	Print some extra information when `--debug-pd' is enabled.

compiler/mercury_compile.m:
	Check whether constraint propagation should be performed when
	working out whether to run the deforestation pass.

compiler/make_hlds.m:
	Add `no_inline' markers to the "recursive" procedures
	introduced for builtins to stop constraint propagation
	attempting to specialize such procedures.

compiler/hlds_pred.m:
	Don't fill in the declared determinism field of the predicates
	introduced by `hlds_pred__define_new_pred', so that rerunning
	determinism inference will compute a more accurate determinism.

compiler/inlining.m:
	Requantify before recomputing instmap_deltas, not after.

compiler/det_report.m:
	Add predicates to disable warnings when rerunning
	determinism analysis after constraint propagation.

compiler/options.m:
	Add documentation for `--constraint-propagation'.

	Add option `--local-constraint-propagation', which makes
	deforestation call constraint.m to move constraints within
	a goal, but does not create specialized versions of procedures
	for which there are calls with constrained outputs.

compiler/handle_options.m:
	`--constraint-propagation' implies `--local-constraint-propagation'.

compiler/notes/compiler_design.html:
	Change the documentation to show that constraint.m is now part
	of the deforestation pass.

NEWS:
	Announce the new transformation.

doc/user_guide.texi:
	Document the new options.

tests/hard_coded/Mmakefile:
tests/hard_coded/constraint.{m,exp}:
tests/hard_coded/constraint_order.{m,exp}:
	Test cases.


--- deforest.m	2001/08/11 06:27:25	1.2
+++ deforest.m	2001/08/11 08:35:43
@@ -49,7 +49,7 @@
 :- import_module dependency_graph, hlds_data, det_analysis, globals.
 :- import_module mode_util, goal_util, prog_data, prog_util, purity.
 :- import_module modes, mode_info, unique_modes, options, hlds_out.
-:- import_module prog_out, quantification.
+:- import_module prog_out, quantification, det_report.
 
 :- import_module assoc_list, bool, getopt, int, list, map, require.
 :- import_module set, std_util, string, term, varset.
@@ -103,9 +103,15 @@
 		% become semidet.
 		list__foldl(reset_inferred_proc_determinism, Versions,
 			ModuleInfo4, ModuleInfo5),
-		ReportErrors = no,
-		determinism_pass(ReportErrors,
-			ModuleInfo5, ModuleInfo, IO3, IO)	
+		module_info_num_errors(ModuleInfo5, Errors5),
+
+		disable_det_warnings(OptionsToRestore, IO3, IO4),
+		determinism_pass(ModuleInfo5, ModuleInfo, IO4, IO5),
+		restore_det_warnings(OptionsToRestore, IO5, IO),
+
+		module_info_num_errors(ModuleInfo, Errors),
+		require(unify(Errors5, Errors),
+			"determinism errors after deforestation")
 	;
 		IO = IO3,
 		ModuleInfo = ModuleInfo4
--- det_report.m	2001/08/11 06:27:25	1.1
+++ det_report.m	2001/08/11 13:57:59
@@ -113,6 +113,19 @@
 
 %-----------------------------------------------------------------------------%
 
+:- type options_to_restore.
+
+	% Call this predicate before rerunning determinism analysis
+	% after an optimization pass to disable all warnings. Errors will
+	% still be reported.
+:- pred disable_det_warnings(options_to_restore, io__state, io__state).
+:- mode disable_det_warnings(out, di, uo) is det.
+
+:- pred restore_det_warnings(options_to_restore, io__state, io__state).
+:- mode restore_det_warnings(in, di, uo) is det.
+
+%-----------------------------------------------------------------------------%
+
 :- type det_comparison	--->	tighter ; sameas ; looser.
 
 :- pred compare_determinisms(determinism, determinism, det_comparison).
@@ -128,8 +141,8 @@
 :- import_module code_util, passes_aux.
 :- import_module globals, options.
 
-:- import_module term, varset.
-:- import_module bool, int, map, set, std_util, require, string.
+:- import_module assoc_list, bool, int, map, set, std_util, require, string.
+:- import_module getopt, term, varset.
 
 %-----------------------------------------------------------------------------%
 
@@ -1374,5 +1387,26 @@
 	),
 	io__write_int(Line),
 	det_report_context_lines(Contexts, no).
+
+%-----------------------------------------------------------------------------%
+
+:- type options_to_restore == assoc_list(option, option_data).
+
+disable_det_warnings(OptionsToRestore) -->
+	globals__io_lookup_option(warn_simple_code, WarnSimple),
+	globals__io_lookup_option(warn_det_decls_too_lax,
+		WarnDeclsTooLax),
+	globals__io_set_option(warn_simple_code, bool(no)),
+	globals__io_set_option(warn_det_decls_too_lax, bool(no)),
+	{ OptionsToRestore = [
+		warn_simple_code - WarnSimple,
+		warn_det_decls_too_lax - WarnDeclsTooLax
+	] }.
+
+restore_det_warnings(OptionsToRestore) -->
+	list__foldl(
+	    (pred((Option - Value)::in, di, uo) is det -->
+		globals__io_set_option(Option, Value)
+	    ), OptionsToRestore).
 
 %-----------------------------------------------------------------------------%
--- pd_util.m	2001/08/11 06:27:25	1.1
+++ pd_util.m	2001/08/11 08:41:15
@@ -142,6 +142,7 @@
 :- import_module unused_args, inst_match, (inst), quantification, mode_util.
 :- import_module code_aux, purity, mode_info, unique_modes, pd_debug.
 :- import_module type_util, det_util, det_analysis, options, goal_util.
+:- import_module det_report.
 :- import_module assoc_list, int, require, set, term.
 
 pd_util__goal_get_calls(Goal0, CalledPreds) :-
@@ -353,7 +354,19 @@
 	{ det_info_init(ModuleInfo, VarTypes, PredId, ProcId,
 		Globals, DetInfo) },
 	pd_info_get_instmap(InstMap),
-	{ det_infer_goal(Goal0, InstMap, SolnContext, DetInfo, Goal, _, _) }.
+	{ det_infer_goal(Goal0, InstMap, SolnContext, DetInfo,
+		Goal, _, Msgs) },
+
+	%
+	% Make sure there were no errors.
+	%
+	pd_info_get_io_state(IO0),
+	{ disable_det_warnings(OptionsToRestore, IO0, IO1) },
+	{ det_report_msgs(Msgs, ModuleInfo, _, ErrCnt, IO1, IO2) },
+	{ restore_det_warnings(OptionsToRestore, IO2, IO) },
+	pd_info_set_io_state(IO),
+	{ require(unify(ErrCnt, 0),
+		"pd_util__rerun_det_analysis: determinism errors") }.
 
 %-----------------------------------------------------------------------------%
 
--------------------------------------------------------------------------
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