[m-rev.] for review: make pred names for lambdas unique

Ian MacLarty maclarty at cs.mu.OZ.AU
Wed May 25 14:57:40 AEST 2005


On Tue, 24 May 2005, Zoltan Somogyi wrote:

> On 24-May-2005, Ian MacLarty <maclarty at cs.mu.OZ.AU> wrote:
> > So I propose that I reverse the part of Zoltan's diff that introduced
> > the user friendly predicate names.  Are there any objections to doing
> > this?
>
> Yes; I object.
>

Okay.

Here's the interdiff:

diff -u compiler/hlds_pred.m compiler/hlds_pred.m
--- compiler/hlds_pred.m	23 May 2005 07:19:48 -0000
+++ compiler/hlds_pred.m	25 May 2005 02:34:36 -0000
@@ -709,8 +709,9 @@
 				% The predicate is a higher-order manifest
 				% constant. The arguments specify its location
 				% in the source, as a filename/line number
-				% pair, and an integer that uniquely identifies
-				% it.
+				% pair, and a sequence number used to
+				% distinguish multiple lambdas on the same
+				% line.
 	;	user(sym_name).
 				% The predicate is a normal user-written
 				% predicate; the string is its name.
diff -u compiler/lambda.m compiler/lambda.m
--- compiler/lambda.m	22 May 2005 04:41:30 -0000
+++ compiler/lambda.m	24 May 2005 10:30:41 -0000
@@ -467,11 +467,11 @@
 		list__append(ArgVars, Vars, AllArgVars),

 		module_info_name(ModuleInfo0, ModuleName),
-		module_info_next_lambda_count(LambdaCount,
-			ModuleInfo0, ModuleInfo1),
 		goal_info_get_context(LambdaGoalInfo, OrigContext),
 		term__context_file(OrigContext, OrigFile),
 		term__context_line(OrigContext, OrigLine),
+		module_info_next_lambda_count(OrigContext, LambdaCount,
+			ModuleInfo0, ModuleInfo1),
 		make_pred_name_with_context(ModuleName, "IntroducedFrom",
 			PredOrFunc, OrigPredName, OrigLine,
 			LambdaCount, PredName),
diff -u compiler/layout_out.m compiler/layout_out.m
--- compiler/layout_out.m	23 May 2005 13:07:45 -0000
+++ compiler/layout_out.m	25 May 2005 03:46:15 -0000
@@ -119,10 +119,11 @@
 	output_proc_layout_data_defn(ProcLabel, Traversal, MaybeRest,
 		!DeclSet, !IO).
 output_layout_data_defn(closure_proc_id_data(CallerProcLabel, SeqNo,
-		ProcLabel, ModuleName, FileName, LineNumber, GoalPath),
-		!DeclSet, !IO) :-
+		ProcLabel, ModuleName, FileName, LineNumber, PredOrigin,
+		GoalPath), !DeclSet, !IO) :-
 	output_closure_proc_id_data_defn(CallerProcLabel, SeqNo, ProcLabel,
-		ModuleName, FileName, LineNumber, GoalPath, !DeclSet, !IO).
+		ModuleName, FileName, LineNumber, PredOrigin, GoalPath,
+		!DeclSet, !IO).
 output_layout_data_defn(module_layout_data(ModuleName, StringTableSize,
 		StringTable, ProcLayoutNames, FileLayouts, TraceLevel,
 		SuppressedEvents, NumLabels), !DeclSet, !IO) :-
@@ -170,7 +171,7 @@
 	Kind = maybe_proc_layout_and_more_kind(MaybeRest, ProcLabel),
 	LayoutName = proc_layout(RttiProcLabel, Kind).
 extract_layout_name(closure_proc_id_data(CallerProcLabel, SeqNo,
-		ClosureProcLabel, _, _, _, _),
+		ClosureProcLabel, _, _, _, _, _),
 		closure_proc_id(CallerProcLabel, SeqNo, ClosureProcLabel)).
 extract_layout_name(module_layout_data(ModuleName, _, _, _, _, _, _, _),
 		LayoutName) :-
@@ -1063,17 +1064,17 @@
 %-----------------------------------------------------------------------------%

 :- pred output_closure_proc_id_data_defn(proc_label::in, int::in,
-	proc_label::in, module_name::in, string::in, int::in, string::in,
-	decl_set::in, decl_set::out, io::di, io::uo) is det.
+	proc_label::in, module_name::in, string::in, int::in, pred_origin::in,
+	string::in, decl_set::in, decl_set::out, io::di, io::uo) is det.

 output_closure_proc_id_data_defn(CallerProcLabel, SeqNo, ClosureProcLabel,
-		ModuleName, FileName, LineNumber, GoalPath, !DeclSet, !IO) :-
+		ModuleName, FileName, LineNumber, PredOrigin, GoalPath,
+		!DeclSet, !IO) :-
 	io__write_string("\n", !IO),
 	LayoutName = closure_proc_id(CallerProcLabel, SeqNo, ClosureProcLabel),
 	output_layout_name_storage_type_name(LayoutName, yes, !IO),
 	io__write_string(" = {\n{\n", !IO),
-	output_proc_id(ClosureProcLabel, lambda(FileName, LineNumber, SeqNo),
-		!IO),
+	output_proc_id(ClosureProcLabel, PredOrigin, !IO),
 	io__write_string("},\n", !IO),
 	mdbcomp__prim_data__sym_name_to_string(ModuleName, ModuleNameStr),
 	quote_and_write_string(ModuleNameStr, !IO),
@@ -1137,16 +1138,19 @@

 origin_name(Origin, Name0) = Name :-
 	(
-		Origin = lambda(FileName0, LineNum, UniqueId),
+		Origin = lambda(FileName0, LineNum, SeqNo),
 		( string__append("IntroducedFrom", _, Name0) ->
-			( string__remove_suffix(FileName0, ".m", FileName1) ->
-				FileName2 = FileName1
+			string__replace_all(FileName0, ".", "_", FileName),
+			(
+				SeqNo > 1
+			->
+				string__format("lambda%d_%s_%d",
+					[i(SeqNo), s(FileName), i(LineNum)],
+					Name)
 			;
-				FileName2 = FileName0
-			),
-			string__replace_all(FileName2, ".", "_", FileName),
-			string__format("lambda_%d_%s_%d",
-				[i(UniqueId), s(FileName), i(LineNum)], Name)
+				string__format("lambda_%s_%d",
+					[s(FileName), i(LineNum)], Name)
+			)
 		;
 			% If the lambda pred has a meaningful name, use it.
 			% This happens when the lambda is a partial application
only in patch2:
--- compiler/unify_gen.m	4 May 2005 07:42:42 -0000	1.149
+++ compiler/unify_gen.m	24 May 2005 13:34:58 -0000
@@ -660,10 +660,10 @@
         code_info__get_cur_proc_label(!.CI, CallerProcLabel),
         code_info__get_next_closure_seq_no(SeqNo, !CI),
         code_info__get_static_cell_info(!.CI, StaticCellInfo0),
+        hlds.hlds_pred.pred_info_get_origin(PredInfo, PredOrigin),
         stack_layout__construct_closure_layout(CallerProcLabel,
-            SeqNo, ClosureInfo, ProcLabel, ModuleName,
-            FileName, LineNumber, GoalPathStr,
-            StaticCellInfo0, StaticCellInfo,
+            SeqNo, ClosureInfo, ProcLabel, ModuleName, FileName, LineNumber,
+            PredOrigin, GoalPathStr, StaticCellInfo0, StaticCellInfo,
             ClosureLayoutRvalsTypes, Data),
         code_info__set_static_cell_info(StaticCellInfo, !CI),
         code_info__add_closure_layout(Data, !CI),
only in patch2:
--- compiler/stack_layout.m	12 Apr 2005 01:53:55 -0000	1.102
+++ compiler/stack_layout.m	24 May 2005 13:43:09 -0000
@@ -28,6 +28,7 @@
 :- interface.

 :- import_module hlds__hlds_module.
+:- import_module hlds__hlds_pred.
 :- import_module ll_backend__continuation_info.
 :- import_module ll_backend__global_data.
 :- import_module ll_backend__llds.
@@ -44,9 +45,9 @@

 :- pred stack_layout__construct_closure_layout(proc_label::in, int::in,
 	closure_layout_info::in, proc_label::in, module_name::in,
-	string::in, int::in, string::in,
-	static_cell_info::in, static_cell_info::out,
-	assoc_list(rval, llds_type)::out, comp_gen_c_data::out) is det.
+	string::in, int::in, pred_origin::in, string::in, static_cell_info::in,
+	static_cell_info::out, assoc_list(rval, llds_type)::out,
+	comp_gen_c_data::out) is det.

 	% Construct a representation of a variable location as a 32-bit
 	% integer.
@@ -1241,12 +1242,13 @@

 stack_layout__construct_closure_layout(CallerProcLabel, SeqNo,
 		ClosureLayoutInfo, ClosureProcLabel, ModuleName,
-		FileName, LineNumber, GoalPath, !StaticCellInfo,
+		FileName, LineNumber, Origin, GoalPath, !StaticCellInfo,
 		RvalsTypes, Data) :-
 	DataAddr = layout_addr(
 		closure_proc_id(CallerProcLabel, SeqNo, ClosureProcLabel)),
 	Data = layout_data(closure_proc_id_data(CallerProcLabel, SeqNo,
-		ClosureProcLabel, ModuleName, FileName, LineNumber, GoalPath)),
+		ClosureProcLabel, ModuleName, FileName, LineNumber, Origin,
+		GoalPath)),
 	ProcIdRvalType = const(data_addr_const(DataAddr, no)) - data_ptr,
 	ClosureLayoutInfo = closure_layout_info(ClosureArgs, TVarLocnMap),
 	stack_layout__construct_closure_arg_rvals(ClosureArgs,
only in patch2:
--- compiler/layout.m	31 Mar 2005 04:44:21 -0000	1.19
+++ compiler/layout.m	25 May 2005 02:35:59 -0000
@@ -79,6 +79,7 @@
 			closure_module_name	:: module_name,
 			closure_file_name	:: string,
 			closure_line_number	:: int,
+			closure_origin		:: pred_origin,
 			closure_goal_path	:: string
 		)
 	;	table_io_decl_data(
only in patch2:
--- compiler/hlds_module.m	24 Mar 2005 13:33:32 -0000	1.113
+++ compiler/hlds_module.m	25 May 2005 01:45:41 -0000
@@ -519,10 +519,11 @@

 :- pred module_info_incr_errors(module_info::in, module_info::out) is det.

-	% The module_info stores a counter which is used to number introduced
-	% lambda predicates as __LambdaGoal__1, __LambdaGoal__2, etc.; this
-	% predicate returns the next number and increments the counter.
-:- pred module_info_next_lambda_count(int::out,
+	% The module_info stores a counter which is used to distinguish
+	% lambda predicates which appear on the same line in the same file.
+	% This predicate returns the next number for the given context
+	% and increments the counter for that context.
+:- pred module_info_next_lambda_count(prog_context::in, int::out,
 	module_info::in, module_info::out) is det.

 :- pred module_info_next_model_non_pragma_count(int::out,
@@ -544,9 +545,10 @@

 :- import_module counter.

-:- pred module_info_get_lambda_counter(module_info::in, counter::out) is det.
+:- pred module_info_get_lambdas_per_context(module_info::in,
+	map(prog_context, counter)::out) is det.

-:- pred module_info_set_lambda_counter(counter::in,
+:- pred module_info_set_lambdas_per_context(map(prog_context, counter)::in,
 	module_info::in, module_info::out) is det.

 :- pred module_info_get_model_non_pragma_counter(module_info::in, counter::out)
@@ -623,7 +625,14 @@
 						% module (this includes
 						% opt_imported procedures).

-		lambda_number_counter		:: counter,
+		lambdas_per_context		:: map(prog_context, counter),
+						% How many lambda expressions
+						% there are at different
+						% contexts in the module.
+						% This is used to uniquely
+						% identify lambda expression
+						% that appear on the same
+						% line of the same file.

 		model_non_pragma_counter	:: counter,
 						% Used to ensure uniqueness of
@@ -717,7 +726,7 @@
 	map__init(NoTagTypes),
 	ModuleSubInfo = module_sub(Name, Globals, no, [], [], [], [], no, 0,
 		[], [], StratPreds, UnusedArgInfo, ExceptionInfo,
-		counter__init(1), counter__init(1), ImportedModules,
+		map.init, counter__init(1), ImportedModules,
 		IndirectlyImportedModules, no_aditi_compilation, TypeSpecInfo,
 		NoTagTypes, no, [], init_analysis_info(mmc),
 		[], counter__init(1)),
@@ -790,7 +799,7 @@
 module_info_stratified_preds(MI, MI ^ sub_info ^ must_be_stratified_preds).
 module_info_unused_arg_info(MI, MI ^ sub_info ^ unused_arg_info).
 module_info_exception_info(MI, MI ^ sub_info ^ exception_info).
-module_info_get_lambda_counter(MI, MI ^ sub_info ^ lambda_number_counter).
+module_info_get_lambdas_per_context(MI, MI ^ sub_info ^ lambdas_per_context).
 module_info_get_model_non_pragma_counter(MI,
 	MI ^ sub_info ^ model_non_pragma_counter).
 module_info_get_imported_module_specifiers(MI,
@@ -842,8 +851,8 @@
 	MI ^ sub_info ^ unused_arg_info := NewVal).
 module_info_set_exception_info(NewVal, MI,
 	MI ^ sub_info ^ exception_info := NewVal).
-module_info_set_lambda_counter(NewVal, MI,
-	MI ^ sub_info ^ lambda_number_counter := NewVal).
+module_info_set_lambdas_per_context(NewVal, MI,
+	MI ^ sub_info ^ lambdas_per_context := NewVal).
 module_info_set_model_non_pragma_counter(NewVal, MI,
 	MI ^ sub_info ^ model_non_pragma_counter := NewVal).
 module_add_imported_module_specifiers(ModuleSpecifiers, MI,
@@ -985,10 +994,20 @@
 	Errs = Errs0 + 1,
 	module_info_set_num_errors(Errs, MI0, MI).

-module_info_next_lambda_count(Count, MI0, MI) :-
-	module_info_get_lambda_counter(MI0, Counter0),
-	counter__allocate(Count, Counter0, Counter),
-	module_info_set_lambda_counter(Counter, MI0, MI).
+module_info_next_lambda_count(Context, Count, MI0, MI) :-
+	module_info_get_lambdas_per_context(MI0, ContextCounter0),
+	(
+		map.insert(ContextCounter0, Context, counter.init(2),
+			FoundContextCounter)
+	->
+		Count = 1,
+		ContextCounter = FoundContextCounter
+	;
+		map.lookup(ContextCounter0, Context, Counter0),
+		counter.allocate(Count, Counter0, Counter),
+		map.set(ContextCounter0, Context, Counter, ContextCounter)
+	),
+	module_info_set_lambdas_per_context(ContextCounter, MI0, MI).

 module_info_next_model_non_pragma_count(Count, MI0, MI) :-
 	module_info_get_model_non_pragma_counter(MI0, Counter0),

--- CVSLOG.old	2005-05-25 12:46:49.000000000 +1000
+++ CVSLOG	2005-05-25 14:56:21.000000000 +1000
@@ -1,25 +1,45 @@
-Estimated hours taken: 2
+Estimated hours taken: 4
 Branches: main

-Make the names of predicates introduced by lambda expressions unique.
-This is necessary so they can be distinguished from each other in
-trace count files.
-
-compiler/hlds_out.m:
-	Use lambda/3 instead of lambda/2.
+Make the user friendly names of predicates introduced by lambda expressions
+(more) unique.  This is necessary so they can be distinguished from each other
+in trace count files.
+
+If two or more lambda expression appear in the same context, then include
+their sequence number in that context in the user friendly predicate name.
+
+compiler/hlds_module.m:
+	Instead of keeping a counter of how many lambdas appear in a module,
+	keep a seperate counter for each context (filename/lineno).  This
+	way we only need to include the sequence number in the predicate
+	name if there are two or more lambdas in the same context.

 compiler/hlds_pred.m:
-	If the source of a predicate is a lambda expression, store a
-	unique number which can be used to generate a unique name.
+	Add a new field to the `lambda' functor which records the count of the
+	lambda expressin in its context.
+
+compiler/hlds_out.m:
+	Unify with lambda/3 instead of lambda/2.

 compiler/lambda.m:
-	Use the lambda count as the unique identifier for each lambda
-	expression.
+	Use the sequence number of the lambda expression in its context
+	when creating the predicate origin.
+
+compiler/layout.m:
+	Store the origin of a closure predicate in the layout data of the
+	closure, so that it's user friendly name can be included in the
+	generated C code.

 compiler/layout_out.m:
-	Use the lambda sequence number as the unique identifier for each
-	lambda expression.
-	Use the unique identifier when generating the predicate name.
+	When generating a user friendly name for lambda expression predicates,
+	include the sequence number of the lambda expression if the sequence
+	number is greater than one.
+
+compiler/stack_layout.m:
+	Pass the closure origin to the closure layout construction predicate.
+
+compiler/unify_gen.m:
+	Pass the closure origin when constructing the closure layout.

 tests/debugger/Mmakefile:
 tests/debugger/lambdatest.exp:
@@ -37,4 +57,4 @@
 tests/debugger/declarative/ho2.exp2:
 tests/debugger/declarative/trust.exp:
 tests/hard_coded/deconstruct_arg.exp:
-	Expect the new unique predicate names.
+	Expect the new (more) unique predicate names.

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