[m-rev.] for review: normalize decl_ids in decl_set

Peter Ross pro at missioncriticalit.com
Fri Nov 1 04:13:50 AEDT 2002


On Fri, Nov 01, 2002 at 03:16:56AM +1100, Fergus Henderson wrote:
> On 31-Oct-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> > Avoid a bug where duplicate declarations were not being detected.
> > This prevented the compiler from bootstraping with MSVC in the grade
> > none.gc.tr.debug.
> > 
> > compiler/llds_out.m:
> > 	Normalize the decl_id used to reference the decl_set before
> > 	inserting or looking for the decl_id.
> 
> I think this is attacking the symptom rather than the cause.
> 
> If feasible, it would be better to change the representation of decl_ids
> so that there was no possibility of two different decl_ids referring to
> the same declaration.
> 
> In particular, rather than keeping the varset for rtti_proc_labels,
> it would suffice to just keep the names of the head variables.
> Is that sufficient to make the problem go away?  Or do the two
> references have different names for the head variables?
> 
> Note that the names of the head variables *is* potentially
> significant -- some languages allow overloading on argument names,
> and we might one day want to target such a language.
> Also, even when compiling to C, using consistent names for
> a function's parameters can make the generated code more readable.
> So if the head variables are not being recorded correctly for
> some references, it would be nice to fix that.
> 
How about this?

===================================================================


Estimated hours taken: 7
Branches: main

Avoid a bug where duplicate declarations were not being detected.
This prevented the compiler from bootstraping with MSVC in the grade
none.gc.tr.debug.

compiler/rtti.m:
	Remove the varset from the rtti_proc_label structure.  This is
	because rtti_proc_label is used as part of the key for the
	decl_set structure and sometimes the varset contains all the
	variables in the proc and sometimes only the headvariables
	leading to different keys representing the same declaration.
	Instead record the prog_var and its name together in an
	assoc_list.

compiler/code_util.m:
compiler/ml_code_util.m:
	Hanle the new rtti_proc_label structure.


Index: compiler/code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.138
diff -u -r1.138 code_util.m
--- compiler/code_util.m	30 Jun 2002 17:06:11 -0000	1.138
+++ compiler/code_util.m	31 Oct 2002 17:06:43 -0000
@@ -294,7 +294,7 @@
 code_util__make_proc_label_from_rtti(RttiProcLabel) = ProcLabel :-
 	RttiProcLabel = rtti_proc_label(PredOrFunc, ThisModule,
 		PredModule, PredName, PredArity, ArgTypes, _PredId, ProcId,
-		_VarSet, _HeadVars, _ArgModes, _CodeModel,
+		_HeadVarsWithNames, _ArgModes, _CodeModel,
 		IsImported, _IsPseudoImported, _IsExported,
 		IsSpecialPredInstance),
 	(
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.64
diff -u -r1.64 ml_code_util.m
--- compiler/ml_code_util.m	15 May 2002 08:17:01 -0000	1.64
+++ compiler/ml_code_util.m	31 Oct 2002 17:06:49 -0000
@@ -1140,13 +1140,15 @@
 	% from the module_info, pred_id, and proc_id.
 	%
 ml_gen_proc_params_from_rtti(ModuleInfo, RttiProcId) = FuncParams :-
-	VarSet = RttiProcId^proc_varset,
 	HeadVars = RttiProcId^proc_headvars,
 	ArgTypes = RttiProcId^arg_types,
 	ArgModes = RttiProcId^proc_arg_modes,
 	PredOrFunc = RttiProcId^pred_or_func,
 	CodeModel = RttiProcId^proc_interface_code_model,
-	HeadVarNames = ml_gen_var_names(VarSet, HeadVars),
+	HeadVarNames = list__map((func(Var - Name) = Result :-
+			term__var_to_int(Var, N),
+			Result = mlds__var_name(Name, yes(N))
+		), HeadVars),
 	ml_gen_params_base(ModuleInfo, HeadVarNames, ArgTypes, ArgModes,
 		PredOrFunc, CodeModel, FuncParams, no, _).
 	
@@ -1434,7 +1436,7 @@
 		MLDS_Module) :-
 	RttiProcLabel = rtti_proc_label(PredOrFunc, ThisModule, PredModule,	
 		PredName, PredArity, ArgTypes, PredId, ProcId,
-		_VarSet, _HeadVars, _ArgModes, CodeModel,
+		_HeadVarsWithNames, _ArgModes, CodeModel,
 		IsImported, _IsPseudoImported, _IsExported,
 		IsSpecialPredInstance),
 	(
Index: compiler/rtti.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.21
diff -u -r1.21 rtti.m
--- compiler/rtti.m	27 Oct 2002 03:18:39 -0000	1.21
+++ compiler/rtti.m	31 Oct 2002 17:07:00 -0000
@@ -413,8 +413,8 @@
 			arg_types		::	list(type),
 			pred_id			::	pred_id,
 			proc_id			::	proc_id,
-			proc_varset		::	prog_varset,
-			proc_headvars		::	list(prog_var),
+			proc_headvars		::	list(pair(prog_var,
+								string)),
 			proc_arg_modes		::	list(arg_mode),
 			proc_interface_code_model ::	code_model,
 			%
@@ -620,7 +620,7 @@
 :- import_module ll_backend__code_util.	% for code_util__compiler_generated
 :- import_module ll_backend__llds_out.	% for name_mangle and sym_name_mangle
 
-:- import_module int, string, require.
+:- import_module int, string, require, varset.
 
 rtti_data_to_name(type_ctor_info(TypeCtorData), RttiTypeCtor,
 		type_ctor_info) :-
@@ -731,14 +731,17 @@
 	IsExported = (procedure_is_exported(PredInfo, ProcId) -> yes ; no),
 	IsSpecialPredInstance =
 		(code_util__compiler_generated(PredInfo) -> yes ; no),
+	ProcHeadVarsWithNames = list__map((func(Var) = Var - Name :-
+			Name = varset__lookup_name(ProcVarSet, Var)
+		), ProcHeadVars),
 	ProcLabel = rtti_proc_label(PredOrFunc, ThisModule, PredModule,
 		PredName, Arity, ArgTypes, PredId, ProcId,
-		ProcVarSet, ProcHeadVars, ProcArgModes, ProcCodeModel,
+		ProcHeadVarsWithNames, ProcArgModes, ProcCodeModel,
 		IsImported, IsPseudoImp, IsExported, IsSpecialPredInstance).
 
 rtti__proc_label_pred_proc_id(ProcLabel, PredId, ProcId) :-
 	ProcLabel = rtti_proc_label(_, _, _, _, _, _, PredId, ProcId,
-		_, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _).
 
 rtti__addr_to_string(RttiTypeCtor, RttiName, Str) :-
 	rtti__mangle_rtti_type_ctor(RttiTypeCtor, ModuleName, TypeName, A_str),

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