[m-rev.] work around a bug for --trace-optimized

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Mar 18 10:16:13 AEDT 2002


This is a workaround for a bug that causes a compiler abort if one tries to
compile e.g. browser/sized_pretty.m with --trace deep --trace-optimized.

compiler/inlining.m:
	Disable the inlining of procedures that have typeclass constraints
	when tracing is enabled. If we inline such procedures, the code
	generator can abort when looking for (and not finding) a typeclass_info
	structure involved in the call. Apparently, the inlining of calls to
	such procedures does not preserve typeinfo liveness, which is
	required by tracing.

diff -u -b -r1.104 inlining.m
--- compiler/inlining.m	2001/12/16 08:11:08	1.104
+++ compiler/inlining.m	2002/03/14 03:48:24
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1994-2001 The University of Melbourne.
+% Copyright (C) 1994-2002 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -155,10 +155,10 @@
 :- import_module passes_aux, purity.
 
 % Misc
-:- import_module globals, options.
+:- import_module globals, options, trace_params.
 
 % Standard library modules
-:- import_module int, list, assoc_list, set, std_util, require.
+:- import_module bool, int, list, assoc_list, set, std_util, require.
 :- import_module term, varset.
 
 %-----------------------------------------------------------------------------%
@@ -171,7 +171,8 @@
 			size_threshold			:: int,
 			simple_goal_threshold		:: int,
 			var_threshold			:: int,
-			highlevel_code			:: bool
+			highlevel_code			:: bool,
+			tracing				:: bool
 		).
 
 inlining(ModuleInfo0, ModuleInfo) -->
@@ -197,8 +198,10 @@
 	globals__io_lookup_int_option(inline_simple_threshold, SimpleThreshold),
 	globals__io_lookup_int_option(inline_vars_threshold, VarThreshold),
 	globals__io_lookup_bool_option(highlevel_code, HighLevelCode),
+	globals__io_get_trace_level(TraceLevel),
+	{ Tracing = bool__not(trace_level_is_none(TraceLevel)) },
 	{ Params = params(Simple, SingleUse, CompoundThreshold,
-			SimpleThreshold, VarThreshold, HighLevelCode) },
+		SimpleThreshold, VarThreshold, HighLevelCode, Tracing) },
 
 		%
 		% Get the usage counts for predicates
@@ -264,9 +267,10 @@
 inlining__mark_predproc(PredProcId, NeededMap, Params, ModuleInfo, 
 		InlinedProcs0, InlinedProcs) -->
 	(
-		{ Params = params(Simple, SingleUse, CompoundThreshold,
-				SimpleThreshold, _VarThreshold,
-				_HighLevelCode) },
+		{ Simple = Params ^ simple },
+		{ SingleUse = Params ^ single_use },
+		{ CompoundThreshold = Params ^ size_threshold },
+		{ SimpleThreshold = Params ^ simple_goal_threshold },
 		{ PredProcId = proc(PredId, ProcId) },
 		{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
 		{ pred_info_procedures(PredInfo, Procs) },
@@ -385,6 +389,7 @@
 	---> inline_info(
 		int,			% variable threshold for inlining
 		bool,			% highlevel_code option
+		bool,			% is executing tracing enabled
 		set(pred_proc_id),	% inlined procs
 		module_info,		% module_info
 		list(tvar),		% universally quantified type vars
@@ -420,6 +425,7 @@
 		ModuleInfo0, ModuleInfo, IoState0, IoState) :-
 	VarThresh = Params^var_threshold,
 	HighLevelCode = Params^highlevel_code,
+	Tracing = Params^tracing,
 
 	PredProcId = proc(PredId, ProcId),
 
@@ -442,14 +448,14 @@
 	DetChanged0 = no,
 	PurityChanged0 = no,
 
-	InlineInfo0 = inline_info(VarThresh, HighLevelCode,
+	InlineInfo0 = inline_info(VarThresh, HighLevelCode, Tracing,
 		InlinedProcs, ModuleInfo0, UnivQTVars, Markers,
 		VarSet0, VarTypes0, TypeVarSet0, TypeInfoVarMap0,
 		DidInlining0, Requantify0, DetChanged0, PurityChanged0),
 
 	inlining__inlining_in_goal(Goal0, Goal, InlineInfo0, InlineInfo),
 
-	InlineInfo = inline_info(_, _, _, _, _, _, VarSet, VarTypes,
+	InlineInfo = inline_info(_, _, _, _, _, _, _, VarSet, VarTypes,
 		TypeVarSet, TypeInfoVarMap, DidInlining, Requantify,
 		DetChanged, PurityChanged),
 
@@ -545,7 +551,7 @@
 inlining__inlining_in_goal(call(PredId, ProcId, ArgVars, Builtin, Context,
 		Sym) - GoalInfo0, Goal - GoalInfo, InlineInfo0, InlineInfo) :-
 
-	InlineInfo0 = inline_info(VarThresh, HighLevelCode,
+	InlineInfo0 = inline_info(VarThresh, HighLevelCode, Tracing,
 		InlinedProcs, ModuleInfo, HeadTypeParams, Markers,
 		VarSet0, VarTypes0, TypeVarSet0, TypeInfoVarMap0,
 		DidInlining0, Requantify0, DetChanged0, PurityChanged0),
@@ -553,7 +559,8 @@
 	% should we inline this call?
 	(
 		inlining__should_inline_proc(PredId, ProcId, Builtin,
-			HighLevelCode, InlinedProcs, Markers, ModuleInfo),
+			HighLevelCode, Tracing, InlinedProcs, Markers,
+			ModuleInfo),
 			% okay, but will we exceed the number-of-variables
 			% threshold?
 		varset__vars(VarSet0, ListOfVars),
@@ -617,7 +624,7 @@
 		DetChanged = DetChanged0,
 		PurityChanged = PurityChanged0
 	),
-	InlineInfo = inline_info(VarThresh, HighLevelCode,
+	InlineInfo = inline_info(VarThresh, HighLevelCode, Tracing,
 		InlinedProcs, ModuleInfo, HeadTypeParams, Markers,
 		VarSet, VarTypes, TypeVarSet, TypeInfoVarMap, DidInlining,
 		Requantify, DetChanged, PurityChanged).
@@ -819,17 +826,17 @@
 	% inlining__mark_predproc as having met its heuristic.
 
 :- pred inlining__should_inline_proc(pred_id, proc_id, builtin_state,
-	bool, set(pred_proc_id), pred_markers, module_info).
-:- mode inlining__should_inline_proc(in, in, in, in, in, in, in) is semidet.
+	bool, bool, set(pred_proc_id), pred_markers, module_info).
+:- mode inlining__should_inline_proc(in, in, in, in, in, in, in, in)
+	is semidet.
 
 inlining__should_inline_proc(PredId, ProcId, BuiltinState, HighLevelCode,
-		InlinedProcs, CallingPredMarkers, ModuleInfo) :-
+		Tracing, InlinedProcs, CallingPredMarkers, ModuleInfo) :-
 	InlinePromisedPure = yes,
 	inlining__can_inline_proc(PredId, ProcId, BuiltinState,
-		HighLevelCode, InlinePromisedPure,
+		HighLevelCode, Tracing, InlinePromisedPure,
 		CallingPredMarkers, ModuleInfo),
 
-
 	% OK, we could inline it - but should we?  Apply our heuristic.
 
 	(
@@ -843,16 +850,18 @@
 		CallingPredMarkers, ModuleInfo) :-
 	module_info_globals(ModuleInfo, Globals),
 	globals__lookup_bool_option(Globals, highlevel_code, HighLevelCode), 
+	globals__get_trace_level(Globals, TraceLevel),
+	Tracing = bool__not(trace_level_is_none(TraceLevel)),
 	inlining__can_inline_proc(PredId, ProcId, BuiltinState,
-		HighLevelCode, InlinePromisedPure,
+		HighLevelCode, Tracing, InlinePromisedPure,
 		CallingPredMarkers, ModuleInfo).
 
 :- pred inlining__can_inline_proc(pred_id, proc_id, builtin_state, bool,
-		bool, pred_markers, module_info).
-:- mode inlining__can_inline_proc(in, in, in, in, in, in, in) is semidet.
+	bool, bool, pred_markers, module_info).
+:- mode inlining__can_inline_proc(in, in, in, in, in, in, in, in) is semidet.
 
 inlining__can_inline_proc(PredId, ProcId, BuiltinState, HighLevelCode,
-		InlinePromisedPure, CallingPredMarkers, ModuleInfo) :-
+		Tracing, InlinePromisedPure, CallingPredMarkers, ModuleInfo) :-
 
 	% don't inline builtins, the code generator will handle them
 	BuiltinState = not_builtin,
@@ -891,6 +900,21 @@
 		CalledGoal = foreign_proc(_,_,_,_,_,_,_) - _,
 		proc_info_interface_determinism(ProcInfo, Detism),
 		( Detism = nondet ; Detism = multidet )
+	),
+
+	% If tracing is enabled, then the code generator will need to figure
+	% out the locations of typeinfos inside typeclass_infos. At the moment,
+	% due to a bug, the algorithm for doing this figuring can cause a
+	% compiler abort if we inline calls that have typeclass constraints.
+	(
+		Tracing = yes
+	=>
+		(
+			pred_info_clauses_info(PredInfo, ClausesInfo),
+			TypeClassInfoVarMap = ClausesInfo ^
+				clause_typeclass_info_varmap,
+			map__is_empty(TypeClassInfoVarMap)
+		)
 	),
 
 	% Only inline foreign_code if it is appropriate for
--------------------------------------------------------------------------
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