[m-rev.] for review: warn about dead procedures

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jul 22 17:48:59 AEST 2003


On 16-Jul-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> This change is not quite right yet; it doesn't handle `pragma type_spec'
> procedures properly yet, and it issues some spurious warnings for
> procedures introduced when expanding lambda expressions in `.opt' files.

I've fixed both of these problems.  Relative diff below.

> Another problem is that it doesn't handle `pragma foreign_proc' clauses
> properly.  Not sure how to fix that one.

Actually this description is a bit imprecise.  `pragma foreign_proc'
clauses work OK if used on their own; the problem comes when mixing
`pragma foreign_proc' clauses and Mercury clauses for the same procedure.
If there is a `pragma foreign_proc' clause for a supported foreign language,
then the Mercury clauses get deleted by make_hlds.m, and so there's no
way for the dead code warning pass to notice which procedures are
referred to from these Mercury clauses.

This is closely related to another problem with mixing `pragma
foreign_proc' and Mercury clauses, which is that we don't do any semantic
analysis (type checking, mode checking, etc.) on such clauses if they're
not used in the current grade.  With warnings about dead code, the symptom
is a bit different -- you get too many diagnostics rather than too few --
but the underlying problem is the same.

I'm not going to try to fix this problem with this diff.
For now, we can just live with the additional spurious warnings.
Because of this problem, I won't enable the --warn-dead-code option
by default.

I will go ahead and commit this once it passes a bootcheck.

--- CHANGES.dead_code.old	Tue Jul 22 17:33:46 2003
+++ CHANGES.dead_code	Tue Jul 22 17:30:58 2003
@@ -22,6 +22,7 @@
 	predicate, specifying whether it should issue warnings or
 	just do the optimizations.  If this argument is warning_pass,
 	issue warnings for dead procedures with import_status local
+	(except for automatically generated procedures)
 	and don't eliminate opt_imported procedures.
 
 compiler/magic.m:
diff -u compiler/dead_proc_elim.m compiler/dead_proc_elim.m
--- compiler/dead_proc_elim.m	16 Jul 2003 10:49:34 -0000
+++ compiler/dead_proc_elim.m	22 Jul 2003 07:25:15 -0000
@@ -593,8 +593,30 @@
 		% must be kept.
 		( Status = local,
 			Keep = no,
-			WarnForThisProc =
-			    (is_unify_or_compare_pred(PredInfo0) -> no ; yes)
+			(
+				% Don't warn for unify or comparison preds,
+				% since they may be automatically generated
+				is_unify_or_compare_pred(PredInfo0)
+			->
+				WarnForThisProc = no
+			;
+				% Don't warn for procedures introduced from
+				% lambda expressions.  The only time those
+				% procedures will be unused is if the procedure
+				% containing the lambda expression is unused,
+				% and in that case, we already warn for that
+				% containing procedure if appropriate.
+				% Likewise, don't warn for procecures
+				% introduced for type specialization.
+				pred_info_name(PredInfo0, PredName),
+				( string__prefix(PredName, "IntroducedFrom__")
+				; string__prefix(PredName, "TypeSpecOf__")
+				)
+			->
+				WarnForThisProc = no
+			;
+				WarnForThisProc = yes
+			)
 		; Status = pseudo_imported,
 			Keep = no,
 			WarnForThisProc = no
diff -u compiler/mercury_compile.m compiler/mercury_compile.m
--- compiler/mercury_compile.m	16 Jul 2003 10:48:44 -0000
+++ compiler/mercury_compile.m	22 Jul 2003 07:30:05 -0000
@@ -2698,17 +2698,27 @@
 		maybe_write_string(Verbose,
 			"% Warning about dead procedures...\n"),
 		maybe_flush_output(Verbose),
-		dead_proc_elim(warning_pass, HLDS0, HLDS1),
+		dead_proc_elim(warning_pass, HLDS0, _HLDS1),
 		maybe_write_string(Verbose, "% done.\n"),
 		maybe_report_stats(Stats),
 
-		globals__io_lookup_bool_option(optimize_dead_procs,
-			OptimizeDead),
-		( { OptimizeDead = yes } ->
-			{ HLDS = HLDS1 }
-		;
-			{ HLDS = HLDS0 }
-		)
+%		XXX The warning pass also does all the work of optimizing
+%		    away the dead procedures.  If we're optimizing, then
+%		    it would be nice if we could keep the HLDS that results.
+%                   However, because this pass gets run before type
+%		    specialization, dead code elimination at this point
+%		    incorrectly optimizes away procedures created for
+%		    `pragma type_spec' declarations.  So we can't use the
+%		    code below.  Instead we need to keep original HLDS.
+%
+%		%%% globals__io_lookup_bool_option(optimize_dead_procs,
+%		%%% 	OptimizeDead),
+%		%%% ( { OptimizeDead = yes } ->
+%		%%% 	{ HLDS = HLDS1 }
+%		%%% ;
+%		%%% 	{ HLDS = HLDS0 }
+%		%%% )
+		{ HLDS = HLDS0 }
 	;
 		{ HLDS = HLDS0 }
 	).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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